-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvscode.proposed.inlineCompletions.d.ts
159 lines (138 loc) · 5.96 KB
/
vscode.proposed.inlineCompletions.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
// https://github.com/microsoft/vscode/issues/124024 @hediet @alexdima
export namespace languages {
/**
* Registers an inline completion provider.
*
* @return A {@link Disposable} that unregisters this provider when being disposed.
*/
// todo@API what are the rules when multiple providers apply
export function registerInlineCompletionItemProvider(selector: DocumentSelector, provider: InlineCompletionItemProvider): Disposable;
}
export interface InlineCompletionItemProvider<T extends InlineCompletionItem = InlineCompletionItem> {
/**
* Provides inline completion items for the given position and document.
* If inline completions are enabled, this method will be called whenever the user stopped typing.
* It will also be called when the user explicitly triggers inline completions or asks for the next or previous inline completion.
* Use `context.triggerKind` to distinguish between these scenarios.
*/
provideInlineCompletionItems(document: TextDocument, position: Position, context: InlineCompletionContext, token: CancellationToken): ProviderResult<InlineCompletionList<T> | T[]>;
}
export interface InlineCompletionContext {
/**
* How the completion was triggered.
*/
readonly triggerKind: InlineCompletionTriggerKind;
/**
* Provides information about the currently selected item in the autocomplete widget if it is visible.
*
* If set, provided inline completions must extend the text of the selected item
* and use the same range, otherwise they are not shown as preview.
* As an example, if the document text is `console.` and the selected item is `.log` replacing the `.` in the document,
* the inline completion must also replace `.` and start with `.log`, for example `.log()`.
*
* Inline completion providers are requested again whenever the selected item changes.
*
* The user must configure `"editor.suggest.preview": true` for this feature.
*/
readonly selectedCompletionInfo: SelectedCompletionInfo | undefined;
}
// todo@API is this to express a possible future outcome of the text document?
export interface SelectedCompletionInfo {
range: Range;
text: string;
completionKind: CompletionItemKind;
isSnippetText: boolean;
}
/**
* How an {@link InlineCompletionItemProvider inline completion provider} was triggered.
*/
export enum InlineCompletionTriggerKind {
/**
* Completion was triggered automatically while editing.
* It is sufficient to return a single completion item in this case.
*/
Automatic = 0,
/**
* Completion was triggered explicitly by a user gesture.
* Return multiple completion items to enable cycling through them.
*/
Explicit = 1,
}
/**
* @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. 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.
*
* 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`.
*/
insertText?: string;
/**
* @deprecated Use `insertText` instead. Will be removed eventually.
*/
text?: string;
/**
* The range to replace.
* Must begin and end on the same line.
*
* Prefer replacements over insertions to avoid cache invalidation:
* Instead of reporting a completion that inserts an extension at the end of a word,
* the whole word (or even the whole line) should be replaced with the extended word (or extended line) to improve the UX.
* That way, when the user presses backspace, the cache can be reused and there is no flickering.
*/
range?: Range;
/**
* An optional {@link Command} that is executed *after* inserting this completion.
*/
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`.
*/
completeBracketPairs?: boolean;
}
/**
* Be aware that this API will not ever be finalized.
*/
export namespace window {
export function getInlineCompletionItemController<T extends InlineCompletionItem>(provider: InlineCompletionItemProvider<T>): InlineCompletionController<T>;
}
/**
* Be aware that this API will not ever be finalized.
*/
export interface InlineCompletionController<T extends InlineCompletionItem> {
/**
* Is fired when an inline completion item is shown to the user.
*/
// eslint-disable-next-line vscode-dts-event-naming
readonly onDidShowCompletionItem: Event<InlineCompletionItemDidShowEvent<T>>;
}
/**
* Be aware that this API will not ever be finalized.
*/
export interface InlineCompletionItemDidShowEvent<T extends InlineCompletionItem> {
completionItem: T;
}
}