@stacksjs/stx-vscode 0.2.351 → 0.2.353
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +84 -77
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5654,6 +5654,88 @@ function createFoldingRangeProvider() {
|
|
|
5654
5654
|
}
|
|
5655
5655
|
// ../vscode/src/providers/semanticTokensProvider.ts
|
|
5656
5656
|
import * as vscode11 from "vscode";
|
|
5657
|
+
|
|
5658
|
+
// ../vscode/src/providers/semanticTokenSpans.ts
|
|
5659
|
+
function semanticTokenSpans(text) {
|
|
5660
|
+
const spans = [];
|
|
5661
|
+
const controlFlowDirectives = ["if", "else", "elseif", "unless", "endif", "endunless", "switch", "case", "default", "endswitch"];
|
|
5662
|
+
const loopDirectives = ["for", "foreach", "while", "forelse", "endfor", "endforeach", "endwhile", "endforelse", "break", "continue"];
|
|
5663
|
+
const functionDirectives = ["component", "include", "includeIf", "includeWhen", "includeUnless", "includeFirst", "extends", "use"];
|
|
5664
|
+
const contentDirectives = ["ts", "js", "script", "css", "markdown", "raw", "verbatim", "json"];
|
|
5665
|
+
const directiveRegex = /@(\w+)/g;
|
|
5666
|
+
let match;
|
|
5667
|
+
match = directiveRegex.exec(text);
|
|
5668
|
+
while (match !== null) {
|
|
5669
|
+
const directiveName = match[1];
|
|
5670
|
+
const startChar = match.index;
|
|
5671
|
+
const length = match[0].length;
|
|
5672
|
+
let tokenType;
|
|
5673
|
+
if (controlFlowDirectives.includes(directiveName)) {
|
|
5674
|
+
tokenType = "keyword";
|
|
5675
|
+
} else if (loopDirectives.includes(directiveName)) {
|
|
5676
|
+
tokenType = "keyword";
|
|
5677
|
+
} else if (functionDirectives.includes(directiveName)) {
|
|
5678
|
+
tokenType = "function";
|
|
5679
|
+
} else if (contentDirectives.includes(directiveName)) {
|
|
5680
|
+
tokenType = "keyword";
|
|
5681
|
+
} else if (directiveName.startsWith("end")) {
|
|
5682
|
+
tokenType = "keyword";
|
|
5683
|
+
} else {
|
|
5684
|
+
tokenType = "function";
|
|
5685
|
+
}
|
|
5686
|
+
spans.push({ start: startChar, end: startChar + length, type: tokenType });
|
|
5687
|
+
match = directiveRegex.exec(text);
|
|
5688
|
+
}
|
|
5689
|
+
const commentRegex = /\{\{--.*?--\}\}/g;
|
|
5690
|
+
let commentMatch;
|
|
5691
|
+
commentMatch = commentRegex.exec(text);
|
|
5692
|
+
while (commentMatch !== null) {
|
|
5693
|
+
const startChar = commentMatch.index;
|
|
5694
|
+
const length = commentMatch[0].length;
|
|
5695
|
+
spans.push({ start: startChar, end: startChar + length, type: "comment" });
|
|
5696
|
+
commentMatch = commentRegex.exec(text);
|
|
5697
|
+
}
|
|
5698
|
+
const expressionRegex = /\{\{(?!--)(.+?)\}\}/g;
|
|
5699
|
+
let exprMatch;
|
|
5700
|
+
exprMatch = expressionRegex.exec(text);
|
|
5701
|
+
while (exprMatch !== null) {
|
|
5702
|
+
const content = exprMatch[1];
|
|
5703
|
+
const startChar = exprMatch.index + 2;
|
|
5704
|
+
const variableRegex = /\b([a-z_$][\w$]*)\b/gi;
|
|
5705
|
+
let varMatch;
|
|
5706
|
+
varMatch = variableRegex.exec(content);
|
|
5707
|
+
while (varMatch !== null) {
|
|
5708
|
+
const varName = varMatch[1];
|
|
5709
|
+
const varStartChar = startChar + varMatch.index;
|
|
5710
|
+
if (["true", "false", "null", "undefined", "const", "let", "var", "function", "return"].includes(varName)) {
|
|
5711
|
+
varMatch = variableRegex.exec(content);
|
|
5712
|
+
continue;
|
|
5713
|
+
}
|
|
5714
|
+
spans.push({ start: varStartChar, end: varStartChar + varName.length, type: "variable" });
|
|
5715
|
+
varMatch = variableRegex.exec(content);
|
|
5716
|
+
}
|
|
5717
|
+
exprMatch = expressionRegex.exec(text);
|
|
5718
|
+
}
|
|
5719
|
+
const directiveWithParamsRegex = /@\w+\s*\(([^)]+)\)/g;
|
|
5720
|
+
let paramMatch;
|
|
5721
|
+
paramMatch = directiveWithParamsRegex.exec(text);
|
|
5722
|
+
while (paramMatch !== null) {
|
|
5723
|
+
const params = paramMatch[1];
|
|
5724
|
+
const paramsStart = paramMatch.index + paramMatch[0].indexOf("(") + 1;
|
|
5725
|
+
const stringRegex = /(['"`])(?:[^\\]|\\.)*?\1/g;
|
|
5726
|
+
let stringMatch;
|
|
5727
|
+
stringMatch = stringRegex.exec(params);
|
|
5728
|
+
while (stringMatch !== null) {
|
|
5729
|
+
const stringStart = paramsStart + stringMatch.index;
|
|
5730
|
+
spans.push({ start: stringStart, end: stringStart + stringMatch[0].length, type: "string" });
|
|
5731
|
+
stringMatch = stringRegex.exec(params);
|
|
5732
|
+
}
|
|
5733
|
+
paramMatch = directiveWithParamsRegex.exec(text);
|
|
5734
|
+
}
|
|
5735
|
+
return spans;
|
|
5736
|
+
}
|
|
5737
|
+
|
|
5738
|
+
// ../vscode/src/providers/semanticTokensProvider.ts
|
|
5657
5739
|
var tokenTypes = [
|
|
5658
5740
|
"keyword",
|
|
5659
5741
|
"function",
|
|
@@ -5679,84 +5761,9 @@ function createSemanticTokensProvider() {
|
|
|
5679
5761
|
return new vscode11.SemanticTokensBuilder(legend).build();
|
|
5680
5762
|
}
|
|
5681
5763
|
const tokensBuilder = new vscode11.SemanticTokensBuilder(legend);
|
|
5682
|
-
const controlFlowDirectives = ["if", "else", "elseif", "unless", "endif", "endunless", "switch", "case", "default", "endswitch"];
|
|
5683
|
-
const loopDirectives = ["for", "foreach", "while", "forelse", "endfor", "endforeach", "endwhile", "endforelse", "break", "continue"];
|
|
5684
|
-
const functionDirectives = ["component", "include", "includeIf", "includeWhen", "includeUnless", "includeFirst", "extends", "use"];
|
|
5685
|
-
const contentDirectives = ["ts", "js", "script", "css", "markdown", "raw", "verbatim", "json"];
|
|
5686
5764
|
for (let lineNum = 0;lineNum < document.lineCount; lineNum++) {
|
|
5687
|
-
const
|
|
5688
|
-
|
|
5689
|
-
const directiveRegex = /@(\w+)/g;
|
|
5690
|
-
let match;
|
|
5691
|
-
match = directiveRegex.exec(text);
|
|
5692
|
-
while (match !== null) {
|
|
5693
|
-
const directiveName = match[1];
|
|
5694
|
-
const startChar = match.index;
|
|
5695
|
-
const length = match[0].length;
|
|
5696
|
-
let tokenType;
|
|
5697
|
-
if (controlFlowDirectives.includes(directiveName)) {
|
|
5698
|
-
tokenType = "keyword";
|
|
5699
|
-
} else if (loopDirectives.includes(directiveName)) {
|
|
5700
|
-
tokenType = "keyword";
|
|
5701
|
-
} else if (functionDirectives.includes(directiveName)) {
|
|
5702
|
-
tokenType = "function";
|
|
5703
|
-
} else if (contentDirectives.includes(directiveName)) {
|
|
5704
|
-
tokenType = "keyword";
|
|
5705
|
-
} else if (directiveName.startsWith("end")) {
|
|
5706
|
-
tokenType = "keyword";
|
|
5707
|
-
} else {
|
|
5708
|
-
tokenType = "function";
|
|
5709
|
-
}
|
|
5710
|
-
const tokenTypeIndex = tokenTypes.indexOf(tokenType);
|
|
5711
|
-
if (tokenTypeIndex >= 0) {
|
|
5712
|
-
tokensBuilder.push(new vscode11.Range(new vscode11.Position(lineNum, startChar), new vscode11.Position(lineNum, startChar + length)), tokenType);
|
|
5713
|
-
}
|
|
5714
|
-
match = directiveRegex.exec(text);
|
|
5715
|
-
}
|
|
5716
|
-
const commentRegex = /\{\{--.*?--\}\}/g;
|
|
5717
|
-
let commentMatch;
|
|
5718
|
-
commentMatch = commentRegex.exec(text);
|
|
5719
|
-
while (commentMatch !== null) {
|
|
5720
|
-
const startChar = commentMatch.index;
|
|
5721
|
-
const length = commentMatch[0].length;
|
|
5722
|
-
tokensBuilder.push(new vscode11.Range(new vscode11.Position(lineNum, startChar), new vscode11.Position(lineNum, startChar + length)), "comment");
|
|
5723
|
-
commentMatch = commentRegex.exec(text);
|
|
5724
|
-
}
|
|
5725
|
-
const expressionRegex = /\{\{(?!--)(.+?)\}\}/;
|
|
5726
|
-
let exprMatch;
|
|
5727
|
-
exprMatch = expressionRegex.exec(text);
|
|
5728
|
-
while (exprMatch !== null) {
|
|
5729
|
-
const content = exprMatch[1];
|
|
5730
|
-
const startChar = exprMatch.index + 2;
|
|
5731
|
-
const variableRegex = /\b([a-z_$][\w$]*)\b/gi;
|
|
5732
|
-
let varMatch;
|
|
5733
|
-
varMatch = variableRegex.exec(content);
|
|
5734
|
-
while (varMatch !== null) {
|
|
5735
|
-
const varName = varMatch[1];
|
|
5736
|
-
const varStartChar = startChar + varMatch.index;
|
|
5737
|
-
if (["true", "false", "null", "undefined", "const", "let", "var", "function", "return"].includes(varName)) {
|
|
5738
|
-
continue;
|
|
5739
|
-
}
|
|
5740
|
-
tokensBuilder.push(new vscode11.Range(new vscode11.Position(lineNum, varStartChar), new vscode11.Position(lineNum, varStartChar + varName.length)), "variable");
|
|
5741
|
-
varMatch = variableRegex.exec(content);
|
|
5742
|
-
}
|
|
5743
|
-
exprMatch = expressionRegex.exec(text);
|
|
5744
|
-
}
|
|
5745
|
-
const directiveWithParamsRegex = /@\w+\s*\(([^)]+)\)/;
|
|
5746
|
-
let paramMatch;
|
|
5747
|
-
paramMatch = directiveWithParamsRegex.exec(text);
|
|
5748
|
-
while (paramMatch !== null) {
|
|
5749
|
-
const params = paramMatch[1];
|
|
5750
|
-
const paramsStart = paramMatch.index + paramMatch[0].indexOf("(") + 1;
|
|
5751
|
-
const stringRegex = /(['"`])(?:[^\\]|\\.)*?\1/g;
|
|
5752
|
-
let stringMatch;
|
|
5753
|
-
stringMatch = stringRegex.exec(params);
|
|
5754
|
-
while (stringMatch !== null) {
|
|
5755
|
-
const stringStart = paramsStart + stringMatch.index;
|
|
5756
|
-
tokensBuilder.push(new vscode11.Range(new vscode11.Position(lineNum, stringStart), new vscode11.Position(lineNum, stringStart + stringMatch[0].length)), "string");
|
|
5757
|
-
stringMatch = stringRegex.exec(params);
|
|
5758
|
-
}
|
|
5759
|
-
paramMatch = directiveWithParamsRegex.exec(text);
|
|
5765
|
+
for (const span of semanticTokenSpans(document.lineAt(lineNum).text)) {
|
|
5766
|
+
tokensBuilder.push(new vscode11.Range(new vscode11.Position(lineNum, span.start), new vscode11.Position(lineNum, span.end)), span.type);
|
|
5760
5767
|
}
|
|
5761
5768
|
}
|
|
5762
5769
|
return tokensBuilder.build();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/stx-vscode",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.353",
|
|
5
5
|
"description": "stx language support for VS Code extensions to embed: the hovers, completions, diagnostics, grammar, snippets and language configuration behind the stx extension.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test": "bun test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@stacksjs/ts-css": "^0.3.
|
|
45
|
+
"@stacksjs/ts-css": "^0.3.7",
|
|
46
46
|
"prettier": "^3.9.9"
|
|
47
47
|
}
|
|
48
48
|
}
|