From e17c164c60cd2b5ac46ade83d94ea9c5fb5fba76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20R=C3=A4tzel?= Date: Sun, 28 Apr 2024 10:53:54 +0000 Subject: [PATCH] Support root directory in `source-directories` in `elm.json` Support apps using the directory containing the `elm.json` file also as a source for Elm module files. Some projects did this using the string "." in the `source-directories` property, but the language server from breaks when using that form. --- implement/Pine.Core/Pine.Core.csproj | 6 +-- implement/pine/Elm019/ElmJsonStructure.cs | 12 +++-- .../compile-elm-program/src/CompileElmApp.elm | 1 + .../tests/CompileElmAppTests.elm | 45 +++++++++++++++++++ implement/pine/Program.cs | 2 +- implement/pine/pine.csproj | 4 +- 6 files changed, 60 insertions(+), 10 deletions(-) diff --git a/implement/Pine.Core/Pine.Core.csproj b/implement/Pine.Core/Pine.Core.csproj index 5e0279c8..4eb28ed3 100644 --- a/implement/Pine.Core/Pine.Core.csproj +++ b/implement/Pine.Core/Pine.Core.csproj @@ -3,13 +3,13 @@ net8.0 enable - 0.3.4 - 0.3.4 + 0.3.5 + 0.3.5 Pine.Core - 0.3.4 + 0.3.5 The cross-platform Elm runtime environment Functional;Elm;Runtime;Compiler;VM;DBMS https://github.com/pine-vm/pine.git diff --git a/implement/pine/Elm019/ElmJsonStructure.cs b/implement/pine/Elm019/ElmJsonStructure.cs index b5251512..99562935 100644 --- a/implement/pine/Elm019/ElmJsonStructure.cs +++ b/implement/pine/Elm019/ElmJsonStructure.cs @@ -16,14 +16,14 @@ public static RelativeDirectory ParseSourceDirectory(string sourceDirectory) { var initialRecord = new RelativeDirectory(ParentLevel: 0, Subdirectories: []); - if (sourceDirectory == ".") - return initialRecord; - sourceDirectory = sourceDirectory.Replace('\\', '/'); sourceDirectory = sourceDirectory.StartsWith("./") ? sourceDirectory[2..] : sourceDirectory; - var segmentsStrings = sourceDirectory.Split('/'); + var segmentsStrings = + sourceDirectory + .Split('/') + .SkipWhile(segment => segment is ""); return segmentsStrings @@ -43,6 +43,10 @@ aggregate with { ParentLevel = aggregate.ParentLevel + 1 }, + + "." => + aggregate, + _ => aggregate with { diff --git a/implement/pine/ElmTime/compile-elm-program/src/CompileElmApp.elm b/implement/pine/ElmTime/compile-elm-program/src/CompileElmApp.elm index eb2f5fa6..b81d553d 100644 --- a/implement/pine/ElmTime/compile-elm-program/src/CompileElmApp.elm +++ b/implement/pine/ElmTime/compile-elm-program/src/CompileElmApp.elm @@ -525,6 +525,7 @@ parseElmJsonSourceDirectoryPath pathInJson = let pathItems = String.split "/" pathInJson + |> List.Extra.dropWhile String.isEmpty in List.foldl (\nextSegment { parentLevel, subdirectories } -> diff --git a/implement/pine/ElmTime/compile-elm-program/tests/CompileElmAppTests.elm b/implement/pine/ElmTime/compile-elm-program/tests/CompileElmAppTests.elm index 7e11c70f..b3805acc 100644 --- a/implement/pine/ElmTime/compile-elm-program/tests/CompileElmAppTests.elm +++ b/implement/pine/ElmTime/compile-elm-program/tests/CompileElmAppTests.elm @@ -1182,6 +1182,51 @@ find_source_directories = } ] } + , { testName = "root as source directory" + , compilationRootFilePath = [ "Main.elm" ] + , sourceFiles = + Dict.fromList + [ ( [ "elm.json" ] + , """ +{ + "type": "application", + "source-directories": [ + "" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} + + """ + ) + ] + , expectedSourceDirectories = + { mainSourceDirectoryPath = [] + , elmJsonDirectoryPath = [] + , secondarySourceDirectories = [] + } + , moduleNameFromFileNameTests = + [ { fileName = [ "Main.elm" ] + , expectedModuleName = Just [ "Main" ] + } + ] + } ] |> List.map (\testCase -> diff --git a/implement/pine/Program.cs b/implement/pine/Program.cs index d1dc2eaf..25080736 100644 --- a/implement/pine/Program.cs +++ b/implement/pine/Program.cs @@ -18,7 +18,7 @@ namespace ElmTime; public class Program { - public static string AppVersionId => "0.3.4"; + public static string AppVersionId => "0.3.5"; private static int AdminInterfaceDefaultPort => 4000; diff --git a/implement/pine/pine.csproj b/implement/pine/pine.csproj index da8d1508..b73356e3 100644 --- a/implement/pine/pine.csproj +++ b/implement/pine/pine.csproj @@ -4,8 +4,8 @@ Exe net8.0 pine - 0.3.4 - 0.3.4 + 0.3.5 + 0.3.5 enable true