Skip to content

Commit 9cb5177

Browse files
committed
fix: Completions & tests
1 parent 441bf5a commit 9cb5177

13 files changed

Lines changed: 91288 additions & 11972 deletions

.vscode-test.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ export const config = {
1010
workspaceFolder: './src/test/',
1111
mocha: {
1212
reporterOptions: {
13-
maxDiffSize: 48000
13+
maxDiffSize: 32768
1414
}
15-
}
15+
},
16+
launchArgs: [
17+
"--disable-extension ms-vscode.js-debug" // is disabled in VSCode Web
18+
],
1619
};
1720

1821
export default defineConfig(

src/DiagnosticCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ function diagnosticsScopePostfix(diagnostics: Diagnostic[], document: vscode.Tex
13581358
if (scope.endsWith(candidatePostfix)) {
13591359
if (candidatePostfixes.scopes[scope] == 1
13601360
&& scope.length - candidatePostfix.length > 3) {
1361-
const spellingSuggestion = getSpellingSuggestion(scope, commonScopes, 2);
1361+
const spellingSuggestion = getSpellingSuggestion(scope, commonScopes, 1.99);
13621362
if (spellingSuggestion) {
13631363
diagnostics.push({
13641364
range,

src/Providers/CompletionItemProvider.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
153153
label: grammar.scopeName || `source.${grammar.language}`,
154154
description: grammar.language,
155155
},
156-
documentation: documentPath,
156+
documentation: relativePath,
157157
range: cursorRange,
158158
kind: vscode.CompletionItemKind.Variable,
159159
});
@@ -426,18 +426,20 @@ export const CompletionItemProvider: vscode.CompletionItemProvider = {
426426
}
427427
const candidateScopePostfix = '.' + candidatePostfixes.candidatePostfixes[0];
428428

429-
const mergedScopePostfix = mergeCandidatesScopePostfix(candidatePostfixes.cursorScope, candidatePostfixes.candidatePostfixes, true);
430-
if (mergedScopePostfix.candidatePostfix !== undefined) {
431-
completionItems.push({
432-
label: {
433-
label: candidatePostfixes.cursorScope,
434-
detail: mergedScopePostfix.scopePostfixEnding,
435-
},
436-
range: cursorRange,
437-
kind: vscode.CompletionItemKind.Text,
438-
sortText: ` ${candidatePostfixes.cursorScope}`,
439-
insertText: candidatePostfixes.cursorScope + mergedScopePostfix.scopePostfixEnding,
440-
});
429+
if (candidatePostfixes.cursorScope) {
430+
const mergedScopePostfix = mergeCandidatesScopePostfix(candidatePostfixes.cursorScope, candidatePostfixes.candidatePostfixes, true);
431+
if (mergedScopePostfix.candidatePostfix !== undefined) {
432+
completionItems.push({
433+
label: {
434+
label: candidatePostfixes.cursorScope,
435+
detail: mergedScopePostfix.candidatePostfixEnding,
436+
},
437+
range: cursorRange,
438+
kind: vscode.CompletionItemKind.Text,
439+
sortText: ` ${candidatePostfixes.cursorScope}`,
440+
insertText: candidatePostfixes.cursorScope + mergedScopePostfix.candidatePostfixEnding,
441+
});
442+
}
441443
}
442444

443445
for (const scope in themeScopes) {
@@ -864,7 +866,7 @@ export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node): {
864866
candidatePostfixes: string[];
865867
};
866868
export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node, position: vscode.Position): {
867-
cursorScope: string;
869+
cursorScope: string | undefined;
868870
scopes: { [scope: string]: number; };
869871
scopeCaptures: webTreeSitter.QueryCapture[];
870872
candidatePostfixes: string[];
@@ -886,6 +888,7 @@ export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node, positi
886888
(contentName (value (scope) @scope (.not-match? @scope "^(\\\\$0*[0-9]{1,3})+$")))
887889
(name_scopeName (value (scope) @scope (.not-match? @scope "^(\\\\$0*[0-9]{1,3})+$")))
888890
(injectionSelector (value (scope) @injectionScope (.not-match? @injectionScope "^(\\\\$0*[0-9]{1,3})+$")))
891+
(injections (injection (key (scope) @injectionScope (.not-match? @injectionScope "^(\\\\$0*[0-9]{1,3})+$"))))
889892
(include (value (scopeName) @includeScope (.not-match? @includeScope "^(\\\\$0*[0-9]{1,3})+$")))
890893
`;
891894
const scopeCaptures = queryNode(rootNode, scopeQuery);
@@ -962,7 +965,7 @@ export function findCandidateScopePostfixes(rootNode: webTreeSitter.Node, positi
962965
};
963966
}
964967

965-
export function mergeCandidatesScopePostfix(scope: string, candidates: readonly string[], merge?: boolean) {
968+
export function mergeCandidatesScopePostfix(scope: string, candidates: readonly string[], forceMerge?: boolean) {
966969
const subScopes: string[] = [];
967970
const scopeParts = scope.split('.');
968971

@@ -976,33 +979,41 @@ export function mergeCandidatesScopePostfix(scope: string, candidates: readonly
976979

977980
const candidatePostfix = candidates[0];
978981
if (candidatePostfix.startsWith(subScopePostfix)
979-
&& (merge || candidatePostfix.split('.')[0] != subScopePostfix)) {
982+
&& (forceMerge || candidatePostfix.split('.')[0] != subScopePostfix)) {
980983
return {
981-
scopePostfixEnding: candidatePostfix.slice(subScopePostfix.length),
982984
subScopePostfix,
983985
candidatePostfix,
986+
candidatePostfixEnding: candidatePostfix.slice(subScopePostfix.length),
984987
};
985988
}
986989
}
987990

988991
// Test for longest postfix
989992
for (let index = 1; index < scopeParts.length; index++) {
990993
const subScopePostfix = scopeParts.slice(index).join('.');
991-
if (!subScopePostfix) {
994+
if (!subScopePostfix && !forceMerge) {
992995
continue;
993996
}
994997

995998
for (const candidatePostfix of candidates) {
996999
if (candidatePostfix.startsWith(subScopePostfix)
997-
&& (merge || candidatePostfix/* .split('.')[0] */ != subScopePostfix)) {
1000+
&& (forceMerge || candidatePostfix/* .split('.')[0] */ != subScopePostfix)) {
9981001
return {
999-
scopePostfixEnding: candidatePostfix.slice(subScopePostfix.length),
10001002
subScopePostfix,
10011003
candidatePostfix,
1004+
candidatePostfixEnding: candidatePostfix.slice(subScopePostfix.length),
10021005
};
10031006
}
10041007
}
10051008
}
10061009

1010+
if (forceMerge) {
1011+
return {
1012+
subScopePostfix: scope,
1013+
candidatePostfix: candidates[0],
1014+
candidatePostfixEnding: '.' + candidates[0],
1015+
};
1016+
}
1017+
10071018
return { subScopes };
10081019
}

src/test/baselines/CodeActionsProvider.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@
712712
"title": "Ignore no reference warnings",
713713
"diagnostics": [
714714
{
715-
"startLineNumber": 110,
715+
"startLineNumber": 115,
716716
"startColumn": 4,
717717
"endLineNumber": 0,
718718
"endColumn": 13,

0 commit comments

Comments
 (0)