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

# Add partial accept kind to inline completion handle #202668

Merged
merged 28 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5ebea18
# Add partial accept kind to inline completion handle
marrej Jan 17, 2024
1e23e16
# add missing properties
marrej Jan 17, 2024
122b4ce
Merge branch 'main' into partial-accept-kind
marrej Jan 17, 2024
63dde63
# Indentation fixes
marrej Jan 17, 2024
2e65eb4
# update monaco.d.ts
marrej Jan 17, 2024
74f6b6a
# fix used trigger kinds
marrej Jan 17, 2024
e6d04f1
# Additional naming fixes
marrej Jan 17, 2024
436c9c2
# updates to monaco.d.ts
marrej Jan 17, 2024
d3175bc
Merge branch 'main' into partial-accept-kind
marrej Jan 17, 2024
5c226d6
# Smaller fixes
marrej Jan 17, 2024
c5b8c25
# Add misssing api impl
marrej Jan 17, 2024
67e2787
# Update monaco.d.ts
marrej Jan 17, 2024
2aef178
# Fixes based on presubmit checks
marrej Jan 17, 2024
5364d5e
# missing properties fix
marrej Jan 17, 2024
6e8af2d
Merge branch 'main' into partial-accept-kind
marrej Jan 17, 2024
4ec7c14
Merge branch 'main' into partial-accept-kind
marrej Jan 17, 2024
9a95c19
Merge branch 'main' into partial-accept-kind
marrej Jan 18, 2024
18e1cac
# Extend the API with another overload rather than direct overwrite
marrej Jan 19, 2024
c827297
Merge branch 'main' into partial-accept-kind
marrej Jan 19, 2024
6c725f2
# Update monaco.d.ts
marrej Jan 19, 2024
cedb2af
# property naming update
marrej Jan 19, 2024
6d66318
Merge branch 'main' into partial-accept-kind
marrej Jan 19, 2024
2740178
# Styling fix
marrej Jan 19, 2024
1ec3713
Merge branch 'main' into partial-accept-kind
marrej Jan 19, 2024
f469a62
Merge branch 'main' into partial-accept-kind
marrej Jan 27, 2024
7835748
Removes duplicate acceptedLength
hediet Feb 28, 2024
516cb6a
Merge branch 'main' into pr/marrej/202668
hediet Feb 28, 2024
88f3f2e
Fixes monaco.d.ts
hediet Mar 4, 2024
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
18 changes: 17 additions & 1 deletion src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,22 @@ export interface CompletionList {
duration?: number;
}

/**
* Info provided on partial acceptance.
*/
export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
}

/**
* How a partial acceptance was triggered.
*/
export const enum PartialAcceptTriggerKind {
Word = 0,
Line = 1,
Suggest = 2,
}

/**
* How a suggest provider was triggered.
*/
Expand Down Expand Up @@ -718,7 +734,7 @@ export interface InlineCompletionsProvider<T extends InlineCompletions = InlineC
/**
* Will be called when an item is partially accepted.
*/
handlePartialAccept?(completions: T, item: T['items'][number], acceptedCharacters: number): void;
handlePartialAccept?(completions: T, item: T['items'][number], acceptedCharacters: number, info: PartialAcceptInfo): void;

/**
* Will be called when a completions list is no longer in use and can be garbage-collected.
Expand Down
11 changes: 10 additions & 1 deletion src/vs/editor/common/standalone/standaloneEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,15 @@ export enum OverviewRulerLane {
Full = 7
}

/**
* How a partial acceptance was triggered.
*/
export enum PartialAcceptTriggerKind {
Word = 0,
Line = 1,
Suggest = 2
}

export enum PositionAffinity {
/**
* Prefers the left most position.
Expand Down Expand Up @@ -941,4 +950,4 @@ export enum WrappingIndent {
* DeepIndent => wrapped lines get +2 indentation toward the parent.
*/
DeepIndent = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { InlineCompletionContext, InlineCompletionTriggerKind } from 'vs/editor/common/languages';
import { InlineCompletionContext, InlineCompletionTriggerKind, PartialAcceptTriggerKind } from 'vs/editor/common/languages';
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
import { EndOfLinePreference, ITextModel } from 'vs/editor/common/model';
import { IFeatureDebounceInformation } from 'vs/editor/common/services/languageFeatureDebounce';
Expand Down Expand Up @@ -379,7 +379,7 @@ export class InlineCompletionsModel extends Disposable {
}
}
return acceptUntilIndexExclusive;
});
}, PartialAcceptTriggerKind.Word);
}

public async acceptNextLine(editor: ICodeEditor): Promise<void> {
Expand All @@ -389,10 +389,10 @@ export class InlineCompletionsModel extends Disposable {
return m.index + 1;
}
return text.length;
});
}, PartialAcceptTriggerKind.Line);
}

private async _acceptNext(editor: ICodeEditor, getAcceptUntilIndex: (position: Position, text: string) => number): Promise<void> {
private async _acceptNext(editor: ICodeEditor, getAcceptUntilIndex: (position: Position, text: string) => number, kind: PartialAcceptTriggerKind): Promise<void> {
if (editor.getModel() !== this.textModel) {
throw new BugIndicatingError();
}
Expand Down Expand Up @@ -448,6 +448,9 @@ export class InlineCompletionsModel extends Disposable {
completion.source.inlineCompletions,
completion.sourceInlineCompletion,
text.length,
{
kind,
}
);
}
} finally {
Expand All @@ -465,6 +468,9 @@ export class InlineCompletionsModel extends Disposable {
inlineCompletion.source.inlineCompletions,
inlineCompletion.sourceInlineCompletion,
itemEdit.text.length,
{
kind: PartialAcceptTriggerKind.Suggest,
}
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/vs/editor/standalone/browser/standaloneLanguages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages {
InlineEditTriggerKind: standaloneEnums.InlineEditTriggerKind,
CodeActionTriggerType: standaloneEnums.CodeActionTriggerType,
NewSymbolNameTag: standaloneEnums.NewSymbolNameTag,
PartialAcceptTriggerKind: standaloneEnums.PartialAcceptTriggerKind,

// classes
FoldingRangeKind: languages.FoldingRangeKind,
Expand Down
19 changes: 18 additions & 1 deletion src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6956,6 +6956,23 @@ declare namespace monaco.languages {
dispose?(): void;
}

/**
* Info provided on partial acceptance.
*/
export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
acceptedLength: number;
}

/**
* How a partial acceptance was triggered.
*/
export enum PartialAcceptTriggerKind {
Word = 0,
Line = 1,
Suggest = 2
}

/**
* How a suggest provider was triggered.
*/
Expand Down Expand Up @@ -7102,7 +7119,7 @@ declare namespace monaco.languages {
/**
* Will be called when an item is partially accepted.
*/
handlePartialAccept?(completions: T, item: T['items'][number], acceptedCharacters: number): void;
handlePartialAccept?(completions: T, item: T['items'][number], acceptedCharacters: number, info: PartialAcceptInfo): void;
/**
* Will be called when a completions list is no longer in use and can be garbage-collected.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,9 @@ export class MainThreadLanguageFeatures extends Disposable implements MainThread
await this._proxy.$handleInlineCompletionDidShow(handle, completions.pid, item.idx, updatedInsertText);
}
},
handlePartialAccept: async (completions, item, acceptedCharacters): Promise<void> => {
handlePartialAccept: async (completions, item, acceptedCharacters, info: languages.PartialAcceptInfo): Promise<void> => {
if (supportsHandleEvents) {
await this._proxy.$handleInlineCompletionPartialAccept(handle, completions.pid, item.idx, acceptedCharacters);
await this._proxy.$handleInlineCompletionPartialAccept(handle, completions.pid, item.idx, acceptedCharacters, info);
}
},
freeInlineCompletions: (completions: IdentifiableInlineCompletions): void => {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
ThreadFocus: extHostTypes.ThreadFocus,
RelatedInformationType: extHostTypes.RelatedInformationType,
SpeechToTextStatus: extHostTypes.SpeechToTextStatus,
PartialAcceptTriggerKind: extHostTypes.PartialAcceptTriggerKind,
KeywordRecognitionStatus: extHostTypes.KeywordRecognitionStatus,
ChatResponseMarkdownPart: extHostTypes.ChatResponseMarkdownPart,
ChatResponseFileTreePart: extHostTypes.ChatResponseFileTreePart,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ export interface ExtHostLanguageFeaturesShape {
$releaseCompletionItems(handle: number, id: number): void;
$provideInlineCompletions(handle: number, resource: UriComponents, position: IPosition, context: languages.InlineCompletionContext, token: CancellationToken): Promise<IdentifiableInlineCompletions | undefined>;
$handleInlineCompletionDidShow(handle: number, pid: number, idx: number, updatedInsertText: string): void;
$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number): void;
$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void;
$freeInlineCompletionsList(handle: number, pid: number): void;
$provideSignatureHelp(handle: number, resource: UriComponents, position: IPosition, context: languages.SignatureHelpContext, token: CancellationToken): Promise<ISignatureHelpDto | undefined>;
$releaseSignatureHelp(handle: number, id: number): void;
Expand Down
9 changes: 5 additions & 4 deletions src/vs/workbench/api/common/extHostLanguageFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ class InlineCompletionAdapterBase {

handleDidShowCompletionItem(pid: number, idx: number, updatedInsertText: string): void { }

handlePartialAccept(pid: number, idx: number, acceptedCharacters: number): void { }
handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void { }
}

class InlineCompletionAdapter extends InlineCompletionAdapterBase {
Expand Down Expand Up @@ -1345,11 +1345,12 @@ class InlineCompletionAdapter extends InlineCompletionAdapterBase {
}
}

override handlePartialAccept(pid: number, idx: number, acceptedCharacters: number): void {
override handlePartialAccept(pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
const completionItem = this._references.get(pid)?.items[idx];
if (completionItem) {
if (this._provider.handleDidPartiallyAcceptCompletionItem && this._isAdditionsProposedApiEnabled) {
this._provider.handleDidPartiallyAcceptCompletionItem(completionItem, acceptedCharacters);
this._provider.handleDidPartiallyAcceptCompletionItem(completionItem, typeConvert.PartialAcceptInfo.to(info));
}
}
}
Expand Down Expand Up @@ -2489,9 +2490,9 @@ export class ExtHostLanguageFeatures implements extHostProtocol.ExtHostLanguageF
}, undefined, undefined);
}

$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number): void {
$handleInlineCompletionPartialAccept(handle: number, pid: number, idx: number, acceptedCharacters: number, info: languages.PartialAcceptInfo): void {
this._withAdapter(handle, InlineCompletionAdapterBase, async adapter => {
adapter.handlePartialAccept(pid, idx, acceptedCharacters);
adapter.handlePartialAccept(pid, idx, acceptedCharacters, info);
}, undefined, undefined);
}

Expand Down
23 changes: 23 additions & 0 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2672,6 +2672,29 @@ export namespace TerminalQuickFix {
}
}

export namespace PartialAcceptInfo {
export function to(info: languages.PartialAcceptInfo): types.PartialAcceptInfo {
return {
kind: PartialAcceptTriggerKind.to(info.kind),
};
}
}

export namespace PartialAcceptTriggerKind {
export function to(kind: languages.PartialAcceptTriggerKind): types.PartialAcceptTriggerKind {
switch (kind) {
case languages.PartialAcceptTriggerKind.Word:
return types.PartialAcceptTriggerKind.Word;
case languages.PartialAcceptTriggerKind.Line:
return types.PartialAcceptTriggerKind.Line;
case languages.PartialAcceptTriggerKind.Suggest:
return types.PartialAcceptTriggerKind.Suggest;
default:
return types.PartialAcceptTriggerKind.Unknown;
}
}
}

export namespace DebugTreeItem {
export function from(item: vscode.DebugTreeItem, id: number): IDebugVisualizationTreeItem {
return {
Expand Down
11 changes: 11 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,17 @@ export class InlineSuggestionList implements vscode.InlineCompletionList {
}
}

export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
}

export enum PartialAcceptTriggerKind {
Unknown = 0,
Word = 1,
Line = 2,
Suggest = 3,
}

export enum ViewColumn {
Active = -1,
Beside = -2,
Expand Down
18 changes: 18 additions & 0 deletions src/vscode-dts/vscode.proposed.inlineCompletionsAdditions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ declare module 'vscode' {
*/
// eslint-disable-next-line local/vscode-dts-provider-naming
handleDidPartiallyAcceptCompletionItem?(completionItem: InlineCompletionItem, acceptedLength: number): void;

/**
* Is called when an inline completion item was accepted partially.
* @param info Additional info for the partial accepted trigger.
*/
// eslint-disable-next-line local/vscode-dts-provider-naming
handleDidPartiallyAcceptCompletionItem?(completionItem: InlineCompletionItem, info: PartialAcceptInfo): void;
}

export interface PartialAcceptInfo {
kind: PartialAcceptTriggerKind;
}

export enum PartialAcceptTriggerKind {
Unknown = 0,
Word = 1,
Line = 2,
Suggest = 3,
}

// When finalizing `commands`, make sure to add a corresponding constructor parameter.
Expand Down
Loading