8
8
* DeltaXML Ltd. - XPath/XSLT Lexer/Syntax Highlighter
9
9
*/
10
10
import * as vscode from 'vscode' ;
11
- import { XPathLexer , ExitCondition , LexPosition , Token } from './xpLexer' ;
11
+ import { XPathLexer , ExitCondition , LexPosition , Token , BaseToken } from './xpLexer' ;
12
12
import { XMLDocumentFormattingProvider } from './xmlDocumentFormattingProvider' ;
13
13
import { SaxonTaskProvider } from './saxonTaskProvider' ;
14
14
import { SaxonJsTaskProvider } from './saxonJsTaskProvider' ;
15
15
import { XSLTConfiguration , XPathConfiguration , XMLConfiguration , XSLTLightConfiguration , DCPConfiguration , SchConfiguration } from './languageConfigurations' ;
16
16
import { SelectionType , XsltSymbolProvider } from './xsltSymbolProvider' ;
17
- import { XslLexer , LanguageConfiguration , DocumentTypes } from './xslLexer' ;
17
+ import { XslLexer , LanguageConfiguration , DocumentTypes , GlobalInstructionData , GlobalInstructionType } from './xslLexer' ;
18
18
import { DocumentChangeHandler } from './documentChangeHandler' ;
19
19
import { on } from 'process' ;
20
20
import { XsltDefinitionProvider } from './xsltDefinitionProvider' ;
@@ -257,13 +257,41 @@ export function activate(context: vscode.ExtensionContext) {
257
257
258
258
}
259
259
260
- class XPathSemanticTokensProvider implements vscode . DocumentSemanticTokensProvider {
260
+ export class XPathSemanticTokensProvider implements vscode . DocumentSemanticTokensProvider {
261
261
private xpLexer = new XPathLexer ( ) ;
262
262
private collection : vscode . DiagnosticCollection ;
263
263
public constructor ( collection : vscode . DiagnosticCollection ) {
264
264
this . collection = collection ;
265
265
}
266
266
267
+ private static globalInstructionData : GlobalInstructionData [ ] = [ ] ;
268
+
269
+ public static getGlobalInstructionData ( ) {
270
+ return XPathSemanticTokensProvider . globalInstructionData ;
271
+ }
272
+
273
+ public static setVariableNames = ( names : string [ ] ) => {
274
+ const data : GlobalInstructionData [ ] = [ ] ;
275
+
276
+ names . forEach ( ( name ) => {
277
+ const token : BaseToken = {
278
+ line : 1 ,
279
+ startCharacter : 0 ,
280
+ length : 1 ,
281
+ value : name ,
282
+ tokenType : 0
283
+ }
284
+ const variableInstruction : GlobalInstructionData = {
285
+ type : GlobalInstructionType . Variable ,
286
+ name : name ,
287
+ token : token ,
288
+ idNumber : 0
289
+ }
290
+ data . push ( variableInstruction ) ;
291
+ } ) ;
292
+ XPathSemanticTokensProvider . globalInstructionData = data ;
293
+ }
294
+
267
295
async provideDocumentSemanticTokens ( document : vscode . TextDocument , token : vscode . CancellationToken ) : Promise < vscode . SemanticTokens > {
268
296
const lexPosition : LexPosition = { line : 0 , startCharacter : 0 , documentOffset : 0 } ;
269
297
this . xpLexer . documentTokens = [ ] ;
@@ -277,7 +305,7 @@ class XPathSemanticTokensProvider implements vscode.DocumentSemanticTokensProvid
277
305
}
278
306
279
307
private reportProblems ( allTokens : Token [ ] , document : vscode . TextDocument ) {
280
- let diagnostics = XsltTokenDiagnostics . calculateDiagnostics ( XPathConfiguration . configuration , DocumentTypes . XPath , document , allTokens , DocumentChangeHandler . lastXMLDocumentGlobalData , [ ] , [ ] ) ;
308
+ let diagnostics = XsltTokenDiagnostics . calculateDiagnostics ( XPathConfiguration . configuration , DocumentTypes . XPath , document , allTokens , DocumentChangeHandler . lastXMLDocumentGlobalData , XPathSemanticTokensProvider . globalInstructionData , [ ] ) ;
281
309
if ( diagnostics . length > 0 ) {
282
310
this . collection . set ( document . uri , diagnostics ) ;
283
311
} else {
0 commit comments