Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/handlers/autoCompleteProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { getStepFileSteps } from '../parsers/stepsParser';
export const autoCompleteProvider = {
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem[] | undefined {
try {
const lcLine = document.lineAt(position).text.trimStart().toLowerCase();
const line = document.lineAt(position);
const lcLine = line.text.trimStart().toLowerCase();
const step = featureFileStepRe.exec(lcLine);
if (!step)
return;
Expand Down Expand Up @@ -38,16 +39,26 @@ export const autoCompleteProvider = {
const stepFileSteps = getStepFileSteps(wkspSettings.featuresUri);
const items: vscode.CompletionItem[] = [];

// Calculate the range to replace: from after the step keyword to the end of line
const leadingWhitespace = line.text.length - line.text.trimStart().length;
const stepKeywordEnd = leadingWhitespace + stepType.length + 1;
const replaceRange = new vscode.Range(
position.line,
stepKeywordEnd,
position.line,
line.text.length
);

for (const [key, value] of stepFileSteps) {
const lcKey = key.toLowerCase();
if (lcKey.startsWith(matchText1) || lcKey.startsWith(matchText2)) {
let itemText = value.textAsRe.startsWith(".*") ? " " + value.textAsRe.slice(1) : value.textAsRe;
itemText = value.textAsRe.replaceAll(".*", "?");
// deal with e.g \( escapes in textAsRe
itemText = itemText.replaceAll("\\\\", "#@slash@#").replaceAll("\\", "").replaceAll("#@slash@#", "\\");
itemText = itemText.replace(textWithoutType, "").trim();
const item = new vscode.CompletionItem(itemText, vscode.CompletionItemKind.Function);
item.detail = vscode.workspace.asRelativePath(value.uri);
item.range = replaceRange;
items.push(item);
}
}
Expand Down