File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,19 @@ export class SemanticTokensRangeHandler {
73
73
) ;
74
74
}
75
75
76
+ if ( semanticTokensParams . requiredHostDocumentVersion == 1 ) {
77
+ // HACK: Workaround for https://github.com/dotnet/razor/issues/9197 to stop errors from being thrown.
78
+ // Sometimes we get asked for semantic tokens on v1, and we have sent a v1 to Roslyn, but its the wrong v1.
79
+ // To prevent Roslyn throwing, lets validate the range we're asking about with the generated document they
80
+ // would have seen.
81
+ const endLine = semanticTokensParams . ranges [ 0 ] . end . line ;
82
+ const lineCount = this . countLines ( razorDocument . csharpDocument . getContent ( ) ) ;
83
+
84
+ if ( lineCount < endLine ) {
85
+ return new ProvideSemanticTokensResponse ( this . emptyTokensResponse , - 1 ) ;
86
+ }
87
+ }
88
+
76
89
const tokens = await vscode . commands . executeCommand < vscode . SemanticTokens > (
77
90
'vscode.provideDocumentRangeSemanticTokens' ,
78
91
razorDocument . csharpDocument . uri ,
@@ -92,4 +105,15 @@ export class SemanticTokensRangeHandler {
92
105
semanticTokensParams . requiredHostDocumentVersion
93
106
) ;
94
107
}
108
+
109
+ private countLines ( text : string ) {
110
+ let lineCount = 0 ;
111
+ for ( const i of text ) {
112
+ if ( i === '\n' ) {
113
+ lineCount ++ ;
114
+ }
115
+ }
116
+
117
+ return lineCount ;
118
+ }
95
119
}
You can’t perform that action at this time.
0 commit comments