8
8
using System . Text . Json ;
9
9
using System . Threading ;
10
10
using System . Threading . Tasks ;
11
+ using ICSharpCode . Decompiler . CSharp . Syntax ;
11
12
using Microsoft . CodeAnalysis . LanguageServer . Handler . Diagnostics ;
12
13
using Microsoft . CodeAnalysis . LanguageServer . Handler . Diagnostics . Public ;
14
+ using Microsoft . CodeAnalysis . UnitTests ;
13
15
using Roslyn . LanguageServer . Protocol ;
14
16
using Roslyn . Test . Utilities ;
15
17
using StreamJsonRpc ;
@@ -25,15 +27,15 @@ public DiagnosticRegistrationTests(ITestOutputHelper? testOutputHelper) : base(t
25
27
}
26
28
27
29
[ Theory , CombinatorialData ]
28
- public async Task TestPublicDiagnosticSourcesAreRegisteredWhenSupported ( bool mutatingLspWorkspace )
30
+ public async Task TestPublicDiagnosticSourcesAreRegisteredWhenSupported ( bool mutatingLspWorkspace , bool dynamicRegistration )
29
31
{
30
32
var clientCapabilities = new ClientCapabilities
31
33
{
32
34
TextDocument = new TextDocumentClientCapabilities
33
35
{
34
36
Diagnostic = new DiagnosticSetting
35
37
{
36
- DynamicRegistration = true ,
38
+ DynamicRegistration = dynamicRegistration ,
37
39
}
38
40
}
39
41
} ;
@@ -49,42 +51,54 @@ public async Task TestPublicDiagnosticSourcesAreRegisteredWhenSupported(bool mut
49
51
await using var testLspServer = await CreateTestLspServerAsync ( string . Empty , mutatingLspWorkspace , initializationOptions ) ;
50
52
51
53
var registrations = clientCallbackTarget . GetRegistrations ( ) ;
54
+ var serverCapabilities = testLspServer . GetServerCapabilities ( ) ;
52
55
53
56
// Get all registrations for diagnostics (note that workspace registrations are registered against document method name).
54
57
var diagnosticRegistrations = registrations
55
58
. Where ( r => r . Method == Methods . TextDocumentDiagnosticName )
56
59
. Select ( r => JsonSerializer . Deserialize < DiagnosticRegistrationOptions > ( ( JsonElement ) r . RegisterOptions ! , ProtocolConversions . LspJsonSerializerOptions ) ! ) ;
57
60
58
- Assert . NotEmpty ( diagnosticRegistrations ) ;
59
-
60
- string [ ] documentSources = [
61
- PullDiagnosticCategories . DocumentCompilerSyntax ,
62
- PullDiagnosticCategories . DocumentCompilerSemantic ,
63
- PullDiagnosticCategories . DocumentAnalyzerSyntax ,
64
- PullDiagnosticCategories . DocumentAnalyzerSemantic ,
65
- PublicDocumentNonLocalDiagnosticSourceProvider . NonLocal
66
- ] ;
67
-
68
- string [ ] documentAndWorkspaceSources = [
69
- PullDiagnosticCategories . EditAndContinue ,
70
- PullDiagnosticCategories . WorkspaceDocumentsAndProject
71
- ] ;
72
-
73
- // Verify document only sources are present (and do not set the workspace diagnostic option).
74
- foreach ( var documentSource in documentSources )
61
+ if ( dynamicRegistration )
75
62
{
76
- var options = Assert . Single ( diagnosticRegistrations , ( r ) => r . Identifier == documentSource ) ;
77
- Assert . False ( options . WorkspaceDiagnostics ) ;
78
- Assert . True ( options . InterFileDependencies ) ;
79
- }
63
+ Assert . NotEmpty ( diagnosticRegistrations ) ;
64
+
65
+ string [ ] documentSources = [
66
+ PullDiagnosticCategories . DocumentCompilerSyntax ,
67
+ PullDiagnosticCategories . DocumentCompilerSemantic ,
68
+ PullDiagnosticCategories . DocumentAnalyzerSyntax ,
69
+ PullDiagnosticCategories . DocumentAnalyzerSemantic ,
70
+ PublicDocumentNonLocalDiagnosticSourceProvider . NonLocal
71
+ ] ;
72
+
73
+ string [ ] documentAndWorkspaceSources = [
74
+ PullDiagnosticCategories . EditAndContinue ,
75
+ PullDiagnosticCategories . WorkspaceDocumentsAndProject
76
+ ] ;
77
+
78
+ // Verify document only sources are present (and do not set the workspace diagnostic option).
79
+ foreach ( var documentSource in documentSources )
80
+ {
81
+ var options = Assert . Single ( diagnosticRegistrations , ( r ) => r . Identifier == documentSource ) ;
82
+ Assert . False ( options . WorkspaceDiagnostics ) ;
83
+ Assert . True ( options . InterFileDependencies ) ;
84
+ }
80
85
81
- // Verify workspace sources are present (and do set the workspace diagnostic option).
82
- foreach ( var workspaceSource in documentAndWorkspaceSources )
86
+ // Verify workspace sources are present (and do set the workspace diagnostic option).
87
+ foreach ( var workspaceSource in documentAndWorkspaceSources )
88
+ {
89
+ var options = Assert . Single ( diagnosticRegistrations , ( r ) => r . Identifier == workspaceSource ) ;
90
+ Assert . True ( options . WorkspaceDiagnostics ) ;
91
+ Assert . True ( options . InterFileDependencies ) ;
92
+ Assert . True ( options . WorkDoneProgress ) ;
93
+ }
94
+ }
95
+ else
83
96
{
84
- var options = Assert . Single ( diagnosticRegistrations , ( r ) => r . Identifier == workspaceSource ) ;
85
- Assert . True ( options . WorkspaceDiagnostics ) ;
86
- Assert . True ( options . InterFileDependencies ) ;
87
- Assert . True ( options . WorkDoneProgress ) ;
97
+ var diagnosticOptions = ( DiagnosticOptions ) serverCapabilities ? . DiagnosticOptions ;
98
+
99
+ Assert . Empty ( diagnosticRegistrations ) ;
100
+ Assert . NotNull ( diagnosticOptions ) ;
101
+ Assert . True ( diagnosticOptions . InterFileDependencies ) ;
88
102
}
89
103
90
104
// Verify task diagnostics are not present.
0 commit comments