Skip to content

Conversation

@mvoggu
Copy link

@mvoggu mvoggu commented May 12, 2025

Adds support for solution filters.
Since dotnet CLI commands as well as MSBuild already support solution filters, letting .slnf files to be discovered by the plugin during directory scan seems to be sufficient.

I have tested the same to be working on a Windows 11 machine.

@mvoggu mvoggu requested a review from GustavEikaas as a code owner May 12, 2025 21:10
@mvoggu
Copy link
Author

mvoggu commented May 12, 2025

As documented here, dotnet sln list command does not support slnf files before .NET SDK 9.0.3xx version.

Marking the PR as draft for now, till we can find a workaround for this.

@mvoggu mvoggu marked this pull request as draft May 12, 2025 21:26
@GustavEikaas
Copy link
Owner

GustavEikaas commented May 13, 2025

Before #315 we parsed the files using lua patterns. I am considering going back to this strategy. Especially on windows there was a major performance difference. For my standard sln file with 6 projects. I used to take 1.4s and after #315 it takes 2.4s

We could look into the slnf format and see if it's easy to parse

@mvoggu
Copy link
Author

mvoggu commented May 13, 2025

Turns out solution filter (.slnf) files are JSON files that list out the projects that need to be included.
Sample .slnf content:

{
  "solution": {
    "path": "MyApplication.sln",
    "projects": [
      "MyApplication\\MyApplication.csproj",
      "ProjectA\\ProjectA.csproj"
    ]
  }
}

So parsing their content as JSON and reading the solution.projects property should suffice to replace executing the dotnet sln list command.

We could check the file extension in sln_file_path passed to list_projects and directly parse the JSON content if the extension matches .slnf. I tried to but wasn't able to come up with a good enough implementation for this, as my familiarity with lua and this plugin is currently limited.

References:
Implementation in MSBuild: https://github.com/dotnet/msbuild/blob/fc7b6394b1460d421a55983b31820c96be182ece/src/Build/Construction/Solution/SolutionFile.cs#L630
Implementation in dotnet SDK: https://github.com/dotnet/sdk/blob/0b589371f4495e68968be99e7f0029b24cf21f14/src/Cli/dotnet/SlnFileFactory.cs#L85
Sample JSON: https://learn.microsoft.com/en-us/visualstudio/msbuild/solution-filters?view=vs-2022

@GustavEikaas
Copy link
Owner

Yeah could definitely do something like this

local contents = vim.fn.readfile(slnf-path)
local projects = vim.fn.json_decode(contents)
--Projects is now a list of paths

@mvoggu
Copy link
Author

mvoggu commented May 13, 2025

We are currently returning the formatted dotnet sln command from list_projects and then executing it right.

In one instance, we seem to be trying to execute the returned command as a background job. That's where I had trouble refactoring the existing code.

I wanted to refactor such that list_projects returns the list of projects instead of just the command. But I wasn't sure how to move running of the background job into the list_projects function itself.

Will provide more details tomorrow if necessary.

@PaddiM8
Copy link
Contributor

PaddiM8 commented Jun 30, 2025

There's also workspace/_roslyn_restorableProjects in the language server, to get a list of all the projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants