Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger chat variable completion on word start #224174

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class BuiltinDynamicCompletions extends Disposable {
return null;
}

const range = computeCompletionRanges(model, position, BuiltinDynamicCompletions.VariableNameDef);
const range = computeCompletionRanges(model, position, BuiltinDynamicCompletions.VariableNameDef, true);
if (!range) {
return null;
}
Expand All @@ -344,12 +344,19 @@ class BuiltinDynamicCompletions extends Disposable {

Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(BuiltinDynamicCompletions, LifecyclePhase.Eventually);

function computeCompletionRanges(model: ITextModel, position: Position, reg: RegExp): { insert: Range; replace: Range; varWord: IWordAtPosition | null } | undefined {
function computeCompletionRanges(model: ITextModel, position: Position, reg: RegExp, onlyOnWordStart = false): { insert: Range; replace: Range; varWord: IWordAtPosition | null } | undefined {
const varWord = getWordAtText(position.column, reg, model.getLineContent(position.lineNumber), 0);
if (!varWord && model.getWordUntilPosition(position).word) {
// inside a "normal" word
return;
}
if (varWord && onlyOnWordStart) {
const wordBefore = model.getWordUntilPosition({ lineNumber: position.lineNumber, column: varWord.startColumn });
if (wordBefore.word) {
// inside a word
return;
}
}

let insert: Range;
let replace: Range;
Expand Down Expand Up @@ -394,7 +401,7 @@ class VariableCompletions extends Disposable {
return null;
}

const range = computeCompletionRanges(model, position, VariableCompletions.VariableNameDef);
const range = computeCompletionRanges(model, position, VariableCompletions.VariableNameDef, true);
if (!range) {
return null;
}
Expand Down
Loading