Skip to content

Commit 9164d6c

Browse files
committed
preparation for setting xpath variables in evaluation context
1 parent d4f325a commit 9164d6c

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

src/extension.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* DeltaXML Ltd. - XPath/XSLT Lexer/Syntax Highlighter
99
*/
1010
import * as vscode from 'vscode';
11-
import { XPathLexer, ExitCondition, LexPosition, Token } from './xpLexer';
11+
import { XPathLexer, ExitCondition, LexPosition, Token, BaseToken } from './xpLexer';
1212
import { XMLDocumentFormattingProvider } from './xmlDocumentFormattingProvider';
1313
import { SaxonTaskProvider } from './saxonTaskProvider';
1414
import { SaxonJsTaskProvider } from './saxonJsTaskProvider';
1515
import { XSLTConfiguration, XPathConfiguration, XMLConfiguration, XSLTLightConfiguration, DCPConfiguration, SchConfiguration } from './languageConfigurations';
1616
import { SelectionType, XsltSymbolProvider } from './xsltSymbolProvider';
17-
import { XslLexer, LanguageConfiguration, DocumentTypes } from './xslLexer';
17+
import { XslLexer, LanguageConfiguration, DocumentTypes, GlobalInstructionData, GlobalInstructionType } from './xslLexer';
1818
import { DocumentChangeHandler } from './documentChangeHandler';
1919
import { on } from 'process';
2020
import { XsltDefinitionProvider } from './xsltDefinitionProvider';
@@ -257,13 +257,41 @@ export function activate(context: vscode.ExtensionContext) {
257257

258258
}
259259

260-
class XPathSemanticTokensProvider implements vscode.DocumentSemanticTokensProvider {
260+
export class XPathSemanticTokensProvider implements vscode.DocumentSemanticTokensProvider {
261261
private xpLexer = new XPathLexer();
262262
private collection: vscode.DiagnosticCollection;
263263
public constructor(collection: vscode.DiagnosticCollection) {
264264
this.collection = collection;
265265
}
266266

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+
267295
async provideDocumentSemanticTokens(document: vscode.TextDocument, token: vscode.CancellationToken): Promise<vscode.SemanticTokens> {
268296
const lexPosition: LexPosition = { line: 0, startCharacter: 0, documentOffset: 0 };
269297
this.xpLexer.documentTokens = [];
@@ -277,7 +305,7 @@ class XPathSemanticTokensProvider implements vscode.DocumentSemanticTokensProvid
277305
}
278306

279307
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, []);
281309
if (diagnostics.length > 0) {
282310
this.collection.set(document.uri, diagnostics);
283311
} else {

src/testper.xsl

Whitespace-only changes.

src/xsltDefinitionProvider.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { XsltTokenCompletions } from './xsltTokenCompletions';
77
import { XSLTSchema, SchemaData } from './xsltSchema';
88
import { SchemaQuery } from './schemaQuery';
99
import { XsltPackage, XsltSymbolProvider } from './xsltSymbolProvider';
10-
import { ExitCondition, LexPosition, XPathLexer } from './xpLexer';
10+
import { BaseToken, ExitCondition, LexPosition, XPathLexer } from './xpLexer';
11+
import { XPathSemanticTokensProvider } from './extension';
1112

1213
interface ImportedGlobals {
1314
href: string,
@@ -47,11 +48,16 @@ export class XsltDefinitionProvider implements vscode.DefinitionProvider, vscode
4748
public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.Location | undefined> {
4849
const lexPosition: LexPosition = { line: 0, startCharacter: 0, documentOffset: 0 };
4950

50-
let allTokens = this.docType === DocumentTypes.XPath ?
51-
this.getXPLexer().analyse(document.getText(), ExitCondition.None, lexPosition) :
52-
this.xslLexer.analyse(document.getText());
51+
let allTokens: BaseToken[] = [];
52+
let globalInstructionData: GlobalInstructionData[] = [];
53+
if (this.docType === DocumentTypes.XPath) {
54+
allTokens = this.getXPLexer().analyse(document.getText(), ExitCondition.None, lexPosition);
55+
globalInstructionData = XPathSemanticTokensProvider.getGlobalInstructionData();
56+
} else {
57+
allTokens = this.xslLexer.analyse(document.getText());
58+
globalInstructionData = this.xslLexer.globalInstructionData;
59+
}
5360

54-
const globalInstructionData = this.xslLexer.globalInstructionData;
5561
const xsltPackages: XsltPackage[] = <XsltPackage[]>vscode.workspace.getConfiguration('XSLT.resources').get('xsltPackages');
5662

5763
// Import/include XSLT - ensuring no duplicates
@@ -100,11 +106,17 @@ export class XsltDefinitionProvider implements vscode.DefinitionProvider, vscode
100106
public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken, context: vscode.CompletionContext): Promise<vscode.CompletionItem[] | undefined> {
101107
const keepNameTests = true;
102108
const lexPosition: LexPosition = { line: 0, startCharacter: 0, documentOffset: 0 };
109+
110+
let allTokens: BaseToken[] = [];
111+
let globalInstructionData: GlobalInstructionData[] = [];
112+
if (this.docType === DocumentTypes.XPath) {
113+
allTokens = this.getXPLexer().analyse(document.getText(), ExitCondition.None, lexPosition);
114+
globalInstructionData = XPathSemanticTokensProvider.getGlobalInstructionData();
115+
} else {
116+
allTokens = this.xslLexer.analyse(document.getText(), keepNameTests);
117+
globalInstructionData = this.xslLexer.globalInstructionData;
118+
}
103119

104-
let allTokens = this.docType === DocumentTypes.XPath ?
105-
this.getXPLexer().analyse(document.getText(), ExitCondition.None, lexPosition) :
106-
this.xslLexer.analyse(document.getText(), keepNameTests);
107-
const globalInstructionData = this.xslLexer.globalInstructionData;
108120
const xsltPackages: XsltPackage[] = <XsltPackage[]>vscode.workspace.getConfiguration('XSLT.resources').get('xsltPackages');
109121

110122
// Import/include XSLT - ensuring no duplicates

src/xsltTokenDiagnostics.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,6 @@ export class XsltTokenDiagnostics {
328328
}
329329
});
330330

331-
if (docType === DocumentTypes.XPath) {
332-
importedGlobalVarNames.push('_');
333-
}
334-
335331
importedInstructionData.forEach((instruction) => {
336332
switch (instruction.type) {
337333
case GlobalInstructionType.Variable:

0 commit comments

Comments
 (0)