Skip to content

Commit b0469d2

Browse files
committed
Return solution folders before solution level projects
1 parent 4d56a44 commit b0469d2

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/Ionide.ProjInfo/InspectSln.fs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,27 @@ module InspectSln =
139139
// three kinds of items - projects, folders, items
140140
// yield them all here
141141
let allItems = [
142-
// Projects at solution level get returned directly
143-
yield!
144-
projectsWeCareAbout
145-
|> Seq.filter (
146-
_.Parent
147-
>> isNull
148-
)
149-
|> Seq.map parseProject
142+
// Return solution folders first, and solution level projects second, see https://github.com/ionide/ionide-vscode-fsharp/issues/2109
150143

151144
// parseFolder will parse any projects or folders within the specified folder itself, so just process the root folders here
152145
yield!
153146
sln.SolutionFolders
154-
|> Seq.filter (
155-
_.Parent
156-
>> isNull
147+
|> Seq.choose (fun folder ->
148+
if isNull folder.Parent then
149+
Some(parseFolder folder)
150+
else
151+
None
152+
)
153+
154+
// Projects at solution level get returned directly
155+
yield!
156+
projectsWeCareAbout
157+
|> Seq.choose (fun project ->
158+
if isNull project.Parent then
159+
Some(parseProject project)
160+
else
161+
None
157162
)
158-
|> Seq.map parseFolder
159163

160164
// 'SolutionItems' contains all of SolutionFolders and SolutionProjects, so only include things that aren't in those to avoid duplication
161165
yield!

test/Ionide.ProjInfo.Tests/Tests.fs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,20 +2412,12 @@ let sample16SolutionFoldersTest testAsset =
24122412
// There should be 3 items at the solution level - build.fsproj, a 'src' folder and a 'tests' folder
24132413
Expect.equal solutionData.Items.Length 3 "There should be 3 items in the solution"
24142414

2415-
// The first item should be "build.fsproj
2415+
// The solution folders are first
2416+
// The first item should be the 'src' folder, which should contain proj1.fsproj
24162417
let firstItem = solutionData.Items[0]
2417-
let expectedBuildProjectPath = Path.Combine(slnDir, "build.fsproj")
2418-
Expect.equal firstItem.Name expectedBuildProjectPath "Should have the expected build project path"
2418+
Expect.equal firstItem.Name "src" "Should have the src folder"
24192419

24202420
match firstItem.Kind with
2421-
| InspectSln.MSBuildFormat items -> Expect.isEmpty items "we don't currently store anything here"
2422-
| unexpected -> failtestf "Expected a project, but got %A" unexpected
2423-
2424-
// The second item should be the 'src' folder, which should contain proj1.fsproj
2425-
let secondItem = solutionData.Items[1]
2426-
Expect.equal secondItem.Name "src" "Should have the src folder"
2427-
2428-
match secondItem.Kind with
24292421
| InspectSln.Folder(solutionItems, _) ->
24302422
match solutionItems with
24312423
| [ {
@@ -2438,10 +2430,10 @@ let sample16SolutionFoldersTest testAsset =
24382430
| unexpected -> failtestf "Expected a folder, but got %A" unexpected
24392431

24402432
// The third item should be the 'src' folder, which should contain proj1.fsproj
2441-
let thirdItem = solutionData.Items[2]
2442-
Expect.equal thirdItem.Name "tests" "Should have the tests folder"
2433+
let secondItem = solutionData.Items[1]
2434+
Expect.equal secondItem.Name "tests" "Should have the tests folder"
24432435

2444-
match thirdItem.Kind with
2436+
match secondItem.Kind with
24452437
| InspectSln.Folder(solutionItems, _) ->
24462438
match solutionItems with
24472439
| [ {
@@ -2453,6 +2445,16 @@ let sample16SolutionFoldersTest testAsset =
24532445
| _ -> failtestf "Expected one folder item, but got %A" solutionItems
24542446
| unexpected -> failtestf "Expected a folder, but got %A" unexpected
24552447

2448+
// Then projects at the root level of the solution.
2449+
// The first item should be "build.fsproj
2450+
let thirdItem = solutionData.Items[2]
2451+
let expectedBuildProjectPath = Path.Combine(slnDir, "build.fsproj")
2452+
Expect.equal thirdItem.Name expectedBuildProjectPath "Should have the expected build project path"
2453+
2454+
match thirdItem.Kind with
2455+
| InspectSln.MSBuildFormat items -> Expect.isEmpty items "we don't currently store anything here"
2456+
| unexpected -> failtestf "Expected a project, but got %A" unexpected
2457+
24562458
/// A test that we can load a solution that contains projects inside solution folders, and get the expected structure
24572459
let sample16SolutionFoldersSlnTest toolsPath loaderType workspaceFactory =
24582460

0 commit comments

Comments
 (0)