Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit df1da29

Browse files
authored
Merge pull request #164 from cschleiden/fix-duplicate-autocomplete
Fix duplicated auto-complete suggestions
2 parents 8d0acf1 + 99cca92 commit df1da29

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/workflow/diagnostics.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ export class WorkflowCompletionItemProvider
162162
vscode.CompletionItemKind.Constant
163163
);
164164

165+
// Fix the replacement range. By default VS Code looks for the current word, which leads to duplicate
166+
// replacements for something like `runs-|` which auto-completes to `runs-runs-on`
167+
const text = document.getText(
168+
new vscode.Range(
169+
position.line,
170+
Math.max(0, position.character - x.value.length),
171+
position.line,
172+
position.character
173+
)
174+
);
175+
for (let i = x.value.length; i >= 0; --i) {
176+
if (text.endsWith(x.value.substr(0, i))) {
177+
completionItem.range = new vscode.Range(
178+
position.line,
179+
Math.max(0, position.character - i),
180+
position.line,
181+
position.character
182+
);
183+
break;
184+
}
185+
}
186+
165187
if (x.description) {
166188
completionItem.documentation = new vscode.MarkdownString(
167189
x.description

0 commit comments

Comments
 (0)