Skip to content

Commit ed40013

Browse files
authored
Only decorate complete @ variables (microsoft#191733)
1 parent 046cfbf commit ed40013

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/vs/workbench/contrib/chat/browser/contrib/chatInputEditorContrib.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { CancellationToken } from 'vs/base/common/cancellation';
7+
import { Iterable } from 'vs/base/common/iterator';
78
import { Disposable } from 'vs/base/common/lifecycle';
89
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
910
import { Position } from 'vs/editor/common/core/position';
@@ -44,6 +45,7 @@ class InputEditorDecorations extends Disposable {
4445
@ICodeEditorService private readonly codeEditorService: ICodeEditorService,
4546
@IThemeService private readonly themeService: IThemeService,
4647
@IChatService private readonly chatService: IChatService,
48+
@IChatVariablesService private readonly chatVariablesService: IChatVariablesService,
4749
) {
4850
super();
4951

@@ -175,21 +177,22 @@ class InputEditorDecorations extends Disposable {
175177
this.widget.inputEditor.setDecorationsByType(decorationDescription, slashCommandTextDecorationType, []);
176178
}
177179

178-
// const variables = this.chatVariablesService.getVariables();
180+
const variables = this.chatVariablesService.getVariables();
179181
const variableReg = /(^|\s)@(\w+)(:\d+)?(?=(\s|$))/ig;
180182
let match: RegExpMatchArray | null;
181183
const varDecorations: IDecorationOptions[] = [];
182184
while (match = variableReg.exec(inputValue)) {
183-
// const candidate = match[2];
184-
// if (Iterable.find(variables, v => v.name === candidate))
185-
varDecorations.push({
186-
range: {
187-
startLineNumber: 1,
188-
endLineNumber: 1,
189-
startColumn: match.index! + match[1].length + 1,
190-
endColumn: match.index! + match[0].length + 1
191-
}
192-
});
185+
const varName = match[2];
186+
if (Iterable.find(variables, v => v.name === varName)) {
187+
varDecorations.push({
188+
range: {
189+
startLineNumber: 1,
190+
endLineNumber: 1,
191+
startColumn: match.index! + match[1].length + 1,
192+
endColumn: match.index! + match[0].length + 1
193+
}
194+
});
195+
}
193196
}
194197

195198
this.widget.inputEditor.setDecorationsByType(decorationDescription, variableTextDecorationType, varDecorations);

0 commit comments

Comments
 (0)