Adresses feedback inline completion API discussion.

This commit is contained in:
Henning Dieterichs
2022-02-09 15:30:26 +01:00
parent 4af471748f
commit 5163f619ea
3 changed files with 39 additions and 20 deletions
@@ -1061,14 +1061,14 @@ class InlineCompletionAdapter {
return undefined;
}
const normalizedResult: vscode.InlineCompletionList = isArray(result) ? { items: result } : result;
const normalizedResult = isArray(result) ? result : result.items;
const pid = this._cache.add(normalizedResult.items);
const pid = this._cache.add(normalizedResult);
let disposableStore: DisposableStore | undefined = undefined;
return {
pid,
items: normalizedResult.items.map<extHostProtocol.IdentifiableInlineCompletion>((item, idx) => {
items: normalizedResult.map<extHostProtocol.IdentifiableInlineCompletion>((item, idx) => {
let command: languages.Command | undefined = undefined;
if (item.command) {
if (!disposableStore) {
@@ -1078,8 +1078,12 @@ class InlineCompletionAdapter {
command = this._commands.toInternal(item.command, disposableStore);
}
const insertText = item.insertText ?? item.text;
if (insertText === undefined) {
throw new Error('text or insertText must be defined');
}
return ({
text: item.text,
text: insertText,
range: item.range ? typeConvert.Range.from(item.range) : undefined,
command,
idx: idx,
+11 -3
View File
@@ -1563,18 +1563,26 @@ export class CompletionList {
@es5ClassCompat
export class InlineSuggestion implements vscode.InlineCompletionItem {
insertText?: string;
/**
* @deprecated Use `insertText` instead. Will be removed eventually.
*/
text?: string;
text: string;
range?: Range;
command?: vscode.Command;
constructor(text: string, range?: Range, command?: vscode.Command) {
this.text = text;
constructor(insertText: string, range?: Range, command?: vscode.Command) {
this.insertText = insertText;
this.range = range;
this.command = command;
}
}
/**
* @deprecated Return an array of inline completion items directly. Will be removed eventually.
*/
@es5ClassCompat
export class InlineSuggestions implements vscode.InlineCompletionList {
items: vscode.InlineCompletionItem[];
+20 -13
View File
@@ -73,16 +73,22 @@ declare module 'vscode' {
Explicit = 1,
}
// todo@API don't have separate type around array
/**
* @deprecated Return an array of Inline Completion items directly. Will be removed eventually.
*/
export class InlineCompletionList<T extends InlineCompletionItem = InlineCompletionItem> {
items: T[];
/**
* @deprecated Return an array of Inline Completion items directly. Will be removed eventually.
*/
constructor(items: T[]);
}
export class InlineCompletionItem {
/**
* The text to replace the range with.
* The text to replace the range with. Must be set.
* Is used both for the preview and the accept operation.
*
* The text the range refers to must be a subword of this value (`AB` and `BEF` are subwords of `ABCDEF`, but `Ab` is not).
* Additionally, if possible, it should be a prefix of this value for a better user-experience.
@@ -90,9 +96,12 @@ declare module 'vscode' {
* However, any indentation of the text to replace does not matter for the subword constraint.
* Thus, ` B` can be replaced with ` ABC`, effectively removing a whitespace and inserting `A` and `C`.
*/
// todo@API is this like CompletionItem#label or insertText?
// todo@API insertText
text: string;
insertText?: string;
/**
* @deprecated Use `insertText` instead. Will be removed eventually.
*/
text?: string;
/**
* The range to replace.
@@ -110,21 +119,19 @@ declare module 'vscode' {
*/
command?: Command;
constructor(insertText: string, range?: Range, command?: Command);
}
// TODO@API validate it is being used, iff so move to a different proposal
export interface InlineCompletionItem {
/**
* If set to `true`, unopened closing brackets are removed and unclosed opening brackets are closed.
* Defaults to `false`.
*/
// todo@API is this to compensate "bad" extensions, why isn't this done for normal completions or formatting?
// todo@API is this an instance property or a provider property?
// (1) leave proposed
completeBracketPairs?: boolean;
constructor(text: string, range?: Range, command?: Command);
}
// TODO@API validate it is being used, iff so move to a different proposal
/**
* Be aware that this API will not ever be finalized.
*/