Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/languages.ts
5243 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { VSBuffer } from '../../base/common/buffer.js';
7
import { CancellationToken } from '../../base/common/cancellation.js';
8
import { Codicon } from '../../base/common/codicons.js';
9
import { Color } from '../../base/common/color.js';
10
import { IReadonlyVSDataTransfer } from '../../base/common/dataTransfer.js';
11
import { Event } from '../../base/common/event.js';
12
import { HierarchicalKind } from '../../base/common/hierarchicalKind.js';
13
import { IMarkdownString } from '../../base/common/htmlContent.js';
14
import { IDisposable } from '../../base/common/lifecycle.js';
15
import { ThemeIcon } from '../../base/common/themables.js';
16
import { URI, UriComponents } from '../../base/common/uri.js';
17
import { EditOperation, ISingleEditOperation } from './core/editOperation.js';
18
import { IPosition, Position } from './core/position.js';
19
import { IRange, Range } from './core/range.js';
20
import { Selection } from './core/selection.js';
21
import { LanguageId } from './encodedTokenAttributes.js';
22
import { LanguageSelector } from './languageSelector.js';
23
import * as model from './model.js';
24
import { TokenizationRegistry as TokenizationRegistryImpl } from './tokenizationRegistry.js';
25
import { ContiguousMultilineTokens } from './tokens/contiguousMultilineTokens.js';
26
import { localize } from '../../nls.js';
27
import { ExtensionIdentifier } from '../../platform/extensions/common/extensions.js';
28
import { IMarkerData } from '../../platform/markers/common/markers.js';
29
import { EditDeltaInfo } from './textModelEditSource.js';
30
import { FontTokensUpdate } from './textModelEvents.js';
31
32
/**
33
* @internal
34
*/
35
export interface ILanguageIdCodec {
36
encodeLanguageId(languageId: string): LanguageId;
37
decodeLanguageId(languageId: LanguageId): string;
38
}
39
40
export class Token {
41
_tokenBrand: void = undefined;
42
43
constructor(
44
public readonly offset: number,
45
public readonly type: string,
46
public readonly language: string,
47
) {
48
}
49
50
public toString(): string {
51
return '(' + this.offset + ', ' + this.type + ')';
52
}
53
}
54
55
/**
56
* @internal
57
*/
58
export class TokenizationResult {
59
_tokenizationResultBrand: void = undefined;
60
61
constructor(
62
public readonly tokens: Token[],
63
public readonly endState: IState,
64
) {
65
}
66
}
67
68
/**
69
* @internal
70
*/
71
export interface IFontToken {
72
readonly startIndex: number;
73
readonly endIndex: number;
74
readonly fontFamily: string | null;
75
readonly fontSizeMultiplier: number | null;
76
readonly lineHeightMultiplier: number | null;
77
}
78
79
/**
80
* @internal
81
*/
82
export class EncodedTokenizationResult {
83
_encodedTokenizationResultBrand: void = undefined;
84
85
constructor(
86
/**
87
* The tokens in binary format. Each token occupies two array indices. For token i:
88
* - at offset 2*i => startIndex
89
* - at offset 2*i + 1 => metadata
90
*
91
*/
92
public readonly tokens: Uint32Array,
93
public readonly fontInfo: IFontToken[],
94
public readonly endState: IState,
95
) {
96
}
97
}
98
99
export interface SyntaxNode {
100
startIndex: number;
101
endIndex: number;
102
startPosition: IPosition;
103
endPosition: IPosition;
104
}
105
106
export interface QueryCapture {
107
name: string;
108
text?: string;
109
node: SyntaxNode;
110
encodedLanguageId: number;
111
}
112
113
/**
114
* @internal
115
*/
116
export interface ITokenizationSupport {
117
/**
118
* If true, the background tokenizer will only be used to verify tokens against the default background tokenizer.
119
* Used for debugging.
120
*/
121
readonly backgroundTokenizerShouldOnlyVerifyTokens?: boolean;
122
123
getInitialState(): IState;
124
125
tokenize(line: string, hasEOL: boolean, state: IState): TokenizationResult;
126
127
tokenizeEncoded(line: string, hasEOL: boolean, state: IState): EncodedTokenizationResult;
128
129
/**
130
* Can be/return undefined if default background tokenization should be used.
131
*/
132
createBackgroundTokenizer?(textModel: model.ITextModel, store: IBackgroundTokenizationStore): IBackgroundTokenizer | undefined;
133
}
134
135
/**
136
* @internal
137
*/
138
export interface IBackgroundTokenizer extends IDisposable {
139
/**
140
* Instructs the background tokenizer to set the tokens for the given range again.
141
*
142
* This might be necessary if the renderer overwrote those tokens with heuristically computed ones for some viewport,
143
* when the change does not even propagate to that viewport.
144
*/
145
requestTokens(startLineNumber: number, endLineNumberExclusive: number): void;
146
147
reportMismatchingTokens?(lineNumber: number): void;
148
}
149
150
/**
151
* @internal
152
*/
153
export interface IBackgroundTokenizationStore {
154
setTokens(tokens: ContiguousMultilineTokens[]): void;
155
156
setFontInfo(changes: FontTokensUpdate): void;
157
158
setEndState(lineNumber: number, state: IState): void;
159
160
/**
161
* Should be called to indicate that the background tokenization has finished for now.
162
* (This triggers bracket pair colorization to re-parse the bracket pairs with token information)
163
*/
164
backgroundTokenizationFinished(): void;
165
}
166
167
/**
168
* The state of the tokenizer between two lines.
169
* It is useful to store flags such as in multiline comment, etc.
170
* The model will clone the previous line's state and pass it in to tokenize the next line.
171
*/
172
export interface IState {
173
clone(): IState;
174
equals(other: IState): boolean;
175
}
176
177
/**
178
* A provider result represents the values a provider, like the {@link HoverProvider},
179
* may return. For once this is the actual result type `T`, like `Hover`, or a thenable that resolves
180
* to that type `T`. In addition, `null` and `undefined` can be returned - either directly or from a
181
* thenable.
182
*/
183
export type ProviderResult<T> = T | undefined | null | Thenable<T | undefined | null>;
184
185
/**
186
* A hover represents additional information for a symbol or word. Hovers are
187
* rendered in a tooltip-like widget.
188
*/
189
export interface Hover {
190
/**
191
* The contents of this hover.
192
*/
193
contents: IMarkdownString[];
194
195
/**
196
* The range to which this hover applies. When missing, the
197
* editor will use the range at the current position or the
198
* current position itself.
199
*/
200
range?: IRange;
201
202
/**
203
* Can increase the verbosity of the hover
204
*/
205
canIncreaseVerbosity?: boolean;
206
207
/**
208
* Can decrease the verbosity of the hover
209
*/
210
canDecreaseVerbosity?: boolean;
211
}
212
213
/**
214
* The hover provider interface defines the contract between extensions and
215
* the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature.
216
*/
217
export interface HoverProvider<THover = Hover> {
218
/**
219
* Provide a hover for the given position, context and document. Multiple hovers at the same
220
* position will be merged by the editor. A hover can have a range which defaults
221
* to the word range at the position when omitted.
222
*/
223
provideHover(model: model.ITextModel, position: Position, token: CancellationToken, context?: HoverContext<THover>): ProviderResult<THover>;
224
}
225
226
export interface HoverContext<THover = Hover> {
227
/**
228
* Hover verbosity request
229
*/
230
verbosityRequest?: HoverVerbosityRequest<THover>;
231
}
232
233
export interface HoverVerbosityRequest<THover = Hover> {
234
/**
235
* The delta by which to increase/decrease the hover verbosity level
236
*/
237
verbosityDelta: number;
238
/**
239
* The previous hover for the same position
240
*/
241
previousHover: THover;
242
}
243
244
export enum HoverVerbosityAction {
245
/**
246
* Increase the verbosity of the hover
247
*/
248
Increase,
249
/**
250
* Decrease the verbosity of the hover
251
*/
252
Decrease
253
}
254
255
/**
256
* An evaluatable expression represents additional information for an expression in a document. Evaluatable expressions are
257
* evaluated by a debugger or runtime and their result is rendered in a tooltip-like widget.
258
* @internal
259
*/
260
export interface EvaluatableExpression {
261
/**
262
* The range to which this expression applies.
263
*/
264
range: IRange;
265
/**
266
* This expression overrides the expression extracted from the range.
267
*/
268
expression?: string;
269
}
270
271
272
/**
273
* The evaluatable expression provider interface defines the contract between extensions and
274
* the debug hover.
275
* @internal
276
*/
277
export interface EvaluatableExpressionProvider {
278
/**
279
* Provide a hover for the given position and document. Multiple hovers at the same
280
* position will be merged by the editor. A hover can have a range which defaults
281
* to the word range at the position when omitted.
282
*/
283
provideEvaluatableExpression(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<EvaluatableExpression>;
284
}
285
286
/**
287
* A value-object that contains contextual information when requesting inline values from a InlineValuesProvider.
288
* @internal
289
*/
290
export interface InlineValueContext {
291
frameId: number;
292
stoppedLocation: Range;
293
}
294
295
/**
296
* Provide inline value as text.
297
* @internal
298
*/
299
export interface InlineValueText {
300
type: 'text';
301
range: IRange;
302
text: string;
303
}
304
305
/**
306
* Provide inline value through a variable lookup.
307
* @internal
308
*/
309
export interface InlineValueVariableLookup {
310
type: 'variable';
311
range: IRange;
312
variableName?: string;
313
caseSensitiveLookup: boolean;
314
}
315
316
/**
317
* Provide inline value through an expression evaluation.
318
* @internal
319
*/
320
export interface InlineValueExpression {
321
type: 'expression';
322
range: IRange;
323
expression?: string;
324
}
325
326
/**
327
* Inline value information can be provided by different means:
328
* - directly as a text value (class InlineValueText).
329
* - as a name to use for a variable lookup (class InlineValueVariableLookup)
330
* - as an evaluatable expression (class InlineValueEvaluatableExpression)
331
* The InlineValue types combines all inline value types into one type.
332
* @internal
333
*/
334
export type InlineValue = InlineValueText | InlineValueVariableLookup | InlineValueExpression;
335
336
/**
337
* The inline values provider interface defines the contract between extensions and
338
* the debugger's inline values feature.
339
* @internal
340
*/
341
export interface InlineValuesProvider {
342
/**
343
*/
344
onDidChangeInlineValues?: Event<void> | undefined;
345
/**
346
* Provide the "inline values" for the given range and document. Multiple hovers at the same
347
* position will be merged by the editor. A hover can have a range which defaults
348
* to the word range at the position when omitted.
349
*/
350
provideInlineValues(model: model.ITextModel, viewPort: Range, context: InlineValueContext, token: CancellationToken): ProviderResult<InlineValue[]>;
351
}
352
353
export const enum CompletionItemKind {
354
Method,
355
Function,
356
Constructor,
357
Field,
358
Variable,
359
Class,
360
Struct,
361
Interface,
362
Module,
363
Property,
364
Event,
365
Operator,
366
Unit,
367
Value,
368
Constant,
369
Enum,
370
EnumMember,
371
Keyword,
372
Text,
373
Color,
374
File,
375
Reference,
376
Customcolor,
377
Folder,
378
TypeParameter,
379
User,
380
Issue,
381
Tool,
382
Snippet, // <- highest value (used for compare!)
383
}
384
385
/**
386
* @internal
387
*/
388
export namespace CompletionItemKinds {
389
390
const byKind = new Map<CompletionItemKind, ThemeIcon>();
391
byKind.set(CompletionItemKind.Method, Codicon.symbolMethod);
392
byKind.set(CompletionItemKind.Function, Codicon.symbolFunction);
393
byKind.set(CompletionItemKind.Constructor, Codicon.symbolConstructor);
394
byKind.set(CompletionItemKind.Field, Codicon.symbolField);
395
byKind.set(CompletionItemKind.Variable, Codicon.symbolVariable);
396
byKind.set(CompletionItemKind.Class, Codicon.symbolClass);
397
byKind.set(CompletionItemKind.Struct, Codicon.symbolStruct);
398
byKind.set(CompletionItemKind.Interface, Codicon.symbolInterface);
399
byKind.set(CompletionItemKind.Module, Codicon.symbolModule);
400
byKind.set(CompletionItemKind.Property, Codicon.symbolProperty);
401
byKind.set(CompletionItemKind.Event, Codicon.symbolEvent);
402
byKind.set(CompletionItemKind.Operator, Codicon.symbolOperator);
403
byKind.set(CompletionItemKind.Unit, Codicon.symbolUnit);
404
byKind.set(CompletionItemKind.Value, Codicon.symbolValue);
405
byKind.set(CompletionItemKind.Enum, Codicon.symbolEnum);
406
byKind.set(CompletionItemKind.Constant, Codicon.symbolConstant);
407
byKind.set(CompletionItemKind.Enum, Codicon.symbolEnum);
408
byKind.set(CompletionItemKind.EnumMember, Codicon.symbolEnumMember);
409
byKind.set(CompletionItemKind.Keyword, Codicon.symbolKeyword);
410
byKind.set(CompletionItemKind.Snippet, Codicon.symbolSnippet);
411
byKind.set(CompletionItemKind.Text, Codicon.symbolText);
412
byKind.set(CompletionItemKind.Color, Codicon.symbolColor);
413
byKind.set(CompletionItemKind.File, Codicon.symbolFile);
414
byKind.set(CompletionItemKind.Reference, Codicon.symbolReference);
415
byKind.set(CompletionItemKind.Customcolor, Codicon.symbolCustomColor);
416
byKind.set(CompletionItemKind.Folder, Codicon.symbolFolder);
417
byKind.set(CompletionItemKind.TypeParameter, Codicon.symbolTypeParameter);
418
byKind.set(CompletionItemKind.User, Codicon.account);
419
byKind.set(CompletionItemKind.Issue, Codicon.issues);
420
byKind.set(CompletionItemKind.Tool, Codicon.tools);
421
422
/**
423
* @internal
424
*/
425
export function toIcon(kind: CompletionItemKind): ThemeIcon {
426
let codicon = byKind.get(kind);
427
if (!codicon) {
428
console.info('No codicon found for CompletionItemKind ' + kind);
429
codicon = Codicon.symbolProperty;
430
}
431
return codicon;
432
}
433
434
/**
435
* @internal
436
*/
437
export function toLabel(kind: CompletionItemKind): string {
438
switch (kind) {
439
case CompletionItemKind.Method: return localize('suggestWidget.kind.method', 'Method');
440
case CompletionItemKind.Function: return localize('suggestWidget.kind.function', 'Function');
441
case CompletionItemKind.Constructor: return localize('suggestWidget.kind.constructor', 'Constructor');
442
case CompletionItemKind.Field: return localize('suggestWidget.kind.field', 'Field');
443
case CompletionItemKind.Variable: return localize('suggestWidget.kind.variable', 'Variable');
444
case CompletionItemKind.Class: return localize('suggestWidget.kind.class', 'Class');
445
case CompletionItemKind.Struct: return localize('suggestWidget.kind.struct', 'Struct');
446
case CompletionItemKind.Interface: return localize('suggestWidget.kind.interface', 'Interface');
447
case CompletionItemKind.Module: return localize('suggestWidget.kind.module', 'Module');
448
case CompletionItemKind.Property: return localize('suggestWidget.kind.property', 'Property');
449
case CompletionItemKind.Event: return localize('suggestWidget.kind.event', 'Event');
450
case CompletionItemKind.Operator: return localize('suggestWidget.kind.operator', 'Operator');
451
case CompletionItemKind.Unit: return localize('suggestWidget.kind.unit', 'Unit');
452
case CompletionItemKind.Value: return localize('suggestWidget.kind.value', 'Value');
453
case CompletionItemKind.Constant: return localize('suggestWidget.kind.constant', 'Constant');
454
case CompletionItemKind.Enum: return localize('suggestWidget.kind.enum', 'Enum');
455
case CompletionItemKind.EnumMember: return localize('suggestWidget.kind.enumMember', 'Enum Member');
456
case CompletionItemKind.Keyword: return localize('suggestWidget.kind.keyword', 'Keyword');
457
case CompletionItemKind.Text: return localize('suggestWidget.kind.text', 'Text');
458
case CompletionItemKind.Color: return localize('suggestWidget.kind.color', 'Color');
459
case CompletionItemKind.File: return localize('suggestWidget.kind.file', 'File');
460
case CompletionItemKind.Reference: return localize('suggestWidget.kind.reference', 'Reference');
461
case CompletionItemKind.Customcolor: return localize('suggestWidget.kind.customcolor', 'Custom Color');
462
case CompletionItemKind.Folder: return localize('suggestWidget.kind.folder', 'Folder');
463
case CompletionItemKind.TypeParameter: return localize('suggestWidget.kind.typeParameter', 'Type Parameter');
464
case CompletionItemKind.User: return localize('suggestWidget.kind.user', 'User');
465
case CompletionItemKind.Issue: return localize('suggestWidget.kind.issue', 'Issue');
466
case CompletionItemKind.Tool: return localize('suggestWidget.kind.tool', 'Tool');
467
case CompletionItemKind.Snippet: return localize('suggestWidget.kind.snippet', 'Snippet');
468
default: return '';
469
}
470
}
471
472
const data = new Map<string, CompletionItemKind>();
473
data.set('method', CompletionItemKind.Method);
474
data.set('function', CompletionItemKind.Function);
475
data.set('constructor', CompletionItemKind.Constructor);
476
data.set('field', CompletionItemKind.Field);
477
data.set('variable', CompletionItemKind.Variable);
478
data.set('class', CompletionItemKind.Class);
479
data.set('struct', CompletionItemKind.Struct);
480
data.set('interface', CompletionItemKind.Interface);
481
data.set('module', CompletionItemKind.Module);
482
data.set('property', CompletionItemKind.Property);
483
data.set('event', CompletionItemKind.Event);
484
data.set('operator', CompletionItemKind.Operator);
485
data.set('unit', CompletionItemKind.Unit);
486
data.set('value', CompletionItemKind.Value);
487
data.set('constant', CompletionItemKind.Constant);
488
data.set('enum', CompletionItemKind.Enum);
489
data.set('enum-member', CompletionItemKind.EnumMember);
490
data.set('enumMember', CompletionItemKind.EnumMember);
491
data.set('keyword', CompletionItemKind.Keyword);
492
data.set('snippet', CompletionItemKind.Snippet);
493
data.set('text', CompletionItemKind.Text);
494
data.set('color', CompletionItemKind.Color);
495
data.set('file', CompletionItemKind.File);
496
data.set('reference', CompletionItemKind.Reference);
497
data.set('customcolor', CompletionItemKind.Customcolor);
498
data.set('folder', CompletionItemKind.Folder);
499
data.set('type-parameter', CompletionItemKind.TypeParameter);
500
data.set('typeParameter', CompletionItemKind.TypeParameter);
501
data.set('account', CompletionItemKind.User);
502
data.set('issue', CompletionItemKind.Issue);
503
data.set('tool', CompletionItemKind.Tool);
504
505
/**
506
* @internal
507
*/
508
export function fromString(value: string): CompletionItemKind;
509
/**
510
* @internal
511
*/
512
export function fromString(value: string, strict: true): CompletionItemKind | undefined;
513
/**
514
* @internal
515
*/
516
export function fromString(value: string, strict?: boolean): CompletionItemKind | undefined {
517
let res = data.get(value);
518
if (typeof res === 'undefined' && !strict) {
519
res = CompletionItemKind.Property;
520
}
521
return res;
522
}
523
}
524
525
export interface CompletionItemLabel {
526
label: string;
527
detail?: string;
528
description?: string;
529
}
530
531
export const enum CompletionItemTag {
532
Deprecated = 1
533
}
534
535
export const enum CompletionItemInsertTextRule {
536
None = 0,
537
538
/**
539
* Adjust whitespace/indentation of multiline insert texts to
540
* match the current line indentation.
541
*/
542
KeepWhitespace = 0b001,
543
544
/**
545
* `insertText` is a snippet.
546
*/
547
InsertAsSnippet = 0b100,
548
}
549
550
export interface CompletionItemRanges {
551
insert: IRange;
552
replace: IRange;
553
}
554
555
/**
556
* A completion item represents a text snippet that is
557
* proposed to complete text that is being typed.
558
*/
559
export interface CompletionItem {
560
/**
561
* The label of this completion item. By default
562
* this is also the text that is inserted when selecting
563
* this completion.
564
*/
565
label: string | CompletionItemLabel;
566
/**
567
* The kind of this completion item. Based on the kind
568
* an icon is chosen by the editor.
569
*/
570
kind: CompletionItemKind;
571
/**
572
* A modifier to the `kind` which affect how the item
573
* is rendered, e.g. Deprecated is rendered with a strikeout
574
*/
575
tags?: ReadonlyArray<CompletionItemTag>;
576
/**
577
* A human-readable string with additional information
578
* about this item, like type or symbol information.
579
*/
580
detail?: string;
581
/**
582
* A human-readable string that represents a doc-comment.
583
*/
584
documentation?: string | IMarkdownString;
585
/**
586
* A string that should be used when comparing this item
587
* with other items. When `falsy` the {@link CompletionItem.label label}
588
* is used.
589
*/
590
sortText?: string;
591
/**
592
* A string that should be used when filtering a set of
593
* completion items. When `falsy` the {@link CompletionItem.label label}
594
* is used.
595
*/
596
filterText?: string;
597
/**
598
* Select this item when showing. *Note* that only one completion item can be selected and
599
* that the editor decides which item that is. The rule is that the *first* item of those
600
* that match best is selected.
601
*/
602
preselect?: boolean;
603
/**
604
* A string or snippet that should be inserted in a document when selecting
605
* this completion.
606
*/
607
insertText: string;
608
/**
609
* Additional rules (as bitmask) that should be applied when inserting
610
* this completion.
611
*/
612
insertTextRules?: CompletionItemInsertTextRule;
613
/**
614
* A range of text that should be replaced by this completion item.
615
*
616
* *Note:* The range must be a {@link Range.isSingleLine single line} and it must
617
* {@link Range.contains contain} the position at which completion has been {@link CompletionItemProvider.provideCompletionItems requested}.
618
*/
619
range: IRange | CompletionItemRanges;
620
/**
621
* An optional set of characters that when pressed while this completion is active will accept it first and
622
* then type that character. *Note* that all commit characters should have `length=1` and that superfluous
623
* characters will be ignored.
624
*/
625
commitCharacters?: string[];
626
/**
627
* An optional array of additional text edits that are applied when
628
* selecting this completion. Edits must not overlap with the main edit
629
* nor with themselves.
630
*/
631
additionalTextEdits?: ISingleEditOperation[];
632
/**
633
* A command that should be run upon acceptance of this item.
634
*/
635
command?: Command;
636
/**
637
* A command that should be run upon acceptance of this item.
638
*/
639
action?: Command;
640
/**
641
* @internal
642
*/
643
extensionId?: ExtensionIdentifier;
644
645
/**
646
* @internal
647
*/
648
_id?: [number, number];
649
}
650
651
export interface CompletionList {
652
suggestions: CompletionItem[];
653
incomplete?: boolean;
654
dispose?(): void;
655
656
/**
657
* @internal
658
*/
659
duration?: number;
660
}
661
662
/**
663
* Info provided on partial acceptance.
664
*/
665
export interface PartialAcceptInfo {
666
kind: PartialAcceptTriggerKind;
667
acceptedLength: number;
668
}
669
670
/**
671
* How a partial acceptance was triggered.
672
*/
673
export const enum PartialAcceptTriggerKind {
674
Word = 0,
675
Line = 1,
676
Suggest = 2,
677
}
678
679
/**
680
* How a suggest provider was triggered.
681
*/
682
export const enum CompletionTriggerKind {
683
Invoke = 0,
684
TriggerCharacter = 1,
685
TriggerForIncompleteCompletions = 2
686
}
687
/**
688
* Contains additional information about the context in which
689
* {@link CompletionItemProvider.provideCompletionItems completion provider} is triggered.
690
*/
691
export interface CompletionContext {
692
/**
693
* How the completion was triggered.
694
*/
695
triggerKind: CompletionTriggerKind;
696
/**
697
* Character that triggered the completion item provider.
698
*
699
* `undefined` if provider was not triggered by a character.
700
*/
701
triggerCharacter?: string;
702
}
703
/**
704
* The completion item provider interface defines the contract between extensions and
705
* the [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense).
706
*
707
* When computing *complete* completion items is expensive, providers can optionally implement
708
* the `resolveCompletionItem`-function. In that case it is enough to return completion
709
* items with a {@link CompletionItem.label label} from the
710
* {@link CompletionItemProvider.provideCompletionItems provideCompletionItems}-function. Subsequently,
711
* when a completion item is shown in the UI and gains focus this provider is asked to resolve
712
* the item, like adding {@link CompletionItem.documentation doc-comment} or {@link CompletionItem.detail details}.
713
*/
714
export interface CompletionItemProvider {
715
716
/**
717
* Used to identify completions in the (debug) UI and telemetry. This isn't the extension identifier because extensions
718
* often contribute multiple completion item providers.
719
*
720
* @internal
721
*/
722
_debugDisplayName: string;
723
724
triggerCharacters?: string[];
725
/**
726
* Provide completion items for the given position and document.
727
*/
728
provideCompletionItems(model: model.ITextModel, position: Position, context: CompletionContext, token: CancellationToken): ProviderResult<CompletionList>;
729
730
/**
731
* Given a completion item fill in more data, like {@link CompletionItem.documentation doc-comment}
732
* or {@link CompletionItem.detail details}.
733
*
734
* The editor will only resolve a completion item once.
735
*/
736
resolveCompletionItem?(item: CompletionItem, token: CancellationToken): ProviderResult<CompletionItem>;
737
}
738
739
/**
740
* How an {@link InlineCompletionsProvider inline completion provider} was triggered.
741
*/
742
export enum InlineCompletionTriggerKind {
743
/**
744
* Completion was triggered automatically while editing.
745
* It is sufficient to return a single completion item in this case.
746
*/
747
Automatic = 0,
748
749
/**
750
* Completion was triggered explicitly by a user gesture.
751
* Return multiple completion items to enable cycling through them.
752
*/
753
Explicit = 1,
754
}
755
756
/**
757
* Arbitrary data that the provider can pass when firing {@link InlineCompletionsProvider.onDidChangeInlineCompletions}.
758
* This data is passed back to the provider in {@link InlineCompletionContext.changeHint}.
759
*/
760
export interface IInlineCompletionChangeHint {
761
/**
762
* Arbitrary data that the provider can use to identify what triggered the change.
763
* This data must be JSON serializable.
764
*/
765
readonly data?: unknown;
766
}
767
768
export interface InlineCompletionContext {
769
770
/**
771
* How the completion was triggered.
772
*/
773
readonly triggerKind: InlineCompletionTriggerKind;
774
readonly selectedSuggestionInfo: SelectedSuggestionInfo | undefined;
775
/**
776
* @experimental
777
* @internal
778
*/
779
readonly userPrompt?: string | undefined;
780
/**
781
* @experimental
782
* @internal
783
*/
784
readonly requestUuid: string;
785
786
readonly includeInlineEdits: boolean;
787
readonly includeInlineCompletions: boolean;
788
readonly requestIssuedDateTime: number;
789
readonly earliestShownDateTime: number;
790
791
/**
792
* The change hint that was passed to {@link InlineCompletionsProvider.onDidChangeInlineCompletions}.
793
* Only set if this request was triggered by such an event.
794
*/
795
readonly changeHint?: IInlineCompletionChangeHint;
796
}
797
798
export interface IInlineCompletionModelInfo {
799
models: IInlineCompletionModel[];
800
currentModelId: string;
801
}
802
803
export interface IInlineCompletionModel {
804
name: string;
805
id: string;
806
}
807
808
export class SelectedSuggestionInfo {
809
constructor(
810
public readonly range: IRange,
811
public readonly text: string,
812
public readonly completionKind: CompletionItemKind,
813
public readonly isSnippetText: boolean,
814
) {
815
}
816
817
public equals(other: SelectedSuggestionInfo) {
818
return Range.lift(this.range).equalsRange(other.range)
819
&& this.text === other.text
820
&& this.completionKind === other.completionKind
821
&& this.isSnippetText === other.isSnippetText;
822
}
823
}
824
825
export interface InlineCompletion {
826
/**
827
* The text to insert.
828
* If the text contains a line break, the range must end at the end of a line.
829
* If existing text should be replaced, the existing text must be a prefix of the text to insert.
830
*
831
* The text can also be a snippet. In that case, a preview with default parameters is shown.
832
* When accepting the suggestion, the full snippet is inserted.
833
*/
834
readonly insertText: string | { snippet: string } | undefined;
835
836
/**
837
* The range to replace.
838
* Must begin and end on the same line.
839
* Refers to the current document or `uri` if provided.
840
*/
841
readonly range?: IRange;
842
843
/**
844
* An optional array of additional text edits that are applied when
845
* selecting this completion. Edits must not overlap with the main edit
846
* nor with themselves.
847
* Refers to the current document or `uri` if provided.
848
*/
849
readonly additionalTextEdits?: ISingleEditOperation[];
850
851
/**
852
* The file for which the edit applies to.
853
*/
854
readonly uri?: UriComponents;
855
856
/**
857
* A command that is run upon acceptance of this item.
858
*/
859
readonly command?: Command;
860
861
readonly gutterMenuLinkAction?: Command;
862
863
/**
864
* Is called the first time an inline completion is shown.
865
* @deprecated. Use `onDidShow` of the provider instead.
866
*/
867
readonly shownCommand?: Command;
868
869
/**
870
* If set to `true`, unopened closing brackets are removed and unclosed opening brackets are closed.
871
* Defaults to `false`.
872
*/
873
readonly completeBracketPairs?: boolean;
874
875
readonly isInlineEdit?: boolean;
876
readonly showInlineEditMenu?: boolean;
877
878
/** Only show the inline suggestion when the cursor is in the showRange. */
879
readonly showRange?: IRange;
880
881
readonly warning?: InlineCompletionWarning;
882
883
readonly hint?: IInlineCompletionHint;
884
885
readonly supportsRename?: boolean;
886
887
/**
888
* Used for telemetry.
889
*/
890
readonly correlationId?: string | undefined;
891
892
readonly jumpToPosition?: IPosition;
893
894
readonly doNotLog?: boolean;
895
}
896
897
export interface InlineCompletionWarning {
898
message: IMarkdownString | string;
899
icon?: IconPath;
900
}
901
902
export enum InlineCompletionHintStyle {
903
Code = 1,
904
Label = 2
905
}
906
907
export interface IInlineCompletionHint {
908
/** Refers to the current document. */
909
range: IRange;
910
style: InlineCompletionHintStyle;
911
content: string;
912
}
913
914
// TODO: add `| URI | { light: URI; dark: URI }`.
915
export type IconPath = ThemeIcon;
916
917
export interface InlineCompletions<TItem extends InlineCompletion = InlineCompletion> {
918
readonly items: readonly TItem[];
919
/**
920
* A list of commands associated with the inline completions of this list.
921
*/
922
readonly commands?: InlineCompletionCommand[];
923
924
readonly suppressSuggestions?: boolean | undefined;
925
926
/**
927
* When set and the user types a suggestion without derivating from it, the inline suggestion is not updated.
928
*/
929
readonly enableForwardStability?: boolean | undefined;
930
}
931
932
export type InlineCompletionCommand = { command: Command; icon?: ThemeIcon };
933
934
export type InlineCompletionProviderGroupId = string;
935
936
export interface InlineCompletionsProvider<T extends InlineCompletions = InlineCompletions> {
937
provideInlineCompletions(model: model.ITextModel, position: Position, context: InlineCompletionContext, token: CancellationToken): ProviderResult<T>;
938
939
/**
940
* Will be called when an item is shown.
941
* @param updatedInsertText Is useful to understand bracket completion.
942
*/
943
handleItemDidShow?(completions: T, item: T['items'][number], updatedInsertText: string, editDeltaInfo: EditDeltaInfo): void;
944
945
/**
946
* Will be called when an item is partially accepted. TODO: also handle full acceptance here!
947
* @param acceptedCharacters Deprecated. Use `info.acceptedCharacters` instead.
948
*/
949
handlePartialAccept?(completions: T, item: T['items'][number], acceptedCharacters: number, info: PartialAcceptInfo): void;
950
951
/**
952
* @deprecated Use `handleEndOfLifetime` instead.
953
*/
954
handleRejection?(completions: T, item: T['items'][number]): void;
955
956
/**
957
* Is called when an inline completion item is no longer being used.
958
* Provides a reason of why it is not used anymore.
959
*/
960
handleEndOfLifetime?(completions: T, item: T['items'][number], reason: InlineCompletionEndOfLifeReason<T['items'][number]>, lifetimeSummary: LifetimeSummary): void;
961
962
/**
963
* Will be called when a completions list is no longer in use and can be garbage-collected.
964
*/
965
disposeInlineCompletions(completions: T, reason: InlineCompletionsDisposeReason): void;
966
967
/**
968
* Fired when the provider wants to trigger a new completion request.
969
* The event can pass a {@link IInlineCompletionChangeHint} which will be
970
* included in the {@link InlineCompletionContext} of the subsequent request.
971
*/
972
onDidChangeInlineCompletions?: Event<IInlineCompletionChangeHint | void>;
973
974
/**
975
* Only used for {@link yieldsToGroupIds}.
976
* Multiple providers can have the same group id.
977
*/
978
groupId?: InlineCompletionProviderGroupId;
979
980
/** @internal */
981
providerId?: ProviderId;
982
983
/**
984
* Returns a list of preferred provider {@link groupId}s.
985
* The current provider is only requested for completions if no provider with a preferred group id returned a result.
986
*/
987
yieldsToGroupIds?: InlineCompletionProviderGroupId[];
988
989
excludesGroupIds?: InlineCompletionProviderGroupId[];
990
991
displayName?: string;
992
993
debounceDelayMs?: number;
994
995
modelInfo?: IInlineCompletionModelInfo;
996
onDidModelInfoChange?: Event<void>;
997
setModelId?(modelId: string): Promise<void>;
998
999
toString?(): string;
1000
}
1001
1002
1003
/** @internal */
1004
export class ProviderId {
1005
public static fromExtensionId(extensionId: string | undefined): ProviderId {
1006
return new ProviderId(extensionId, undefined, undefined);
1007
}
1008
1009
constructor(
1010
public readonly extensionId: string | undefined,
1011
public readonly extensionVersion: string | undefined,
1012
public readonly providerId: string | undefined
1013
) {
1014
}
1015
1016
toString(): string {
1017
let result = '';
1018
if (this.extensionId) {
1019
result += this.extensionId;
1020
}
1021
if (this.extensionVersion) {
1022
result += `@${this.extensionVersion}`;
1023
}
1024
if (this.providerId) {
1025
result += `:${this.providerId}`;
1026
}
1027
if (result.length === 0) {
1028
result = 'unknown';
1029
}
1030
return result;
1031
}
1032
1033
toStringWithoutVersion(): string {
1034
let result = '';
1035
if (this.extensionId) {
1036
result += this.extensionId;
1037
}
1038
if (this.providerId) {
1039
result += `:${this.providerId}`;
1040
}
1041
return result;
1042
}
1043
}
1044
1045
/** @internal */
1046
export class VersionedExtensionId {
1047
public static tryCreate(extensionId: string | undefined, version: string | undefined): VersionedExtensionId | undefined {
1048
if (!extensionId || !version) {
1049
return undefined;
1050
}
1051
return new VersionedExtensionId(extensionId, version);
1052
}
1053
1054
constructor(
1055
public readonly extensionId: string,
1056
public readonly version: string,
1057
) { }
1058
1059
toString(): string {
1060
return `${this.extensionId}@${this.version}`;
1061
}
1062
}
1063
1064
export type InlineCompletionsDisposeReason = { kind: 'lostRace' | 'tokenCancellation' | 'other' | 'empty' | 'notTaken' };
1065
1066
export enum InlineCompletionEndOfLifeReasonKind {
1067
Accepted = 0,
1068
Rejected = 1,
1069
Ignored = 2,
1070
}
1071
1072
export type InlineCompletionEndOfLifeReason<TInlineCompletion = InlineCompletion> = {
1073
kind: InlineCompletionEndOfLifeReasonKind.Accepted; // User did an explicit action to accept
1074
alternativeAction: boolean; // Whether the user performed an alternative action.
1075
} | {
1076
kind: InlineCompletionEndOfLifeReasonKind.Rejected; // User did an explicit action to reject
1077
} | {
1078
kind: InlineCompletionEndOfLifeReasonKind.Ignored;
1079
supersededBy?: TInlineCompletion;
1080
userTypingDisagreed: boolean;
1081
};
1082
1083
export type LifetimeSummary = {
1084
requestUuid: string;
1085
correlationId: string | undefined;
1086
partiallyAccepted: number;
1087
partiallyAcceptedCountSinceOriginal: number;
1088
partiallyAcceptedRatioSinceOriginal: number;
1089
partiallyAcceptedCharactersSinceOriginal: number;
1090
shown: boolean;
1091
shownDuration: number;
1092
shownDurationUncollapsed: number;
1093
timeUntilShown: number | undefined;
1094
timeUntilActuallyShown: number | undefined;
1095
timeUntilProviderRequest: number;
1096
timeUntilProviderResponse: number;
1097
notShownReason: string | undefined;
1098
editorType: string;
1099
viewKind: string | undefined;
1100
preceeded: boolean;
1101
languageId: string;
1102
requestReason: string;
1103
performanceMarkers?: string;
1104
cursorColumnDistance?: number;
1105
cursorLineDistance?: number;
1106
lineCountOriginal?: number;
1107
lineCountModified?: number;
1108
characterCountOriginal?: number;
1109
characterCountModified?: number;
1110
disjointReplacements?: number;
1111
sameShapeReplacements?: boolean;
1112
typingInterval: number;
1113
typingIntervalCharacterCount: number;
1114
selectedSuggestionInfo: boolean;
1115
availableProviders: string;
1116
skuPlan: string | undefined;
1117
skuType: string | undefined;
1118
renameCreated: boolean | undefined;
1119
renameDuration: number | undefined;
1120
renameTimedOut: boolean | undefined;
1121
renameDroppedOtherEdits: number | undefined;
1122
renameDroppedRenameEdits: number | undefined;
1123
editKind: string | undefined;
1124
longDistanceHintVisible?: boolean;
1125
longDistanceHintDistance?: number;
1126
};
1127
1128
export interface CodeAction {
1129
title: string;
1130
command?: Command;
1131
edit?: WorkspaceEdit;
1132
diagnostics?: IMarkerData[];
1133
kind?: string;
1134
isPreferred?: boolean;
1135
isAI?: boolean;
1136
disabled?: string;
1137
ranges?: IRange[];
1138
}
1139
1140
export const enum CodeActionTriggerType {
1141
Invoke = 1,
1142
Auto = 2,
1143
}
1144
1145
/**
1146
* @internal
1147
*/
1148
export interface CodeActionContext {
1149
only?: string;
1150
trigger: CodeActionTriggerType;
1151
}
1152
1153
export interface CodeActionList extends IDisposable {
1154
readonly actions: ReadonlyArray<CodeAction>;
1155
}
1156
1157
/**
1158
* The code action interface defines the contract between extensions and
1159
* the [light bulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature.
1160
* @internal
1161
*/
1162
export interface CodeActionProvider {
1163
1164
displayName?: string;
1165
1166
extensionId?: string;
1167
1168
/**
1169
* Provide commands for the given document and range.
1170
*/
1171
provideCodeActions(model: model.ITextModel, range: Range | Selection, context: CodeActionContext, token: CancellationToken): ProviderResult<CodeActionList>;
1172
1173
/**
1174
* Given a code action fill in the edit. Will only invoked when missing.
1175
*/
1176
resolveCodeAction?(codeAction: CodeAction, token: CancellationToken): ProviderResult<CodeAction>;
1177
1178
/**
1179
* Optional list of CodeActionKinds that this provider returns.
1180
*/
1181
readonly providedCodeActionKinds?: ReadonlyArray<string>;
1182
1183
readonly documentation?: ReadonlyArray<{ readonly kind: string; readonly command: Command }>;
1184
1185
/**
1186
* @internal
1187
*/
1188
_getAdditionalMenuItems?(context: CodeActionContext, actions: readonly CodeAction[]): Command[];
1189
}
1190
1191
/**
1192
* @internal
1193
*/
1194
export interface DocumentPasteEdit {
1195
readonly title: string;
1196
readonly kind: HierarchicalKind;
1197
readonly handledMimeType?: string;
1198
yieldTo?: readonly DropYieldTo[];
1199
insertText: string | { readonly snippet: string };
1200
additionalEdit?: WorkspaceEdit;
1201
}
1202
1203
/**
1204
* @internal
1205
*/
1206
export enum DocumentPasteTriggerKind {
1207
Automatic = 0,
1208
PasteAs = 1,
1209
}
1210
1211
/**
1212
* @internal
1213
*/
1214
export interface DocumentPasteContext {
1215
readonly only?: HierarchicalKind;
1216
readonly triggerKind: DocumentPasteTriggerKind;
1217
}
1218
1219
/**
1220
* @internal
1221
*/
1222
export interface DocumentPasteEditsSession {
1223
edits: readonly DocumentPasteEdit[];
1224
dispose(): void;
1225
}
1226
1227
/**
1228
* @internal
1229
*/
1230
export interface DocumentPasteEditProvider {
1231
readonly id?: string;
1232
readonly copyMimeTypes: readonly string[];
1233
readonly pasteMimeTypes: readonly string[];
1234
readonly providedPasteEditKinds: readonly HierarchicalKind[];
1235
1236
prepareDocumentPaste?(model: model.ITextModel, ranges: readonly IRange[], dataTransfer: IReadonlyVSDataTransfer, token: CancellationToken): Promise<undefined | IReadonlyVSDataTransfer>;
1237
1238
provideDocumentPasteEdits?(model: model.ITextModel, ranges: readonly IRange[], dataTransfer: IReadonlyVSDataTransfer, context: DocumentPasteContext, token: CancellationToken): Promise<DocumentPasteEditsSession | undefined>;
1239
1240
resolveDocumentPasteEdit?(edit: DocumentPasteEdit, token: CancellationToken): Promise<DocumentPasteEdit>;
1241
}
1242
1243
/**
1244
* Represents a parameter of a callable-signature. A parameter can
1245
* have a label and a doc-comment.
1246
*/
1247
export interface ParameterInformation {
1248
/**
1249
* The label of this signature. Will be shown in
1250
* the UI.
1251
*/
1252
label: string | [number, number];
1253
/**
1254
* The human-readable doc-comment of this signature. Will be shown
1255
* in the UI but can be omitted.
1256
*/
1257
documentation?: string | IMarkdownString;
1258
}
1259
/**
1260
* Represents the signature of something callable. A signature
1261
* can have a label, like a function-name, a doc-comment, and
1262
* a set of parameters.
1263
*/
1264
export interface SignatureInformation {
1265
/**
1266
* The label of this signature. Will be shown in
1267
* the UI.
1268
*/
1269
label: string;
1270
/**
1271
* The human-readable doc-comment of this signature. Will be shown
1272
* in the UI but can be omitted.
1273
*/
1274
documentation?: string | IMarkdownString;
1275
/**
1276
* The parameters of this signature.
1277
*/
1278
parameters: ParameterInformation[];
1279
/**
1280
* Index of the active parameter.
1281
*
1282
* If provided, this is used in place of `SignatureHelp.activeSignature`.
1283
*/
1284
activeParameter?: number;
1285
}
1286
/**
1287
* Signature help represents the signature of something
1288
* callable. There can be multiple signatures but only one
1289
* active and only one active parameter.
1290
*/
1291
export interface SignatureHelp {
1292
/**
1293
* One or more signatures.
1294
*/
1295
signatures: SignatureInformation[];
1296
/**
1297
* The active signature.
1298
*/
1299
activeSignature: number;
1300
/**
1301
* The active parameter of the active signature.
1302
*/
1303
activeParameter: number;
1304
}
1305
1306
export interface SignatureHelpResult extends IDisposable {
1307
value: SignatureHelp;
1308
}
1309
1310
export enum SignatureHelpTriggerKind {
1311
Invoke = 1,
1312
TriggerCharacter = 2,
1313
ContentChange = 3,
1314
}
1315
1316
export interface SignatureHelpContext {
1317
readonly triggerKind: SignatureHelpTriggerKind;
1318
readonly triggerCharacter?: string;
1319
readonly isRetrigger: boolean;
1320
readonly activeSignatureHelp?: SignatureHelp;
1321
}
1322
1323
/**
1324
* The signature help provider interface defines the contract between extensions and
1325
* the [parameter hints](https://code.visualstudio.com/docs/editor/intellisense)-feature.
1326
*/
1327
export interface SignatureHelpProvider {
1328
1329
readonly signatureHelpTriggerCharacters?: ReadonlyArray<string>;
1330
readonly signatureHelpRetriggerCharacters?: ReadonlyArray<string>;
1331
1332
/**
1333
* Provide help for the signature at the given position and document.
1334
*/
1335
provideSignatureHelp(model: model.ITextModel, position: Position, token: CancellationToken, context: SignatureHelpContext): ProviderResult<SignatureHelpResult>;
1336
}
1337
1338
/**
1339
* A document highlight kind.
1340
*/
1341
export enum DocumentHighlightKind {
1342
/**
1343
* A textual occurrence.
1344
*/
1345
Text,
1346
/**
1347
* Read-access of a symbol, like reading a variable.
1348
*/
1349
Read,
1350
/**
1351
* Write-access of a symbol, like writing to a variable.
1352
*/
1353
Write
1354
}
1355
/**
1356
* A document highlight is a range inside a text document which deserves
1357
* special attention. Usually a document highlight is visualized by changing
1358
* the background color of its range.
1359
*/
1360
export interface DocumentHighlight {
1361
/**
1362
* The range this highlight applies to.
1363
*/
1364
range: IRange;
1365
/**
1366
* The highlight kind, default is {@link DocumentHighlightKind.Text text}.
1367
*/
1368
kind?: DocumentHighlightKind;
1369
}
1370
1371
/**
1372
* Represents a set of document highlights for a specific URI.
1373
*/
1374
export interface MultiDocumentHighlight {
1375
/**
1376
* The URI of the document that the highlights belong to.
1377
*/
1378
uri: URI;
1379
1380
/**
1381
* The set of highlights for the document.
1382
*/
1383
highlights: DocumentHighlight[];
1384
}
1385
1386
/**
1387
* The document highlight provider interface defines the contract between extensions and
1388
* the word-highlight-feature.
1389
*/
1390
export interface DocumentHighlightProvider {
1391
/**
1392
* Provide a set of document highlights, like all occurrences of a variable or
1393
* all exit-points of a function.
1394
*/
1395
provideDocumentHighlights(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<DocumentHighlight[]>;
1396
}
1397
1398
/**
1399
* A provider that can provide document highlights across multiple documents.
1400
*/
1401
export interface MultiDocumentHighlightProvider {
1402
readonly selector: LanguageSelector;
1403
1404
/**
1405
* Provide a Map of URI --> document highlights, like all occurrences of a variable or
1406
* all exit-points of a function.
1407
*
1408
* Used in cases such as split view, notebooks, etc. where there can be multiple documents
1409
* with shared symbols.
1410
*
1411
* @param primaryModel The primary text model.
1412
* @param position The position at which to provide document highlights.
1413
* @param otherModels The other text models to search for document highlights.
1414
* @param token A cancellation token.
1415
* @returns A map of URI to document highlights.
1416
*/
1417
provideMultiDocumentHighlights(primaryModel: model.ITextModel, position: Position, otherModels: model.ITextModel[], token: CancellationToken): ProviderResult<Map<URI, DocumentHighlight[]>>;
1418
}
1419
1420
/**
1421
* The linked editing range provider interface defines the contract between extensions and
1422
* the linked editing feature.
1423
*/
1424
export interface LinkedEditingRangeProvider {
1425
1426
/**
1427
* Provide a list of ranges that can be edited together.
1428
*/
1429
provideLinkedEditingRanges(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<LinkedEditingRanges>;
1430
}
1431
1432
/**
1433
* Represents a list of ranges that can be edited together along with a word pattern to describe valid contents.
1434
*/
1435
export interface LinkedEditingRanges {
1436
/**
1437
* A list of ranges that can be edited together. The ranges must have
1438
* identical length and text content. The ranges cannot overlap
1439
*/
1440
ranges: IRange[];
1441
1442
/**
1443
* An optional word pattern that describes valid contents for the given ranges.
1444
* If no pattern is provided, the language configuration's word pattern will be used.
1445
*/
1446
wordPattern?: RegExp;
1447
}
1448
1449
/**
1450
* Value-object that contains additional information when
1451
* requesting references.
1452
*/
1453
export interface ReferenceContext {
1454
/**
1455
* Include the declaration of the current symbol.
1456
*/
1457
includeDeclaration: boolean;
1458
}
1459
/**
1460
* The reference provider interface defines the contract between extensions and
1461
* the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature.
1462
*/
1463
export interface ReferenceProvider {
1464
/**
1465
* Provide a set of project-wide references for the given position and document.
1466
*/
1467
provideReferences(model: model.ITextModel, position: Position, context: ReferenceContext, token: CancellationToken): ProviderResult<Location[]>;
1468
}
1469
1470
/**
1471
* Represents a location inside a resource, such as a line
1472
* inside a text file.
1473
*/
1474
export interface Location {
1475
/**
1476
* The resource identifier of this location.
1477
*/
1478
uri: URI;
1479
/**
1480
* The document range of this locations.
1481
*/
1482
range: IRange;
1483
}
1484
1485
export interface LocationLink {
1486
/**
1487
* A range to select where this link originates from.
1488
*/
1489
originSelectionRange?: IRange;
1490
1491
/**
1492
* The target uri this link points to.
1493
*/
1494
uri: URI;
1495
1496
/**
1497
* The full range this link points to.
1498
*/
1499
range: IRange;
1500
1501
/**
1502
* A range to select this link points to. Must be contained
1503
* in `LocationLink.range`.
1504
*/
1505
targetSelectionRange?: IRange;
1506
}
1507
1508
/**
1509
* @internal
1510
*/
1511
export function isLocationLink(thing: unknown): thing is LocationLink {
1512
return !!thing
1513
&& URI.isUri((thing as LocationLink).uri)
1514
&& Range.isIRange((thing as LocationLink).range)
1515
&& (Range.isIRange((thing as LocationLink).originSelectionRange) || Range.isIRange((thing as LocationLink).targetSelectionRange));
1516
}
1517
1518
/**
1519
* @internal
1520
*/
1521
export function isLocation(thing: unknown): thing is Location {
1522
return !!thing
1523
&& URI.isUri((thing as Location).uri)
1524
&& Range.isIRange((thing as Location).range);
1525
}
1526
1527
1528
export type Definition = Location | Location[] | LocationLink[];
1529
1530
/**
1531
* The definition provider interface defines the contract between extensions and
1532
* the [go to definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition)
1533
* and peek definition features.
1534
*/
1535
export interface DefinitionProvider {
1536
/**
1537
* Provide the definition of the symbol at the given position and document.
1538
*/
1539
provideDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
1540
}
1541
1542
/**
1543
* The definition provider interface defines the contract between extensions and
1544
* the [go to definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition)
1545
* and peek definition features.
1546
*/
1547
export interface DeclarationProvider {
1548
/**
1549
* Provide the declaration of the symbol at the given position and document.
1550
*/
1551
provideDeclaration(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
1552
}
1553
1554
/**
1555
* The implementation provider interface defines the contract between extensions and
1556
* the go to implementation feature.
1557
*/
1558
export interface ImplementationProvider {
1559
/**
1560
* Provide the implementation of the symbol at the given position and document.
1561
*/
1562
provideImplementation(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
1563
}
1564
1565
/**
1566
* The type definition provider interface defines the contract between extensions and
1567
* the go to type definition feature.
1568
*/
1569
export interface TypeDefinitionProvider {
1570
/**
1571
* Provide the type definition of the symbol at the given position and document.
1572
*/
1573
provideTypeDefinition(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<Definition | LocationLink[]>;
1574
}
1575
1576
/**
1577
* A symbol kind.
1578
*/
1579
export const enum SymbolKind {
1580
File = 0,
1581
Module = 1,
1582
Namespace = 2,
1583
Package = 3,
1584
Class = 4,
1585
Method = 5,
1586
Property = 6,
1587
Field = 7,
1588
Constructor = 8,
1589
Enum = 9,
1590
Interface = 10,
1591
Function = 11,
1592
Variable = 12,
1593
Constant = 13,
1594
String = 14,
1595
Number = 15,
1596
Boolean = 16,
1597
Array = 17,
1598
Object = 18,
1599
Key = 19,
1600
Null = 20,
1601
EnumMember = 21,
1602
Struct = 22,
1603
Event = 23,
1604
Operator = 24,
1605
TypeParameter = 25
1606
}
1607
1608
/**
1609
* @internal
1610
*/
1611
export const symbolKindNames: { [symbol: number]: string } = {
1612
[SymbolKind.Array]: localize('Array', "array"),
1613
[SymbolKind.Boolean]: localize('Boolean', "boolean"),
1614
[SymbolKind.Class]: localize('Class', "class"),
1615
[SymbolKind.Constant]: localize('Constant', "constant"),
1616
[SymbolKind.Constructor]: localize('Constructor', "constructor"),
1617
[SymbolKind.Enum]: localize('Enum', "enumeration"),
1618
[SymbolKind.EnumMember]: localize('EnumMember', "enumeration member"),
1619
[SymbolKind.Event]: localize('Event', "event"),
1620
[SymbolKind.Field]: localize('Field', "field"),
1621
[SymbolKind.File]: localize('File', "file"),
1622
[SymbolKind.Function]: localize('Function', "function"),
1623
[SymbolKind.Interface]: localize('Interface', "interface"),
1624
[SymbolKind.Key]: localize('Key', "key"),
1625
[SymbolKind.Method]: localize('Method', "method"),
1626
[SymbolKind.Module]: localize('Module', "module"),
1627
[SymbolKind.Namespace]: localize('Namespace', "namespace"),
1628
[SymbolKind.Null]: localize('Null', "null"),
1629
[SymbolKind.Number]: localize('Number', "number"),
1630
[SymbolKind.Object]: localize('Object', "object"),
1631
[SymbolKind.Operator]: localize('Operator', "operator"),
1632
[SymbolKind.Package]: localize('Package', "package"),
1633
[SymbolKind.Property]: localize('Property', "property"),
1634
[SymbolKind.String]: localize('String', "string"),
1635
[SymbolKind.Struct]: localize('Struct', "struct"),
1636
[SymbolKind.TypeParameter]: localize('TypeParameter', "type parameter"),
1637
[SymbolKind.Variable]: localize('Variable', "variable"),
1638
};
1639
1640
/**
1641
* @internal
1642
*/
1643
export function getAriaLabelForSymbol(symbolName: string, kind: SymbolKind): string {
1644
return localize('symbolAriaLabel', '{0} ({1})', symbolName, symbolKindNames[kind]);
1645
}
1646
1647
export const enum SymbolTag {
1648
Deprecated = 1,
1649
}
1650
1651
/**
1652
* @internal
1653
*/
1654
export namespace SymbolKinds {
1655
1656
const byKind = new Map<SymbolKind, ThemeIcon>();
1657
byKind.set(SymbolKind.File, Codicon.symbolFile);
1658
byKind.set(SymbolKind.Module, Codicon.symbolModule);
1659
byKind.set(SymbolKind.Namespace, Codicon.symbolNamespace);
1660
byKind.set(SymbolKind.Package, Codicon.symbolPackage);
1661
byKind.set(SymbolKind.Class, Codicon.symbolClass);
1662
byKind.set(SymbolKind.Method, Codicon.symbolMethod);
1663
byKind.set(SymbolKind.Property, Codicon.symbolProperty);
1664
byKind.set(SymbolKind.Field, Codicon.symbolField);
1665
byKind.set(SymbolKind.Constructor, Codicon.symbolConstructor);
1666
byKind.set(SymbolKind.Enum, Codicon.symbolEnum);
1667
byKind.set(SymbolKind.Interface, Codicon.symbolInterface);
1668
byKind.set(SymbolKind.Function, Codicon.symbolFunction);
1669
byKind.set(SymbolKind.Variable, Codicon.symbolVariable);
1670
byKind.set(SymbolKind.Constant, Codicon.symbolConstant);
1671
byKind.set(SymbolKind.String, Codicon.symbolString);
1672
byKind.set(SymbolKind.Number, Codicon.symbolNumber);
1673
byKind.set(SymbolKind.Boolean, Codicon.symbolBoolean);
1674
byKind.set(SymbolKind.Array, Codicon.symbolArray);
1675
byKind.set(SymbolKind.Object, Codicon.symbolObject);
1676
byKind.set(SymbolKind.Key, Codicon.symbolKey);
1677
byKind.set(SymbolKind.Null, Codicon.symbolNull);
1678
byKind.set(SymbolKind.EnumMember, Codicon.symbolEnumMember);
1679
byKind.set(SymbolKind.Struct, Codicon.symbolStruct);
1680
byKind.set(SymbolKind.Event, Codicon.symbolEvent);
1681
byKind.set(SymbolKind.Operator, Codicon.symbolOperator);
1682
byKind.set(SymbolKind.TypeParameter, Codicon.symbolTypeParameter);
1683
/**
1684
* @internal
1685
*/
1686
export function toIcon(kind: SymbolKind): ThemeIcon {
1687
let icon = byKind.get(kind);
1688
if (!icon) {
1689
console.info('No codicon found for SymbolKind ' + kind);
1690
icon = Codicon.symbolProperty;
1691
}
1692
return icon;
1693
}
1694
1695
const byCompletionKind = new Map<SymbolKind, CompletionItemKind>();
1696
byCompletionKind.set(SymbolKind.File, CompletionItemKind.File);
1697
byCompletionKind.set(SymbolKind.Module, CompletionItemKind.Module);
1698
byCompletionKind.set(SymbolKind.Namespace, CompletionItemKind.Module);
1699
byCompletionKind.set(SymbolKind.Package, CompletionItemKind.Module);
1700
byCompletionKind.set(SymbolKind.Class, CompletionItemKind.Class);
1701
byCompletionKind.set(SymbolKind.Method, CompletionItemKind.Method);
1702
byCompletionKind.set(SymbolKind.Property, CompletionItemKind.Property);
1703
byCompletionKind.set(SymbolKind.Field, CompletionItemKind.Field);
1704
byCompletionKind.set(SymbolKind.Constructor, CompletionItemKind.Constructor);
1705
byCompletionKind.set(SymbolKind.Enum, CompletionItemKind.Enum);
1706
byCompletionKind.set(SymbolKind.Interface, CompletionItemKind.Interface);
1707
byCompletionKind.set(SymbolKind.Function, CompletionItemKind.Function);
1708
byCompletionKind.set(SymbolKind.Variable, CompletionItemKind.Variable);
1709
byCompletionKind.set(SymbolKind.Constant, CompletionItemKind.Constant);
1710
byCompletionKind.set(SymbolKind.String, CompletionItemKind.Text);
1711
byCompletionKind.set(SymbolKind.Number, CompletionItemKind.Value);
1712
byCompletionKind.set(SymbolKind.Boolean, CompletionItemKind.Value);
1713
byCompletionKind.set(SymbolKind.Array, CompletionItemKind.Value);
1714
byCompletionKind.set(SymbolKind.Object, CompletionItemKind.Value);
1715
byCompletionKind.set(SymbolKind.Key, CompletionItemKind.Keyword);
1716
byCompletionKind.set(SymbolKind.Null, CompletionItemKind.Value);
1717
byCompletionKind.set(SymbolKind.EnumMember, CompletionItemKind.EnumMember);
1718
byCompletionKind.set(SymbolKind.Struct, CompletionItemKind.Struct);
1719
byCompletionKind.set(SymbolKind.Event, CompletionItemKind.Event);
1720
byCompletionKind.set(SymbolKind.Operator, CompletionItemKind.Operator);
1721
byCompletionKind.set(SymbolKind.TypeParameter, CompletionItemKind.TypeParameter);
1722
/**
1723
* @internal
1724
*/
1725
export function toCompletionKind(kind: SymbolKind): CompletionItemKind {
1726
let completionKind = byCompletionKind.get(kind);
1727
if (completionKind === undefined) {
1728
console.info('No completion kind found for SymbolKind ' + kind);
1729
completionKind = CompletionItemKind.File;
1730
}
1731
return completionKind;
1732
}
1733
}
1734
1735
export interface DocumentSymbol {
1736
name: string;
1737
detail: string;
1738
kind: SymbolKind;
1739
tags: ReadonlyArray<SymbolTag>;
1740
containerName?: string;
1741
range: IRange;
1742
selectionRange: IRange;
1743
children?: DocumentSymbol[];
1744
}
1745
1746
/**
1747
* The document symbol provider interface defines the contract between extensions and
1748
* the [go to symbol](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-symbol)-feature.
1749
*/
1750
export interface DocumentSymbolProvider {
1751
1752
displayName?: string;
1753
1754
/**
1755
* Provide symbol information for the given document.
1756
*/
1757
provideDocumentSymbols(model: model.ITextModel, token: CancellationToken): ProviderResult<DocumentSymbol[]>;
1758
}
1759
1760
export interface TextEdit {
1761
range: IRange;
1762
text: string;
1763
eol?: model.EndOfLineSequence;
1764
}
1765
1766
/** @internal */
1767
export abstract class TextEdit {
1768
static asEditOperation(edit: TextEdit): ISingleEditOperation {
1769
const range = Range.lift(edit.range);
1770
return range.isEmpty()
1771
? EditOperation.insert(range.getStartPosition(), edit.text) // moves marker
1772
: EditOperation.replace(range, edit.text);
1773
}
1774
static isTextEdit(thing: unknown): thing is TextEdit {
1775
const possibleTextEdit = thing as TextEdit;
1776
return typeof possibleTextEdit.text === 'string' && Range.isIRange(possibleTextEdit.range);
1777
}
1778
}
1779
1780
/**
1781
* Interface used to format a model
1782
*/
1783
export interface FormattingOptions {
1784
/**
1785
* Size of a tab in spaces.
1786
*/
1787
tabSize: number;
1788
/**
1789
* Prefer spaces over tabs.
1790
*/
1791
insertSpaces: boolean;
1792
}
1793
/**
1794
* The document formatting provider interface defines the contract between extensions and
1795
* the formatting-feature.
1796
*/
1797
export interface DocumentFormattingEditProvider {
1798
1799
/**
1800
* @internal
1801
*/
1802
readonly extensionId?: ExtensionIdentifier;
1803
1804
readonly displayName?: string;
1805
1806
/**
1807
* Provide formatting edits for a whole document.
1808
*/
1809
provideDocumentFormattingEdits(model: model.ITextModel, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
1810
}
1811
/**
1812
* The document formatting provider interface defines the contract between extensions and
1813
* the formatting-feature.
1814
*/
1815
export interface DocumentRangeFormattingEditProvider {
1816
/**
1817
* @internal
1818
*/
1819
readonly extensionId?: ExtensionIdentifier;
1820
1821
readonly displayName?: string;
1822
1823
/**
1824
* Provide formatting edits for a range in a document.
1825
*
1826
* The given range is a hint and providers can decide to format a smaller
1827
* or larger range. Often this is done by adjusting the start and end
1828
* of the range to full syntax nodes.
1829
*/
1830
provideDocumentRangeFormattingEdits(model: model.ITextModel, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
1831
1832
provideDocumentRangesFormattingEdits?(model: model.ITextModel, ranges: Range[], options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
1833
}
1834
/**
1835
* The document formatting provider interface defines the contract between extensions and
1836
* the formatting-feature.
1837
*/
1838
export interface OnTypeFormattingEditProvider {
1839
1840
1841
/**
1842
* @internal
1843
*/
1844
readonly extensionId?: ExtensionIdentifier;
1845
1846
autoFormatTriggerCharacters: string[];
1847
1848
/**
1849
* Provide formatting edits after a character has been typed.
1850
*
1851
* The given position and character should hint to the provider
1852
* what range the position to expand to, like find the matching `{`
1853
* when `}` has been entered.
1854
*/
1855
provideOnTypeFormattingEdits(model: model.ITextModel, position: Position, ch: string, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
1856
}
1857
1858
/**
1859
* @internal
1860
*/
1861
export interface IInplaceReplaceSupportResult {
1862
value: string;
1863
range: IRange;
1864
}
1865
1866
/**
1867
* A link inside the editor.
1868
*/
1869
export interface ILink {
1870
range: IRange;
1871
url?: URI | string;
1872
tooltip?: string;
1873
}
1874
1875
export interface ILinksList {
1876
links: ILink[];
1877
dispose?(): void;
1878
}
1879
/**
1880
* A provider of links.
1881
*/
1882
export interface LinkProvider {
1883
provideLinks(model: model.ITextModel, token: CancellationToken): ProviderResult<ILinksList>;
1884
resolveLink?: (link: ILink, token: CancellationToken) => ProviderResult<ILink>;
1885
}
1886
1887
/**
1888
* A color in RGBA format.
1889
*/
1890
export interface IColor {
1891
1892
/**
1893
* The red component in the range [0-1].
1894
*/
1895
readonly red: number;
1896
1897
/**
1898
* The green component in the range [0-1].
1899
*/
1900
readonly green: number;
1901
1902
/**
1903
* The blue component in the range [0-1].
1904
*/
1905
readonly blue: number;
1906
1907
/**
1908
* The alpha component in the range [0-1].
1909
*/
1910
readonly alpha: number;
1911
}
1912
1913
/**
1914
* String representations for a color
1915
*/
1916
export interface IColorPresentation {
1917
/**
1918
* The label of this color presentation. It will be shown on the color
1919
* picker header. By default this is also the text that is inserted when selecting
1920
* this color presentation.
1921
*/
1922
label: string;
1923
/**
1924
* An {@link TextEdit edit} which is applied to a document when selecting
1925
* this presentation for the color.
1926
*/
1927
textEdit?: TextEdit;
1928
/**
1929
* An optional array of additional {@link TextEdit text edits} that are applied when
1930
* selecting this color presentation.
1931
*/
1932
additionalTextEdits?: TextEdit[];
1933
}
1934
1935
/**
1936
* A color range is a range in a text model which represents a color.
1937
*/
1938
export interface IColorInformation {
1939
1940
/**
1941
* The range within the model.
1942
*/
1943
range: IRange;
1944
1945
/**
1946
* The color represented in this range.
1947
*/
1948
color: IColor;
1949
}
1950
1951
/**
1952
* A provider of colors for editor models.
1953
*/
1954
export interface DocumentColorProvider {
1955
/**
1956
* Provides the color ranges for a specific model.
1957
*/
1958
provideDocumentColors(model: model.ITextModel, token: CancellationToken): ProviderResult<IColorInformation[]>;
1959
/**
1960
* Provide the string representations for a color.
1961
*/
1962
provideColorPresentations(model: model.ITextModel, colorInfo: IColorInformation, token: CancellationToken): ProviderResult<IColorPresentation[]>;
1963
}
1964
1965
export interface SelectionRange {
1966
range: IRange;
1967
}
1968
1969
export interface SelectionRangeProvider {
1970
/**
1971
* Provide ranges that should be selected from the given position.
1972
*/
1973
provideSelectionRanges(model: model.ITextModel, positions: Position[], token: CancellationToken): ProviderResult<SelectionRange[][]>;
1974
}
1975
1976
export interface FoldingContext {
1977
}
1978
/**
1979
* A provider of folding ranges for editor models.
1980
*/
1981
export interface FoldingRangeProvider {
1982
1983
/**
1984
* @internal
1985
*/
1986
readonly id?: string;
1987
1988
/**
1989
* An optional event to signal that the folding ranges from this provider have changed.
1990
*/
1991
onDidChange?: Event<this>;
1992
1993
/**
1994
* Provides the folding ranges for a specific model.
1995
*/
1996
provideFoldingRanges(model: model.ITextModel, context: FoldingContext, token: CancellationToken): ProviderResult<FoldingRange[]>;
1997
}
1998
1999
export interface FoldingRange {
2000
2001
/**
2002
* The one-based start line of the range to fold. The folded area starts after the line's last character.
2003
*/
2004
start: number;
2005
2006
/**
2007
* The one-based end line of the range to fold. The folded area ends with the line's last character.
2008
*/
2009
end: number;
2010
2011
/**
2012
* Describes the {@link FoldingRangeKind Kind} of the folding range such as {@link FoldingRangeKind.Comment Comment} or
2013
* {@link FoldingRangeKind.Region Region}. The kind is used to categorize folding ranges and used by commands
2014
* like 'Fold all comments'. See
2015
* {@link FoldingRangeKind} for an enumeration of standardized kinds.
2016
*/
2017
kind?: FoldingRangeKind;
2018
}
2019
export class FoldingRangeKind {
2020
/**
2021
* Kind for folding range representing a comment. The value of the kind is 'comment'.
2022
*/
2023
static readonly Comment = new FoldingRangeKind('comment');
2024
/**
2025
* Kind for folding range representing a import. The value of the kind is 'imports'.
2026
*/
2027
static readonly Imports = new FoldingRangeKind('imports');
2028
/**
2029
* Kind for folding range representing regions (for example marked by `#region`, `#endregion`).
2030
* The value of the kind is 'region'.
2031
*/
2032
static readonly Region = new FoldingRangeKind('region');
2033
2034
/**
2035
* Returns a {@link FoldingRangeKind} for the given value.
2036
*
2037
* @param value of the kind.
2038
*/
2039
static fromValue(value: string) {
2040
switch (value) {
2041
case 'comment': return FoldingRangeKind.Comment;
2042
case 'imports': return FoldingRangeKind.Imports;
2043
case 'region': return FoldingRangeKind.Region;
2044
}
2045
return new FoldingRangeKind(value);
2046
}
2047
2048
/**
2049
* Creates a new {@link FoldingRangeKind}.
2050
*
2051
* @param value of the kind.
2052
*/
2053
public constructor(public value: string) {
2054
}
2055
}
2056
2057
2058
export interface WorkspaceEditMetadata {
2059
needsConfirmation: boolean;
2060
label: string;
2061
description?: string;
2062
/**
2063
* @internal
2064
*/
2065
iconPath?: ThemeIcon | URI | { light: URI; dark: URI };
2066
}
2067
2068
export interface WorkspaceFileEditOptions {
2069
overwrite?: boolean;
2070
ignoreIfNotExists?: boolean;
2071
ignoreIfExists?: boolean;
2072
recursive?: boolean;
2073
copy?: boolean;
2074
folder?: boolean;
2075
skipTrashBin?: boolean;
2076
maxSize?: number;
2077
2078
/**
2079
* @internal
2080
*/
2081
contents?: Promise<VSBuffer>;
2082
}
2083
2084
export interface IWorkspaceFileEdit {
2085
oldResource?: URI;
2086
newResource?: URI;
2087
options?: WorkspaceFileEditOptions;
2088
metadata?: WorkspaceEditMetadata;
2089
}
2090
2091
export interface IWorkspaceTextEdit {
2092
resource: URI;
2093
textEdit: TextEdit & { insertAsSnippet?: boolean; keepWhitespace?: boolean };
2094
versionId: number | undefined;
2095
metadata?: WorkspaceEditMetadata;
2096
}
2097
2098
export interface WorkspaceEdit {
2099
edits: Array<IWorkspaceTextEdit | IWorkspaceFileEdit | ICustomEdit>;
2100
}
2101
2102
export interface ICustomEdit {
2103
readonly resource: URI;
2104
readonly metadata?: WorkspaceEditMetadata;
2105
undo(): Promise<void> | void;
2106
redo(): Promise<void> | void;
2107
}
2108
2109
export interface Rejection {
2110
rejectReason?: string;
2111
}
2112
export interface RenameLocation {
2113
range: IRange;
2114
text: string;
2115
}
2116
2117
export interface RenameProvider {
2118
provideRenameEdits(model: model.ITextModel, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit & Rejection>;
2119
resolveRenameLocation?(model: model.ITextModel, position: Position, token: CancellationToken): ProviderResult<RenameLocation & Rejection>;
2120
}
2121
2122
export enum NewSymbolNameTag {
2123
AIGenerated = 1
2124
}
2125
2126
export enum NewSymbolNameTriggerKind {
2127
Invoke = 0,
2128
Automatic = 1,
2129
}
2130
2131
export interface NewSymbolName {
2132
readonly newSymbolName: string;
2133
readonly tags?: readonly NewSymbolNameTag[];
2134
}
2135
2136
export interface NewSymbolNamesProvider {
2137
supportsAutomaticNewSymbolNamesTriggerKind?: Promise<boolean | undefined>;
2138
provideNewSymbolNames(model: model.ITextModel, range: IRange, triggerKind: NewSymbolNameTriggerKind, token: CancellationToken): ProviderResult<NewSymbolName[]>;
2139
}
2140
2141
export interface Command {
2142
id: string;
2143
title: string;
2144
tooltip?: string;
2145
arguments?: unknown[];
2146
}
2147
2148
/**
2149
* @internal
2150
*/
2151
export namespace Command {
2152
2153
/**
2154
* @internal
2155
*/
2156
export function is(obj: unknown): obj is Command {
2157
if (!obj || typeof obj !== 'object') {
2158
return false;
2159
}
2160
return typeof (<Command>obj).id === 'string' &&
2161
typeof (<Command>obj).title === 'string';
2162
}
2163
}
2164
2165
/**
2166
* @internal
2167
*/
2168
export interface CommentThreadTemplate {
2169
controllerHandle: number;
2170
label: string;
2171
acceptInputCommand?: Command;
2172
additionalCommands?: Command[];
2173
deleteCommand?: Command;
2174
}
2175
2176
/**
2177
* @internal
2178
*/
2179
export interface CommentInfo<T = IRange> {
2180
extensionId?: string;
2181
threads: CommentThread<T>[];
2182
pendingCommentThreads?: PendingCommentThread[];
2183
commentingRanges: CommentingRanges;
2184
}
2185
2186
2187
/**
2188
* @internal
2189
*/
2190
export interface CommentingRangeResourceHint {
2191
schemes: readonly string[];
2192
}
2193
2194
/**
2195
* @internal
2196
*/
2197
export enum CommentThreadCollapsibleState {
2198
/**
2199
* Determines an item is collapsed
2200
*/
2201
Collapsed = 0,
2202
/**
2203
* Determines an item is expanded
2204
*/
2205
Expanded = 1
2206
}
2207
2208
/**
2209
* @internal
2210
*/
2211
export enum CommentThreadState {
2212
Unresolved = 0,
2213
Resolved = 1
2214
}
2215
2216
/**
2217
* @internal
2218
*/
2219
export enum CommentThreadApplicability {
2220
Current = 0,
2221
Outdated = 1
2222
}
2223
2224
/**
2225
* @internal
2226
*/
2227
export interface CommentWidget {
2228
commentThread: CommentThread;
2229
comment?: Comment;
2230
input: string;
2231
readonly onDidChangeInput: Event<string>;
2232
}
2233
2234
/**
2235
* @internal
2236
*/
2237
export interface CommentInput {
2238
value: string;
2239
uri: URI;
2240
}
2241
2242
export interface CommentThreadRevealOptions {
2243
preserveFocus: boolean;
2244
focusReply: boolean;
2245
}
2246
2247
/**
2248
* @internal
2249
*/
2250
export interface CommentThread<T = IRange> {
2251
isDocumentCommentThread(): this is CommentThread<IRange>;
2252
commentThreadHandle: number;
2253
controllerHandle: number;
2254
extensionId?: string;
2255
threadId: string;
2256
resource: string | null;
2257
range: T | undefined;
2258
label: string | undefined;
2259
contextValue: string | undefined;
2260
comments: ReadonlyArray<Comment> | undefined;
2261
readonly onDidChangeComments: Event<readonly Comment[] | undefined>;
2262
collapsibleState?: CommentThreadCollapsibleState;
2263
initialCollapsibleState?: CommentThreadCollapsibleState;
2264
readonly onDidChangeInitialCollapsibleState: Event<CommentThreadCollapsibleState | undefined>;
2265
state?: CommentThreadState;
2266
applicability?: CommentThreadApplicability;
2267
canReply: boolean | CommentAuthorInformation;
2268
input?: CommentInput;
2269
readonly onDidChangeInput: Event<CommentInput | undefined>;
2270
readonly onDidChangeLabel: Event<string | undefined>;
2271
readonly onDidChangeCollapsibleState: Event<CommentThreadCollapsibleState | undefined>;
2272
readonly onDidChangeState: Event<CommentThreadState | undefined>;
2273
readonly onDidChangeCanReply: Event<boolean>;
2274
isDisposed: boolean;
2275
isTemplate: boolean;
2276
}
2277
2278
/**
2279
* @internal
2280
*/
2281
export interface AddedCommentThread<T = IRange> extends CommentThread<T> {
2282
editorId?: string;
2283
}
2284
2285
/**
2286
* @internal
2287
*/
2288
2289
export interface CommentingRanges {
2290
readonly resource: URI;
2291
ranges: IRange[];
2292
fileComments: boolean;
2293
}
2294
2295
export interface CommentAuthorInformation {
2296
name: string;
2297
iconPath?: UriComponents;
2298
2299
}
2300
2301
/**
2302
* @internal
2303
*/
2304
export interface CommentReaction {
2305
readonly label?: string;
2306
readonly iconPath?: UriComponents;
2307
readonly count?: number;
2308
readonly hasReacted?: boolean;
2309
readonly canEdit?: boolean;
2310
readonly reactors?: readonly string[];
2311
}
2312
2313
/**
2314
* @internal
2315
*/
2316
export interface CommentOptions {
2317
/**
2318
* An optional string to show on the comment input box when it's collapsed.
2319
*/
2320
prompt?: string;
2321
2322
/**
2323
* An optional string to show as placeholder in the comment input box when it's focused.
2324
*/
2325
placeHolder?: string;
2326
}
2327
2328
/**
2329
* @internal
2330
*/
2331
export enum CommentMode {
2332
Editing = 0,
2333
Preview = 1
2334
}
2335
2336
/**
2337
* @internal
2338
*/
2339
export enum CommentState {
2340
Published = 0,
2341
Draft = 1
2342
}
2343
2344
/**
2345
* @internal
2346
*/
2347
export interface Comment {
2348
readonly uniqueIdInThread: number;
2349
readonly body: string | IMarkdownString;
2350
readonly userName: string;
2351
readonly userIconPath?: UriComponents;
2352
readonly contextValue?: string;
2353
readonly commentReactions?: CommentReaction[];
2354
readonly label?: string;
2355
readonly mode?: CommentMode;
2356
readonly state?: CommentState;
2357
readonly timestamp?: string;
2358
}
2359
2360
export interface PendingCommentThread {
2361
range: IRange | undefined;
2362
uri: URI;
2363
uniqueOwner: string;
2364
isReply: boolean;
2365
comment: PendingComment;
2366
}
2367
2368
export interface PendingComment {
2369
body: string;
2370
cursor: IPosition;
2371
}
2372
2373
/**
2374
* @internal
2375
*/
2376
export interface CommentThreadChangedEvent<T> {
2377
/**
2378
* Pending comment threads.
2379
*/
2380
readonly pending: PendingCommentThread[];
2381
2382
/**
2383
* Added comment threads.
2384
*/
2385
readonly added: AddedCommentThread<T>[];
2386
2387
/**
2388
* Removed comment threads.
2389
*/
2390
readonly removed: CommentThread<T>[];
2391
2392
/**
2393
* Changed comment threads.
2394
*/
2395
readonly changed: CommentThread<T>[];
2396
}
2397
2398
export interface CodeLens {
2399
range: IRange;
2400
id?: string;
2401
command?: Command;
2402
}
2403
2404
export interface CodeLensList {
2405
readonly lenses: readonly CodeLens[];
2406
dispose?(): void;
2407
}
2408
2409
export interface CodeLensProvider {
2410
onDidChange?: Event<this>;
2411
provideCodeLenses(model: model.ITextModel, token: CancellationToken): ProviderResult<CodeLensList>;
2412
resolveCodeLens?(model: model.ITextModel, codeLens: CodeLens, token: CancellationToken): ProviderResult<CodeLens>;
2413
}
2414
2415
2416
export enum InlayHintKind {
2417
Type = 1,
2418
Parameter = 2,
2419
}
2420
2421
export interface InlayHintLabelPart {
2422
label: string;
2423
tooltip?: string | IMarkdownString;
2424
// collapsible?: boolean;
2425
command?: Command;
2426
location?: Location;
2427
}
2428
2429
export interface InlayHint {
2430
label: string | InlayHintLabelPart[];
2431
tooltip?: string | IMarkdownString;
2432
textEdits?: TextEdit[];
2433
position: IPosition;
2434
kind?: InlayHintKind;
2435
paddingLeft?: boolean;
2436
paddingRight?: boolean;
2437
}
2438
2439
export interface InlayHintList {
2440
hints: InlayHint[];
2441
dispose(): void;
2442
}
2443
2444
export interface InlayHintsProvider {
2445
displayName?: string;
2446
onDidChangeInlayHints?: Event<void>;
2447
provideInlayHints(model: model.ITextModel, range: Range, token: CancellationToken): ProviderResult<InlayHintList>;
2448
resolveInlayHint?(hint: InlayHint, token: CancellationToken): ProviderResult<InlayHint>;
2449
}
2450
2451
export interface SemanticTokensLegend {
2452
readonly tokenTypes: string[];
2453
readonly tokenModifiers: string[];
2454
}
2455
2456
export interface SemanticTokens {
2457
readonly resultId?: string;
2458
readonly data: Uint32Array;
2459
}
2460
2461
export interface SemanticTokensEdit {
2462
readonly start: number;
2463
readonly deleteCount: number;
2464
readonly data?: Uint32Array;
2465
}
2466
2467
export interface SemanticTokensEdits {
2468
readonly resultId?: string;
2469
readonly edits: SemanticTokensEdit[];
2470
}
2471
2472
export interface DocumentSemanticTokensProvider {
2473
readonly onDidChange?: Event<void>;
2474
getLegend(): SemanticTokensLegend;
2475
provideDocumentSemanticTokens(model: model.ITextModel, lastResultId: string | null, token: CancellationToken): ProviderResult<SemanticTokens | SemanticTokensEdits>;
2476
releaseDocumentSemanticTokens(resultId: string | undefined): void;
2477
}
2478
2479
export interface DocumentRangeSemanticTokensProvider {
2480
readonly onDidChange?: Event<void>;
2481
getLegend(): SemanticTokensLegend;
2482
provideDocumentRangeSemanticTokens(model: model.ITextModel, range: Range, token: CancellationToken): ProviderResult<SemanticTokens>;
2483
}
2484
2485
/**
2486
* @internal
2487
*/
2488
export interface ITokenizationSupportChangedEvent {
2489
changedLanguages: string[];
2490
changedColorMap: boolean;
2491
}
2492
2493
/**
2494
* @internal
2495
*/
2496
export interface ILazyTokenizationSupport<TSupport> {
2497
get tokenizationSupport(): Promise<TSupport | null>;
2498
}
2499
2500
/**
2501
* @internal
2502
*/
2503
export class LazyTokenizationSupport<TSupport = ITokenizationSupport> implements IDisposable, ILazyTokenizationSupport<TSupport> {
2504
private _tokenizationSupport: Promise<TSupport & IDisposable | null> | null = null;
2505
2506
constructor(private readonly createSupport: () => Promise<TSupport & IDisposable | null>) {
2507
}
2508
2509
dispose(): void {
2510
if (this._tokenizationSupport) {
2511
this._tokenizationSupport.then((support) => {
2512
if (support) {
2513
support.dispose();
2514
}
2515
});
2516
}
2517
}
2518
2519
get tokenizationSupport(): Promise<TSupport | null> {
2520
if (!this._tokenizationSupport) {
2521
this._tokenizationSupport = this.createSupport();
2522
}
2523
return this._tokenizationSupport;
2524
}
2525
}
2526
2527
/**
2528
* @internal
2529
*/
2530
export interface ITokenizationRegistry<TSupport> {
2531
2532
/**
2533
* An event triggered when:
2534
* - a tokenization support is registered, unregistered or changed.
2535
* - the color map is changed.
2536
*/
2537
readonly onDidChange: Event<ITokenizationSupportChangedEvent>;
2538
2539
/**
2540
* Fire a change event for a language.
2541
* This is useful for languages that embed other languages.
2542
*/
2543
handleChange(languageIds: string[]): void;
2544
2545
/**
2546
* Register a tokenization support.
2547
*/
2548
register(languageId: string, support: TSupport): IDisposable;
2549
2550
/**
2551
* Register a tokenization support factory.
2552
*/
2553
registerFactory(languageId: string, factory: ILazyTokenizationSupport<TSupport>): IDisposable;
2554
2555
/**
2556
* Get or create the tokenization support for a language.
2557
* Returns `null` if not found.
2558
*/
2559
getOrCreate(languageId: string): Promise<TSupport | null>;
2560
2561
/**
2562
* Get the tokenization support for a language.
2563
* Returns `null` if not found.
2564
*/
2565
get(languageId: string): TSupport | null;
2566
2567
/**
2568
* Returns false if a factory is still pending.
2569
*/
2570
isResolved(languageId: string): boolean;
2571
2572
/**
2573
* Set the new color map that all tokens will use in their ColorId binary encoded bits for foreground and background.
2574
*/
2575
setColorMap(colorMap: Color[]): void;
2576
2577
getColorMap(): Color[] | null;
2578
2579
getDefaultBackground(): Color | null;
2580
}
2581
2582
/**
2583
* @internal
2584
*/
2585
export const TokenizationRegistry: ITokenizationRegistry<ITokenizationSupport> = new TokenizationRegistryImpl();
2586
2587
/**
2588
* @internal
2589
*/
2590
export enum ExternalUriOpenerPriority {
2591
None = 0,
2592
Option = 1,
2593
Default = 2,
2594
Preferred = 3,
2595
}
2596
2597
/**
2598
* @internal
2599
*/
2600
export type DropYieldTo = { readonly kind: HierarchicalKind } | { readonly mimeType: string };
2601
2602
/**
2603
* @internal
2604
*/
2605
export interface DocumentDropEdit {
2606
readonly title: string;
2607
readonly kind: HierarchicalKind | undefined;
2608
readonly handledMimeType?: string;
2609
readonly yieldTo?: readonly DropYieldTo[];
2610
insertText: string | { readonly snippet: string };
2611
additionalEdit?: WorkspaceEdit;
2612
}
2613
2614
/**
2615
* @internal
2616
*/
2617
export interface DocumentDropEditsSession {
2618
edits: readonly DocumentDropEdit[];
2619
dispose(): void;
2620
}
2621
2622
/**
2623
* @internal
2624
*/
2625
export interface DocumentDropEditProvider {
2626
readonly id?: string;
2627
readonly dropMimeTypes?: readonly string[];
2628
readonly providedDropEditKinds?: readonly HierarchicalKind[];
2629
2630
provideDocumentDropEdits(model: model.ITextModel, position: IPosition, dataTransfer: IReadonlyVSDataTransfer, token: CancellationToken): ProviderResult<DocumentDropEditsSession>;
2631
resolveDocumentDropEdit?(edit: DocumentDropEdit, token: CancellationToken): Promise<DocumentDropEdit>;
2632
}
2633
2634