Skip to content

Commit a7ade53

Browse files
Merge remote-tracking branch 'upstream/main' into sortUsings
2 parents 68f88d9 + 59ebcb9 commit a7ade53

File tree

22 files changed

+295
-110
lines changed

22 files changed

+295
-110
lines changed

src/EditorFeatures/Core/LanguageServer/AbstractInProcLanguageClient.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,10 @@ internal abstract partial class AbstractInProcLanguageClient(
110110

111111
public event AsyncEventHandler<EventArgs>? StartAsync;
112112

113-
public event AsyncEventHandler<EventArgs>? StopAsync;
114-
115113
/// <summary>
116-
/// Stops the server if it has been started.
114+
/// Unused, implementing <see cref="ILanguageClient"/>
117115
/// </summary>
118-
/// <remarks>
119-
/// Per the documentation on <see cref="ILanguageClient.StopAsync"/>, the event is ignored if the server has not been started.
120-
/// </remarks>
121-
public Task StopServerAsync()
122-
=> StopAsync?.InvokeAsync(this, EventArgs.Empty) ?? Task.CompletedTask;
116+
public event AsyncEventHandler<EventArgs>? StopAsync { add { } remove { } }
123117

124118
public async Task<Connection?> ActivateAsync(CancellationToken cancellationToken)
125119
{

src/EditorFeatures/Core/LanguageServer/AlwaysActiveLanguageClientEventListener.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,8 @@ internal sealed class AlwaysActiveLanguageClientEventListener(
4040
/// </summary>
4141
public void StartListening(Workspace workspace)
4242
{
43-
_ = workspace.RegisterWorkspaceChangedHandler(Workspace_WorkspaceChanged);
44-
}
45-
46-
private void Workspace_WorkspaceChanged(WorkspaceChangeEventArgs e)
47-
{
48-
if (e.Kind == WorkspaceChangeKind.SolutionAdded)
49-
{
50-
// Normally VS will load the language client when an editor window is created for one of our content types,
51-
// but we want to load it as soon as a solution is loaded so workspace diagnostics work, and so 3rd parties
52-
// like Razor can use dynamic registration.
53-
Load();
54-
}
43+
// Trigger a fire and forget request to the VS LSP client to load our ILanguageClient.
44+
Load();
5545
}
5646

5747
public void StopListening(Workspace workspace)
@@ -66,15 +56,12 @@ private void Load()
6656

6757
async Task LoadAsync()
6858
{
59+
6960
// Explicitly switch to the bg so that if this causes any expensive work (like mef loads) it
7061
// doesn't block the UI thread. Note, we always yield because sometimes our caller starts
7162
// on the threadpool thread but is indirectly blocked on by the UI thread.
7263
await TaskScheduler.Default.SwitchTo(alwaysYield: true);
7364

74-
// Sometimes the editor can be slow to stop the old server instance when the old solution is closed, so we force it here.
75-
// This will no-op if the server hasn't been started yet.
76-
await _languageClient.StopServerAsync().ConfigureAwait(false);
77-
7865
await _languageClientBroker.Value.LoadAsync(new LanguageClientMetadata(
7966
[
8067
ContentTypeNames.CSharpContentType,

src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/Razor/RazorDynamicFileInfoProvider.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.Razor;
1919
[ExportMetadata("Extensions", new string[] { "cshtml", "razor", })]
2020
[method: ImportingConstructor]
2121
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
22-
internal sealed partial class RazorDynamicFileInfoProvider(Lazy<LanguageServerWorkspaceFactory> workspaceFactory, ILoggerFactory loggerFactory) : IDynamicFileInfoProvider, ILspService, IOnInitialized
22+
internal sealed partial class RazorDynamicFileInfoProvider(Lazy<LanguageServerWorkspaceFactory> workspaceFactory, ILoggerFactory loggerFactory) : IDynamicFileInfoProvider, ILspService, IOnInitialized, IDisposable
2323
{
2424
private RazorWorkspaceService? _razorWorkspaceService;
2525
private RazorLspDynamicFileInfoProvider? _dynamicFileInfoProvider;
@@ -80,4 +80,11 @@ public async Task RemoveDynamicFileInfoAsync(ProjectId projectId, string? projec
8080

8181
await _dynamicFileInfoProvider.RemoveDynamicFileInfoAsync(workspaceFactory.Value.HostWorkspace, projectId, projectFilePath, filePath, cancellationToken).ConfigureAwait(false);
8282
}
83+
84+
public void Dispose()
85+
{
86+
// Dispose is called when the LSP server is being shut down. Clear the dynamic file provider in case a workspace
87+
// event is raised after, as the actual provider will try to make LSP requests.
88+
_dynamicFileInfoProvider = null;
89+
}
8390
}

src/RoslynAnalyzers/Directory.Build.props

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
<!-- Set 'NoDefaultExcludes' to ensure that we can package .editorconfig files into our analyzer NuGet packages -->
1010
<NoDefaultExcludes>true</NoDefaultExcludes>
11-
11+
1212
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
13+
</PropertyGroup>
14+
15+
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
1316
<DefineConstants>$(DefineConstants),ROSLYN_4_12_OR_LOWER</DefineConstants>
1417
</PropertyGroup>
1518

@@ -25,6 +28,12 @@
2528
<DefineConstants Condition="'$(LEGACY_CODE_METRICS_MODE)' == 'true'">$(DefineConstants),LEGACY_CODE_METRICS_MODE</DefineConstants>
2629
</PropertyGroup>
2730

31+
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' != 'true'">
32+
<!-- Since SourceBuild uses project references and brings additional nullability annotations, -->
33+
<!-- suppressions were added that are unncessary when building against older Roslyn packages. -->
34+
<NoWarn>$(NoWarn);IDE0079</NoWarn>
35+
</PropertyGroup>
36+
2837
<PropertyGroup Condition="'$(DotNetBuildSourceOnly)' == 'true'">
2938
<!-- When building in source build mode, treat this set of warnings not as errors.-->
3039
<!-- Some crefs reference internal APIs not present in the reference package. -->

src/RoslynAnalyzers/Microsoft.CodeAnalysis.AnalyzerUtilities/Microsoft.CodeAnalysis.AnalyzerUtilities.csproj

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,21 @@
1717
<NoWarn>$(NoWarn);RS0026</NoWarn>
1818
</PropertyGroup>
1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
2120
<PackageReference Include="System.Threading.Channels" />
2221
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" />
2322
</ItemGroup>
23+
<Choose>
24+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
25+
<ItemGroup>
26+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
27+
</ItemGroup>
28+
</When>
29+
<Otherwise>
30+
<ItemGroup>
31+
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
32+
</ItemGroup>
33+
</Otherwise>
34+
</Choose>
2435
<ItemGroup>
2536
<InternalsVisibleTo Include="Analyzer.Utilities.UnitTests" />
2637
</ItemGroup>
@@ -35,7 +46,7 @@
3546
<Import Project="..\..\Dependencies\PooledObjects\Microsoft.CodeAnalysis.PooledObjects.projitems" Label="Shared" />
3647
<Import Project="..\..\Dependencies\Threading\Microsoft.CodeAnalysis.Threading.projitems" Label="Shared" />
3748
<Import Project="..\..\Dependencies\Contracts\Microsoft.CodeAnalysis.Contracts.projitems" Label="Shared" />
38-
49+
3950
<Import Project="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Extensions\Microsoft.CodeAnalysis.Extensions.projitems" Label="Shared"/>
4051
<Import Project="..\..\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\CompilerExtensions.projitems" Label="Shared" />
4152
</Project>

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/CSharp/Microsoft.CodeAnalysis.CSharp.Analyzers.csproj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@
99
<ItemGroup>
1010
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Analyzers.UnitTests" />
1111
</ItemGroup>
12-
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17-
</ItemGroup>
12+
<Choose>
13+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
19+
</ItemGroup>
20+
</When>
21+
<Otherwise>
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
24+
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
25+
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
26+
<ProjectReference Include="..\..\..\Workspaces\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.Workspaces.csproj" />
27+
</ItemGroup>
28+
</Otherwise>
29+
</Choose>
1830
</Project>

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/Core/Microsoft.CodeAnalysis.Analyzers.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@
1010
<PackageId>*$(MSBuildProjectFile)*</PackageId>
1111
<RootNamespace>Microsoft.CodeAnalysis</RootNamespace>
1212
</PropertyGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16-
</ItemGroup>
13+
<Choose>
14+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18+
</ItemGroup>
19+
</When>
20+
<Otherwise>
21+
<ItemGroup>
22+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
23+
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
24+
</ItemGroup>
25+
</Otherwise>
26+
</Choose>
1727
<ItemGroup>
1828
<Compile Include="..\..\Microsoft.CodeAnalysis.BannedApiAnalyzers\Core\DocumentationCommentIdParser.cs" Link="DocumentationCommentIdParser.cs" />
1929
<Compile Include="..\..\Microsoft.CodeAnalysis.BannedApiAnalyzers\Core\SymbolIsBannedAnalyzerBase.cs" Link="SymbolIsBannedAnalyzerBase.cs" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/UnitTests/Microsoft.CodeAnalysis.Analyzers.UnitTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>$(NetRoslyn)</TargetFramework>
55
<ServerGarbageCollection>true</ServerGarbageCollection>
6+
<ExcludeFromSourceOnlyBuild>true</ExcludeFromSourceOnlyBuild>
67
</PropertyGroup>
78
<ItemGroup>
89
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzerTests)" />

src/RoslynAnalyzers/Microsoft.CodeAnalysis.Analyzers/VisualBasic/Microsoft.CodeAnalysis.VisualBasic.Analyzers.vbproj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@
1010
<ItemGroup>
1111
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Analyzers.UnitTests" />
1212
</ItemGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17-
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18-
</ItemGroup>
13+
<Choose>
14+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
18+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
19+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
20+
</ItemGroup>
21+
</When>
22+
<Otherwise>
23+
<ItemGroup>
24+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
25+
<ProjectReference Include="..\..\..\Compilers\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.vbproj" />
26+
<ProjectReference Include="..\..\..\Workspaces\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
27+
<ProjectReference Include="..\..\..\Workspaces\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" />
28+
</ItemGroup>
29+
</Otherwise>
30+
</Choose>
1931
</Project>

src/RoslynAnalyzers/Microsoft.CodeAnalysis.ResxSourceGenerator/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp/Microsoft.CodeAnalysis.ResxSourceGenerator.CSharp.csproj

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@
99
<PackageId>*$(MSBuildProjectFile)*</PackageId>
1010
</PropertyGroup>
1111

12-
<ItemGroup>
13-
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
14-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
15-
</ItemGroup>
12+
<Choose>
13+
<When Condition="'$(DotNetBuildSourceOnly)' != 'true'">
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
16+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(MicrosoftCodeAnalysisVersionForAnalyzers)" />
17+
</ItemGroup>
18+
</When>
19+
<Otherwise>
20+
<ItemGroup>
21+
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
22+
<ProjectReference Include="..\..\..\Compilers\CSharp\Portable\Microsoft.CodeAnalysis.CSharp.csproj" />
23+
</ItemGroup>
24+
</Otherwise>
25+
</Choose>
1626

1727
<ItemGroup>
1828
<ProjectReference Include="..\Microsoft.CodeAnalysis.ResxSourceGenerator\Microsoft.CodeAnalysis.ResxSourceGenerator.csproj" />

0 commit comments

Comments
 (0)