Skip to content

Commit 33df113

Browse files
committed
Tweaks to solution filter loading
refs ionide/ionide-vscode-fsharp#1708 1) When reading the path to the solution file out of the filter file, create the abolsute path to it based on the filter path, instead of just using the name directly (it might just be the solution file name, with on path) 2) When parseSln is called with a filter list, it calls makeAbsoluteFromSlnDir on each project in the parent solution when searching in the filter list. That fails to match anything in the paths in the filter are relative rather than absolute. Try to fix that by calling makeAbsoluteFromSlnDir on each project in the filter file.
1 parent 774c03f commit 33df113

File tree

9 files changed

+138
-13
lines changed

9 files changed

+138
-13
lines changed

src/Ionide.ProjInfo/InspectSln.fs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@ module InspectSln =
5858

5959
/// Parses a file on disk and returns data about its contents. Supports sln, slnf, and slnx files.
6060
let tryParseSln (slnFilePath: string) =
61-
let parseSln (sln: Model.SolutionModel) (projectsToRead: string Set option) =
62-
sln.DistillProjectConfigurations()
6361

64-
let slnDir = Path.GetDirectoryName slnFilePath
62+
let slnDir = Path.GetDirectoryName slnFilePath
63+
64+
let makeAbsoluteFromSlnDir =
65+
let makeAbs (path: string) =
66+
if Path.IsPathRooted path then
67+
path
68+
else
69+
Path.Combine(slnDir, path)
70+
|> Path.GetFullPath
6571

66-
let makeAbsoluteFromSlnDir =
67-
let makeAbs (path: string) =
68-
if Path.IsPathRooted path then
69-
path
70-
else
71-
Path.Combine(slnDir, path)
72-
|> Path.GetFullPath
72+
normalizeDirSeparators
73+
>> makeAbs
7374

74-
normalizeDirSeparators
75-
>> makeAbs
75+
let parseSln (sln: Model.SolutionModel) (projectsToRead: string Set option) =
76+
sln.DistillProjectConfigurations()
7677

7778
let parseItem (item: Model.SolutionItemModel) : SolutionItem = {
7879
Guid = item.Id
@@ -141,9 +142,10 @@ module InspectSln =
141142
let projects =
142143
solutionElement.GetProperty("projects").EnumerateArray()
143144
|> Seq.map (fun p -> p.GetString())
145+
|> Seq.map makeAbsoluteFromSlnDir
144146
|> Set.ofSeq
145147

146-
slnPath, projects
148+
makeAbsoluteFromSlnDir slnPath, projects
147149

148150
match tryLoadSolutionModel slnFilePath with
149151
| Ok sln -> Ok(parseSln sln (Some projectsToRead))

test/Ionide.ProjInfo.Tests/TestAssets.fs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,3 +329,23 @@ let ``sample 11 sln with other project types`` = {
329329
TargetFrameworks = Map.empty
330330
ProjectReferences = []
331331
}
332+
333+
let ``sample 12 slnf with one project`` = {
334+
ProjDir = "sample12-solution-filter-with-one-project"
335+
AssemblyName = ""
336+
ProjectFile = "sample12-solution-filter-with-one-project.slnf"
337+
TargetFrameworks = Map.empty
338+
ProjectReferences = [
339+
{
340+
ProjDir =
341+
"sample12-solution-filter-with-one-project"
342+
/ "classlibf2"
343+
AssemblyName = "lclasslibf2"
344+
ProjectFile =
345+
"classlibf2"
346+
/ "classlibf2.fsproj"
347+
TargetFrameworks = Map.ofList [ "netstandard8.0", sourceFiles [ "Library.fs" ] ]
348+
ProjectReferences = []
349+
}
350+
]
351+
}

test/Ionide.ProjInfo.Tests/Tests.fs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,36 @@ let sample11OtherProjectsTest toolsPath loaderType workspaceFactory =
22732273
Expect.hasLength parsed 1 "Should have fsproj"
22742274
)
22752275

2276+
let sample12SlnFilterTest toolsPath loaderType workspaceFactory =
2277+
ftestCase
2278+
$"Can load sample12 with solution folder with one project - {loaderType}"
2279+
(fun () ->
2280+
2281+
let projPath = pathForProject ``sample 12 slnf with one project``
2282+
2283+
let projPaths =
2284+
// using Inspectsln emulates what we do in FsAutocomplete for gathering projects to load
2285+
InspectSln.tryParseSln projPath
2286+
|> getResult
2287+
|> InspectSln.loadingBuildOrder
2288+
2289+
let loader: IWorkspaceLoader = workspaceFactory toolsPath
2290+
2291+
let parsed =
2292+
loader.LoadProjects projPaths
2293+
|> Seq.toList
2294+
2295+
Expect.hasLength parsed 1 "Should have fsproj"
2296+
2297+
let projDir = Path.GetDirectoryName projPath
2298+
2299+
let fsproj =
2300+
projDir
2301+
/ ``sample 12 slnf with one project``.ProjectReferences.[0].ProjectFile
2302+
2303+
Expect.equal parsed[0].ProjectFileName fsproj "should contain the expected project"
2304+
)
2305+
22762306
let tests toolsPath =
22772307
let testSample3WorkspaceLoaderExpected = [
22782308
ExpectNotification.loading "c1.fsproj"
@@ -2402,4 +2432,7 @@ let tests toolsPath =
24022432

24032433
sample11OtherProjectsTest toolsPath (nameof (WorkspaceLoader)) WorkspaceLoader.Create
24042434
sample11OtherProjectsTest toolsPath (nameof (WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create
2435+
2436+
sample12SlnFilterTest toolsPath (nameof (WorkspaceLoader)) WorkspaceLoader.Create
2437+
sample12SlnFilterTest toolsPath (nameof (WorkspaceLoaderViaProjectGraph)) WorkspaceLoaderViaProjectGraph.Create
24052438
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace classlibf1
2+
3+
module Say =
4+
let hello name =
5+
printfn "Hello %s" name
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Library.fs" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace classlibf1
2+
3+
module Say =
4+
let hello name =
5+
printfn "Hello %s" name
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<Compile Include="Library.fs" />
10+
</ItemGroup>
11+
12+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"solution": {
3+
"path": "sample12-solution-with-two-projects.sln",
4+
"projects": [
5+
"classlibf2\\classlibf2.fsproj"
6+
]
7+
}
8+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "classlibf2", "classlibf2\classlibf2.fsproj", "{33979FCF-E6B6-9D63-2EE4-C57768538882}"
7+
EndProject
8+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "classlibf1", "classlibf1\classlibf1.fsproj", "{E62CCF4F-11A1-8E40-9021-4C8FB585B5F2}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{33979FCF-E6B6-9D63-2EE4-C57768538882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{33979FCF-E6B6-9D63-2EE4-C57768538882}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{33979FCF-E6B6-9D63-2EE4-C57768538882}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{33979FCF-E6B6-9D63-2EE4-C57768538882}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{E62CCF4F-11A1-8E40-9021-4C8FB585B5F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{E62CCF4F-11A1-8E40-9021-4C8FB585B5F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{E62CCF4F-11A1-8E40-9021-4C8FB585B5F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{E62CCF4F-11A1-8E40-9021-4C8FB585B5F2}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

0 commit comments

Comments
 (0)