Skip to content

Commit 181088e

Browse files
committed
Fix showRange field regression in InlineCompletionItem
The showRange field in InlineCompletionItem (part of the inlineCompletionsAdditions proposed API) stopped working after the InlineCompletionsSource refactoring in commit b0abf06. While the field is still defined in the API and accepted from extensions, the implementation that checks cursor position against this range was removed. This commit restores the showRange functionality by: 1. Adding showRange field to InlineSuggestData constructor 2. Passing showRange from InlineCompletion to InlineSuggestData in toInlineSuggestData 3. Adding showRange getter to InlineSuggestionItemBase 4. Implementing showRange check in InlineCompletionItem.isVisible() method 5. Adding cursor position check against showRange in inlineCompletionsModel state computation The fix ensures that inline completions are only shown when the cursor is within the specified showRange (if provided), matching the original behavior from PR #237532. Fixes regression from commit b0abf06 (Refactors InlineCompletionsSource) Restores functionality from commit a016c0b (Support show range for inline edits)
1 parent 0a2707c commit 181088e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsModel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,15 @@ export class InlineCompletionsModel extends Disposable {
626626
let edit = inlineEditResult.getSingleTextEdit();
627627
edit = singleTextRemoveCommonPrefix(edit, model);
628628

629+
const cursorPos = this.primaryPosition.read(reader);
629630
const cursorAtInlineEdit = this.primaryPosition.map(cursorPos => LineRange.fromRangeInclusive(inlineEditResult.targetRange).addMargin(1, 1).contains(cursorPos.lineNumber));
630631

632+
// Check if cursor is within showRange (if specified)
633+
const cursorInsideShowRange = cursorAtInlineEdit.get() || (inlineEditResult.showRange?.containsPosition(cursorPos) ?? true);
634+
if (!cursorInsideShowRange && !this._inAcceptFlow.read(reader)) {
635+
return undefined;
636+
}
637+
631638
const commands = inlineEditResult.source.inlineSuggestions.commands;
632639
const inlineEdit = new InlineEdit(edit, commands ?? [], inlineEditResult);
633640

src/vs/editor/contrib/inlineCompletions/browser/model/inlineSuggestionItem.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ abstract class InlineSuggestionItemBase {
6767
public get renameCommand(): Command | undefined { return this._data.renameCommand; }
6868
public get warning(): InlineCompletionWarning | undefined { return this._sourceInlineCompletion.warning; }
6969
public get showInlineEditMenu(): boolean { return !!this._sourceInlineCompletion.showInlineEditMenu; }
70+
public get showRange(): Range | undefined { return this._data.showRange; }
7071
public get hash() {
7172
return JSON.stringify([
7273
this.getSingleTextEdit().text,
@@ -307,11 +308,16 @@ export class InlineCompletionItem extends InlineSuggestionItemBase {
307308

308309
public isVisible(model: ITextModel, cursorPosition: Position): boolean {
309310
const singleTextEdit = this.getSingleTextEdit();
310-
return inlineCompletionIsVisible(singleTextEdit, this._originalRange, model, cursorPosition);
311+
return inlineCompletionIsVisible(singleTextEdit, this._originalRange, model, cursorPosition, this.showRange);
311312
}
312313
}
313314

314-
export function inlineCompletionIsVisible(singleTextEdit: TextReplacement, originalRange: Range | undefined, model: ITextModel, cursorPosition: Position): boolean {
315+
export function inlineCompletionIsVisible(singleTextEdit: TextReplacement, originalRange: Range | undefined, model: ITextModel, cursorPosition: Position, showRange?: Range): boolean {
316+
// Check if cursor is within showRange (if specified)
317+
if (showRange && !showRange.containsPosition(cursorPosition)) {
318+
return false;
319+
}
320+
315321
const minimizedReplacement = singleTextRemoveCommonPrefix(singleTextEdit, model);
316322
const editRange = singleTextEdit.range;
317323
if (!editRange

src/vs/editor/contrib/inlineCompletions/browser/model/provideInlineCompletions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function provideInlineCompletions(
8080
}
8181
if (item.insertText !== undefined) {
8282
const t = new TextReplacement(Range.lift(item.range) ?? defaultReplaceRange, item.insertText);
83-
if (inlineCompletionIsVisible(t, undefined, model, position)) {
83+
if (inlineCompletionIsVisible(t, undefined, model, position, Range.lift(item.showRange) ?? undefined)) {
8484
return undefined;
8585
}
8686
}
@@ -248,6 +248,7 @@ function toInlineSuggestData(
248248
inlineCompletion.isInlineEdit ?? false,
249249
inlineCompletion.supportsRename ?? false,
250250
undefined,
251+
Range.lift(inlineCompletion.showRange) ?? undefined,
251252
requestInfo,
252253
providerRequestInfo,
253254
inlineCompletion.correlationId,
@@ -318,6 +319,7 @@ export class InlineSuggestData {
318319
public readonly isInlineEdit: boolean,
319320
public readonly supportsRename: boolean,
320321
public readonly renameCommand: Command | undefined,
322+
public readonly showRange: Range | undefined,
321323

322324
private readonly _requestInfo: InlineSuggestRequestInfo,
323325
private readonly _providerRequestInfo: InlineSuggestProviderRequestInfo,
@@ -493,6 +495,7 @@ export class InlineSuggestData {
493495
this.isInlineEdit,
494496
this.supportsRename,
495497
command,
498+
this.showRange,
496499
this._requestInfo,
497500
this._providerRequestInfo,
498501
this._correlationId,

0 commit comments

Comments
 (0)