Skip to content

Commit 9cec336

Browse files
committed
fix path autocompletion trigger logic
1 parent 8f7b53d commit 9cec336

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/vs/workbench/contrib/chat/common/promptSyntax/codecs/tokens/fileReference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class FileReference extends PromptVariableWithData {
5656
* Get the range of the `link` part of the token (e.g.,
5757
* the `/path/to/file.md` part of `#file:/path/to/file.md`).
5858
*/
59-
public get linkRange(): IRange {
59+
public get linkRange(): IRange | undefined {
6060
return super.dataRange;
6161
}
6262
}

src/vs/workbench/contrib/chat/common/promptSyntax/codecs/tokens/promptVariable.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,28 @@ export class PromptVariableWithData extends PromptVariable {
125125
/**
126126
* Range of the `data` part of the variable.
127127
*/
128-
public get dataRange(): IRange {
128+
public get dataRange(): IRange | undefined {
129129
const { range } = this;
130+
131+
// calculate the start column number of the `data` part of the variable
130132
const dataStartColumn = range.startColumn +
131133
START_CHARACTER.length + this.name.length +
132134
DATA_SEPARATOR.length;
133135

134-
return new Range(
136+
// create `range` of the `data` part of the variable
137+
const result = new Range(
135138
range.startLineNumber,
136139
dataStartColumn,
137140
range.endLineNumber,
138141
range.endColumn,
139142
);
143+
144+
// if the resulting range is empty, return `undefined`
145+
// because there is no `data` part present in the variable
146+
if (result.isEmpty()) {
147+
return undefined;
148+
}
149+
150+
return result;
140151
}
141152
}

src/vs/workbench/contrib/chat/common/promptSyntax/languageFeatures/promptPathAutocompletion.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,21 +244,20 @@ export class PromptPathAutocompletion extends Disposable implements CompletionIt
244244
// when character is `:`, there must be no link present yet
245245
// otherwise the `:` was used in the middle of the link hence
246246
// we don't want to provide suggestions for that
247-
if (character === ':' && linkRange !== undefined) {
247+
if ((character === ':') && (linkRange !== undefined)) {
248248
return [];
249249
}
250250

251251
// otherwise when the `.` character is present, it is inside the link part
252252
// of the reference, hence we always expect the link range to be present
253-
if (character === '.' && linkRange === undefined) {
253+
if ((character === '.') && (linkRange === undefined)) {
254254
return [];
255255
}
256256

257257
const suggestions = await this.getFolderSuggestions(fileFolderUri);
258258

259-
// replacement range of the suggestions
260-
// when character is `.` we want to also replace it, because we add
261-
// the `./` at the beginning of all the relative paths
259+
// replacement range for suggestions; when character is `.`, we want to also
260+
// replace it, because we add `./` at the beginning of all the relative paths
262261
const startColumnOffset = (character === '.') ? 1 : 0;
263262
const range = {
264263
...fileReference.range,

0 commit comments

Comments
 (0)