Skip to content

Commit a31a206

Browse files
committed
support navigating into sibling directory in elm.json
1 parent a51fcc5 commit a31a206

1 file changed

Lines changed: 40 additions & 15 deletions

File tree

implement/pine/Elm/ElmCompiler.cs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ public static BlobTreeWithStringPath ElmCompilerFileTreeFromBundledFileTree(
183183
compilerPackageSourcesTrees
184184
.SelectMany(tree => tree.tree.EnumerateBlobsTransitive())
185185
.Where(blobAtPath =>
186-
blobAtPath.path.First() == "src" && blobAtPath.path.Last().ToLower().EndsWith(".elm"));
186+
blobAtPath.path.First() == "src" && blobAtPath.path.Last().EndsWith(".elm", StringComparison.OrdinalIgnoreCase));
187187

188188
var compilerAppCodeSourceFiles =
189189
bundledFileTree.EnumerateBlobsTransitive()
190-
.Where(blobAtPath => blobAtPath.path.Last().ToLower().EndsWith(".elm"))
190+
.Where(blobAtPath => blobAtPath.path.Last().EndsWith(".elm", StringComparison.OrdinalIgnoreCase))
191191
.ToImmutableArray();
192192

193193
var compilerProgramOnlyElmJson =
@@ -697,8 +697,12 @@ public static BlobTreeWithStringPath FilterTreeForCompilationRoot(
697697

698698
var elmModulesIncluded =
699699
ElmTime.ElmSyntax.ElmModule.ModulesTextOrderedForCompilationByDependencies(
700-
rootModulesTexts: [.. rootElmFiles.Select(file => Encoding.UTF8.GetString(file.blobContent.Span))],
701-
availableModulesTexts: [.. availableElmFiles.Select(file => Encoding.UTF8.GetString(file.blobContent.Span))]);
700+
rootModulesTexts:
701+
[.. rootElmFiles.Select(file => Encoding.UTF8.GetString(file.blobContent.Span))
702+
],
703+
availableModulesTexts:
704+
[.. availableElmFiles.Select(file => Encoding.UTF8.GetString(file.blobContent.Span))
705+
]);
702706

703707
var filePathsExcluded =
704708
allAvailableElmFiles
@@ -726,22 +730,43 @@ private static Func<IReadOnlyList<string>, bool> BuildPredicateFilePathIsInSourc
726730
IReadOnlyList<ElmJsonStructure.RelativeDirectory> sourceDirectories =
727731
[.. elmJsonForEntryPoint.elmJsonParsed.ParsedSourceDirectories];
728732

729-
bool filePathIsInSourceDirectory(IReadOnlyList<string> filePath)
733+
IReadOnlyList<string> elmJsonDirectoryPath =
734+
[.. elmJsonForEntryPoint.filePath.SkipLast(1)];
735+
736+
var sourceDirectoriesMapped = new List<IReadOnlyList<string>>();
737+
738+
foreach (var sourceDirectory in sourceDirectories)
730739
{
731-
foreach (var sourceDirectory in sourceDirectories)
740+
if (sourceDirectory.ParentLevel > elmJsonDirectoryPath.Count)
732741
{
733-
if (sourceDirectory.ParentLevel is not 0)
734-
{
735-
throw new NotImplementedException(
736-
"ParentLevel in elm.json source-directories not implemented");
737-
}
742+
throw new InvalidOperationException(
743+
"Path is not contained in source: Source directory parent level is " +
744+
sourceDirectory.ParentLevel +
745+
" but elm.json is at path " +
746+
string.Join("/", elmJsonDirectoryPath));
747+
}
738748

739-
if (filePath.Count < sourceDirectory.Subdirectories.Count)
749+
IReadOnlyList<string> mappedPrefix =
750+
[.. elmJsonDirectoryPath.SkipLast(sourceDirectory.ParentLevel)];
751+
752+
IReadOnlyList<string> mappedSourceDirectory =
753+
[..mappedPrefix,
754+
..sourceDirectory.Subdirectories
755+
];
756+
757+
sourceDirectoriesMapped.Add(mappedSourceDirectory);
758+
}
759+
760+
bool FilePathIsInSourceDirectory(IReadOnlyList<string> filePath)
761+
{
762+
foreach (var mappedSourceDirectory in sourceDirectoriesMapped)
763+
{
764+
if (filePath.Count < mappedSourceDirectory.Count)
740765
{
741766
continue;
742767
}
743768

744-
if (filePath.Take(sourceDirectory.Subdirectories.Count).SequenceEqual(sourceDirectory.Subdirectories))
769+
if (filePath.Take(mappedSourceDirectory.Count).SequenceEqual(mappedSourceDirectory))
745770
{
746771
return true;
747772
}
@@ -750,7 +775,7 @@ bool filePathIsInSourceDirectory(IReadOnlyList<string> filePath)
750775
return false;
751776
}
752777

753-
return filePathIsInSourceDirectory;
778+
return FilePathIsInSourceDirectory;
754779
}
755780

756781
public static (IReadOnlyList<string> filePath, ElmJsonStructure elmJsonParsed)?
@@ -782,7 +807,7 @@ public static (IReadOnlyList<string> filePath, ElmJsonStructure elmJsonParsed)?
782807
(filePath: (IReadOnlyList<string>)pathAndContent.path, elmJsonParsed)
783808
};
784809
}
785-
catch (Exception e)
810+
catch (Exception)
786811
{
787812
return [];
788813
}

0 commit comments

Comments
 (0)