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