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

# Extend the partial accept handler #241356

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ export interface CompletionList {
export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
acceptedLength: number;
addedLength?: number;
replacedRange?: IRange;
versionBeforeAccept?: number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ export class InlineCompletionsModel extends Disposable {

const positions = this._positions.get();
const cursorPosition = positions[0];
const originalTextLength = editor.getModel()!.getValue(EndOfLinePreference.LF).length;
const versionBeforeAccept = editor.getModel()!.getVersionId();

// Executing the edit might free the completion, so we have to hold a reference on it.
completion.source.addRef();
Expand All @@ -750,11 +752,12 @@ export class InlineCompletionsModel extends Disposable {
// This assumes that the inline completion and the model use the same EOL style.
const text = editor.getModel()!.getValueInRange(acceptedRange, EndOfLinePreference.LF);
const acceptedLength = text.length;
const addedLength = editor.getModel()!.getValue(EndOfLinePreference.LF).length - originalTextLength;
completion.source.provider.handlePartialAccept(
completion.source.inlineCompletions,
completion.sourceInlineCompletion,
acceptedLength,
{ kind, acceptedLength: acceptedLength, }
{ kind, acceptedLength: acceptedLength, addedLength, versionBeforeAccept, replacedRange: Range.fromPositions(ghostTextPos) }
);
}
} finally {
Expand Down
3 changes: 3 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7171,6 +7171,9 @@ declare namespace monaco.languages {
export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
acceptedLength: number;
addedLength?: number;
replacedRange?: IRange;
versionBeforeAccept?: number;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3014,6 +3014,9 @@ export namespace PartialAcceptInfo {
return {
kind: PartialAcceptTriggerKind.to(info.kind),
acceptedLength: info.acceptedLength,
addedLength: info.addedLength,
versionBeforeAccept: info.versionBeforeAccept,
replacedRange: Range.to(info.replacedRange)
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,9 @@ export class InlineSuggestionList implements vscode.InlineCompletionList {
export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
acceptedLength: number;
addedLength?: number;
versionBeforeAccept?: number;
replacedRange?: vscode.Range;
}

export enum PartialAcceptTriggerKind {
Expand Down
12 changes: 12 additions & 0 deletions src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ declare module 'vscode' {
* The length of the substring of the provided inline completion text that was accepted already.
*/
acceptedLength: number;
/**
* The length of characters added to the document by accepting inline completion.
*/
addedLength?: number;
/**
* Version of the document before the inline completion was accepted.
*/
versionBeforeAccept?: number;
/**
* Replaced range in document at version before acceptance, where the inline completion was inserted.
*/
replacedRange?: Range;
}

export enum PartialAcceptTriggerKind {
Expand Down