Skip to content

Commit

Permalink
Support root directory in source-directories in elm.json
Browse files Browse the repository at this point in the history
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 <https://github.com/elm-tooling/elm-language-server> breaks when using that form.
  • Loading branch information
Viir committed Apr 28, 2024
1 parent 2b26f0b commit e17c164
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
6 changes: 3 additions & 3 deletions implement/Pine.Core/Pine.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyVersion>0.3.4</AssemblyVersion>
<FileVersion>0.3.4</FileVersion>
<AssemblyVersion>0.3.5</AssemblyVersion>
<FileVersion>0.3.5</FileVersion>
</PropertyGroup>

<PropertyGroup>
<PackageId>Pine.Core</PackageId>
<Version>0.3.4</Version>
<Version>0.3.5</Version>
<Description>The cross-platform Elm runtime environment</Description>
<PackageTags>Functional;Elm;Runtime;Compiler;VM;DBMS</PackageTags>
<RepositoryUrl>https://github.com/pine-vm/pine.git</RepositoryUrl>
Expand Down
12 changes: 8 additions & 4 deletions implement/pine/Elm019/ElmJsonStructure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,6 +43,10 @@ aggregate with
{
ParentLevel = aggregate.ParentLevel + 1
},

"." =>
aggregate,

_ =>
aggregate with
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ parseElmJsonSourceDirectoryPath pathInJson =
let
pathItems =
String.split "/" pathInJson
|> List.Extra.dropWhile String.isEmpty
in
List.foldl
(\nextSegment { parentLevel, subdirectories } ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
2 changes: 1 addition & 1 deletion implement/pine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions implement/pine/pine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>pine</AssemblyName>
<AssemblyVersion>0.3.4</AssemblyVersion>
<FileVersion>0.3.4</FileVersion>
<AssemblyVersion>0.3.5</AssemblyVersion>
<FileVersion>0.3.5</FileVersion>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
Expand Down

0 comments on commit e17c164

Please sign in to comment.