-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Use a canonical misc files project for misc files in VSCode #80744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: dibarbet <[email protected]>
Co-authored-by: dibarbet <[email protected]>
| } | ||
|
|
||
| // Add the source file to the project | ||
| _loadedProject.ProjectSystemProject.AddSourceFile(filePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like the wrong thing. We want to obtain the "Workspaces-layer" Project instance, which is produced as a result/output of the LoadedProject, and create a new derived Project instance containing the user's document, without making any changes to _loadedProject. Any "blank/meaningless" C# documents which we included in the canonical project, should also not be present in the derived Project instance.
| var artifactsPath = GetCanonicalProjectDirectory(); | ||
| var targetFramework = Environment.GetEnvironmentVariable("DOTNET_RUN_FILE_TFM") ?? "net$(BundledNETCoreAppTargetFrameworkVersion)"; | ||
|
|
||
| var virtualProjectXml = $""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that since the canonical project and all its on-disk contents are in a temp directory, there shouldn't be any need to do most/all the virtual project stuff that is done for file-based apps. i.e. the project file used for dotnet new classlib should work here.
Co-authored-by: dibarbet <[email protected]>
| private CanonicalMiscFilesProject? _canonicalMiscFilesProject; | ||
| private readonly SemaphoreSlim _canonicalProjectGate = new(initialCount: 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just create the CanonicalMiscFilesProject instance when constructing this project system. Then have its internal operations use its internal gate. No need for a gate out here.
| { | ||
| if (_canonicalMiscFilesProject != null) | ||
| { | ||
| var removedFromCanonical = await _canonicalMiscFilesProject.RemoveDocumentAsync(documentPath, CancellationToken.None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also be unnecessary when the change is made to use derived Workspaces Project instances, instead of adding documents to the LoadedProject.
|
closing in favor of attempt 2 #80748 |
Summary
This PR implements a shared "canonical miscellaneous files project" for genuine miscellaneous files in the VSCode language server, avoiding the overhead of running individual design-time builds for each misc file.
Problem
Previously, the
FileBasedProgramsProjectSystemtreated both genuine miscellaneous files and file-based programs similarly - for each file it would:This approach caused several issues for genuine miscellaneous files:
Solution
This PR introduces a canonical miscellaneous files project that is shared across all genuine misc files (non-file-based programs):
Key Changes
New
CanonicalMiscFilesProjectclass - Manages a single shared project:roslyn-lsp/canonical-misc-files) to hold the projectUpdated
FileBasedProgramsProjectSystem- Intelligently routes files:VirtualProjectXmlProvider.IsFileBasedProgram()(checks for global statements or#!directive)Updated
LoadedProject- ExposesProjectSystemProjectproperty to enable the canonical project to manage source filesBenefits
✅ Only one design-time build for all misc files instead of per-file builds
✅ No restore popups for misc files - restore happens once
✅ Clean artifact location - all build outputs in a single temp directory
✅ Supports virtual misc files - no physical file needed for design-time build
✅ Backward compatible - file-based programs continue to work as before
Example
Before:
After:
Testing
Fixes #78560
Original prompt
Fixes #80743
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.