From 1dd2f8a267de89ef87bb12e082c32fa26c587d61 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 17 Jan 2020 15:59:56 +0100 Subject: [PATCH 1/7] requires imports to be specified without file extension --- samples/ListClient.mo | 2 +- samples/app/client.mo | 2 +- samples/app/main.mo | 4 +- samples/app/server.mo | 4 +- src/languageServer/completion_test.ml | 6 +-- src/languageServer/source_file_tests.ml | 8 ++-- src/pipeline/resolve_import.ml | 37 +++++++++++++------ src/pipeline/resolve_import.mli | 3 ++ src/pipeline/resolve_import_test.ml | 20 ++++++++++ stdlib/arrayTest.mo | 6 +-- stdlib/assocList.mo | 2 +- stdlib/buf.mo | 6 +-- stdlib/bufTest.mo | 4 +- stdlib/docTable.mo | 4 +- stdlib/examples/actorspec/demo/Demo.mo | 2 +- stdlib/examples/actorspec/src/ActorSpec.mo | 8 ++-- .../examples/produce-exchange/profileActor.mo | 4 +- .../examples/produce-exchange/serverActor.mo | 20 +++++----- .../examples/produce-exchange/serverLang.mo | 4 +- .../examples/produce-exchange/serverModel.mo | 32 ++++++++-------- .../produce-exchange/serverModelTypes.mo | 6 +-- .../produce-exchange/test/evalBulk.mo | 10 ++--- .../test/loadWorkloadAndQueryBig.mo | 8 ++-- .../test/producerRemInventory.mo | 10 ++--- .../test/profileFastCounts.mo | 6 +-- .../test/retailerReserveMany.mo | 10 ++--- .../test/simpleSetupAndQuery.mo | 10 ++--- stdlib/examples/rx/src/Observable.mo | 4 +- stdlib/examples/rx/src/Observer.mo | 2 +- stdlib/examples/rx/src/Rx.mo | 8 ++-- stdlib/examples/rx/test/RxTest.mo | 4 +- stdlib/functionTest.mo | 6 +-- stdlib/hash.mo | 2 +- stdlib/hashMap.mo | 10 ++--- stdlib/hashMapTest.mo | 4 +- stdlib/int.mo | 2 +- stdlib/intTest.mo | 4 +- stdlib/iter.mo | 4 +- stdlib/iterTest.mo | 6 +-- stdlib/list.mo | 4 +- stdlib/listTest.mo | 4 +- stdlib/nat.mo | 4 +- stdlib/natTest.mo | 4 +- stdlib/noneTest.mo | 6 +-- stdlib/option.mo | 2 +- stdlib/optionTest.mo | 4 +- stdlib/result.mo | 4 +- stdlib/text.mo | 2 +- stdlib/textTest.mo | 4 +- stdlib/trie.mo | 12 +++--- stdlib/trieMap.mo | 10 ++--- stdlib/trieMapTest.mo | 4 +- stdlib/trieSet.mo | 4 +- test/compare-wat.sh | 4 +- test/fail/not-static.mo | 2 +- test/fail/ok/self-import.tc.ok | 2 +- test/fail/self-import.mo | 2 +- test/lsp-int-test-project/ListClient.mo | 6 +-- test/lsp-int-test-project/app.mo | 4 +- test/lsp-int-test-project/definitions.mo | 4 +- test/lsp-int-test-project/entrypoint.mo | 2 +- test/lsp-int-test-project/lib/ListFuncs.mo | 2 +- test/lsp-int-test-project/lib/option.mo | 2 +- test/lsp-int/Main.hs | 4 +- test/repl/double-import.sh | 4 +- test/repl/lib/a.mo | 2 +- test/repl/lib/b.mo | 2 +- test/repl/lib/nested.mo | 4 +- test/repl/lib/nested/b.mo | 2 +- test/repl/lib/triangle.mo | 2 +- test/repl/nested-import.sh | 2 +- test/repl/triangle-import.sh | 8 ++-- test/run-drun/test_oneway.mo | 2 +- test/run/import-module.mo | 2 +- test/run/import.mo | 4 +- test/run/pkg-import-absolute.mo | 2 +- test/run/pkg-import-relative.mo | 2 +- 77 files changed, 236 insertions(+), 198 deletions(-) create mode 100644 src/pipeline/resolve_import_test.ml diff --git a/samples/ListClient.mo b/samples/ListClient.mo index 6df35c58472..274eb702adb 100644 --- a/samples/ListClient.mo +++ b/samples/ListClient.mo @@ -1,4 +1,4 @@ -import List = "ListLib.mo"; // private, so we don't re-export List +import List = "ListLib"; // private, so we don't re-export List module { diff --git a/samples/app/client.mo b/samples/app/client.mo index 4de8d62e10a..2b021e8d333 100644 --- a/samples/app/client.mo +++ b/samples/app/client.mo @@ -1,5 +1,5 @@ import Prim "mo:prim"; -import S "server.mo"; +import S "server"; actor class Client() = this { // TODO: these should be constructor params once we can compile them diff --git a/samples/app/main.mo b/samples/app/main.mo index fb06fc323c6..4ca4b1805ca 100644 --- a/samples/app/main.mo +++ b/samples/app/main.mo @@ -1,5 +1,5 @@ -import Server "server.mo"; -import Client "client.mo"; +import Server "server"; +import Client "client"; let server = Server.Server(); let bob = Client.Client(); diff --git a/samples/app/server.mo b/samples/app/server.mo index 787b5e4f121..578ea40fe6c 100644 --- a/samples/app/server.mo +++ b/samples/app/server.mo @@ -1,6 +1,6 @@ import Prim "mo:prim"; -import L "list.mo"; -import T "types.mo"; +import L "list"; +import T "types"; type ClientData = { id : Nat; diff --git a/src/languageServer/completion_test.ml b/src/languageServer/completion_test.ml index bdf654b84ae..793063ca9ad 100644 --- a/src/languageServer/completion_test.ml +++ b/src/languageServer/completion_test.ml @@ -77,7 +77,7 @@ List.| let%test "it handles a full module" = prefix_test_case {|module { - private import List = "./ListLib.mo"; + private import List = "./ListLib"; func singleton(x: T): List.List = List.cons(x, Test.|()); @@ -89,8 +89,8 @@ let%test "it handles a full module" = let%test "it doesn't fall through to the next valid prefix" = prefix_test_case {|module { -private import List = "lib/ListLib.mo"; // private, so we don't re-export List -private import ListFns = "lib/ListFuncs.mo"; // private, so we don't re-export List +private import List = "lib/ListLib"; // private, so we don't re-export List +private import ListFns = "lib/ListFuncs"; // private, so we don't re-export List type Stack = List.List; func push(x : Int, s : Stack) : Stack = List.cons(x, s); func empty():Stack = List.nil(); diff --git a/src/languageServer/source_file_tests.ml b/src/languageServer/source_file_tests.ml index 1cede45b808..4fad8c72b72 100644 --- a/src/languageServer/source_file_tests.ml +++ b/src/languageServer/source_file_tests.ml @@ -67,7 +67,7 @@ let%test "it parses a simple module header" = parse_module_header_test_case "/project" "/project/src/Main.mo" - "import P \"lib/prelude.mo\"" + "import P \"lib/prelude\"" ["P", "src/lib/prelude.mo"] let%test "it parses a simple module header that contains a prim import" = @@ -81,7 +81,7 @@ let%test "it parses a simple module header with package paths" = parse_module_header_test_case "/project" "/project/src/Main.mo" - "import P \"mo:stdlib/prelude.mo\"" + "import P \"mo:stdlib/prelude\"" ["P", "mo:stdlib/prelude.mo"] let%test "it parses a simple module header" = @@ -91,8 +91,8 @@ let%test "it parses a simple module header" = {| module { -private import List "lib/ListLib.mo"; -private import ListFuncs "lib/ListFuncs.mo"; +private import List "lib/ListLib"; +private import ListFuncs "lib/ListFuncs"; type Stack = List.List; diff --git a/src/pipeline/resolve_import.ml b/src/pipeline/resolve_import.ml index a3037419054..17850911fcd 100644 --- a/src/pipeline/resolve_import.ml +++ b/src/pipeline/resolve_import.ml @@ -47,10 +47,12 @@ type package_map = filepath M.t open Syntax open Source -let append_lib_if_needed f = - if Sys.file_exists f && Sys.is_directory f - then Filename.concat f "lib.mo" - else f +let append_extension f = + if Option.is_some (Lib.String.chop_suffix "/" f) + then Some (Filename.concat f "lib.mo") + else if Filename.extension f = "" + then Some (f ^ ".mo") + else None let err_unrecognized_url msgs at url msg = let open Diag in @@ -88,6 +90,15 @@ let err_file_does_not_exist msgs at full_path = text = Printf.sprintf "file \"%s\" does not exist" full_path } +let err_import_musnt_have_extension msgs at full_path = + let open Diag in + add_msg msgs { + sev = Error; + at; + cat = "import"; + text = Printf.sprintf "an import must not have an extension, try importing %s as %s instead" full_path (Filename.chop_extension full_path) + } + let err_package_not_defined msgs at pkg = let open Diag in add_msg msgs { @@ -135,13 +146,17 @@ let err_prim_pkg msgs = } let add_lib_import msgs imported ri_ref at full_path = - let full_path = append_lib_if_needed full_path in - if Sys.file_exists full_path - then begin - ri_ref := LibPath full_path; - imported := RIM.add (LibPath full_path) at !imported - end else - err_file_does_not_exist msgs at full_path + match append_extension full_path with + | Some full_path -> + if Sys.file_exists full_path + then begin + ri_ref := LibPath full_path; + imported := RIM.add (LibPath full_path) at !imported + end else + err_file_does_not_exist msgs at full_path + | None -> + err_import_musnt_have_extension msgs at full_path + let add_idl_import msgs imported ri_ref at full_path bytes = if Sys.file_exists full_path diff --git a/src/pipeline/resolve_import.mli b/src/pipeline/resolve_import.mli index 63368ddfc66..dced43ff983 100644 --- a/src/pipeline/resolve_import.mli +++ b/src/pipeline/resolve_import.mli @@ -21,3 +21,6 @@ type flags = { } val resolve : flags -> Syntax.prog -> filepath -> resolved_imports Diag.result + +(* Exported for tests *) +val append_extension : filepath -> filepath option diff --git a/src/pipeline/resolve_import_test.ml b/src/pipeline/resolve_import_test.ml new file mode 100644 index 00000000000..913d44c9812 --- /dev/null +++ b/src/pipeline/resolve_import_test.ml @@ -0,0 +1,20 @@ +let import_relative_test_case import expected = + let actual = Resolve_import.append_extension import in + let show = function + | None -> "None" + | Some s -> "Some " ^ s in + Option.equal String.equal actual expected || + (Printf.printf + "\nExpected: %s\nActual: %s\n" + (show expected) + (show actual); + false) + +let%test "it resolves a relative file import" = + import_relative_test_case "list" (Some "list") + +let%test "it resolves a relative directory import" = + import_relative_test_case "list/" (Some "list/lib") + +let%test "it fails on a relative import with an extension" = + import_relative_test_case "list" None diff --git a/stdlib/arrayTest.mo b/stdlib/arrayTest.mo index a8775d562fd..e9430c236d8 100644 --- a/stdlib/arrayTest.mo +++ b/stdlib/arrayTest.mo @@ -1,6 +1,6 @@ -import Array "array.mo"; -import Prelude "prelude.mo"; -import Text "text.mo"; +import Array "array"; +import Prelude "prelude"; +import Text "text"; Prelude.printLn("Array"); diff --git a/stdlib/assocList.mo b/stdlib/assocList.mo index 693b595d124..9477308a4ef 100644 --- a/stdlib/assocList.mo +++ b/stdlib/assocList.mo @@ -1,4 +1,4 @@ -import List "list.mo"; +import List "list"; module { /** diff --git a/stdlib/buf.mo b/stdlib/buf.mo index 610bb3af413..31de3a963ec 100644 --- a/stdlib/buf.mo +++ b/stdlib/buf.mo @@ -1,6 +1,6 @@ -import P "prelude.mo"; -import I "iter.mo"; -import A "array.mo"; +import P "prelude"; +import I "iter"; +import A "array"; module { diff --git a/stdlib/bufTest.mo b/stdlib/bufTest.mo index 119b36a3ce3..3da8d300c03 100644 --- a/stdlib/bufTest.mo +++ b/stdlib/bufTest.mo @@ -1,6 +1,6 @@ import Prim "mo:prim"; -import B "buf.mo"; -import I "iter.mo"; +import B "buf"; +import I "iter"; // test repeated growing let a = B.Buf(3); diff --git a/stdlib/docTable.mo b/stdlib/docTable.mo index 99d7e0844f1..0e8b5ca2e97 100644 --- a/stdlib/docTable.mo +++ b/stdlib/docTable.mo @@ -1,6 +1,6 @@ -import Hash "hash.mo"; +import Hash "hash"; -import Trie "trie.mo"; +import Trie "trie"; module { /** diff --git a/stdlib/examples/actorspec/demo/Demo.mo b/stdlib/examples/actorspec/demo/Demo.mo index 4da0be7bccf..154dff6f8e5 100644 --- a/stdlib/examples/actorspec/demo/Demo.mo +++ b/stdlib/examples/actorspec/demo/Demo.mo @@ -1,4 +1,4 @@ -import ActorSpec "../src/ActorSpec.mo"; +import ActorSpec "../src/ActorSpec"; type Group = ActorSpec.Group; diff --git a/stdlib/examples/actorspec/src/ActorSpec.mo b/stdlib/examples/actorspec/src/ActorSpec.mo index 100d9a72ee1..99dd513739c 100644 --- a/stdlib/examples/actorspec/src/ActorSpec.mo +++ b/stdlib/examples/actorspec/src/ActorSpec.mo @@ -1,7 +1,7 @@ -import Debug "../../../debug.mo"; -import Array "../../../array.mo"; -import Int "../../../int.mo"; -import Text "../../../text.mo"; +import Debug "../../../debug"; +import Array "../../../array"; +import Int "../../../int"; +import Text "../../../text"; module { public type Group = { diff --git a/stdlib/examples/produce-exchange/profileActor.mo b/stdlib/examples/produce-exchange/profileActor.mo index 79d5f62486b..39030355df6 100644 --- a/stdlib/examples/produce-exchange/profileActor.mo +++ b/stdlib/examples/produce-exchange/profileActor.mo @@ -1,5 +1,5 @@ -import T = "serverTypes.mo"; -import Model = "serverModel.mo"; +import T = "serverTypes"; +import Model = "serverModel"; actor server { // morally: loadQuery (region_count:Nat, scale_factor:Nat) { diff --git a/stdlib/examples/produce-exchange/serverActor.mo b/stdlib/examples/produce-exchange/serverActor.mo index 8bc814608a8..c2e0b8376ab 100644 --- a/stdlib/examples/produce-exchange/serverActor.mo +++ b/stdlib/examples/produce-exchange/serverActor.mo @@ -4,16 +4,16 @@ -------------------- */ -import Debug "../../debug.mo"; -import P = "../../prelude.mo"; -import Option = "../../option.mo"; -import T = "serverTypes.mo"; -import L = "serverLang.mo"; -import Model = "serverModel.mo"; -import Result = "../../result.mo"; - -import Trie = "../../trie.mo"; -import List = "../../list.mo"; +import Debug "../../debug"; +import P = "../../prelude"; +import Option = "../../option"; +import T = "serverTypes"; +import L = "serverLang"; +import Model = "serverModel"; +import Result = "../../result"; + +import Trie = "../../trie"; +import List = "../../list"; type List = List.List; diff --git a/stdlib/examples/produce-exchange/serverLang.mo b/stdlib/examples/produce-exchange/serverLang.mo index 5ce8f33d1b3..f08a0bc205a 100644 --- a/stdlib/examples/produce-exchange/serverLang.mo +++ b/stdlib/examples/produce-exchange/serverLang.mo @@ -1,5 +1,5 @@ -import Result = "../../result.mo"; -import T = "serverTypes.mo"; +import Result = "../../result"; +import T = "serverTypes"; module { diff --git a/stdlib/examples/produce-exchange/serverModel.mo b/stdlib/examples/produce-exchange/serverModel.mo index 7da988945d6..3cb50d5cb76 100644 --- a/stdlib/examples/produce-exchange/serverModel.mo +++ b/stdlib/examples/produce-exchange/serverModel.mo @@ -1,19 +1,19 @@ -import Debug = "../../debug.mo"; -import P = "../../prelude.mo"; - -import T = "serverTypes.mo"; -import L = "serverLang.mo"; -import M = "serverModelTypes.mo"; - -import List = "../../list.mo"; -import Hash_ = "../../hash.mo"; -import Option = "../../option.mo"; -import Trie = "../../trie.mo"; -import Iter = "../../iter.mo"; -import Array = "../../array.mo"; - -import DT = "../../docTable.mo"; -import Result = "../../result.mo"; +import Debug = "../../debug"; +import P = "../../prelude"; + +import T = "serverTypes"; +import L = "serverLang"; +import M = "serverModelTypes"; + +import List = "../../list"; +import Hash_ = "../../hash"; +import Option = "../../option"; +import Trie = "../../trie"; +import Iter = "../../iter"; +import Array = "../../array"; + +import DT = "../../docTable"; +import Result = "../../result"; module { diff --git a/stdlib/examples/produce-exchange/serverModelTypes.mo b/stdlib/examples/produce-exchange/serverModelTypes.mo index 6352769d368..e0d9c21f8de 100644 --- a/stdlib/examples/produce-exchange/serverModelTypes.mo +++ b/stdlib/examples/produce-exchange/serverModelTypes.mo @@ -1,6 +1,6 @@ -import T = "serverTypes.mo"; -import Trie = "../../trie.mo"; -import DocTable = "../../docTable.mo"; +import T = "serverTypes"; +import Trie = "../../trie"; +import DocTable = "../../docTable"; module { diff --git a/stdlib/examples/produce-exchange/test/evalBulk.mo b/stdlib/examples/produce-exchange/test/evalBulk.mo index 8a8986dd4d0..654f26081ac 100644 --- a/stdlib/examples/produce-exchange/test/evalBulk.mo +++ b/stdlib/examples/produce-exchange/test/evalBulk.mo @@ -1,8 +1,8 @@ -import Debug = "../../../debug.mo"; -import T = "../serverTypes.mo"; -import A = "../serverActor.mo"; -import Result = "../../../result.mo"; -import Option = "../../../option.mo"; +import Debug = "../../../debug"; +import T = "../serverTypes"; +import A = "../serverActor"; +import Result = "../../../result"; +import Option = "../../../option"; func printEntityCount(entname:Text, count:Nat) { Debug.print ("- " # entname # " count: " # debug_show count # "\n"); diff --git a/stdlib/examples/produce-exchange/test/loadWorkloadAndQueryBig.mo b/stdlib/examples/produce-exchange/test/loadWorkloadAndQueryBig.mo index ac60d00a63c..ac3579fe898 100644 --- a/stdlib/examples/produce-exchange/test/loadWorkloadAndQueryBig.mo +++ b/stdlib/examples/produce-exchange/test/loadWorkloadAndQueryBig.mo @@ -1,7 +1,7 @@ -//let T = (import "../serverTypes.mo"); -//let A = (import "../serverActor.mo"); -//let Result = (import "../../../result.mo"); -//let Option = (import "../../../option.mo"); +//let T = (import "../serverTypes"); +//let A = (import "../serverActor"); +//let Result = (import "../../../result"); +//let Option = (import "../../../option"); func scaledParams(region_count_:Nat, factor:Nat) : T.WorkloadParams = shared { region_count = region_count_:Nat; diff --git a/stdlib/examples/produce-exchange/test/producerRemInventory.mo b/stdlib/examples/produce-exchange/test/producerRemInventory.mo index d637b0b3951..82d58c6b486 100644 --- a/stdlib/examples/produce-exchange/test/producerRemInventory.mo +++ b/stdlib/examples/produce-exchange/test/producerRemInventory.mo @@ -1,8 +1,8 @@ -import Debug "../../../debug.mo"; -import T = "../serverTypes.mo"; -import A = "../serverActor.mo"; -import Result = "../../../result.mo"; -import Option = "../../../option.mo"; +import Debug "../../../debug"; +import T = "../serverTypes"; +import A = "../serverActor"; +import Result = "../../../result"; +import Option = "../../../option"; func printEntityCount(entname:Text, count:Nat) { Debug.print ("- " # entname # " count: " # debug_show count # "\n"); diff --git a/stdlib/examples/produce-exchange/test/profileFastCounts.mo b/stdlib/examples/produce-exchange/test/profileFastCounts.mo index 78498b0ac48..70ca29c36fe 100644 --- a/stdlib/examples/produce-exchange/test/profileFastCounts.mo +++ b/stdlib/examples/produce-exchange/test/profileFastCounts.mo @@ -2,9 +2,9 @@ // we correlate these numbers with times that we // measure elsewhere, where these numbers are not available. -import Debug "../../../debug.mo"; -import T = "../serverTypes.mo"; -import Model = "../serverModel.mo"; +import Debug "../../../debug"; +import T = "../serverTypes"; +import Model = "../serverModel"; let m = Model.Model(); diff --git a/stdlib/examples/produce-exchange/test/retailerReserveMany.mo b/stdlib/examples/produce-exchange/test/retailerReserveMany.mo index eff0bdf02d6..c2aeec7b2b2 100644 --- a/stdlib/examples/produce-exchange/test/retailerReserveMany.mo +++ b/stdlib/examples/produce-exchange/test/retailerReserveMany.mo @@ -1,8 +1,8 @@ -import Debug "../../../debug.mo"; -import T = "../serverTypes.mo"; -import A = "../serverActor.mo"; -import Result = "../../../result.mo"; -import Option = "../../../option.mo"; +import Debug "../../../debug"; +import T = "../serverTypes"; +import A = "../serverActor"; +import Result = "../../../result"; +import Option = "../../../option"; func printEntityCount(entname:Text, count:Nat) { Debug.print ("- " # entname # " count: " # debug_show count # "\n"); diff --git a/stdlib/examples/produce-exchange/test/simpleSetupAndQuery.mo b/stdlib/examples/produce-exchange/test/simpleSetupAndQuery.mo index c434db2fef2..76aca9cf9c9 100644 --- a/stdlib/examples/produce-exchange/test/simpleSetupAndQuery.mo +++ b/stdlib/examples/produce-exchange/test/simpleSetupAndQuery.mo @@ -1,8 +1,8 @@ -import Debug "../../../debug.mo"; -import T = "../serverTypes.mo"; -import A = "../serverActor.mo"; -import Result = "../../../result.mo"; -import Option = "../../../option.mo"; +import Debug "../../../debug"; +import T = "../serverTypes"; +import A = "../serverActor"; +import Result = "../../../result"; +import Option = "../../../option"; func printEntityCount(entname:Text, count:Nat) { Debug.print ("- " # entname # " count: " # debug_show count # "\n"); diff --git a/stdlib/examples/rx/src/Observable.mo b/stdlib/examples/rx/src/Observable.mo index 19be16008f9..181dc4e738d 100644 --- a/stdlib/examples/rx/src/Observable.mo +++ b/stdlib/examples/rx/src/Observable.mo @@ -1,5 +1,5 @@ -import Disposable "Disposable.mo"; -import Observer "Observer.mo"; +import Disposable "Disposable"; +import Observer "Observer"; module { type Subscriber = Observer.Type -> Disposable.Type; diff --git a/stdlib/examples/rx/src/Observer.mo b/stdlib/examples/rx/src/Observer.mo index c7e32d8a0d3..3e5fccf6ad6 100644 --- a/stdlib/examples/rx/src/Observer.mo +++ b/stdlib/examples/rx/src/Observer.mo @@ -1,4 +1,4 @@ -import Event "Event.mo"; +import Event "Event"; module { public type EventHandler = Event.Type -> (); diff --git a/stdlib/examples/rx/src/Rx.mo b/stdlib/examples/rx/src/Rx.mo index d5faf0ac9bd..d8971ae0c98 100644 --- a/stdlib/examples/rx/src/Rx.mo +++ b/stdlib/examples/rx/src/Rx.mo @@ -1,7 +1,7 @@ -import DisposableLib = "Disposable.mo"; -import EventLib = "Event.mo"; -import ObservableLib = "Observable.mo"; -import ObserverLib = "Observer.mo"; +import DisposableLib = "Disposable"; +import EventLib = "Event"; +import ObservableLib = "Observable"; +import ObserverLib = "Observer"; module { public let Disposable = DisposableLib; diff --git a/stdlib/examples/rx/test/RxTest.mo b/stdlib/examples/rx/test/RxTest.mo index 69eaf73d630..e288862de5a 100644 --- a/stdlib/examples/rx/test/RxTest.mo +++ b/stdlib/examples/rx/test/RxTest.mo @@ -1,5 +1,5 @@ -import Array "../../../array.mo"; -import Rx "../src/Rx.mo"; +import Array "../../../array"; +import Rx "../src/Rx"; type Error = { description : Text; diff --git a/stdlib/functionTest.mo b/stdlib/functionTest.mo index 37c82fa5918..fb800c5f271 100644 --- a/stdlib/functionTest.mo +++ b/stdlib/functionTest.mo @@ -1,6 +1,6 @@ -import Function "function.mo"; -import Prelude "prelude.mo"; -import Text "text.mo"; +import Function "function"; +import Prelude "prelude"; +import Text "text"; Prelude.printLn("Function"); diff --git a/stdlib/hash.mo b/stdlib/hash.mo index deb6951fd7c..36a1823bee6 100644 --- a/stdlib/hash.mo +++ b/stdlib/hash.mo @@ -1,5 +1,5 @@ import Prim "mo:prim"; -import Iter "iter.mo"; +import Iter "iter"; module { /** diff --git a/stdlib/hashMap.mo b/stdlib/hashMap.mo index 87f509bcac2..613adec9698 100644 --- a/stdlib/hashMap.mo +++ b/stdlib/hashMap.mo @@ -1,9 +1,9 @@ import Prim "mo:prim"; -import P "prelude.mo"; -import A "array.mo"; -import Hash "hash.mo"; -import Iter "iter.mo"; -import AssocList "assocList.mo"; +import P "prelude"; +import A "array"; +import Hash "hash"; +import Iter "iter"; +import AssocList "assocList"; module { diff --git a/stdlib/hashMapTest.mo b/stdlib/hashMapTest.mo index 56c0dc571aa..5fff39f2751 100644 --- a/stdlib/hashMapTest.mo +++ b/stdlib/hashMapTest.mo @@ -1,6 +1,6 @@ import Prim "mo:prim"; -import H "hashMap.mo"; -import Hash "hash.mo"; +import H "hashMap"; +import Hash "hash"; func textIsEq(x:Text,y:Text):Bool { x == y }; diff --git a/stdlib/int.mo b/stdlib/int.mo index 456950d91ca..f7d1dffcec0 100644 --- a/stdlib/int.mo +++ b/stdlib/int.mo @@ -1,5 +1,5 @@ import Prim "mo:prim"; -import Prelude "prelude.mo"; +import Prelude "prelude"; module { public func abs(x : Int) : Nat = Prim.abs x; diff --git a/stdlib/intTest.mo b/stdlib/intTest.mo index 495116948b9..54d3cf6863f 100644 --- a/stdlib/intTest.mo +++ b/stdlib/intTest.mo @@ -1,5 +1,5 @@ -import Prelude "prelude.mo"; -import Int "int.mo"; +import Prelude "prelude"; +import Int "int"; Prelude.printLn("Int"); diff --git a/stdlib/iter.mo b/stdlib/iter.mo index 67b2a335f24..df3fc70bf5b 100644 --- a/stdlib/iter.mo +++ b/stdlib/iter.mo @@ -1,5 +1,5 @@ -import Array "array.mo"; -import List "list.mo"; +import Array "array"; +import List "list"; module { public type Iter = {next : () -> ?T}; diff --git a/stdlib/iterTest.mo b/stdlib/iterTest.mo index 14f6f20c731..ccb0d2ccee2 100644 --- a/stdlib/iterTest.mo +++ b/stdlib/iterTest.mo @@ -1,6 +1,6 @@ -import Iter "iter.mo"; -import List "list.mo"; -import Prelude "prelude.mo"; +import Iter "iter"; +import List "list"; +import Prelude "prelude"; Prelude.printLn("Iter"); diff --git a/stdlib/list.mo b/stdlib/list.mo index 90b156e8182..775512d0158 100644 --- a/stdlib/list.mo +++ b/stdlib/list.mo @@ -1,5 +1,5 @@ -import Array "array.mo"; -import Option "option.mo"; +import Array "array"; +import Option "option"; module { /** diff --git a/stdlib/listTest.mo b/stdlib/listTest.mo index e6e1e21aa11..dcb6d35098c 100644 --- a/stdlib/listTest.mo +++ b/stdlib/listTest.mo @@ -1,5 +1,5 @@ -import List "list.mo"; -import Prelude "prelude.mo"; +import List "list"; +import Prelude "prelude"; type X = Nat; diff --git a/stdlib/nat.mo b/stdlib/nat.mo index 9db8be1e94a..f3709b04d17 100644 --- a/stdlib/nat.mo +++ b/stdlib/nat.mo @@ -1,6 +1,6 @@ import Prim "mo:prim"; -import Int "int.mo"; -import Prelude "prelude.mo"; +import Int "int"; +import Prelude "prelude"; module { public func add(x : Nat, y : Nat) : Nat { diff --git a/stdlib/natTest.mo b/stdlib/natTest.mo index c6a2b7c3b49..67e2373f492 100644 --- a/stdlib/natTest.mo +++ b/stdlib/natTest.mo @@ -1,5 +1,5 @@ -import Prelude "prelude.mo"; -import Nat "nat.mo"; +import Prelude "prelude"; +import Nat "nat"; Prelude.printLn("Nat"); diff --git a/stdlib/noneTest.mo b/stdlib/noneTest.mo index 389d878a5b4..1e3aecfa166 100644 --- a/stdlib/noneTest.mo +++ b/stdlib/noneTest.mo @@ -1,6 +1,6 @@ -import Array "array.mo"; -import None "none.mo"; -import Prelude "prelude.mo"; +import Array "array"; +import None "none"; +import Prelude "prelude"; Prelude.printLn("None"); diff --git a/stdlib/option.mo b/stdlib/option.mo index da0db4424c8..4d271a64514 100644 --- a/stdlib/option.mo +++ b/stdlib/option.mo @@ -1,4 +1,4 @@ -import P "prelude.mo"; +import P "prelude"; module { /** diff --git a/stdlib/optionTest.mo b/stdlib/optionTest.mo index 70f09ced846..9134f5b4b5f 100644 --- a/stdlib/optionTest.mo +++ b/stdlib/optionTest.mo @@ -1,5 +1,5 @@ -import Option "option.mo"; -import Prelude "prelude.mo"; +import Option "option"; +import Prelude "prelude"; Prelude.printLn("Option"); diff --git a/stdlib/result.mo b/stdlib/result.mo index 56e76f71b52..2f7461de9ec 100644 --- a/stdlib/result.mo +++ b/stdlib/result.mo @@ -1,5 +1,5 @@ -import P "prelude.mo"; -import Array "array.mo"; +import P "prelude"; +import Array "array"; module { /** diff --git a/stdlib/text.mo b/stdlib/text.mo index b1e9d82d4ac..e78678500be 100644 --- a/stdlib/text.mo +++ b/stdlib/text.mo @@ -1,4 +1,4 @@ -import Iter "iter.mo"; +import Iter "iter"; module { diff --git a/stdlib/textTest.mo b/stdlib/textTest.mo index af3cdbd46de..aa1b8670253 100644 --- a/stdlib/textTest.mo +++ b/stdlib/textTest.mo @@ -1,5 +1,5 @@ -import Prelude "prelude.mo"; -import Text "text.mo"; +import Prelude "prelude"; +import Text "text"; Prelude.printLn("Text"); diff --git a/stdlib/trie.mo b/stdlib/trie.mo index d0267f7b379..9783e2eb9e8 100644 --- a/stdlib/trie.mo +++ b/stdlib/trie.mo @@ -1,11 +1,11 @@ import Prim "mo:prim"; -import P "prelude.mo"; -import Option "option.mo"; -import H "hash.mo"; -import A "array.mo"; +import P "prelude"; +import Option "option"; +import H "hash"; +import A "array"; -import List "list.mo"; -import AssocList "assocList.mo"; +import List "list"; +import AssocList "assocList"; module { /** diff --git a/stdlib/trieMap.mo b/stdlib/trieMap.mo index f67c6563ed1..71beca9662b 100644 --- a/stdlib/trieMap.mo +++ b/stdlib/trieMap.mo @@ -1,8 +1,8 @@ -import T "trie.mo"; -import P "prelude.mo"; -import I "iter.mo"; -import Hash "hash.mo"; -import List "list.mo"; +import T "trie"; +import P "prelude"; +import I "iter"; +import Hash "hash"; +import List "list"; /** diff --git a/stdlib/trieMapTest.mo b/stdlib/trieMapTest.mo index fd4a1fbb52d..d8bef87ab82 100644 --- a/stdlib/trieMapTest.mo +++ b/stdlib/trieMapTest.mo @@ -1,6 +1,6 @@ import Prim "mo:prim"; -import H "trieMap.mo"; -import Hash "hash.mo"; +import H "trieMap"; +import Hash "hash"; func textIsEq(x:Text,y:Text):Bool { x == y }; diff --git a/stdlib/trieSet.mo b/stdlib/trieSet.mo index 249c0e3800f..1315ea9cc0c 100644 --- a/stdlib/trieSet.mo +++ b/stdlib/trieSet.mo @@ -17,8 +17,8 @@ in the future, we might avoid this via https://dfinity.atlassian.net/browse/AST-32 */ -import Trie "trie.mo"; -import Hash "hash.mo"; +import Trie "trie"; +import Hash "hash"; module { public type Hash = Hash.Hash; diff --git a/test/compare-wat.sh b/test/compare-wat.sh index d4791551085..0fc6fadfb11 100755 --- a/test/compare-wat.sh +++ b/test/compare-wat.sh @@ -28,7 +28,7 @@ function build_ref_to { if [ -z "$1" ] then echo "Building $2 moc from working copy.." - chronic nix-build -E '((import ./..) {}).moc' \ + chronic nix-build -E '((import ./..) {})c' \ --option binary-caches '' \ -o $2-moc/ else @@ -42,7 +42,7 @@ function build_ref_to { let nixpkg = import (../nix/nixpkgs.nix).nixpkgs {}; in let checkout = (builtins.fetchGit {url = path; ref = ref; rev = rev; name = "old-moc";}).outPath; in builtins.trace checkout ( - ((import checkout) {}).moc)' \ + ((import checkout) {})c)' \ --option binary-caches '' \ -o $2-moc/ fi diff --git a/test/fail/not-static.mo b/test/fail/not-static.mo index d6e681668bb..3fd9b4de589 100644 --- a/test/fail/not-static.mo +++ b/test/fail/not-static.mo @@ -1 +1 @@ -import "lib/not-static.mo" +import "lib/not-static" diff --git a/test/fail/ok/self-import.tc.ok b/test/fail/ok/self-import.tc.ok index d51b2ac1b9b..6b826b74e91 100644 --- a/test/fail/ok/self-import.tc.ok +++ b/test/fail/ok/self-import.tc.ok @@ -1 +1 @@ -self-import.mo:1.1-1.24: import error, file self-import.mo must not depend on itself +self-import.mo:1.1-1.21: import error, file self-import.mo must not depend on itself diff --git a/test/fail/self-import.mo b/test/fail/self-import.mo index 2dbe7b954c5..b766dfeb263 100644 --- a/test/fail/self-import.mo +++ b/test/fail/self-import.mo @@ -1 +1 @@ -import "self-import.mo"; +import "self-import"; diff --git a/test/lsp-int-test-project/ListClient.mo b/test/lsp-int-test-project/ListClient.mo index cfc3026321d..5af4fd5991b 100644 --- a/test/lsp-int-test-project/ListClient.mo +++ b/test/lsp-int-test-project/ListClient.mo @@ -1,7 +1,7 @@ import Prim "mo:prim"; -import List "lib/list.mo"; -import Option "lib/option.mo"; -import P "lib/prelude.mo"; +import List "lib/list"; +import Option "lib/option"; +import P "lib/prelude"; module { public type Stack = List.List; diff --git a/test/lsp-int-test-project/app.mo b/test/lsp-int-test-project/app.mo index cd3673b4255..b14c821611f 100644 --- a/test/lsp-int-test-project/app.mo +++ b/test/lsp-int-test-project/app.mo @@ -1,6 +1,6 @@ -import Stack "ListClient.mo"; +import Stack "ListClient"; import Prim "mo:prim"; -import Entry "entrypoint.mo"; +import Entry "entrypoint"; actor { func main(): () { diff --git a/test/lsp-int-test-project/definitions.mo b/test/lsp-int-test-project/definitions.mo index ee38e119ac0..5a896306d38 100644 --- a/test/lsp-int-test-project/definitions.mo +++ b/test/lsp-int-test-project/definitions.mo @@ -1,5 +1,5 @@ -import MyDependency "mo:mydep/lib.mo"; -import List "lib/list.mo"; +import MyDependency "mo:mydep/lib"; +import List "lib/list"; module { public func myFunc() { diff --git a/test/lsp-int-test-project/entrypoint.mo b/test/lsp-int-test-project/entrypoint.mo index fd395f7c5f0..b57b68665e2 100644 --- a/test/lsp-int-test-project/entrypoint.mo +++ b/test/lsp-int-test-project/entrypoint.mo @@ -1,3 +1,3 @@ -import Definitions "definitions.mo"; +import Definitions "definitions"; module {} diff --git a/test/lsp-int-test-project/lib/ListFuncs.mo b/test/lsp-int-test-project/lib/ListFuncs.mo index e25064736d8..4d3907382a4 100644 --- a/test/lsp-int-test-project/lib/ListFuncs.mo +++ b/test/lsp-int-test-project/lib/ListFuncs.mo @@ -1,4 +1,4 @@ -import List = "./ListLib.mo"; +import List = "./ListLib"; module { public func singleton(x: T): List.List = diff --git a/test/lsp-int-test-project/lib/option.mo b/test/lsp-int-test-project/lib/option.mo index a4ad45219e6..df93548d50f 100644 --- a/test/lsp-int-test-project/lib/option.mo +++ b/test/lsp-int-test-project/lib/option.mo @@ -1,5 +1,5 @@ import Prim "mo:prim"; -import P "prelude.mo"; +import P "prelude"; module { /** diff --git a/test/lsp-int/Main.hs b/test/lsp-int/Main.hs index 7a3fc05c838..f6e7202c552 100644 --- a/test/lsp-int/Main.hs +++ b/test/lsp-int/Main.hs @@ -218,7 +218,7 @@ main = do withDoc "app.mo" \doc -> do -- It knows how to handle package paths for rebuilding, and also -- for completions - let edit = TextEdit (Range (Position 4 0) (Position 4 0)) "\nimport MyDep \"mo:mydep/broken.mo\"" + let edit = TextEdit (Range (Position 4 0) (Position 4 0)) "\nimport MyDep \"mo:mydep/broken\"" _ <- applyEdit doc edit sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc) [diag] <- waitForActualDiagnostics @@ -227,7 +227,7 @@ main = do log "Completions from package paths" withDoc "app.mo" \doc -> do -- Imports the non-broken dependency module - let edit = TextEdit (Range (Position 4 0) (Position 4 0)) "\nimport MyDep \"mo:mydep/lib.mo\"" + let edit = TextEdit (Range (Position 4 0) (Position 4 0)) "\nimport MyDep \"mo:mydep/lib\"" _ <- applyEdit doc edit sendNotification TextDocumentDidSave (DidSaveTextDocumentParams doc) let edit2 = TextEdit (Range (Position 5 0) (Position 5 0)) "\nMyDep." diff --git a/test/repl/double-import.sh b/test/repl/double-import.sh index 052db3fb5cf..befabcdb33e 100755 --- a/test/repl/double-import.sh +++ b/test/repl/double-import.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash ${MOC:-$(dirname "$BASH_SOURCE")/../../src/moc} -v -i <<__END__ -import "lib/empty.mo"; -import "lib/empty.mo"; +import "lib/empty"; +import "lib/empty"; __END__ diff --git a/test/repl/lib/a.mo b/test/repl/lib/a.mo index 7aa0183b2a5..50451bf6f3d 100644 --- a/test/repl/lib/a.mo +++ b/test/repl/lib/a.mo @@ -1,3 +1,3 @@ -import C "c.mo"; +import C "c"; let i = C.i; diff --git a/test/repl/lib/b.mo b/test/repl/lib/b.mo index b07786fc5c0..0fc4ef4834a 100644 --- a/test/repl/lib/b.mo +++ b/test/repl/lib/b.mo @@ -1,2 +1,2 @@ -import C "c.mo"; +import C "c"; let i = C.i; diff --git a/test/repl/lib/nested.mo b/test/repl/lib/nested.mo index 16a66c3d2f6..fa3d7e178aa 100644 --- a/test/repl/lib/nested.mo +++ b/test/repl/lib/nested.mo @@ -1,4 +1,4 @@ -import A "nested/a.mo"; -import "nested/b.mo"; +import A "nested/a"; +import "nested/b"; let i = A.i; diff --git a/test/repl/lib/nested/b.mo b/test/repl/lib/nested/b.mo index 81829339bc9..7816afc1816 100644 --- a/test/repl/lib/nested/b.mo +++ b/test/repl/lib/nested/b.mo @@ -1,4 +1,4 @@ -import A "./a.mo"; +import A "./a"; module { public let i = A.i } diff --git a/test/repl/lib/triangle.mo b/test/repl/lib/triangle.mo index b5f67a31883..4c80e9772cf 100644 --- a/test/repl/lib/triangle.mo +++ b/test/repl/lib/triangle.mo @@ -1 +1 @@ -import "a.mo" +import "a" diff --git a/test/repl/nested-import.sh b/test/repl/nested-import.sh index 4400a0a52b5..2aa139ee092 100755 --- a/test/repl/nested-import.sh +++ b/test/repl/nested-import.sh @@ -1,4 +1,4 @@ #!/bin/bash ${MOC:-$(dirname "$BASH_SOURCE")/../../src/moc} -v -i <<__END__ | grep Parsing -import "lib/nested.mo"; +import "lib/nested"; __END__ diff --git a/test/repl/triangle-import.sh b/test/repl/triangle-import.sh index 6890ac4f8b4..adbbe1fa91f 100755 --- a/test/repl/triangle-import.sh +++ b/test/repl/triangle-import.sh @@ -1,7 +1,7 @@ #!/bin/bash ${MOC:-$(dirname "$BASH_SOURCE")/../../src/moc} -v -i <<__END__ -import "lib/b.mo"; -import "lib/a.mo"; -import "lib/c.mo"; -import "lib/triangle.mo"; +import "lib/b"; +import "lib/a"; +import "lib/c"; +import "lib/triangle"; __END__ diff --git a/test/run-drun/test_oneway.mo b/test/run-drun/test_oneway.mo index 0ff6ddfc072..cc4b4f2e8fe 100644 --- a/test/run-drun/test_oneway.mo +++ b/test/run-drun/test_oneway.mo @@ -1,3 +1,3 @@ -import M "oneway.mo"; +import M "oneway"; //SKIP comp diff --git a/test/run/import-module.mo b/test/run/import-module.mo index d6faf86caab..9ab3d3e18bf 100644 --- a/test/run/import-module.mo +++ b/test/run/import-module.mo @@ -1,3 +1,3 @@ -import L = "lib/ListM.mo"; +import L = "lib/ListM"; type stack = L.List; let s = L.cons(1, L.nil()); diff --git a/test/run/import.mo b/test/run/import.mo index 6967a661ef8..ea75b7f4c99 100644 --- a/test/run/import.mo +++ b/test/run/import.mo @@ -1,5 +1,5 @@ -import A "lib/hello-string.mo"; -import B "lib/dir"; +import A "lib/hello-string"; +import B "lib/dir/"; assert (A.hello == "Hello!"); assert (B.hello == "Hello!"); diff --git a/test/run/pkg-import-absolute.mo b/test/run/pkg-import-absolute.mo index 1f5ba383e1f..37b0098a779 100644 --- a/test/run/pkg-import-absolute.mo +++ b/test/run/pkg-import-absolute.mo @@ -1,6 +1,6 @@ //MOC-FLAG --package pkg "$(realpath lib/pkg)" import P1 "mo:pkg"; -import P2 "mo:pkg/other-module.mo"; +import P2 "mo:pkg/other-module"; P1.foo(); P2.bar(); diff --git a/test/run/pkg-import-relative.mo b/test/run/pkg-import-relative.mo index f2a52b4a99c..00368c86654 100644 --- a/test/run/pkg-import-relative.mo +++ b/test/run/pkg-import-relative.mo @@ -1,5 +1,5 @@ //MOC-FLAG --package pkg lib/pkg import P1 "mo:pkg"; -import P2 "mo:pkg/other-module.mo"; +import P2 "mo:pkg/other-module"; P1.foo(); P2.bar(); From 6fa2470d5dcea7914d7e0b435b1784f1950bec09 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 17 Jan 2020 16:23:56 +0100 Subject: [PATCH 2/7] fixes print-deps tests --- design/DFX-Interface.md | 1 + test/repl/ok/print-deps.stdout.ok | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/design/DFX-Interface.md b/design/DFX-Interface.md index cb899a61a40..b139adf11b0 100644 --- a/design/DFX-Interface.md +++ b/design/DFX-Interface.md @@ -138,6 +138,7 @@ prints to the standard output all URLs _directly_ imported by mo:other_package/Some/Module ic:ABCDE01A7 ic:alias + relative/path This _reads_ only `some/path/input.mo`, and writes no files. diff --git a/test/repl/ok/print-deps.stdout.ok b/test/repl/ok/print-deps.stdout.ok index a98fe175b79..b8c4099a282 100644 --- a/test/repl/ok/print-deps.stdout.ok +++ b/test/repl/ok/print-deps.stdout.ok @@ -1,4 +1,4 @@ -nested/a.mo -nested/b.mo +nested/a +nested/b ic:ABCDE01A7 ic:alias From f7be367b1e47fe0f253b0effd649547445e31493 Mon Sep 17 00:00:00 2001 From: Christoph Date: Fri, 17 Jan 2020 16:58:30 +0100 Subject: [PATCH 3/7] fixes tests that got caught up in the regex replace --- src/languageServer/source_file_tests.ml | 8 ++++---- src/pipeline/resolve_import_test.ml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/languageServer/source_file_tests.ml b/src/languageServer/source_file_tests.ml index 4fad8c72b72..f304440d8b6 100644 --- a/src/languageServer/source_file_tests.ml +++ b/src/languageServer/source_file_tests.ml @@ -68,7 +68,7 @@ let%test "it parses a simple module header" = "/project" "/project/src/Main.mo" "import P \"lib/prelude\"" - ["P", "src/lib/prelude.mo"] + ["P", "src/lib/prelude"] let%test "it parses a simple module header that contains a prim import" = parse_module_header_test_case @@ -82,7 +82,7 @@ let%test "it parses a simple module header with package paths" = "/project" "/project/src/Main.mo" "import P \"mo:stdlib/prelude\"" - ["P", "mo:stdlib/prelude.mo"] + ["P", "mo:stdlib/prelude"] let%test "it parses a simple module header" = parse_module_header_test_case @@ -106,6 +106,6 @@ func singleton(x: Int): Stack = ListFuncs.doubleton(x, x); } |} - [ ("List", "lib/ListLib.mo") - ; ("ListFuncs", "lib/ListFuncs.mo") + [ ("List", "lib/ListLib") + ; ("ListFuncs", "lib/ListFuncs") ] diff --git a/src/pipeline/resolve_import_test.ml b/src/pipeline/resolve_import_test.ml index 913d44c9812..567737dcd4e 100644 --- a/src/pipeline/resolve_import_test.ml +++ b/src/pipeline/resolve_import_test.ml @@ -11,10 +11,10 @@ let import_relative_test_case import expected = false) let%test "it resolves a relative file import" = - import_relative_test_case "list" (Some "list") + import_relative_test_case "list" (Some "list.mo") let%test "it resolves a relative directory import" = - import_relative_test_case "list/" (Some "list/lib") + import_relative_test_case "list/" (Some "list/lib.mo") let%test "it fails on a relative import with an extension" = - import_relative_test_case "list" None + import_relative_test_case "list.mo" None From 85d77020f2038b02aec51c5102b68122a9bfd555 Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 20 Jan 2020 11:39:41 +0100 Subject: [PATCH 4/7] don't require trailing slash for dir imports --- src/pipeline/resolve_import.ml | 18 +++++++++++------- src/pipeline/resolve_import.mli | 2 +- src/pipeline/resolve_import_test.ml | 15 ++++++++++----- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/pipeline/resolve_import.ml b/src/pipeline/resolve_import.ml index 17850911fcd..6f44d762943 100644 --- a/src/pipeline/resolve_import.ml +++ b/src/pipeline/resolve_import.ml @@ -47,12 +47,16 @@ type package_map = filepath M.t open Syntax open Source -let append_extension f = - if Option.is_some (Lib.String.chop_suffix "/" f) - then Some (Filename.concat f "lib.mo") - else if Filename.extension f = "" - then Some (f ^ ".mo") - else None +let append_extension file_exists f = + if Option.is_some (Lib.String.chop_suffix "/" f) then + Some (Filename.concat f "lib.mo") + else if Filename.extension f = "" then + if file_exists (f ^ ".mo") then + Some (f ^ ".mo") + else + Some (Filename.concat f "lib.mo") + else + None let err_unrecognized_url msgs at url msg = let open Diag in @@ -146,7 +150,7 @@ let err_prim_pkg msgs = } let add_lib_import msgs imported ri_ref at full_path = - match append_extension full_path with + match append_extension Sys.file_exists full_path with | Some full_path -> if Sys.file_exists full_path then begin diff --git a/src/pipeline/resolve_import.mli b/src/pipeline/resolve_import.mli index dced43ff983..0fbe1bc7427 100644 --- a/src/pipeline/resolve_import.mli +++ b/src/pipeline/resolve_import.mli @@ -23,4 +23,4 @@ type flags = { val resolve : flags -> Syntax.prog -> filepath -> resolved_imports Diag.result (* Exported for tests *) -val append_extension : filepath -> filepath option +val append_extension : (filepath -> bool) -> filepath -> filepath option diff --git a/src/pipeline/resolve_import_test.ml b/src/pipeline/resolve_import_test.ml index 567737dcd4e..5b93e9f8ca4 100644 --- a/src/pipeline/resolve_import_test.ml +++ b/src/pipeline/resolve_import_test.ml @@ -1,5 +1,7 @@ -let import_relative_test_case import expected = - let actual = Resolve_import.append_extension import in +(** Given a list of filenames that should be reported as existing + tests what a given import path resolves to *) +let import_relative_test_case files import expected = + let actual = Resolve_import.append_extension (fun x -> List.mem x files) import in let show = function | None -> "None" | Some s -> "Some " ^ s in @@ -11,10 +13,13 @@ let import_relative_test_case import expected = false) let%test "it resolves a relative file import" = - import_relative_test_case "list" (Some "list.mo") + import_relative_test_case ["list.mo"] "list" (Some "list.mo") let%test "it resolves a relative directory import" = - import_relative_test_case "list/" (Some "list/lib.mo") + import_relative_test_case [] "list/" (Some "list/lib.mo") + +let%test "it resolves to a relative directory import if no .mo file is found" = + import_relative_test_case [] "list" (Some "list/lib.mo") let%test "it fails on a relative import with an extension" = - import_relative_test_case "list.mo" None + import_relative_test_case [] "list.mo" None From 0c843b3888c66b89ac1407c437d0cfdda3fe2a4d Mon Sep 17 00:00:00 2001 From: Christoph Date: Mon, 20 Jan 2020 11:54:47 +0100 Subject: [PATCH 5/7] reverts accidental modification --- test/compare-wat.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/compare-wat.sh b/test/compare-wat.sh index 8a5f37c3c3f..6c7692f989b 100755 --- a/test/compare-wat.sh +++ b/test/compare-wat.sh @@ -28,7 +28,7 @@ function build_ref_to { if [ -z "$1" ] then echo "Building $2 moc from working copy.." - chronic nix-build -E '((import ./..) {})c' \ + chronic nix-build -E '((import ./..) {}).moc' \ --option binary-caches '' \ -o $2-moc/ else @@ -42,7 +42,7 @@ function build_ref_to { let nixpkg = import ../nix {}; in let checkout = (builtins.fetchGit {url = path; ref = ref; rev = rev; name = "old-moc";}).outPath; in builtins.trace checkout ( - ((import checkout) {})c)' \ + ((import checkout) {}).moc)' \ --option binary-caches '' \ -o $2-moc/ fi From 2fbd63533b144dcb5741a4e775d4f14b19d0f9f9 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 22 Jan 2020 14:35:09 +0100 Subject: [PATCH 6/7] Makes the IDE use the same extension resolution as pipeline --- src/languageServer/completion.ml | 4 ++-- src/languageServer/declaration_index.ml | 20 ++++++++++++++++---- src/languageServer/declaration_index.mli | 2 +- src/languageServer/definition.ml | 11 +++++++---- src/languageServer/hover.ml | 4 ++-- src/languageServer/source_file.ml | 6 +++++- 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/languageServer/completion.ml b/src/languageServer/completion.ml index f30cf6175d3..76dc967fab8 100644 --- a/src/languageServer/completion.ml +++ b/src/languageServer/completion.ml @@ -134,7 +134,7 @@ let completions index logger project_root file_path file_contents line column = let current_module_decls = current_uri_opt |> opt_bind (fun uri -> DI.lookup_module uri index) - |> Fun.flip Lib.Option.get [] in + |> Option.fold ~none:[] ~some:snd in current_module_decls in let module_alias_completion_item alias = @@ -165,7 +165,7 @@ let completions index logger project_root file_path file_contents line column = match module_path with | Some mp -> (match DI.lookup_module (snd mp) index with - | Some decls -> + | Some (_, decls) -> decls |> List.filter (has_prefix prefix) |> List.map item_of_ide_decl diff --git a/src/languageServer/declaration_index.ml b/src/languageServer/declaration_index.ml index 6a43e549e18..f525f0242ed 100644 --- a/src/languageServer/declaration_index.ml +++ b/src/languageServer/declaration_index.ml @@ -65,20 +65,32 @@ let add_module : string -> ide_decl list -> declaration_index -> declaration_ind let lookup_module (path : string) (index : t) - : ide_decl list option = + : (string * ide_decl list) option = let open Pipeline.URL in let make_absolute = Lib.FilePath.make_absolute (Sys.getcwd ()) in match parse path with | Ok (Relative path) -> + let path = + Pipeline.ResolveImport.append_extension Sys.file_exists path + |> Option.value ~default:path in Index.find_opt (make_absolute path) index.modules + |> Option.map (fun decls -> (path, decls)) | Ok (Package (pkg, path)) -> Option.bind (Flags.M.find_opt pkg index.package_map) (fun pkg_path -> + let path = + Pipeline.ResolveImport.append_extension + Sys.file_exists (Filename.concat pkg_path path) + |> Option.value ~default:path in Index.find_opt - (make_absolute (Filename.concat pkg_path path)) - index.modules) - | Ok Prim -> Index.find_opt "@prim" index.modules + (make_absolute path) + index.modules + |> Option.map (fun decls -> (path, decls)) + ) + | Ok Prim -> + Index.find_opt "@prim" index.modules + |> Option.map (fun decls -> ("@prim", decls)) | Ok (Ic _ | IcAlias _) -> (* TODO *) None | Error _ -> None diff --git a/src/languageServer/declaration_index.mli b/src/languageServer/declaration_index.mli index 46d0ffc3868..3da4650704f 100644 --- a/src/languageServer/declaration_index.mli +++ b/src/languageServer/declaration_index.mli @@ -24,6 +24,6 @@ type ide_decl = val string_of_ide_decl : ide_decl -> string val name_of_ide_decl : ide_decl -> string -val lookup_module : string -> t -> ide_decl list option +val lookup_module : string -> t -> (string * ide_decl list) option val make_index : (string -> string -> unit) -> Vfs.t -> string list -> t Diag.result diff --git a/src/languageServer/definition.ml b/src/languageServer/definition.ml index c736d5c02b4..717d5f7b4c5 100644 --- a/src/languageServer/definition.ml +++ b/src/languageServer/definition.ml @@ -12,7 +12,11 @@ let range_of_region (at : Source.region) : Lsp.range = Lsp. range_end_ = position_of_pos at.Source.right; } -let find_named (name : string) : DI.ide_decl list -> Source.region option = +let find_named + : string -> + (string * DI.ide_decl list) -> + (string * Source.region) option = + fun name (path, decls) -> Lib.List.first_opt (function | DI.ValueDecl value -> if String.equal value.DI.name name @@ -21,7 +25,8 @@ let find_named (name : string) : DI.ide_decl list -> Source.region option = | DI.TypeDecl typ -> if String.equal typ.DI.name name then typ.DI.definition - else None) + else None) decls + |> Option.map (fun x -> (path, x)) let opt_bind f = function | Some x -> f x @@ -47,13 +52,11 @@ let definition_handler | Resolved resolved -> DI.lookup_module resolved.path index |> opt_bind (find_named resolved.ident) - |> Option.map (fun loc -> (resolved.path, loc)) | Ident ident -> Lib.FilePath.relative_to project_root file_path |> opt_bind (fun uri -> DI.lookup_module uri index |> opt_bind (find_named ident) - |> Option.map (fun loc -> (uri, loc)) )) in let location = Option.map (fun (path, region) -> diff --git a/src/languageServer/hover.ml b/src/languageServer/hover.ml index 2cbc9f2be2d..8723fa034c7 100644 --- a/src/languageServer/hover.ml +++ b/src/languageServer/hover.ml @@ -26,7 +26,7 @@ let hover_handler let current_module_decls = current_uri_opt |> Fun.flip Option.bind (fun uri -> lookup_module uri index) - |> Fun.flip Lib.Option.get [] in + |> Option.fold ~none:[] ~some:snd in current_module_decls in let mk_hover_result ide_decl = Lsp.{ hover_result_contents = markup_content (hover_detail ide_decl) } in @@ -42,7 +42,7 @@ let hover_handler Some Lsp.{ hover_result_contents = markup_content path } | Source_file.Resolved resolved -> lookup_module resolved.Source_file.path index - |> Fun.flip Option.bind (fun decls -> + |> Fun.flip Option.bind (fun (_, decls) -> List.find_opt (fun d -> name_of_ide_decl d = resolved.Source_file.ident) decls) diff --git a/src/languageServer/source_file.ml b/src/languageServer/source_file.ml index 299bb5658a3..4f11ea379d4 100644 --- a/src/languageServer/source_file.ml +++ b/src/languageServer/source_file.ml @@ -6,6 +6,10 @@ type cursor_target = | CIdent of string | CQualified of string * string +let string_of_cursor_target = function + | CIdent i -> "(CIdent " ^ i ^ ")" + | CQualified (q, i) -> "CQUalified (" ^ q ^ ", " ^ i ^ ")" + let cursor_target_at_pos (position : Lsp.position) (file_contents : string) @@ -118,7 +122,7 @@ let identifier_at_pos project_root file_path file_contents position = file_path file_contents in cursor_target_at_pos position file_contents - |> Option.map (function + |> Option.map (function | CIdent s -> (match List.find_opt (fun (alias, _) -> alias = s) imported with | None -> Ident s From 527bbb4e2e00129e4d763b5e0e777fe260254c65 Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 22 Jan 2020 14:44:35 +0100 Subject: [PATCH 7/7] fixes more `.mo` import leftovers --- stdlib/src/principalId.mo | 2 +- stdlib/test/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/src/principalId.mo b/stdlib/src/principalId.mo index 3fd298abb29..e54d2dfdc80 100644 --- a/stdlib/src/principalId.mo +++ b/stdlib/src/principalId.mo @@ -1,5 +1,5 @@ import Prim "mo:prim"; -import Blob "blob.mo"; +import Blob "blob"; module { public func hash(x : Principal) : Word32 = Blob.hash (Prim.blobOfPrincipal x); } diff --git a/stdlib/test/Makefile b/stdlib/test/Makefile index df698fc5de5..2dd01c71a0d 100644 --- a/stdlib/test/Makefile +++ b/stdlib/test/Makefile @@ -18,7 +18,7 @@ $(OUTDIR): $(OUTDIR)/import_all.mo: $(STDLIB_FILES) | $(OUTDIR) > $@ for f in $(patsubst $(STDLIB)/%.mo,%,$(STDLIB_FILES)); do \ - echo "import Import_$$f \"mo:stdlib/$$f.mo\";" >> $@; \ + echo "import Import_$$f \"mo:stdlib/$$f\";" >> $@; \ done $(OUTDIR)/%.wasm: %.mo | $(OUTDIR)