add proposed api for CompletionItemInsertTextRule, #57093
This commit is contained in:
parent
349c18db22
commit
078b1415e4
|
@ -358,16 +358,16 @@ export let completionKindFromLegacyString = (function () {
|
|||
})();
|
||||
|
||||
export enum CompletionItemInsertTextRule {
|
||||
/**
|
||||
* `insertText` is a snippet.
|
||||
*/
|
||||
InsertAsSnippet = 0b01,
|
||||
|
||||
/**
|
||||
* Adjust whitespace/indentation of multiline insert texts to
|
||||
* match the current line indentation.
|
||||
*/
|
||||
AdjustWhitespace = 0b10
|
||||
KeepWhitespace = 0b001,
|
||||
|
||||
/**
|
||||
* `insertText` is a snippet.
|
||||
*/
|
||||
InsertAsSnippet = 0b100,
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -251,7 +251,7 @@ export class SuggestController implements IEditorContribution {
|
|||
overwriteBefore + columnDelta,
|
||||
overwriteAfter,
|
||||
false, false,
|
||||
Boolean(suggestion.insertTextRules & CompletionItemInsertTextRule.AdjustWhitespace)
|
||||
!(suggestion.insertTextRules & CompletionItemInsertTextRule.KeepWhitespace)
|
||||
);
|
||||
|
||||
if (undoStops) {
|
||||
|
|
11
src/vs/monaco.d.ts
vendored
11
src/vs/monaco.d.ts
vendored
|
@ -4701,15 +4701,14 @@ declare namespace monaco.languages {
|
|||
}
|
||||
|
||||
export enum CompletionItemInsertTextRule {
|
||||
/**
|
||||
* Keep whitespace as-is
|
||||
*/
|
||||
KeepWhitespace = 1,
|
||||
/**
|
||||
* `insertText` is a snippet.
|
||||
*/
|
||||
InsertAsSnippet = 1,
|
||||
/**
|
||||
* Adjust whitespace/indentation of multiline insert texts to
|
||||
* match the current line indentation.
|
||||
*/
|
||||
AdjustWhitespace = 2
|
||||
InsertAsSnippet = 4
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
27
src/vs/vscode.proposed.d.ts
vendored
27
src/vs/vscode.proposed.d.ts
vendored
|
@ -11,6 +11,33 @@ declare module 'vscode' {
|
|||
export function sampleFunction(): Thenable<any>;
|
||||
}
|
||||
|
||||
//#region Joh - https://github.com/Microsoft/vscode/issues/57093
|
||||
|
||||
/**
|
||||
* An insert text rule defines how the [`insertText`](#CompletionItem.insertText) of a
|
||||
* completion item should be modified.
|
||||
*/
|
||||
export enum CompletionItemInsertTextRule {
|
||||
|
||||
/**
|
||||
* Keep whitespace as is. By default, the editor adjust leading
|
||||
* whitespace of new lines in completion items so that they match
|
||||
* the indentation of the line for the item is accepeted.
|
||||
*/
|
||||
KeepWhitespace = 0b01
|
||||
}
|
||||
|
||||
export interface CompletionItem {
|
||||
|
||||
/**
|
||||
* Rules about how/if the `insertText` should be modified by the
|
||||
* editor. Can be a bit mask of many rules.
|
||||
*/
|
||||
insertTextRules?: CompletionItemInsertTextRule;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Joh - clipboard https://github.com/Microsoft/vscode/issues/217
|
||||
|
||||
export interface Clipboard {
|
||||
|
|
|
@ -731,6 +731,7 @@ export function createApiFactory(
|
|||
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState,
|
||||
CompletionItem: extHostTypes.CompletionItem,
|
||||
CompletionItemKind: extHostTypes.CompletionItemKind,
|
||||
CompletionItemInsertTextRule: extension.enableProposedApi ? extHostTypes.CompletionItemInsertTextRule : null,
|
||||
CompletionList: extHostTypes.CompletionList,
|
||||
CompletionTriggerKind: extHostTypes.CompletionTriggerKind,
|
||||
ConfigurationTarget: extHostTypes.ConfigurationTarget,
|
||||
|
|
|
@ -377,7 +377,7 @@ export class ExtHostApiCommands {
|
|||
};
|
||||
return this._commands.executeCommand<modes.CompletionList>('_executeCompletionItemProvider', args).then(result => {
|
||||
if (result) {
|
||||
const items = result.suggestions.map(suggestion => typeConverters.Suggest.to(suggestion));
|
||||
const items = result.suggestions.map(suggestion => typeConverters.CompletionItem.to(suggestion));
|
||||
return new types.CompletionList(items, result.incomplete);
|
||||
}
|
||||
return undefined;
|
||||
|
|
|
@ -671,6 +671,7 @@ class SuggestAdapter {
|
|||
//
|
||||
range: undefined,
|
||||
insertText: undefined,
|
||||
insertTextRules: typeConvert.CompletionItemInsertTextRule.from(item.insertTextRules),
|
||||
additionalTextEdits: item.additionalTextEdits && item.additionalTextEdits.map(typeConvert.TextEdit.from),
|
||||
command: this._commands.toInternal(item.command),
|
||||
commitCharacters: item.commitCharacters,
|
||||
|
@ -683,19 +684,16 @@ class SuggestAdapter {
|
|||
// 'insertText'-logic
|
||||
if (item.textEdit) {
|
||||
result.insertText = item.textEdit.newText;
|
||||
result.insertTextRules = modes.CompletionItemInsertTextRule.AdjustWhitespace;
|
||||
|
||||
} else if (typeof item.insertText === 'string') {
|
||||
result.insertText = item.insertText;
|
||||
result.insertTextRules = modes.CompletionItemInsertTextRule.AdjustWhitespace;
|
||||
|
||||
} else if (item.insertText instanceof SnippetString) {
|
||||
result.insertText = item.insertText.value;
|
||||
result.insertTextRules = modes.CompletionItemInsertTextRule.AdjustWhitespace | modes.CompletionItemInsertTextRule.InsertAsSnippet;
|
||||
result.insertTextRules += modes.CompletionItemInsertTextRule.InsertAsSnippet;
|
||||
|
||||
} else {
|
||||
result.insertText = item.label;
|
||||
result.insertTextRules = modes.CompletionItemInsertTextRule.AdjustWhitespace;
|
||||
}
|
||||
|
||||
// 'overwrite[Before|After]'-logic
|
||||
|
|
|
@ -541,7 +541,26 @@ export const CompletionItemKind = {
|
|||
}
|
||||
};
|
||||
|
||||
export namespace Suggest {
|
||||
export namespace CompletionItemInsertTextRule {
|
||||
|
||||
export function from(rule: types.CompletionItemInsertTextRule): modes.CompletionItemInsertTextRule {
|
||||
let result = 0;
|
||||
if ((rule & types.CompletionItemInsertTextRule.KeepWhitespace)) {
|
||||
result += modes.CompletionItemInsertTextRule.KeepWhitespace;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function to(rule: modes.CompletionItemInsertTextRule): types.CompletionItemInsertTextRule {
|
||||
let result = 0;
|
||||
if ((rule & modes.CompletionItemInsertTextRule.KeepWhitespace)) {
|
||||
result += types.CompletionItemInsertTextRule.KeepWhitespace;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace CompletionItem {
|
||||
|
||||
export function to(suggestion: modes.CompletionItem): types.CompletionItem {
|
||||
const result = new types.CompletionItem(suggestion.label);
|
||||
|
@ -554,7 +573,7 @@ export namespace Suggest {
|
|||
result.preselect = suggestion.preselect;
|
||||
result.commitCharacters = suggestion.commitCharacters;
|
||||
result.range = Range.to(suggestion.range);
|
||||
|
||||
result.insertTextRules = CompletionItemInsertTextRule.to(suggestion.insertTextRules);
|
||||
// 'inserText'-logic
|
||||
if (suggestion.insertTextRules & modes.CompletionItemInsertTextRule.InsertAsSnippet) {
|
||||
result.insertText = new types.SnippetString(suggestion.insertText);
|
||||
|
@ -562,7 +581,6 @@ export namespace Suggest {
|
|||
result.insertText = suggestion.insertText;
|
||||
result.textEdit = new types.TextEdit(result.range, result.insertText);
|
||||
}
|
||||
|
||||
// TODO additionalEdits, command
|
||||
|
||||
return result;
|
||||
|
|
|
@ -1157,6 +1157,10 @@ export enum CompletionItemKind {
|
|||
TypeParameter = 24
|
||||
}
|
||||
|
||||
export enum CompletionItemInsertTextRule {
|
||||
KeepWhitespace = 0b1
|
||||
}
|
||||
|
||||
export class CompletionItem implements vscode.CompletionItem {
|
||||
|
||||
label: string;
|
||||
|
@ -1167,6 +1171,7 @@ export class CompletionItem implements vscode.CompletionItem {
|
|||
filterText: string;
|
||||
preselect: boolean;
|
||||
insertText: string | SnippetString;
|
||||
insertTextRules: CompletionItemInsertTextRule;
|
||||
range: Range;
|
||||
commitCharacters: string[];
|
||||
textEdit: TextEdit;
|
||||
|
|
|
@ -38,7 +38,7 @@ export class SnippetCompletion implements CompletionItem {
|
|||
this.range = range;
|
||||
this.sortText = `${snippet.snippetSource === SnippetSource.Extension ? 'z' : 'a'}-${snippet.prefix}`;
|
||||
this.kind = CompletionItemKind.Snippet;
|
||||
this.insertTextRules = CompletionItemInsertTextRule.InsertAsSnippet | CompletionItemInsertTextRule.AdjustWhitespace;
|
||||
this.insertTextRules = CompletionItemInsertTextRule.InsertAsSnippet;
|
||||
}
|
||||
|
||||
resolve(): this {
|
||||
|
|
Loading…
Reference in a new issue