@@ -8,6 +8,10 @@ import { RequestType } from 'vscode-languageclient';
8
8
import { RazorLanguageServerClient } from '../razorLanguageServerClient' ;
9
9
import { ProvideSemanticTokensResponse } from './provideSemanticTokensResponse' ;
10
10
import { SerializableSemanticTokensParams } from './serializableSemanticTokensParams' ;
11
+ import { RazorDocumentSynchronizer } from '../document/razorDocumentSynchronizer' ;
12
+ import { RazorDocumentManager } from '../document/razorDocumentManager' ;
13
+ import { RazorLanguageServiceClient } from '../razorLanguageServiceClient' ;
14
+ import { RazorLogger } from '../razorLogger' ;
11
15
12
16
export class SemanticTokensRangeHandler {
13
17
private static readonly getSemanticTokensRangeEndpoint = 'razor/provideSemanticTokensRange' ;
@@ -18,10 +22,16 @@ export class SemanticTokensRangeHandler {
18
22
> = new RequestType ( SemanticTokensRangeHandler . getSemanticTokensRangeEndpoint ) ;
19
23
private emptySemanticTokensResponse : ProvideSemanticTokensResponse = new ProvideSemanticTokensResponse (
20
24
new Array < Array < number > > ( ) ,
21
- - 5
25
+ - 1
22
26
) ;
23
27
24
- constructor ( private readonly serverClient : RazorLanguageServerClient ) { }
28
+ constructor (
29
+ private readonly documentSynchronizer : RazorDocumentSynchronizer ,
30
+ protected readonly serverClient : RazorLanguageServerClient ,
31
+ protected readonly serviceClient : RazorLanguageServiceClient ,
32
+ protected readonly documentManager : RazorDocumentManager ,
33
+ protected readonly logger : RazorLogger
34
+ ) { }
25
35
26
36
public async register ( ) {
27
37
await this . serverClient . onRequestWithParams <
@@ -39,10 +49,33 @@ export class SemanticTokensRangeHandler {
39
49
_semanticTokensParams : SerializableSemanticTokensParams ,
40
50
_cancellationToken : vscode . CancellationToken
41
51
) : Promise < ProvideSemanticTokensResponse > {
52
+ let version = - 1 ;
53
+ try {
54
+ const razorDocumentUri = vscode . Uri . parse ( _semanticTokensParams . textDocument . uri ) ;
55
+ const razorDocument = await this . documentManager . getDocument ( razorDocumentUri ) ;
56
+ if ( razorDocument === undefined ) {
57
+ return this . emptySemanticTokensResponse ;
58
+ }
59
+
60
+ const textDocument = await vscode . workspace . openTextDocument ( razorDocumentUri ) ;
61
+ version = textDocument . version ;
62
+ const synchronized = await this . documentSynchronizer . trySynchronizeProjectedDocument (
63
+ textDocument ,
64
+ razorDocument . csharpDocument ,
65
+ version ,
66
+ _cancellationToken
67
+ ) ;
68
+ if ( ! synchronized ) {
69
+ return this . emptySemanticTokensResponse ;
70
+ }
71
+ } catch ( error ) {
72
+ this . logger . logWarning ( `${ SemanticTokensRangeHandler . getSemanticTokensRangeEndpoint } failed with ${ error } ` ) ;
73
+ }
74
+
42
75
// This is currently a no-op since (1) the default C# semantic tokens experience is already powerful and
43
76
// (2) there seems to be an issue with the semantic tokens execute command - possibly either O# not
44
77
// returning tokens, or an issue with the command itself:
45
78
// https://github.com/dotnet/razor/issues/6922
46
- return this . emptySemanticTokensResponse ;
79
+ return new ProvideSemanticTokensResponse ( new Array < Array < number > > ( ) , version ) ;
47
80
}
48
81
}
0 commit comments