Skip to content
Open
Show file tree
Hide file tree
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 @@ -626,8 +626,15 @@ export class InlineCompletionsModel extends Disposable {
let edit = inlineEditResult.getSingleTextEdit();
edit = singleTextRemoveCommonPrefix(edit, model);

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

// Check if cursor is within showRange (if specified)
const cursorInsideShowRange = cursorAtInlineEdit.get() || (inlineEditResult.showRange?.containsPosition(cursorPos) ?? true);
if (!cursorInsideShowRange && !this._inAcceptFlow.read(reader)) {
return undefined;
}

const commands = inlineEditResult.source.inlineSuggestions.commands;
const inlineEdit = new InlineEdit(edit, commands ?? [], inlineEditResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ abstract class InlineSuggestionItemBase {
public get renameCommand(): Command | undefined { return this._data.renameCommand; }
public get warning(): InlineCompletionWarning | undefined { return this._sourceInlineCompletion.warning; }
public get showInlineEditMenu(): boolean { return !!this._sourceInlineCompletion.showInlineEditMenu; }
public get showRange(): Range | undefined { return this._data.showRange; }
public get hash() {
return JSON.stringify([
this.getSingleTextEdit().text,
Expand Down Expand Up @@ -307,11 +308,16 @@ export class InlineCompletionItem extends InlineSuggestionItemBase {

public isVisible(model: ITextModel, cursorPosition: Position): boolean {
const singleTextEdit = this.getSingleTextEdit();
return inlineCompletionIsVisible(singleTextEdit, this._originalRange, model, cursorPosition);
return inlineCompletionIsVisible(singleTextEdit, this._originalRange, model, cursorPosition, this.showRange);
}
}

export function inlineCompletionIsVisible(singleTextEdit: TextReplacement, originalRange: Range | undefined, model: ITextModel, cursorPosition: Position): boolean {
export function inlineCompletionIsVisible(singleTextEdit: TextReplacement, originalRange: Range | undefined, model: ITextModel, cursorPosition: Position, showRange?: Range): boolean {
// Check if cursor is within showRange (if specified)
if (showRange && !showRange.containsPosition(cursorPosition)) {
return false;
}

const minimizedReplacement = singleTextRemoveCommonPrefix(singleTextEdit, model);
const editRange = singleTextEdit.range;
if (!editRange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function provideInlineCompletions(
}
if (item.insertText !== undefined) {
const t = new TextReplacement(Range.lift(item.range) ?? defaultReplaceRange, item.insertText);
if (inlineCompletionIsVisible(t, undefined, model, position)) {
if (inlineCompletionIsVisible(t, undefined, model, position, Range.lift(item.showRange) ?? undefined)) {
return undefined;
}
}
Expand Down Expand Up @@ -248,6 +248,7 @@ function toInlineSuggestData(
inlineCompletion.isInlineEdit ?? false,
inlineCompletion.supportsRename ?? false,
undefined,
Range.lift(inlineCompletion.showRange) ?? undefined,
requestInfo,
providerRequestInfo,
inlineCompletion.correlationId,
Expand Down Expand Up @@ -318,6 +319,7 @@ export class InlineSuggestData {
public readonly isInlineEdit: boolean,
public readonly supportsRename: boolean,
public readonly renameCommand: Command | undefined,
public readonly showRange: Range | undefined,

private readonly _requestInfo: InlineSuggestRequestInfo,
private readonly _providerRequestInfo: InlineSuggestProviderRequestInfo,
Expand Down Expand Up @@ -493,6 +495,7 @@ export class InlineSuggestData {
this.isInlineEdit,
this.supportsRename,
command,
this.showRange,
this._requestInfo,
this._providerRequestInfo,
this._correlationId,
Expand Down