-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix file-based programs getting stuck in the host workspace #79730
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
Merged
jasonmalinowski
merged 5 commits into
dotnet:main
from
jasonmalinowski:fix-file-based-programs-getting-stuck-in-workspace
Aug 4, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
24615d1
Refactor how TestWorkspaces interact with TestCompositions
jasonmalinowski 99dcf19
Allow our LanguageServer tests to use Protocol.Test.Utilities
jasonmalinowski 95b45e7
Run our LSP Miscellaneous Files tests against both implementations
jasonmalinowski 9593910
Consolidate and unify the miscellaneous files tests more
jasonmalinowski 9ae7e86
Fix file-based programs getting stuck in the host workspace
jasonmalinowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...Server/Microsoft.CodeAnalysis.LanguageServer.UnitTests/FileBasedProgramsWorkspaceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace; | ||
| using Microsoft.CodeAnalysis.LanguageServer.UnitTests.Miscellaneous; | ||
| using Microsoft.CodeAnalysis.Shared.Extensions; | ||
| using Microsoft.CodeAnalysis.Shared.TestHooks; | ||
| using Microsoft.CodeAnalysis.Test.Utilities; | ||
| using Microsoft.CodeAnalysis.UnitTests; | ||
| using Microsoft.CodeAnalysis.Workspaces.ProjectSystem; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.VisualStudio.Composition; | ||
| using Roslyn.Test.Utilities; | ||
| using Xunit.Abstractions; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.LanguageServer.UnitTests; | ||
|
|
||
| public sealed class FileBasedProgramsWorkspaceTests : AbstractLspMiscellaneousFilesWorkspaceTests, IDisposable | ||
| { | ||
| private readonly ILoggerFactory _loggerFactory; | ||
| private readonly TestOutputLoggerProvider _loggerProvider; | ||
| private readonly TempRoot _tempRoot; | ||
| private readonly TempDirectory _mefCacheDirectory; | ||
|
|
||
| public FileBasedProgramsWorkspaceTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) | ||
| { | ||
| _loggerProvider = new TestOutputLoggerProvider(testOutputHelper); | ||
| _loggerFactory = new LoggerFactory([_loggerProvider]); | ||
| _tempRoot = new(); | ||
| _mefCacheDirectory = _tempRoot.CreateDirectory(); | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| _tempRoot.Dispose(); | ||
| _loggerProvider.Dispose(); | ||
| } | ||
|
|
||
| protected override async ValueTask<ExportProvider> CreateExportProviderAsync() | ||
| { | ||
| AsynchronousOperationListenerProvider.Enable(enable: true); | ||
|
|
||
| var (exportProvider, _) = await LanguageServerTestComposition.CreateExportProviderAsync( | ||
| _loggerFactory, | ||
| includeDevKitComponents: false, | ||
| cacheDirectory: _mefCacheDirectory.Path, | ||
| extensionPaths: []); | ||
|
|
||
| return exportProvider; | ||
| } | ||
|
|
||
| private protected override async ValueTask<Document> AddDocumentAsync(TestLspServer testLspServer, string filePath, string content) | ||
| { | ||
| // For the file-based programs, we want to put them in the real workspace via the real host service | ||
| var workspaceFactory = testLspServer.TestWorkspace.ExportProvider.GetExportedValue<LanguageServerWorkspaceFactory>(); | ||
| var project = await workspaceFactory.HostProjectFactory.CreateAndAddToWorkspaceAsync( | ||
| Guid.NewGuid().ToString(), | ||
| LanguageNames.CSharp, | ||
| new ProjectSystemProjectCreationInfo { AssemblyName = Guid.NewGuid().ToString() }, | ||
| workspaceFactory.ProjectSystemHostInfo); | ||
|
|
||
| project.AddSourceFile(filePath); | ||
|
|
||
| return workspaceFactory.HostWorkspace.CurrentSolution.GetRequiredProject(project.Id).Documents.Single(); | ||
| } | ||
|
|
||
| private protected override Workspace GetHostWorkspace(TestLspServer testLspServer) | ||
| { | ||
| var workspaceFactory = testLspServer.TestWorkspace.ExportProvider.GetExportedValue<LanguageServerWorkspaceFactory>(); | ||
| return workspaceFactory.HostWorkspace; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.