-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml-validation.ts
More file actions
771 lines (684 loc) · 23.2 KB
/
Copy pathhtml-validation.ts
File metadata and controls
771 lines (684 loc) · 23.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
import path from "path";
import vscode from "vscode";
import { Parser, DomHandler } from "htmlparser2";
import {
getLineAndColumnFromIndex,
CollectedClassInfo,
ViewResolution,
resolveViewBinding,
createClassInfoLookup,
getRelatedTsFiles,
loadClassInfosFromFiles,
filterScreenLikeClasses,
collectActionProperties,
parseConfigObject,
filterClassesBySource,
} from "../../utils";
import { findParentViewName } from "../../providers/html-shared";
import { getIncludeMetadata } from "../../services/include-service";
import { getScreenTemplates } from "../../services/screen-template-service";
import { getClientControlsMetadata, ClientControlMetadata } from "../../services/client-controls-service";
import { AcuMateContext } from "../../plugin-context";
import {
getBaseScreenDocument,
isCustomizationSelectorAttribute,
queryBaseScreenElements,
BaseScreenDocument,
getCustomizationSelectorAttributes,
} from "../../services/screen-html-service";
import { createSuppressionEngine, SuppressionEngine } from "../../diagnostics/suppression";
// The validator turns the TypeScript model into CollectedClassInfo entries for every PXScreen/PXView
// and then uses that metadata when validating the HTML DOM.
const includeIntrinsicAttributes = new Set(["id", "class", "style", "slot"]);
const idOptionalTags = new Set(["qp-field", "qp-label", "qp-include"]);
function pushHtmlDiagnostic(
diagnostics: vscode.Diagnostic[],
suppression: SuppressionEngine,
range: vscode.Range,
message: string,
severity: vscode.DiagnosticSeverity = vscode.DiagnosticSeverity.Warning
) {
if (suppression.isSuppressed(range.start.line, "htmlValidator")) {
return;
}
diagnostics.push({
severity,
range,
message,
source: "htmlValidator",
code: "htmlValidator",
});
}
// Entrypoint invoked by the extension whenever an HTML file should be validated.
export async function validateHtmlFile(document: vscode.TextDocument) {
const diagnostics: vscode.Diagnostic[] = [];
const filePath = document.uri.fsPath;
const content = document.getText();
const suppression = createSuppressionEngine(content, "html");
const tsFilePaths = getRelatedTsFiles(filePath);
// Each CollectedClassInfo entry represents a TypeScript class along with a map of its
// properties (PXActionState, PXView, PXViewCollection, PXFieldState) including inherited ones.
const classProperties = tsFilePaths.length ? loadClassInfosFromFiles(tsFilePaths) : [];
const relevantClassInfos = filterClassesBySource(classProperties, tsFilePaths);
// Parse the HTML content
const workspaceRoots = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath);
const screenTemplateNames = new Set(
getScreenTemplates({ startingPath: filePath, workspaceRoots })
);
const controlMetadata = new Map(
getClientControlsMetadata({ startingPath: filePath, workspaceRoots }).map((control) => [control.tagName.toLowerCase(), control])
);
const baseScreenDocument = getBaseScreenDocument(filePath);
const handler = new DomHandler(
(error, dom): void => {
if (error) {
const range = new vscode.Range(0, 0, 0, 0);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`Parsing error: ${error.message}`,
vscode.DiagnosticSeverity.Error
);
} else {
// Custom validation logic
// Custom validation logic goes here
validateDom(
dom,
diagnostics,
classProperties,
relevantClassInfos,
content,
filePath,
workspaceRoots,
screenTemplateNames,
controlMetadata,
baseScreenDocument,
suppression,
undefined,
false
);
}
},
{
withEndIndices: true,
withStartIndices: true,
}
);
const parser = new Parser(handler);
parser.write(content);
parser.end();
// Report diagnostics back to VS Code
AcuMateContext.HtmlValidator.set(document.uri, diagnostics);
}
// Traverses the DOM tree, resolving view bindings to PXView classes so we can validate
// qp-fieldset nodes and their child field nodes against the TypeScript metadata.
function validateDom(
dom: any[],
diagnostics: vscode.Diagnostic[],
classProperties: CollectedClassInfo[],
relevantClassInfos: CollectedClassInfo[],
content: string,
htmlFilePath: string,
workspaceRoots: string[] | undefined,
screenTemplateNames: Set<string>,
controlMetadata: Map<string, ClientControlMetadata>,
baseScreenDocument: BaseScreenDocument | undefined,
suppression: SuppressionEngine,
panelViewContext?: CollectedClassInfo,
isInsideDataFeed = false
) {
const classInfoMap = createClassInfoLookup(classProperties);
const screenClasses = filterScreenLikeClasses(relevantClassInfos);
const actionLookup = collectActionProperties(screenClasses);
const hasScreenMetadata = screenClasses.length > 0;
const canValidateActions = classProperties.length > 0;
const viewResolutionCache = new Map<string, ViewResolution | undefined>();
// Screen classes contain PXView and PXViewCollection properties. We cache resolutions so
// repeated use of the same view name does not require scanning every screen class again.
function resolveView(viewName: string | undefined): ViewResolution | undefined {
if (!viewName) {
return undefined;
}
if (viewResolutionCache.has(viewName)) {
return viewResolutionCache.get(viewName);
}
const resolution = resolveViewBinding(viewName, screenClasses, classInfoMap);
viewResolutionCache.set(viewName, resolution);
return resolution;
}
// Custom validation logic goes here
dom.forEach((node) => {
let nextPanelViewContext = panelViewContext;
const normalizedTagName =
node.type === "tag" && typeof node.name === "string" ? node.name.toLowerCase() : "";
const elementId = node.type === "tag" ? getElementId(node) : "";
const nodeIsDataFeed = normalizedTagName === "qp-data-feed";
const currentDataFeedContext = isInsideDataFeed || nodeIsDataFeed;
if (node.type === "tag") {
const requiresIdAttribute =
normalizedTagName === "qp-panel" ||
(normalizedTagName && controlMetadata.has(normalizedTagName) && !idOptionalTags.has(normalizedTagName));
if (requiresIdAttribute && !elementId.length) {
const range = getRange(content, node);
const message =
normalizedTagName === "qp-panel"
? "The <qp-panel> element must define an id attribute."
: `The <${node.name}> element must define an id attribute.`;
pushHtmlDiagnostic(diagnostics, suppression, range, message);
}
validateCustomizationSelectors(node);
}
if (
hasScreenMetadata &&
node.type === "tag" &&
node.name === "qp-fieldset" &&
node.attribs[`view.bind`]
) {
const viewName = node.attribs[`view.bind`];
const viewResolution = resolveView(viewName);
const hasValidView =
viewResolution &&
viewResolution.property.viewClassName &&
viewResolution.viewClass &&
viewResolution.viewClass.type === "PXView";
if (!hasValidView) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"The <qp-fieldset> element must be bound to a valid view."
);
}
}
if (hasScreenMetadata && node.type === "tag" && node.name === "qp-panel") {
if (elementId.length) {
const viewResolution = resolveView(elementId);
if (!viewResolution) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"The <qp-panel> id must reference a valid view."
);
} else if (viewResolution.viewClass) {
nextPanelViewContext = viewResolution.viewClass;
}
}
}
if (hasScreenMetadata && node.type === "tag" && node.name === "using" && node.attribs.view) {
const viewName = node.attribs.view;
const viewResolution = resolveView(viewName);
const hasValidView =
viewResolution &&
viewResolution.property.viewClassName &&
viewResolution.viewClass &&
viewResolution.viewClass.type === "PXView";
if (!hasValidView) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"The <using> element must reference a valid view."
);
}
}
const actionBinding = node.attribs?.["state.bind"];
if (canValidateActions && typeof actionBinding === "string" && actionBinding.length) {
const panelHasAction = panelViewContext?.properties.get(actionBinding)?.kind === "action";
if (!actionLookup.has(actionBinding) && !panelHasAction) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"The state.bind attribute must reference a valid PXAction."
);
}
}
if (node.type === "tag" && node.name === "qp-include") {
validateIncludeNode(node, diagnostics, content, htmlFilePath, workspaceRoots, suppression);
}
if (
node.type === "tag" &&
node.name === "qp-template" &&
typeof node.attribs?.name === "string" &&
node.attribs.name.length
) {
validateTemplateName(node.attribs.name, node, currentDataFeedContext);
}
if (
hasScreenMetadata &&
node.type === "tag" &&
node.name === "qp-field" &&
typeof node.attribs?.["control-state.bind"] === "string" &&
node.attribs["control-state.bind"].length
) {
validateControlStateBinding(node.attribs["control-state.bind"], node);
}
if (
node.type === "tag" &&
typeof node.attribs?.["config.bind"] === "string" &&
node.attribs["config.bind"].length
) {
validateConfigBinding(node.attribs["config.bind"], node);
}
if (
node.type === "tag" &&
(node.name === "field" || node.name === "qp-field") &&
typeof node.attribs?.["control-type"] === "string"
) {
validateControlTypeAttribute(node);
}
if (
hasScreenMetadata &&
node.type === "tag" &&
node.name === "field" &&
node.attribs.name
) {
const viewSpecified = node.attribs.name.includes(".");
const [viewFromNameAttribute, fieldFromNameAttribute] = viewSpecified ? node.attribs.name.split(".") : [];
const isUnboundReplacement =
Object.prototype.hasOwnProperty.call(node.attribs, "unbound") &&
Object.prototype.hasOwnProperty.call(node.attribs, "replace-content");
if (!isUnboundReplacement) {
let viewName = viewSpecified ? viewFromNameAttribute : findParentViewName(node);
if (!viewName) {
viewName = getViewNameFromCustomizationSelectors(node);
}
const fieldName = viewSpecified ? fieldFromNameAttribute : node.attribs.name;
const viewResolution = resolveView(viewName);
const viewClass = viewResolution?.viewClass;
const fieldProperty = viewClass?.properties.get(fieldName);
const isValidField = fieldProperty?.kind === "field";
if (!isValidField) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
viewName
? `The field "${fieldName}" is not defined on view "${viewName}".`
: "The <field> element must be bound to a valid field."
);
}
}
}
if ((<any>node).children) {
validateDom(
(<any>node).children,
diagnostics,
classProperties,
relevantClassInfos,
content,
htmlFilePath,
workspaceRoots,
screenTemplateNames,
controlMetadata,
baseScreenDocument,
suppression,
nextPanelViewContext,
currentDataFeedContext
);
}
});
function validateTemplateName(templateName: string, node: any, insideDataFeed: boolean) {
const normalizedTemplateName = templateName.trim();
if (normalizedTemplateName.startsWith("record-") && !insideDataFeed) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"Templates prefixed with record- can only be used inside a <qp-data-feed> element."
);
return;
}
if (!screenTemplateNames.size) {
return;
}
if (!screenTemplateNames.has(normalizedTemplateName)) {
const range = getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The qp-template name "${normalizedTemplateName}" is not one of the predefined screen templates.`
);
}
}
function validateCustomizationSelectors(node: any) {
if (!baseScreenDocument) {
return;
}
forEachCustomizationSelector(node, (attributeName, rawValue, normalizedValue) => {
const range =
getAttributeValueRange(content, node, attributeName, rawValue) ?? getRange(content, node);
const { nodes, error } = queryBaseScreenElements(baseScreenDocument, normalizedValue);
if (error) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The ${attributeName} selector "${rawValue}" is not a valid CSS selector (${error}).`
);
return;
}
if (!nodes.length) {
const baseName = path.basename(baseScreenDocument.filePath);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The ${attributeName} selector "${rawValue}" does not match any elements in ${baseName}.`
);
}
});
}
function getViewNameFromCustomizationSelectors(node: any): string | undefined {
if (!baseScreenDocument) {
return undefined;
}
let selectorViewName: string | undefined;
forEachCustomizationSelector(node, (_attributeName, _rawValue, normalizedValue) => {
if (selectorViewName) {
return;
}
const { nodes, error } = queryBaseScreenElements(baseScreenDocument, normalizedValue);
if (error || !nodes.length) {
return;
}
for (const target of nodes) {
const candidateViewName = findParentViewName(target);
if (candidateViewName) {
selectorViewName = candidateViewName;
return;
}
}
});
return selectorViewName;
}
function forEachCustomizationSelector(
node: any,
callback: (attributeName: string, rawValue: string, normalizedValue: string) => void
) {
if (!node?.attribs) {
return;
}
for (const [attributeName, attributeValue] of Object.entries(node.attribs)) {
if (!isCustomizationSelectorAttribute(attributeName) || typeof attributeValue !== "string") {
continue;
}
const normalizedValue = attributeValue.trim();
if (!normalizedValue.length) {
continue;
}
callback(attributeName, attributeValue, normalizedValue);
}
}
function validateConfigBinding(bindingValue: string, node: any) {
const trimmed = bindingValue.trim();
if (!trimmed.startsWith("{")) {
return;
}
const controlName = typeof node.name === "string" ? node.name.toLowerCase() : undefined;
const control = controlName ? controlMetadata.get(controlName) : undefined;
const definition = control?.config?.definition;
if (!definition) {
return;
}
const configObject = parseConfigObject(bindingValue);
const range = getRange(content, node);
if (!configObject) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The ${node.name} config.bind value must be valid object matching ${definition.typeName}.`
);
return;
}
const providedKeys = new Set(Object.keys(configObject));
// commented out to reduce noise in diagnostics
/*for (const property of definition.properties) {
if (!property.optional && !providedKeys.has(property.name)) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The ${node.name} config.bind is missing required property "${property.name}".`
);
}
}*/
for (const key of providedKeys) {
if (!definition.properties.some((property) => property.name === key)) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The ${node.name} config.bind property "${key}" is not defined by ${definition.typeName}.`
);
}
}
}
function validateControlTypeAttribute(node: any) {
if (!controlMetadata.size) {
return;
}
const rawValue = node.attribs?.["control-type"];
if (typeof rawValue !== "string") {
return;
}
const normalizedValue = rawValue.trim();
if (!normalizedValue.length) {
return;
}
const metadata = controlMetadata.get(normalizedValue.toLowerCase());
if (metadata) {
return;
}
const range =
getAttributeValueRange(content, node, "control-type", rawValue) ?? getRange(content, node);
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The control-type value "${normalizedValue}" does not match any known qp-controls.`
);
}
function validateControlStateBinding(bindingValue: string, node: any) {
const parts = bindingValue.split(".");
const range = getRange(content, node);
if (parts.length !== 2) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"The control-state.bind attribute must use the <view>.<field> format."
);
return;
}
const viewName = parts[0]?.trim();
const fieldName = parts[1]?.trim();
if (!viewName || !fieldName) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
"The control-state.bind attribute must include both a view and field name."
);
return;
}
const viewResolution = resolveView(viewName);
const viewClass = viewResolution?.viewClass;
if (!viewClass) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The control-state.bind attribute references unknown view "${viewName}".`
);
return;
}
const fieldProperty = viewClass.properties.get(fieldName);
if (!fieldProperty || fieldProperty.kind !== "field") {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The control-state.bind attribute references unknown field "${fieldName}" on view "${viewName}".`
);
}
}
}
function validateIncludeNode(
node: any,
diagnostics: vscode.Diagnostic[],
content: string,
htmlFilePath: string,
workspaceRoots: string[] | undefined,
suppression: SuppressionEngine
) {
const includeUrl = node.attribs?.url;
if (typeof includeUrl !== "string" || !includeUrl.length) {
return;
}
const metadata = getIncludeMetadata({
includeUrl,
sourceHtmlPath: htmlFilePath,
workspaceRoots,
});
if (!metadata || metadata.parameters.length === 0) {
return;
}
const range = getRange(content, node);
const providedAttributes = node.attribs ?? {};
const parameterMap = new Map(metadata.parameters.map((param) => [param.name, param]));
for (const parameter of metadata.parameters) {
if (parameter.required && !Object.prototype.hasOwnProperty.call(providedAttributes, parameter.name)) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The qp-include is missing required parameter "${parameter.name}".`
);
}
}
for (const attributeName of Object.keys(providedAttributes)) {
if (attributeName === "url" || shouldIgnoreIncludeAttribute(attributeName)) {
continue;
}
if (!parameterMap.has(attributeName)) {
pushHtmlDiagnostic(
diagnostics,
suppression,
range,
`The qp-include attribute "${attributeName}" is not defined by the include template.`
);
}
}
}
function shouldIgnoreIncludeAttribute(attributeName: string): boolean {
if (!attributeName) {
return true;
}
if (includeIntrinsicAttributes.has(attributeName)) {
return true;
}
if (attributeName.startsWith("data-") || attributeName.startsWith("aria-")) {
return true;
}
if (attributeName.includes(".")) {
return true;
}
return false;
}
function getAttributeValueRange(
content: string,
node: any,
attributeName: string,
attributeValue: string
): vscode.Range | undefined {
if (typeof node.startIndex !== "number" || typeof node.endIndex !== "number") {
return undefined;
}
const sliceStart = node.startIndex;
const sliceEnd = node.endIndex;
const slice = content.substring(sliceStart, sliceEnd + 1);
const lowerSlice = slice.toLowerCase();
const lowerAttr = attributeName.toLowerCase();
let searchIndex = 0;
while (searchIndex < lowerSlice.length) {
const attrIndex = lowerSlice.indexOf(lowerAttr, searchIndex);
if (attrIndex === -1) {
break;
}
const precedingChar = attrIndex > 0 ? lowerSlice[attrIndex - 1] : undefined;
if (precedingChar && /[A-Za-z0-9_.:-]/.test(precedingChar)) {
searchIndex = attrIndex + lowerAttr.length;
continue;
}
let cursor = attrIndex + lowerAttr.length;
while (cursor < slice.length && /\s/.test(slice[cursor])) {
cursor++;
}
if (cursor >= slice.length || slice[cursor] !== "=") {
searchIndex = attrIndex + lowerAttr.length;
continue;
}
cursor++;
while (cursor < slice.length && /\s/.test(slice[cursor])) {
cursor++;
}
if (cursor >= slice.length) {
break;
}
let valueStart = cursor;
let valueEnd = cursor;
if (slice[cursor] === '"' || slice[cursor] === "'") {
const quote = slice[cursor];
valueStart = cursor + 1;
valueEnd = valueStart;
while (valueEnd < slice.length && slice[valueEnd] !== quote) {
valueEnd++;
}
if (valueEnd >= slice.length) {
valueEnd = slice.length;
}
} else {
while (valueEnd < slice.length && !/[\s>]/.test(slice[valueEnd])) {
valueEnd++;
}
}
const candidate = slice.substring(valueStart, valueEnd);
if (candidate === attributeValue) {
const absoluteStart = sliceStart + valueStart;
const absoluteEnd = sliceStart + valueEnd;
const startPosition = getLineAndColumnFromIndex(content, absoluteStart);
const endPosition = getLineAndColumnFromIndex(content, absoluteEnd);
return new vscode.Range(
new vscode.Position(startPosition.line, startPosition.column),
new vscode.Position(endPosition.line, endPosition.column)
);
}
searchIndex = valueEnd + 1;
}
return undefined;
}
function getElementId(node: any): string {
const rawId = node.attribs?.id;
return typeof rawId === "string" ? rawId.trim() : "";
}
// Converts parser indices into VS Code ranges for diagnostics.
function getRange(content: string, node: any) {
const startPosition = getLineAndColumnFromIndex(content, node.startIndex);
const endPosition = getLineAndColumnFromIndex(content, node.endIndex);
const range = new vscode.Range(
new vscode.Position(startPosition.line, startPosition.column),
new vscode.Position(endPosition.line, endPosition.column)
);
return range;
}