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 {
7373 ) ;
7474 }
7575
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+
7689 const tokens = await vscode . commands . executeCommand < vscode . SemanticTokens > (
7790 'vscode.provideDocumentRangeSemanticTokens' ,
7891 razorDocument . csharpDocument . uri ,
@@ -92,4 +105,15 @@ export class SemanticTokensRangeHandler {
92105 semanticTokensParams . requiredHostDocumentVersion
93106 ) ;
94107 }
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+ }
95119}
You can’t perform that action at this time.
0 commit comments