Add Roslyn LSP entry-point query for file-based programs and refresh discovery#84367
Add Roslyn LSP entry-point query for file-based programs and refresh discovery#84367Copilot wants to merge 4 commits into
Conversation
Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
|
|
||
| private static bool ContainsTopLevelStatements(SourceText sourceText, CancellationToken cancellationToken) | ||
| { | ||
| var syntaxTree = CSharpSyntaxTree.ParseText(sourceText, options: s_fileBasedProgramParseOptions, cancellationToken: cancellationToken); |
There was a problem hiding this comment.
We chose to require the leading #! to make a file-based app auto-discoverable, in part because doing this parse on all the C# files in a workspace folder is taxing on memory and cpu.
If we want to move forward with this, we should def be measuring and comparing the perf very carefully.
To be honest I am also a little hesitant about CreateTokenParser based solution for auto-discovery as creating SourceText requires reading the whole file content from disk (checksum is produced eagerly). This extra I/O is hard to notice on an nvme drive when auto-discovery is the only thing running, but, in a real editor startup scenario, there's a lot of contention, and being able to read less (<= ~4KB, say), does help a bit, IIRC.
|
This worked on microsoft/vscode-dotnettools#2369 but introduces too many changes at once. We're going to improve this heuristic with a series of PRs for reviewability. |
Roslyn already had file-based-program entry-point heuristics, but the client was adding its own copy. This change exposes Roslyn’s decision over LSP and fixes the known discovery gaps around top-level statements, workspace-folder updates, and newly created
.csfiles.New LSP surface
workspace/_roslyn_isFileBasedProgramEntryPointso clients can ask Roslyn whether a file should be treated as an FBA entry point under the current workspace state.{ "method": "workspace/_roslyn_isFileBasedProgramEntryPoint", "params": { "textDocument": { "uri": "file:///workspace/App.cs" } } }Shared entry-point heuristic
#!files as explicit entry points#:+ top-level statements as explicit entry pointsDiscovery correctness
#!/#:markers.Workspace change handling
workspace/didChangeWorkspaceFoldershandling.InitializeManagerandCsprojInConeCheckerso workspace-folder state is live rather than captured once at initialization.File watching
.csand.csproj.Unit test coverage
Microsoft Reviewers: Open in CodeFlow