index.d.ts (741400B)
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 /** 7 * Type Definition for Visual Studio Code 1.108 Extension API 8 * See https://code.visualstudio.com/api for more information 9 */ 10 11 declare module 'vscode' { 12 13 /** 14 * The version of the editor. 15 */ 16 export const version: string; 17 18 /** 19 * Represents a reference to a command. Provides a title which 20 * will be used to represent a command in the UI and, optionally, 21 * an array of arguments which will be passed to the command handler 22 * function when invoked. 23 */ 24 export interface Command { 25 /** 26 * Title of the command, like `save`. 27 */ 28 title: string; 29 30 /** 31 * The identifier of the actual command handler. 32 * @see {@link commands.registerCommand} 33 */ 34 command: string; 35 36 /** 37 * A tooltip for the command, when represented in the UI. 38 */ 39 tooltip?: string; 40 41 /** 42 * Arguments that the command handler should be 43 * invoked with. 44 */ 45 arguments?: any[]; 46 } 47 48 /** 49 * Represents a line of text, such as a line of source code. 50 * 51 * TextLine objects are __immutable__. When a {@link TextDocument document} changes, 52 * previously retrieved lines will not represent the latest state. 53 */ 54 export interface TextLine { 55 56 /** 57 * The zero-based line number. 58 */ 59 readonly lineNumber: number; 60 61 /** 62 * The text of this line without the line separator characters. 63 */ 64 readonly text: string; 65 66 /** 67 * The range this line covers without the line separator characters. 68 */ 69 readonly range: Range; 70 71 /** 72 * The range this line covers with the line separator characters. 73 */ 74 readonly rangeIncludingLineBreak: Range; 75 76 /** 77 * The offset of the first character which is not a whitespace character as defined 78 * by `/\s/`. **Note** that if a line is all whitespace the length of the line is returned. 79 */ 80 readonly firstNonWhitespaceCharacterIndex: number; 81 82 /** 83 * Whether this line is whitespace only, shorthand 84 * for {@link TextLine.firstNonWhitespaceCharacterIndex} === {@link TextLine.text TextLine.text.length}. 85 */ 86 readonly isEmptyOrWhitespace: boolean; 87 } 88 89 /** 90 * Represents a text document, such as a source file. Text documents have 91 * {@link TextLine lines} and knowledge about an underlying resource like a file. 92 */ 93 export interface TextDocument { 94 95 /** 96 * The associated uri for this document. 97 * 98 * *Note* that most documents use the `file`-scheme, which means they are files on disk. However, **not** all documents are 99 * saved on disk and therefore the `scheme` must be checked before trying to access the underlying file or siblings on disk. 100 * 101 * @see {@link FileSystemProvider} 102 * @see {@link TextDocumentContentProvider} 103 */ 104 readonly uri: Uri; 105 106 /** 107 * The file system path of the associated resource. Shorthand 108 * notation for {@link TextDocument.uri TextDocument.uri.fsPath}. Independent of the uri scheme. 109 */ 110 readonly fileName: string; 111 112 /** 113 * Is this document representing an untitled file which has never been saved yet. *Note* that 114 * this does not mean the document will be saved to disk, use {@linkcode Uri.scheme} 115 * to figure out where a document will be {@link FileSystemProvider saved}, e.g. `file`, `ftp` etc. 116 */ 117 readonly isUntitled: boolean; 118 119 /** 120 * The identifier of the language associated with this document. 121 */ 122 readonly languageId: string; 123 124 /** 125 * The file encoding of this document that will be used when the document is saved. 126 * 127 * Use the {@link workspace.onDidChangeTextDocument onDidChangeTextDocument}-event to 128 * get notified when the document encoding changes. 129 * 130 * Note that the possible encoding values are currently defined as any of the following: 131 * 'utf8', 'utf8bom', 'utf16le', 'utf16be', 'windows1252', 'iso88591', 'iso88593', 132 * 'iso885915', 'macroman', 'cp437', 'windows1256', 'iso88596', 'windows1257', 133 * 'iso88594', 'iso885914', 'windows1250', 'iso88592', 'cp852', 'windows1251', 134 * 'cp866', 'cp1125', 'iso88595', 'koi8r', 'koi8u', 'iso885913', 'windows1253', 135 * 'iso88597', 'windows1255', 'iso88598', 'iso885910', 'iso885916', 'windows1254', 136 * 'iso88599', 'windows1258', 'gbk', 'gb18030', 'cp950', 'big5hkscs', 'shiftjis', 137 * 'eucjp', 'euckr', 'windows874', 'iso885911', 'koi8ru', 'koi8t', 'gb2312', 138 * 'cp865', 'cp850'. 139 */ 140 readonly encoding: string; 141 142 /** 143 * The version number of this document (it will strictly increase after each 144 * change, including undo/redo). 145 */ 146 readonly version: number; 147 148 /** 149 * `true` if there are unpersisted changes. 150 */ 151 readonly isDirty: boolean; 152 153 /** 154 * `true` if the document has been closed. A closed document isn't synchronized anymore 155 * and won't be re-used when the same resource is opened again. 156 */ 157 readonly isClosed: boolean; 158 159 /** 160 * Save the underlying file. 161 * 162 * @returns A promise that will resolve to `true` when the file 163 * has been saved. If the save failed, will return `false`. 164 */ 165 save(): Thenable<boolean>; 166 167 /** 168 * The {@link EndOfLine end of line} sequence that is predominately 169 * used in this document. 170 */ 171 readonly eol: EndOfLine; 172 173 /** 174 * The number of lines in this document. 175 */ 176 readonly lineCount: number; 177 178 /** 179 * Returns a text line denoted by the line number. Note 180 * that the returned object is *not* live and changes to the 181 * document are not reflected. 182 * 183 * @param line A line number in `[0, lineCount)`. 184 * @returns A {@link TextLine line}. 185 */ 186 lineAt(line: number): TextLine; 187 188 /** 189 * Returns a text line denoted by the position. Note 190 * that the returned object is *not* live and changes to the 191 * document are not reflected. 192 * 193 * The position will be {@link TextDocument.validatePosition adjusted}. 194 * 195 * @see {@link TextDocument.lineAt} 196 * 197 * @param position A position. 198 * @returns A {@link TextLine line}. 199 */ 200 lineAt(position: Position): TextLine; 201 202 /** 203 * Converts the position to a zero-based offset. 204 * 205 * The position will be {@link TextDocument.validatePosition adjusted}. 206 * 207 * @param position A position. 208 * @returns A valid zero-based offset in UTF-16 [code units](https://developer.mozilla.org/en-US/docs/Glossary/Code_unit). 209 */ 210 offsetAt(position: Position): number; 211 212 /** 213 * Converts a zero-based offset to a position. 214 * 215 * @param offset A zero-based offset into the document. This offset is in UTF-16 [code units](https://developer.mozilla.org/en-US/docs/Glossary/Code_unit). 216 * @returns A valid {@link Position}. 217 */ 218 positionAt(offset: number): Position; 219 220 /** 221 * Get the text of this document. A substring can be retrieved by providing 222 * a range. The range will be {@link TextDocument.validateRange adjusted}. 223 * 224 * @param range Include only the text included by the range. 225 * @returns The text inside the provided range or the entire text. 226 */ 227 getText(range?: Range): string; 228 229 /** 230 * Get a word-range at the given position. By default words are defined by 231 * common separators, like space, -, _, etc. In addition, per language custom 232 * [word definitions] can be defined. It 233 * is also possible to provide a custom regular expression. 234 * 235 * * *Note 1:* A custom regular expression must not match the empty string and 236 * if it does, it will be ignored. 237 * * *Note 2:* A custom regular expression will fail to match multiline strings 238 * and in the name of speed regular expressions should not match words with 239 * spaces. Use {@linkcode TextLine.text} for more complex, non-wordy, scenarios. 240 * 241 * The position will be {@link TextDocument.validatePosition adjusted}. 242 * 243 * @param position A position. 244 * @param regex Optional regular expression that describes what a word is. 245 * @returns A range spanning a word, or `undefined`. 246 */ 247 getWordRangeAtPosition(position: Position, regex?: RegExp): Range | undefined; 248 249 /** 250 * Ensure a range is completely contained in this document. 251 * 252 * @param range A range. 253 * @returns The given range or a new, adjusted range. 254 */ 255 validateRange(range: Range): Range; 256 257 /** 258 * Ensure a position is contained in the range of this document. 259 * 260 * @param position A position. 261 * @returns The given position or a new, adjusted position. 262 */ 263 validatePosition(position: Position): Position; 264 } 265 266 /** 267 * Represents a line and character position, such as 268 * the position of the cursor. 269 * 270 * Position objects are __immutable__. Use the {@link Position.with with} or 271 * {@link Position.translate translate} methods to derive new positions 272 * from an existing position. 273 */ 274 export class Position { 275 276 /** 277 * The zero-based line value. 278 */ 279 readonly line: number; 280 281 /** 282 * The zero-based character value. 283 * 284 * Character offsets are expressed using UTF-16 [code units](https://developer.mozilla.org/en-US/docs/Glossary/Code_unit). 285 */ 286 readonly character: number; 287 288 /** 289 * @param line A zero-based line value. 290 * @param character A zero-based character value. 291 */ 292 constructor(line: number, character: number); 293 294 /** 295 * Check if this position is before `other`. 296 * 297 * @param other A position. 298 * @returns `true` if position is on a smaller line 299 * or on the same line on a smaller character. 300 */ 301 isBefore(other: Position): boolean; 302 303 /** 304 * Check if this position is before or equal to `other`. 305 * 306 * @param other A position. 307 * @returns `true` if position is on a smaller line 308 * or on the same line on a smaller or equal character. 309 */ 310 isBeforeOrEqual(other: Position): boolean; 311 312 /** 313 * Check if this position is after `other`. 314 * 315 * @param other A position. 316 * @returns `true` if position is on a greater line 317 * or on the same line on a greater character. 318 */ 319 isAfter(other: Position): boolean; 320 321 /** 322 * Check if this position is after or equal to `other`. 323 * 324 * @param other A position. 325 * @returns `true` if position is on a greater line 326 * or on the same line on a greater or equal character. 327 */ 328 isAfterOrEqual(other: Position): boolean; 329 330 /** 331 * Check if this position is equal to `other`. 332 * 333 * @param other A position. 334 * @returns `true` if the line and character of the given position are equal to 335 * the line and character of this position. 336 */ 337 isEqual(other: Position): boolean; 338 339 /** 340 * Compare this to `other`. 341 * 342 * @param other A position. 343 * @returns A number smaller than zero if this position is before the given position, 344 * a number greater than zero if this position is after the given position, or zero when 345 * this and the given position are equal. 346 */ 347 compareTo(other: Position): number; 348 349 /** 350 * Create a new position relative to this position. 351 * 352 * @param lineDelta Delta value for the line value, default is `0`. 353 * @param characterDelta Delta value for the character value, default is `0`. 354 * @returns A position which line and character is the sum of the current line and 355 * character and the corresponding deltas. 356 */ 357 translate(lineDelta?: number, characterDelta?: number): Position; 358 359 /** 360 * Derived a new position relative to this position. 361 * 362 * @param change An object that describes a delta to this position. 363 * @returns A position that reflects the given delta. Will return `this` position if the change 364 * is not changing anything. 365 */ 366 translate(change: { 367 /** 368 * Delta value for the line value, default is `0`. 369 */ 370 lineDelta?: number; 371 /** 372 * Delta value for the character value, default is `0`. 373 */ 374 characterDelta?: number; 375 }): Position; 376 377 /** 378 * Create a new position derived from this position. 379 * 380 * @param line Value that should be used as line value, default is the {@link Position.line existing value} 381 * @param character Value that should be used as character value, default is the {@link Position.character existing value} 382 * @returns A position where line and character are replaced by the given values. 383 */ 384 with(line?: number, character?: number): Position; 385 386 /** 387 * Derived a new position from this position. 388 * 389 * @param change An object that describes a change to this position. 390 * @returns A position that reflects the given change. Will return `this` position if the change 391 * is not changing anything. 392 */ 393 with(change: { 394 /** 395 * New line value, defaults the line value of `this`. 396 */ 397 line?: number; 398 /** 399 * New character value, defaults the character value of `this`. 400 */ 401 character?: number; 402 }): Position; 403 } 404 405 /** 406 * A range represents an ordered pair of two positions. 407 * It is guaranteed that {@link Range.start start}.isBeforeOrEqual({@link Range.end end}) 408 * 409 * Range objects are __immutable__. Use the {@link Range.with with}, 410 * {@link Range.intersection intersection}, or {@link Range.union union} methods 411 * to derive new ranges from an existing range. 412 */ 413 export class Range { 414 415 /** 416 * The start position. It is before or equal to {@link Range.end end}. 417 */ 418 readonly start: Position; 419 420 /** 421 * The end position. It is after or equal to {@link Range.start start}. 422 */ 423 readonly end: Position; 424 425 /** 426 * Create a new range from two positions. If `start` is not 427 * before or equal to `end`, the values will be swapped. 428 * 429 * @param start A position. 430 * @param end A position. 431 */ 432 constructor(start: Position, end: Position); 433 434 /** 435 * Create a new range from number coordinates. It is a shorter equivalent of 436 * using `new Range(new Position(startLine, startCharacter), new Position(endLine, endCharacter))` 437 * 438 * @param startLine A zero-based line value. 439 * @param startCharacter A zero-based character value. 440 * @param endLine A zero-based line value. 441 * @param endCharacter A zero-based character value. 442 */ 443 constructor(startLine: number, startCharacter: number, endLine: number, endCharacter: number); 444 445 /** 446 * `true` if `start` and `end` are equal. 447 */ 448 isEmpty: boolean; 449 450 /** 451 * `true` if `start.line` and `end.line` are equal. 452 */ 453 isSingleLine: boolean; 454 455 /** 456 * Check if a position or a range is contained in this range. 457 * 458 * @param positionOrRange A position or a range. 459 * @returns `true` if the position or range is inside or equal 460 * to this range. 461 */ 462 contains(positionOrRange: Position | Range): boolean; 463 464 /** 465 * Check if `other` equals this range. 466 * 467 * @param other A range. 468 * @returns `true` when start and end are {@link Position.isEqual equal} to 469 * start and end of this range. 470 */ 471 isEqual(other: Range): boolean; 472 473 /** 474 * Intersect `range` with this range and returns a new range or `undefined` 475 * if the ranges have no overlap. 476 * 477 * @param range A range. 478 * @returns A range of the greater start and smaller end positions. Will 479 * return undefined when there is no overlap. 480 */ 481 intersection(range: Range): Range | undefined; 482 483 /** 484 * Compute the union of `other` with this range. 485 * 486 * @param other A range. 487 * @returns A range of smaller start position and the greater end position. 488 */ 489 union(other: Range): Range; 490 491 /** 492 * Derived a new range from this range. 493 * 494 * @param start A position that should be used as start. The default value is the {@link Range.start current start}. 495 * @param end A position that should be used as end. The default value is the {@link Range.end current end}. 496 * @returns A range derived from this range with the given start and end position. 497 * If start and end are not different `this` range will be returned. 498 */ 499 with(start?: Position, end?: Position): Range; 500 501 /** 502 * Derived a new range from this range. 503 * 504 * @param change An object that describes a change to this range. 505 * @returns A range that reflects the given change. Will return `this` range if the change 506 * is not changing anything. 507 */ 508 with(change: { 509 /** 510 * New start position, defaults to {@link Range.start current start} 511 */ 512 start?: Position; 513 /** 514 * New end position, defaults to {@link Range.end current end} 515 */ 516 end?: Position; 517 }): Range; 518 } 519 520 /** 521 * Represents a text selection in an editor. 522 */ 523 export class Selection extends Range { 524 525 /** 526 * The position at which the selection starts. 527 * This position might be before or after {@link Selection.active active}. 528 */ 529 readonly anchor: Position; 530 531 /** 532 * The position of the cursor. 533 * This position might be before or after {@link Selection.anchor anchor}. 534 */ 535 readonly active: Position; 536 537 /** 538 * Create a selection from two positions. 539 * 540 * @param anchor A position. 541 * @param active A position. 542 */ 543 constructor(anchor: Position, active: Position); 544 545 /** 546 * Create a selection from four coordinates. 547 * 548 * @param anchorLine A zero-based line value. 549 * @param anchorCharacter A zero-based character value. 550 * @param activeLine A zero-based line value. 551 * @param activeCharacter A zero-based character value. 552 */ 553 constructor(anchorLine: number, anchorCharacter: number, activeLine: number, activeCharacter: number); 554 555 /** 556 * A selection is reversed if its {@link Selection.anchor anchor} is the {@link Selection.end end} position. 557 */ 558 readonly isReversed: boolean; 559 } 560 561 /** 562 * Represents sources that can cause {@link window.onDidChangeTextEditorSelection selection change events}. 563 */ 564 export enum TextEditorSelectionChangeKind { 565 /** 566 * Selection changed due to typing in the editor. 567 */ 568 Keyboard = 1, 569 /** 570 * Selection change due to clicking in the editor. 571 */ 572 Mouse = 2, 573 /** 574 * Selection changed because a command ran. 575 */ 576 Command = 3 577 } 578 579 /** 580 * Represents an event describing the change in a {@link TextEditor.selections text editor's selections}. 581 */ 582 export interface TextEditorSelectionChangeEvent { 583 /** 584 * The {@link TextEditor text editor} for which the selections have changed. 585 */ 586 readonly textEditor: TextEditor; 587 /** 588 * The new value for the {@link TextEditor.selections text editor's selections}. 589 */ 590 readonly selections: readonly Selection[]; 591 /** 592 * The {@link TextEditorSelectionChangeKind change kind} which has triggered this 593 * event. Can be `undefined`. 594 */ 595 readonly kind: TextEditorSelectionChangeKind | undefined; 596 } 597 598 /** 599 * Represents an event describing the change in a {@link TextEditor.visibleRanges text editor's visible ranges}. 600 */ 601 export interface TextEditorVisibleRangesChangeEvent { 602 /** 603 * The {@link TextEditor text editor} for which the visible ranges have changed. 604 */ 605 readonly textEditor: TextEditor; 606 /** 607 * The new value for the {@link TextEditor.visibleRanges text editor's visible ranges}. 608 */ 609 readonly visibleRanges: readonly Range[]; 610 } 611 612 /** 613 * Represents an event describing the change in a {@link TextEditor.options text editor's options}. 614 */ 615 export interface TextEditorOptionsChangeEvent { 616 /** 617 * The {@link TextEditor text editor} for which the options have changed. 618 */ 619 readonly textEditor: TextEditor; 620 /** 621 * The new value for the {@link TextEditor.options text editor's options}. 622 */ 623 readonly options: TextEditorOptions; 624 } 625 626 /** 627 * Represents an event describing the change of a {@link TextEditor.viewColumn text editor's view column}. 628 */ 629 export interface TextEditorViewColumnChangeEvent { 630 /** 631 * The {@link TextEditor text editor} for which the view column has changed. 632 */ 633 readonly textEditor: TextEditor; 634 /** 635 * The new value for the {@link TextEditor.viewColumn text editor's view column}. 636 */ 637 readonly viewColumn: ViewColumn; 638 } 639 640 /** 641 * Rendering style of the cursor. 642 */ 643 export enum TextEditorCursorStyle { 644 /** 645 * Render the cursor as a vertical thick line. 646 */ 647 Line = 1, 648 /** 649 * Render the cursor as a block filled. 650 */ 651 Block = 2, 652 /** 653 * Render the cursor as a thick horizontal line. 654 */ 655 Underline = 3, 656 /** 657 * Render the cursor as a vertical thin line. 658 */ 659 LineThin = 4, 660 /** 661 * Render the cursor as a block outlined. 662 */ 663 BlockOutline = 5, 664 /** 665 * Render the cursor as a thin horizontal line. 666 */ 667 UnderlineThin = 6 668 } 669 670 /** 671 * Rendering style of the line numbers. 672 */ 673 export enum TextEditorLineNumbersStyle { 674 /** 675 * Do not render the line numbers. 676 */ 677 Off = 0, 678 /** 679 * Render the line numbers. 680 */ 681 On = 1, 682 /** 683 * Render the line numbers with values relative to the primary cursor location. 684 */ 685 Relative = 2, 686 /** 687 * Render the line numbers on every 10th line number. 688 */ 689 Interval = 3, 690 } 691 692 /** 693 * Represents a {@link TextEditor text editor}'s {@link TextEditor.options options}. 694 */ 695 export interface TextEditorOptions { 696 697 /** 698 * The size in spaces a tab takes. This is used for two purposes: 699 * - the rendering width of a tab character; 700 * - the number of spaces to insert when {@link TextEditorOptions.insertSpaces insertSpaces} is true 701 * and `indentSize` is set to `"tabSize"`. 702 * 703 * When getting a text editor's options, this property will always be a number (resolved). 704 * When setting a text editor's options, this property is optional and it can be a number or `"auto"`. 705 */ 706 tabSize?: number | string; 707 708 /** 709 * The number of spaces to insert when {@link TextEditorOptions.insertSpaces insertSpaces} is true. 710 * 711 * When getting a text editor's options, this property will always be a number (resolved). 712 * When setting a text editor's options, this property is optional and it can be a number or `"tabSize"`. 713 */ 714 indentSize?: number | string; 715 716 /** 717 * When pressing Tab insert {@link TextEditorOptions.tabSize n} spaces. 718 * When getting a text editor's options, this property will always be a boolean (resolved). 719 * When setting a text editor's options, this property is optional and it can be a boolean or `"auto"`. 720 */ 721 insertSpaces?: boolean | string; 722 723 /** 724 * The rendering style of the cursor in this editor. 725 * When getting a text editor's options, this property will always be present. 726 * When setting a text editor's options, this property is optional. 727 */ 728 cursorStyle?: TextEditorCursorStyle; 729 730 /** 731 * Render relative line numbers w.r.t. the current line number. 732 * When getting a text editor's options, this property will always be present. 733 * When setting a text editor's options, this property is optional. 734 */ 735 lineNumbers?: TextEditorLineNumbersStyle; 736 } 737 738 /** 739 * Represents a handle to a set of decorations 740 * sharing the same {@link DecorationRenderOptions styling options} in a {@link TextEditor text editor}. 741 * 742 * To get an instance of a `TextEditorDecorationType` use 743 * {@link window.createTextEditorDecorationType createTextEditorDecorationType}. 744 */ 745 export interface TextEditorDecorationType { 746 747 /** 748 * Internal representation of the handle. 749 */ 750 readonly key: string; 751 752 /** 753 * Remove this decoration type and all decorations on all text editors using it. 754 */ 755 dispose(): void; 756 } 757 758 /** 759 * Represents different {@link TextEditor.revealRange reveal} strategies in a text editor. 760 */ 761 export enum TextEditorRevealType { 762 /** 763 * The range will be revealed with as little scrolling as possible. 764 */ 765 Default = 0, 766 /** 767 * The range will always be revealed in the center of the viewport. 768 */ 769 InCenter = 1, 770 /** 771 * If the range is outside the viewport, it will be revealed in the center of the viewport. 772 * Otherwise, it will be revealed with as little scrolling as possible. 773 */ 774 InCenterIfOutsideViewport = 2, 775 /** 776 * The range will always be revealed at the top of the viewport. 777 */ 778 AtTop = 3 779 } 780 781 /** 782 * Represents different positions for rendering a decoration in an {@link DecorationRenderOptions.overviewRulerLane overview ruler}. 783 * The overview ruler supports three lanes. 784 */ 785 export enum OverviewRulerLane { 786 /** 787 * The left lane of the overview ruler. 788 */ 789 Left = 1, 790 /** 791 * The center lane of the overview ruler. 792 */ 793 Center = 2, 794 /** 795 * The right lane of the overview ruler. 796 */ 797 Right = 4, 798 /** 799 * All lanes of the overview ruler. 800 */ 801 Full = 7 802 } 803 804 /** 805 * Describes the behavior of decorations when typing/editing at their edges. 806 */ 807 export enum DecorationRangeBehavior { 808 /** 809 * The decoration's range will widen when edits occur at the start or end. 810 */ 811 OpenOpen = 0, 812 /** 813 * The decoration's range will not widen when edits occur at the start or end. 814 */ 815 ClosedClosed = 1, 816 /** 817 * The decoration's range will widen when edits occur at the start, but not at the end. 818 */ 819 OpenClosed = 2, 820 /** 821 * The decoration's range will widen when edits occur at the end, but not at the start. 822 */ 823 ClosedOpen = 3 824 } 825 826 /** 827 * Represents options to configure the behavior of showing a {@link TextDocument document} in an {@link TextEditor editor}. 828 */ 829 export interface TextDocumentShowOptions { 830 /** 831 * An optional view column in which the {@link TextEditor editor} should be shown. 832 * The default is the {@link ViewColumn.Active active}. Columns that do not exist 833 * will be created as needed up to the maximum of {@linkcode ViewColumn.Nine}. 834 * Use {@linkcode ViewColumn.Beside} to open the editor to the side of the currently 835 * active one. 836 */ 837 viewColumn?: ViewColumn; 838 839 /** 840 * An optional flag that when `true` will stop the {@link TextEditor editor} from taking focus. 841 */ 842 preserveFocus?: boolean; 843 844 /** 845 * An optional flag that controls if an {@link TextEditor editor}-tab shows as preview. Preview tabs will 846 * be replaced and reused until set to stay - either explicitly or through editing. 847 * 848 * *Note* that the flag is ignored if a user has disabled preview editors in settings. 849 */ 850 preview?: boolean; 851 852 /** 853 * An optional selection to apply for the document in the {@link TextEditor editor}. 854 */ 855 selection?: Range; 856 } 857 858 /** 859 * Represents an event describing the change in a {@link NotebookEditor.selections notebook editor's selections}. 860 */ 861 export interface NotebookEditorSelectionChangeEvent { 862 /** 863 * The {@link NotebookEditor notebook editor} for which the selections have changed. 864 */ 865 readonly notebookEditor: NotebookEditor; 866 867 /** 868 * The new value for the {@link NotebookEditor.selections notebook editor's selections}. 869 */ 870 readonly selections: readonly NotebookRange[]; 871 } 872 873 /** 874 * Represents an event describing the change in a {@link NotebookEditor.visibleRanges notebook editor's visibleRanges}. 875 */ 876 export interface NotebookEditorVisibleRangesChangeEvent { 877 /** 878 * The {@link NotebookEditor notebook editor} for which the visible ranges have changed. 879 */ 880 readonly notebookEditor: NotebookEditor; 881 882 /** 883 * The new value for the {@link NotebookEditor.visibleRanges notebook editor's visibleRanges}. 884 */ 885 readonly visibleRanges: readonly NotebookRange[]; 886 } 887 888 /** 889 * Represents options to configure the behavior of showing a {@link NotebookDocument notebook document} in an {@link NotebookEditor notebook editor}. 890 */ 891 export interface NotebookDocumentShowOptions { 892 /** 893 * An optional view column in which the {@link NotebookEditor notebook editor} should be shown. 894 * The default is the {@link ViewColumn.Active active}. Columns that do not exist 895 * will be created as needed up to the maximum of {@linkcode ViewColumn.Nine}. 896 * Use {@linkcode ViewColumn.Beside} to open the editor to the side of the currently 897 * active one. 898 */ 899 readonly viewColumn?: ViewColumn; 900 901 /** 902 * An optional flag that when `true` will stop the {@link NotebookEditor notebook editor} from taking focus. 903 */ 904 readonly preserveFocus?: boolean; 905 906 /** 907 * An optional flag that controls if an {@link NotebookEditor notebook editor}-tab shows as preview. Preview tabs will 908 * be replaced and reused until set to stay - either explicitly or through editing. The default behaviour depends 909 * on the `workbench.editor.enablePreview`-setting. 910 */ 911 readonly preview?: boolean; 912 913 /** 914 * An optional selection to apply for the document in the {@link NotebookEditor notebook editor}. 915 */ 916 readonly selections?: readonly NotebookRange[]; 917 } 918 919 /** 920 * A reference to one of the workbench colors as defined in https://code.visualstudio.com/api/references/theme-color. 921 * Using a theme color is preferred over a custom color as it gives theme authors and users the possibility to change the color. 922 */ 923 export class ThemeColor { 924 925 /** 926 * The id of this color. 927 */ 928 readonly id: string; 929 930 /** 931 * Creates a reference to a theme color. 932 * @param id of the color. The available colors are listed in https://code.visualstudio.com/api/references/theme-color. 933 */ 934 constructor(id: string); 935 } 936 937 /** 938 * A reference to a named icon. Currently, {@link ThemeIcon.File File}, {@link ThemeIcon.Folder Folder}, 939 * and [ThemeIcon ids](https://code.visualstudio.com/api/references/icons-in-labels#icon-listing) are supported. 940 * Using a theme icon is preferred over a custom icon as it gives product theme authors the possibility to change the icons. 941 * 942 * *Note* that theme icons can also be rendered inside labels and descriptions. Places that support theme icons spell this out 943 * and they use the `$(<name>)`-syntax, for instance `quickPick.label = "Hello World $(globe)"`. 944 */ 945 export class ThemeIcon { 946 /** 947 * Reference to an icon representing a file. The icon is taken from the current file icon theme or a placeholder icon is used. 948 */ 949 static readonly File: ThemeIcon; 950 951 /** 952 * Reference to an icon representing a folder. The icon is taken from the current file icon theme or a placeholder icon is used. 953 */ 954 static readonly Folder: ThemeIcon; 955 956 /** 957 * The id of the icon. The available icons are listed in https://code.visualstudio.com/api/references/icons-in-labels#icon-listing. 958 */ 959 readonly id: string; 960 961 /** 962 * The optional ThemeColor of the icon. The color is currently only used in {@link TreeItem}. 963 */ 964 readonly color?: ThemeColor | undefined; 965 966 /** 967 * Creates a reference to a theme icon. 968 * @param id id of the icon. The available icons are listed in https://code.visualstudio.com/api/references/icons-in-labels#icon-listing. 969 * @param color optional `ThemeColor` for the icon. The color is currently only used in {@link TreeItem}. 970 */ 971 constructor(id: string, color?: ThemeColor); 972 } 973 974 /** 975 * Represents an icon in the UI. This is either an uri, separate uris for the light- and dark-themes, 976 * or a {@link ThemeIcon theme icon}. 977 */ 978 export type IconPath = Uri | { 979 /** 980 * The icon path for the light theme. 981 */ 982 light: Uri; 983 /** 984 * The icon path for the dark theme. 985 */ 986 dark: Uri; 987 } | ThemeIcon; 988 989 /** 990 * Represents theme specific rendering styles for a {@link TextEditorDecorationType text editor decoration}. 991 */ 992 export interface ThemableDecorationRenderOptions { 993 /** 994 * Background color of the decoration. Use rgba() and define transparent background colors to play well with other decorations. 995 * Alternatively a color from the color registry can be {@link ThemeColor referenced}. 996 */ 997 backgroundColor?: string | ThemeColor; 998 999 /** 1000 * CSS styling property that will be applied to text enclosed by a decoration. 1001 */ 1002 outline?: string; 1003 1004 /** 1005 * CSS styling property that will be applied to text enclosed by a decoration. 1006 * Better use 'outline' for setting one or more of the individual outline properties. 1007 */ 1008 outlineColor?: string | ThemeColor; 1009 1010 /** 1011 * CSS styling property that will be applied to text enclosed by a decoration. 1012 * Better use 'outline' for setting one or more of the individual outline properties. 1013 */ 1014 outlineStyle?: string; 1015 1016 /** 1017 * CSS styling property that will be applied to text enclosed by a decoration. 1018 * Better use 'outline' for setting one or more of the individual outline properties. 1019 */ 1020 outlineWidth?: string; 1021 1022 /** 1023 * CSS styling property that will be applied to text enclosed by a decoration. 1024 */ 1025 border?: string; 1026 1027 /** 1028 * CSS styling property that will be applied to text enclosed by a decoration. 1029 * Better use 'border' for setting one or more of the individual border properties. 1030 */ 1031 borderColor?: string | ThemeColor; 1032 1033 /** 1034 * CSS styling property that will be applied to text enclosed by a decoration. 1035 * Better use 'border' for setting one or more of the individual border properties. 1036 */ 1037 borderRadius?: string; 1038 1039 /** 1040 * CSS styling property that will be applied to text enclosed by a decoration. 1041 * Better use 'border' for setting one or more of the individual border properties. 1042 */ 1043 borderSpacing?: string; 1044 1045 /** 1046 * CSS styling property that will be applied to text enclosed by a decoration. 1047 * Better use 'border' for setting one or more of the individual border properties. 1048 */ 1049 borderStyle?: string; 1050 1051 /** 1052 * CSS styling property that will be applied to text enclosed by a decoration. 1053 * Better use 'border' for setting one or more of the individual border properties. 1054 */ 1055 borderWidth?: string; 1056 1057 /** 1058 * CSS styling property that will be applied to text enclosed by a decoration. 1059 */ 1060 fontStyle?: string; 1061 1062 /** 1063 * CSS styling property that will be applied to text enclosed by a decoration. 1064 */ 1065 fontWeight?: string; 1066 1067 /** 1068 * CSS styling property that will be applied to text enclosed by a decoration. 1069 */ 1070 textDecoration?: string; 1071 1072 /** 1073 * CSS styling property that will be applied to text enclosed by a decoration. 1074 */ 1075 cursor?: string; 1076 1077 /** 1078 * CSS styling property that will be applied to text enclosed by a decoration. 1079 */ 1080 color?: string | ThemeColor; 1081 1082 /** 1083 * CSS styling property that will be applied to text enclosed by a decoration. 1084 */ 1085 opacity?: string; 1086 1087 /** 1088 * CSS styling property that will be applied to text enclosed by a decoration. 1089 */ 1090 letterSpacing?: string; 1091 1092 /** 1093 * An **absolute path** or an URI to an image to be rendered in the gutter. 1094 */ 1095 gutterIconPath?: string | Uri; 1096 1097 /** 1098 * Specifies the size of the gutter icon. 1099 * Available values are 'auto', 'contain', 'cover' and any percentage value. 1100 * For further information: https://msdn.microsoft.com/en-us/library/jj127316(v=vs.85).aspx 1101 */ 1102 gutterIconSize?: string; 1103 1104 /** 1105 * The color of the decoration in the overview ruler. Use rgba() and define transparent colors to play well with other decorations. 1106 */ 1107 overviewRulerColor?: string | ThemeColor; 1108 1109 /** 1110 * Defines the rendering options of the attachment that is inserted before the decorated text. 1111 */ 1112 before?: ThemableDecorationAttachmentRenderOptions; 1113 1114 /** 1115 * Defines the rendering options of the attachment that is inserted after the decorated text. 1116 */ 1117 after?: ThemableDecorationAttachmentRenderOptions; 1118 } 1119 1120 /** 1121 * Represents theme specific rendering styles for {@link ThemableDecorationRenderOptions.before before} and 1122 * {@link ThemableDecorationRenderOptions.after after} the content of text decorations. 1123 */ 1124 export interface ThemableDecorationAttachmentRenderOptions { 1125 /** 1126 * Defines a text content that is shown in the attachment. Either an icon or a text can be shown, but not both. 1127 */ 1128 contentText?: string; 1129 /** 1130 * An **absolute path** or an URI to an image to be rendered in the attachment. Either an icon 1131 * or a text can be shown, but not both. 1132 */ 1133 contentIconPath?: string | Uri; 1134 /** 1135 * CSS styling property that will be applied to the decoration attachment. 1136 */ 1137 border?: string; 1138 /** 1139 * CSS styling property that will be applied to text enclosed by a decoration. 1140 */ 1141 borderColor?: string | ThemeColor; 1142 /** 1143 * CSS styling property that will be applied to the decoration attachment. 1144 */ 1145 fontStyle?: string; 1146 /** 1147 * CSS styling property that will be applied to the decoration attachment. 1148 */ 1149 fontWeight?: string; 1150 /** 1151 * CSS styling property that will be applied to the decoration attachment. 1152 */ 1153 textDecoration?: string; 1154 /** 1155 * CSS styling property that will be applied to the decoration attachment. 1156 */ 1157 color?: string | ThemeColor; 1158 /** 1159 * CSS styling property that will be applied to the decoration attachment. 1160 */ 1161 backgroundColor?: string | ThemeColor; 1162 /** 1163 * CSS styling property that will be applied to the decoration attachment. 1164 */ 1165 margin?: string; 1166 /** 1167 * CSS styling property that will be applied to the decoration attachment. 1168 */ 1169 width?: string; 1170 /** 1171 * CSS styling property that will be applied to the decoration attachment. 1172 */ 1173 height?: string; 1174 } 1175 1176 /** 1177 * Represents rendering styles for a {@link TextEditorDecorationType text editor decoration}. 1178 */ 1179 export interface DecorationRenderOptions extends ThemableDecorationRenderOptions { 1180 /** 1181 * Should the decoration be rendered also on the whitespace after the line text. 1182 * Defaults to `false`. 1183 */ 1184 isWholeLine?: boolean; 1185 1186 /** 1187 * Customize the growing behavior of the decoration when edits occur at the edges of the decoration's range. 1188 * Defaults to `DecorationRangeBehavior.OpenOpen`. 1189 */ 1190 rangeBehavior?: DecorationRangeBehavior; 1191 1192 /** 1193 * The position in the overview ruler where the decoration should be rendered. 1194 */ 1195 overviewRulerLane?: OverviewRulerLane; 1196 1197 /** 1198 * Overwrite options for light themes. 1199 */ 1200 light?: ThemableDecorationRenderOptions; 1201 1202 /** 1203 * Overwrite options for dark themes. 1204 */ 1205 dark?: ThemableDecorationRenderOptions; 1206 } 1207 1208 /** 1209 * Represents options for a specific decoration in a {@link TextEditorDecorationType decoration set}. 1210 */ 1211 export interface DecorationOptions { 1212 1213 /** 1214 * Range to which this decoration is applied. The range must not be empty. 1215 */ 1216 range: Range; 1217 1218 /** 1219 * A message that should be rendered when hovering over the decoration. 1220 */ 1221 hoverMessage?: MarkdownString | MarkedString | Array<MarkdownString | MarkedString>; 1222 1223 /** 1224 * Render options applied to the current decoration. For performance reasons, keep the 1225 * number of decoration specific options small, and use decoration types wherever possible. 1226 */ 1227 renderOptions?: DecorationInstanceRenderOptions; 1228 } 1229 1230 /** 1231 * Represents themable render options for decoration instances. 1232 */ 1233 export interface ThemableDecorationInstanceRenderOptions { 1234 /** 1235 * Defines the rendering options of the attachment that is inserted before the decorated text. 1236 */ 1237 before?: ThemableDecorationAttachmentRenderOptions; 1238 1239 /** 1240 * Defines the rendering options of the attachment that is inserted after the decorated text. 1241 */ 1242 after?: ThemableDecorationAttachmentRenderOptions; 1243 } 1244 1245 /** 1246 * Represents render options for decoration instances. See {@link DecorationOptions.renderOptions}. 1247 */ 1248 export interface DecorationInstanceRenderOptions extends ThemableDecorationInstanceRenderOptions { 1249 /** 1250 * Overwrite options for light themes. 1251 */ 1252 light?: ThemableDecorationInstanceRenderOptions; 1253 1254 /** 1255 * Overwrite options for dark themes. 1256 */ 1257 dark?: ThemableDecorationInstanceRenderOptions; 1258 } 1259 1260 /** 1261 * Represents an editor that is attached to a {@link TextDocument document}. 1262 */ 1263 export interface TextEditor { 1264 1265 /** 1266 * The document associated with this text editor. The document will be the same for the entire lifetime of this text editor. 1267 */ 1268 readonly document: TextDocument; 1269 1270 /** 1271 * The primary selection on this text editor. Shorthand for `TextEditor.selections[0]`. 1272 */ 1273 selection: Selection; 1274 1275 /** 1276 * The selections in this text editor. The primary selection is always at index 0. 1277 */ 1278 selections: readonly Selection[]; 1279 1280 /** 1281 * The current visible ranges in the editor (vertically). 1282 * This accounts only for vertical scrolling, and not for horizontal scrolling. 1283 */ 1284 readonly visibleRanges: readonly Range[]; 1285 1286 /** 1287 * Text editor options. 1288 */ 1289 options: TextEditorOptions; 1290 1291 /** 1292 * The column in which this editor shows. Will be `undefined` in case this 1293 * isn't one of the main editors, e.g. an embedded editor, or when the editor 1294 * column is larger than three. 1295 */ 1296 readonly viewColumn: ViewColumn | undefined; 1297 1298 /** 1299 * Perform an edit on the document associated with this text editor. 1300 * 1301 * The given callback-function is invoked with an {@link TextEditorEdit edit-builder} which must 1302 * be used to make edits. Note that the edit-builder is only valid while the 1303 * callback executes. 1304 * 1305 * @param callback A function which can create edits using an {@link TextEditorEdit edit-builder}. 1306 * @param options The undo/redo behavior around this edit. By default, undo stops will be created before and after this edit. 1307 * @returns A promise that resolves with a value indicating if the edits could be applied. 1308 */ 1309 edit(callback: (editBuilder: TextEditorEdit) => void, options?: { 1310 /** 1311 * Add undo stop before making the edits. 1312 */ 1313 readonly undoStopBefore: boolean; 1314 /** 1315 * Add undo stop after making the edits. 1316 */ 1317 readonly undoStopAfter: boolean; 1318 }): Thenable<boolean>; 1319 1320 /** 1321 * Insert a {@link SnippetString snippet} and put the editor into snippet mode. "Snippet mode" 1322 * means the editor adds placeholders and additional cursors so that the user can complete 1323 * or accept the snippet. 1324 * 1325 * @param snippet The snippet to insert in this edit. 1326 * @param location Position or range at which to insert the snippet, defaults to the current editor selection or selections. 1327 * @param options The undo/redo behavior around this edit. By default, undo stops will be created before and after this edit. 1328 * @returns A promise that resolves with a value indicating if the snippet could be inserted. Note that the promise does not signal 1329 * that the snippet is completely filled-in or accepted. 1330 */ 1331 insertSnippet(snippet: SnippetString, location?: Position | Range | readonly Position[] | readonly Range[], options?: { 1332 /** 1333 * Add undo stop before making the edits. 1334 */ 1335 readonly undoStopBefore: boolean; 1336 /** 1337 * Add undo stop after making the edits. 1338 */ 1339 readonly undoStopAfter: boolean; 1340 /** 1341 * Keep whitespace of the {@link SnippetString.value} as is. 1342 */ 1343 readonly keepWhitespace?: boolean; 1344 }): Thenable<boolean>; 1345 1346 /** 1347 * Adds a set of decorations to the text editor. If a set of decorations already exists with 1348 * the given {@link TextEditorDecorationType decoration type}, they will be replaced. If 1349 * `rangesOrOptions` is empty, the existing decorations with the given {@link TextEditorDecorationType decoration type} 1350 * will be removed. 1351 * 1352 * @see {@link window.createTextEditorDecorationType createTextEditorDecorationType}. 1353 * 1354 * @param decorationType A decoration type. 1355 * @param rangesOrOptions Either {@link Range ranges} or more detailed {@link DecorationOptions options}. 1356 */ 1357 setDecorations(decorationType: TextEditorDecorationType, rangesOrOptions: readonly Range[] | readonly DecorationOptions[]): void; 1358 1359 /** 1360 * Scroll as indicated by `revealType` in order to reveal the given range. 1361 * 1362 * @param range A range. 1363 * @param revealType The scrolling strategy for revealing `range`. 1364 */ 1365 revealRange(range: Range, revealType?: TextEditorRevealType): void; 1366 1367 /** 1368 * Show the text editor. 1369 * 1370 * @deprecated Use {@link window.showTextDocument} instead. 1371 * 1372 * @param column The {@link ViewColumn column} in which to show this editor. 1373 * This method shows unexpected behavior and will be removed in the next major update. 1374 */ 1375 show(column?: ViewColumn): void; 1376 1377 /** 1378 * Hide the text editor. 1379 * 1380 * @deprecated Use the command `workbench.action.closeActiveEditor` instead. 1381 * This method shows unexpected behavior and will be removed in the next major update. 1382 */ 1383 hide(): void; 1384 } 1385 1386 /** 1387 * Represents an end of line character sequence in a {@link TextDocument document}. 1388 */ 1389 export enum EndOfLine { 1390 /** 1391 * The line feed `\n` character. 1392 */ 1393 LF = 1, 1394 /** 1395 * The carriage return line feed `\r\n` sequence. 1396 */ 1397 CRLF = 2 1398 } 1399 1400 /** 1401 * A complex edit that will be applied in one transaction on a TextEditor. 1402 * This holds a description of the edits and if the edits are valid (i.e. no overlapping regions, document was not changed in the meantime, etc.) 1403 * they can be applied on a {@link TextDocument document} associated with a {@link TextEditor text editor}. 1404 */ 1405 export interface TextEditorEdit { 1406 /** 1407 * Replace a certain text region with a new value. 1408 * You can use `\r\n` or `\n` in `value` and they will be normalized to the current {@link TextDocument document}. 1409 * 1410 * @param location The range this operation should remove. 1411 * @param value The new text this operation should insert after removing `location`. 1412 */ 1413 replace(location: Position | Range | Selection, value: string): void; 1414 1415 /** 1416 * Insert text at a location. 1417 * You can use `\r\n` or `\n` in `value` and they will be normalized to the current {@link TextDocument document}. 1418 * Although the equivalent text edit can be made with {@link TextEditorEdit.replace replace}, `insert` will produce a different resulting selection (it will get moved). 1419 * 1420 * @param location The position where the new text should be inserted. 1421 * @param value The new text this operation should insert. 1422 */ 1423 insert(location: Position, value: string): void; 1424 1425 /** 1426 * Delete a certain text region. 1427 * 1428 * @param location The range this operation should remove. 1429 */ 1430 delete(location: Range | Selection): void; 1431 1432 /** 1433 * Set the end of line sequence. 1434 * 1435 * @param endOfLine The new end of line for the {@link TextDocument document}. 1436 */ 1437 setEndOfLine(endOfLine: EndOfLine): void; 1438 } 1439 1440 /** 1441 * A universal resource identifier representing either a file on disk 1442 * or another resource, like untitled resources. 1443 */ 1444 export class Uri { 1445 1446 /** 1447 * Create an URI from a string, e.g. `http://www.example.com/some/path`, 1448 * `file:///usr/home`, or `scheme:with/path`. 1449 * 1450 * *Note* that for a while uris without a `scheme` were accepted. That is not correct 1451 * as all uris should have a scheme. To avoid breakage of existing code the optional 1452 * `strict`-argument has been added. We *strongly* advise to use it, e.g. `Uri.parse('my:uri', true)` 1453 * 1454 * @see {@link Uri.toString} 1455 * @param value The string value of an Uri. 1456 * @param strict Throw an error when `value` is empty or when no `scheme` can be parsed. 1457 * @returns A new Uri instance. 1458 */ 1459 static parse(value: string, strict?: boolean): Uri; 1460 1461 /** 1462 * Create an URI from a file system path. The {@link Uri.scheme scheme} 1463 * will be `file`. 1464 * 1465 * The *difference* between {@link Uri.parse} and {@link Uri.file} is that the latter treats the argument 1466 * as path, not as stringified-uri. E.g. `Uri.file(path)` is *not* the same as 1467 * `Uri.parse('file://' + path)` because the path might contain characters that are 1468 * interpreted (# and ?). See the following sample: 1469 * ```ts 1470 * const good = URI.file('/coding/c#/project1'); 1471 * good.scheme === 'file'; 1472 * good.path === '/coding/c#/project1'; 1473 * good.fragment === ''; 1474 * 1475 * const bad = URI.parse('file://' + '/coding/c#/project1'); 1476 * bad.scheme === 'file'; 1477 * bad.path === '/coding/c'; // path is now broken 1478 * bad.fragment === '/project1'; 1479 * ``` 1480 * 1481 * @param path A file system or UNC path. 1482 * @returns A new Uri instance. 1483 */ 1484 static file(path: string): Uri; 1485 1486 /** 1487 * Create a new uri which path is the result of joining 1488 * the path of the base uri with the provided path segments. 1489 * 1490 * - Note 1: `joinPath` only affects the path component 1491 * and all other components (scheme, authority, query, and fragment) are 1492 * left as they are. 1493 * - Note 2: The base uri must have a path; an error is thrown otherwise. 1494 * 1495 * The path segments are normalized in the following ways: 1496 * - sequences of path separators (`/` or `\`) are replaced with a single separator 1497 * - for `file`-uris on windows, the backslash-character (`\`) is considered a path-separator 1498 * - the `..`-segment denotes the parent segment, the `.` denotes the current segment 1499 * - paths have a root which always remains, for instance on windows drive-letters are roots 1500 * so that is true: `joinPath(Uri.file('file:///c:/root'), '../../other').fsPath === 'c:/other'` 1501 * 1502 * @param base An uri. Must have a path. 1503 * @param pathSegments One more more path fragments 1504 * @returns A new uri which path is joined with the given fragments 1505 */ 1506 static joinPath(base: Uri, ...pathSegments: string[]): Uri; 1507 1508 /** 1509 * Create an URI from its component parts 1510 * 1511 * @see {@link Uri.toString} 1512 * @param components The component parts of an Uri. 1513 * @returns A new Uri instance. 1514 */ 1515 static from(components: { 1516 /** 1517 * The scheme of the uri 1518 */ 1519 readonly scheme: string; 1520 /** 1521 * The authority of the uri 1522 */ 1523 readonly authority?: string; 1524 /** 1525 * The path of the uri 1526 */ 1527 readonly path?: string; 1528 /** 1529 * The query string of the uri 1530 */ 1531 readonly query?: string; 1532 /** 1533 * The fragment identifier of the uri 1534 */ 1535 readonly fragment?: string; 1536 }): Uri; 1537 1538 /** 1539 * Use the `file` and `parse` factory functions to create new `Uri` objects. 1540 */ 1541 private constructor(scheme: string, authority: string, path: string, query: string, fragment: string); 1542 1543 /** 1544 * Scheme is the `http` part of `http://www.example.com/some/path?query#fragment`. 1545 * The part before the first colon. 1546 */ 1547 readonly scheme: string; 1548 1549 /** 1550 * Authority is the `www.example.com` part of `http://www.example.com/some/path?query#fragment`. 1551 * The part between the first double slashes and the next slash. 1552 */ 1553 readonly authority: string; 1554 1555 /** 1556 * Path is the `/some/path` part of `http://www.example.com/some/path?query#fragment`. 1557 */ 1558 readonly path: string; 1559 1560 /** 1561 * Query is the `query` part of `http://www.example.com/some/path?query#fragment`. 1562 */ 1563 readonly query: string; 1564 1565 /** 1566 * Fragment is the `fragment` part of `http://www.example.com/some/path?query#fragment`. 1567 */ 1568 readonly fragment: string; 1569 1570 /** 1571 * The string representing the corresponding file system path of this Uri. 1572 * 1573 * Will handle UNC paths and normalize windows drive letters to lower-case. Also 1574 * uses the platform specific path separator. 1575 * 1576 * * Will *not* validate the path for invalid characters and semantics. 1577 * * Will *not* look at the scheme of this Uri. 1578 * * The resulting string shall *not* be used for display purposes but 1579 * for disk operations, like `readFile` et al. 1580 * 1581 * The *difference* to the {@linkcode Uri.path path}-property is the use of the platform specific 1582 * path separator and the handling of UNC paths. The sample below outlines the difference: 1583 * ```ts 1584 * const u = URI.parse('file://server/c$/folder/file.txt') 1585 * u.authority === 'server' 1586 * u.path === '/c$/folder/file.txt' 1587 * u.fsPath === '\\server\c$\folder\file.txt' 1588 * ``` 1589 */ 1590 readonly fsPath: string; 1591 1592 /** 1593 * Derive a new Uri from this Uri. 1594 * 1595 * ```ts 1596 * let file = Uri.parse('before:some/file/path'); 1597 * let other = file.with({ scheme: 'after' }); 1598 * assert.ok(other.toString() === 'after:some/file/path'); 1599 * ``` 1600 * 1601 * @param change An object that describes a change to this Uri. To unset components use `null` or 1602 * the empty string. 1603 * @returns A new Uri that reflects the given change. Will return `this` Uri if the change 1604 * is not changing anything. 1605 */ 1606 with(change: { 1607 /** 1608 * The new scheme, defaults to this Uri's scheme. 1609 */ 1610 scheme?: string; 1611 /** 1612 * The new authority, defaults to this Uri's authority. 1613 */ 1614 authority?: string; 1615 /** 1616 * The new path, defaults to this Uri's path. 1617 */ 1618 path?: string; 1619 /** 1620 * The new query, defaults to this Uri's query. 1621 */ 1622 query?: string; 1623 /** 1624 * The new fragment, defaults to this Uri's fragment. 1625 */ 1626 fragment?: string; 1627 }): Uri; 1628 1629 /** 1630 * Returns a string representation of this Uri. The representation and normalization 1631 * of a URI depends on the scheme. 1632 * 1633 * * The resulting string can be safely used with {@link Uri.parse}. 1634 * * The resulting string shall *not* be used for display purposes. 1635 * 1636 * *Note* that the implementation will encode _aggressive_ which often leads to unexpected, 1637 * but not incorrect, results. For instance, colons are encoded to `%3A` which might be unexpected 1638 * in file-uri. Also `&` and `=` will be encoded which might be unexpected for http-uris. For stability 1639 * reasons this cannot be changed anymore. If you suffer from too aggressive encoding you should use 1640 * the `skipEncoding`-argument: `uri.toString(true)`. 1641 * 1642 * @param skipEncoding Do not percentage-encode the result, defaults to `false`. Note that 1643 * the `#` and `?` characters occurring in the path will always be encoded. 1644 * @returns A string representation of this Uri. 1645 */ 1646 toString(skipEncoding?: boolean): string; 1647 1648 /** 1649 * Returns a JSON representation of this Uri. 1650 * 1651 * @returns An object. 1652 */ 1653 toJSON(): any; 1654 } 1655 1656 /** 1657 * A cancellation token is passed to an asynchronous or long running 1658 * operation to request cancellation, like cancelling a request 1659 * for completion items because the user continued to type. 1660 * 1661 * To get an instance of a `CancellationToken` use a 1662 * {@link CancellationTokenSource}. 1663 */ 1664 export interface CancellationToken { 1665 1666 /** 1667 * Is `true` when the token has been cancelled, `false` otherwise. 1668 */ 1669 isCancellationRequested: boolean; 1670 1671 /** 1672 * An {@link Event} which fires upon cancellation. 1673 */ 1674 readonly onCancellationRequested: Event<any>; 1675 } 1676 1677 /** 1678 * A cancellation source creates and controls a {@link CancellationToken cancellation token}. 1679 */ 1680 export class CancellationTokenSource { 1681 1682 /** 1683 * The cancellation token of this source. 1684 */ 1685 token: CancellationToken; 1686 1687 /** 1688 * Signal cancellation on the token. 1689 */ 1690 cancel(): void; 1691 1692 /** 1693 * Dispose object and free resources. 1694 */ 1695 dispose(): void; 1696 } 1697 1698 /** 1699 * An error type that should be used to signal cancellation of an operation. 1700 * 1701 * This type can be used in response to a {@link CancellationToken cancellation token} 1702 * being cancelled or when an operation is being cancelled by the 1703 * executor of that operation. 1704 */ 1705 export class CancellationError extends Error { 1706 1707 /** 1708 * Creates a new cancellation error. 1709 */ 1710 constructor(); 1711 } 1712 1713 /** 1714 * Represents a type which can release resources, such 1715 * as event listening or a timer. 1716 */ 1717 export class Disposable { 1718 1719 /** 1720 * Combine many disposable-likes into one. You can use this method when having objects with 1721 * a dispose function which aren't instances of `Disposable`. 1722 * 1723 * @param disposableLikes Objects that have at least a `dispose`-function member. Note that asynchronous 1724 * dispose-functions aren't awaited. 1725 * @returns Returns a new disposable which, upon dispose, will 1726 * dispose all provided disposables. 1727 */ 1728 static from(...disposableLikes: { 1729 /** 1730 * Function to clean up resources. 1731 */ 1732 dispose: () => any; 1733 }[]): Disposable; 1734 1735 /** 1736 * Creates a new disposable that calls the provided function 1737 * on dispose. 1738 * 1739 * *Note* that an asynchronous function is not awaited. 1740 * 1741 * @param callOnDispose Function that disposes something. 1742 */ 1743 constructor(callOnDispose: () => any); 1744 1745 /** 1746 * Dispose this object. 1747 */ 1748 dispose(): any; 1749 } 1750 1751 /** 1752 * Represents a typed event. 1753 * 1754 * A function that represents an event to which you subscribe by calling it with 1755 * a listener function as argument. 1756 * 1757 * @example 1758 * item.onDidChange(function(event) { console.log("Event happened: " + event); }); 1759 */ 1760 export interface Event<T> { 1761 1762 /** 1763 * A function that represents an event to which you subscribe by calling it with 1764 * a listener function as argument. 1765 * 1766 * @param listener The listener function will be called when the event happens. 1767 * @param thisArgs The `this`-argument which will be used when calling the event listener. 1768 * @param disposables An array to which a {@link Disposable} will be added. 1769 * @returns A disposable which unsubscribes the event listener. 1770 */ 1771 (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable; 1772 } 1773 1774 /** 1775 * An event emitter can be used to create and manage an {@link Event} for others 1776 * to subscribe to. One emitter always owns one event. 1777 * 1778 * Use this class if you want to provide event from within your extension, for instance 1779 * inside a {@link TextDocumentContentProvider} or when providing 1780 * API to other extensions. 1781 */ 1782 export class EventEmitter<T> { 1783 1784 /** 1785 * The event listeners can subscribe to. 1786 */ 1787 event: Event<T>; 1788 1789 /** 1790 * Notify all subscribers of the {@link EventEmitter.event event}. Failure 1791 * of one or more listener will not fail this function call. 1792 * 1793 * @param data The event object. 1794 */ 1795 fire(data: T): void; 1796 1797 /** 1798 * Dispose this object and free resources. 1799 */ 1800 dispose(): void; 1801 } 1802 1803 /** 1804 * A file system watcher notifies about changes to files and folders 1805 * on disk or from other {@link FileSystemProvider FileSystemProviders}. 1806 * 1807 * To get an instance of a `FileSystemWatcher` use 1808 * {@link workspace.createFileSystemWatcher createFileSystemWatcher}. 1809 */ 1810 export interface FileSystemWatcher extends Disposable { 1811 1812 /** 1813 * true if this file system watcher has been created such that 1814 * it ignores creation file system events. 1815 */ 1816 readonly ignoreCreateEvents: boolean; 1817 1818 /** 1819 * true if this file system watcher has been created such that 1820 * it ignores change file system events. 1821 */ 1822 readonly ignoreChangeEvents: boolean; 1823 1824 /** 1825 * true if this file system watcher has been created such that 1826 * it ignores delete file system events. 1827 */ 1828 readonly ignoreDeleteEvents: boolean; 1829 1830 /** 1831 * An event which fires on file/folder creation. 1832 */ 1833 readonly onDidCreate: Event<Uri>; 1834 1835 /** 1836 * An event which fires on file/folder change. 1837 */ 1838 readonly onDidChange: Event<Uri>; 1839 1840 /** 1841 * An event which fires on file/folder deletion. 1842 */ 1843 readonly onDidDelete: Event<Uri>; 1844 } 1845 1846 /** 1847 * A text document content provider allows to add readonly documents 1848 * to the editor, such as source from a dll or generated html from md. 1849 * 1850 * Content providers are {@link workspace.registerTextDocumentContentProvider registered} 1851 * for a {@link Uri.scheme uri-scheme}. When a uri with that scheme is to 1852 * be {@link workspace.openTextDocument loaded} the content provider is 1853 * asked. 1854 */ 1855 export interface TextDocumentContentProvider { 1856 1857 /** 1858 * An event to signal a resource has changed. 1859 */ 1860 onDidChange?: Event<Uri>; 1861 1862 /** 1863 * Provide textual content for a given uri. 1864 * 1865 * The editor will use the returned string-content to create a readonly 1866 * {@link TextDocument document}. Resources allocated should be released when 1867 * the corresponding document has been {@link workspace.onDidCloseTextDocument closed}. 1868 * 1869 * **Note**: The contents of the created {@link TextDocument document} might not be 1870 * identical to the provided text due to end-of-line-sequence normalization. 1871 * 1872 * @param uri An uri which scheme matches the scheme this provider was {@link workspace.registerTextDocumentContentProvider registered} for. 1873 * @param token A cancellation token. 1874 * @returns A string or a thenable that resolves to such. 1875 */ 1876 provideTextDocumentContent(uri: Uri, token: CancellationToken): ProviderResult<string>; 1877 } 1878 1879 /** 1880 * Defines the kind of {@link QuickPickItem quick pick item}. 1881 */ 1882 export enum QuickPickItemKind { 1883 /** 1884 * A separator item that provides a visual grouping. 1885 * 1886 * When a {@link QuickPickItem} has a kind of {@link Separator}, the item is just a visual separator 1887 * and does not represent a selectable item. The only property that applies is 1888 * {@link QuickPickItem.label label}. All other properties on {@link QuickPickItem} will be ignored 1889 * and have no effect. 1890 */ 1891 Separator = -1, 1892 /** 1893 * The default kind for an item that can be selected in the quick pick. 1894 */ 1895 Default = 0, 1896 } 1897 1898 /** 1899 * Represents an item that can be selected from a list of items. 1900 */ 1901 export interface QuickPickItem { 1902 1903 /** 1904 * A human-readable string which is rendered prominently. 1905 * 1906 * Supports rendering of {@link ThemeIcon theme icons} via the `$(<name>)`-syntax. 1907 * 1908 * **Note:** When {@link QuickPickItem.kind kind} is set to {@link QuickPickItemKind.Default} (so a regular 1909 * item instead of a separator), it supports rendering of {@link ThemeIcon theme icons} via the 1910 * `$(<name>)`-syntax. 1911 */ 1912 label: string; 1913 1914 /** 1915 * The kind of this item that determines how it is rendered in the quick pick. 1916 * 1917 * When not specified, the default is {@link QuickPickItemKind.Default}. 1918 */ 1919 kind?: QuickPickItemKind; 1920 1921 /** 1922 * The icon for the item. 1923 */ 1924 iconPath?: IconPath; 1925 1926 /** 1927 * A human-readable string which is rendered less prominently in the same line. 1928 * 1929 * Supports rendering of {@link ThemeIcon theme icons} via the `$(<name>)`-syntax. 1930 * 1931 * **Note:** This property is ignored when {@link QuickPickItem.kind kind} is set to 1932 * {@link QuickPickItemKind.Separator}. 1933 */ 1934 description?: string; 1935 1936 /** 1937 * A human-readable string which is rendered less prominently in a separate line. 1938 * 1939 * Supports rendering of {@link ThemeIcon theme icons} via the `$(<name>)`-syntax. 1940 * 1941 * **Note:** This property is ignored when {@link QuickPickItem.kind kind} is set to 1942 * {@link QuickPickItemKind.Separator}. 1943 */ 1944 detail?: string; 1945 1946 /** 1947 * A {@link Uri} representing the resource associated with this item. 1948 * 1949 * When set, this property is used to automatically derive several item properties if they are not explicitly provided: 1950 * - **Label**: Derived from the resource's file name when {@link QuickPickItem.label label} is not provided or is empty. 1951 * - **Description**: Derived from the resource's path when {@link QuickPickItem.description description} is not provided or is empty. 1952 * - **Icon**: Derived from the current file icon theme when {@link QuickPickItem.iconPath iconPath} is set to 1953 * {@link ThemeIcon.File} or {@link ThemeIcon.Folder}. 1954 */ 1955 resourceUri?: Uri; 1956 1957 /** 1958 * Optional flag indicating if this item is initially selected. 1959 * 1960 * This is only honored when using the {@link window.showQuickPick showQuickPick} API. To do the same 1961 * thing with the {@link window.createQuickPick createQuickPick} API, simply set the 1962 * {@link QuickPick.selectedItems selectedItems} to the items you want selected initially. 1963 * 1964 * **Note:** This is only honored when the picker allows multiple selections. 1965 * 1966 * @see {@link QuickPickOptions.canPickMany} 1967 * 1968 * **Note:** This property is ignored when {@link QuickPickItem.kind kind} is set to 1969 * {@link QuickPickItemKind.Separator}. 1970 */ 1971 picked?: boolean; 1972 1973 /** 1974 * Determines if this item is always shown, even when filtered out by the user's input. 1975 * 1976 * **Note:** This property is ignored when {@link QuickPickItem.kind kind} is set to 1977 * {@link QuickPickItemKind.Separator}. 1978 */ 1979 alwaysShow?: boolean; 1980 1981 /** 1982 * Optional buttons that will be rendered on this particular item. 1983 * 1984 * These buttons will trigger an {@link QuickPickItemButtonEvent} when pressed. Buttons are only rendered 1985 * when using a quick pick created by the {@link window.createQuickPick createQuickPick} API. Buttons are 1986 * not rendered when using the {@link window.showQuickPick showQuickPick} API. 1987 * 1988 * **Note:** This property is ignored when {@link QuickPickItem.kind kind} is set to 1989 * {@link QuickPickItemKind.Separator}. 1990 */ 1991 buttons?: readonly QuickInputButton[]; 1992 } 1993 1994 /** 1995 * Options to configure the behavior of the quick pick UI. 1996 */ 1997 export interface QuickPickOptions { 1998 1999 /** 2000 * An optional title for the quick pick. 2001 */ 2002 title?: string; 2003 2004 /** 2005 * Determines if the {@link QuickPickItem.description description} should be included when filtering items. Defaults to `false`. 2006 */ 2007 matchOnDescription?: boolean; 2008 2009 /** 2010 * Determines if the {@link QuickPickItem.detail detail} should be included when filtering items. Defaults to `false`. 2011 */ 2012 matchOnDetail?: boolean; 2013 2014 /** 2015 * An optional string to show as placeholder in the input box to guide the user. 2016 */ 2017 placeHolder?: string; 2018 2019 /** 2020 * Optional text that provides instructions or context to the user. 2021 * 2022 * The prompt is displayed below the input box and above the list of items. 2023 */ 2024 prompt?: string; 2025 2026 /** 2027 * Set to `true` to keep the picker open when focus moves to another part of the editor or to another window. 2028 * This setting is ignored on iPad and is always `false`. 2029 */ 2030 ignoreFocusOut?: boolean; 2031 2032 /** 2033 * Determines if the picker allows multiple selections. When `true`, the result is an array of picks. 2034 */ 2035 canPickMany?: boolean; 2036 2037 /** 2038 * An optional function that is invoked whenever an item is selected. 2039 */ 2040 onDidSelectItem?(item: QuickPickItem | string): any; 2041 } 2042 2043 /** 2044 * Options to configure the behavior of the {@link WorkspaceFolder workspace folder} pick UI. 2045 */ 2046 export interface WorkspaceFolderPickOptions { 2047 2048 /** 2049 * An optional string to show as placeholder in the input box to guide the user. 2050 */ 2051 placeHolder?: string; 2052 2053 /** 2054 * Set to `true` to keep the picker open when focus moves to another part of the editor or to another window. 2055 * This setting is ignored on iPad and is always `false`. 2056 */ 2057 ignoreFocusOut?: boolean; 2058 } 2059 2060 /** 2061 * Options to configure the behavior of a file open dialog. 2062 * 2063 * * Note 1: On Windows and Linux, a file dialog cannot be both a file selector and a folder selector, so if you 2064 * set both `canSelectFiles` and `canSelectFolders` to `true` on these platforms, a folder selector will be shown. 2065 * * Note 2: Explicitly setting `canSelectFiles` and `canSelectFolders` to `false` is futile 2066 * and the editor then silently adjusts the options to select files. 2067 */ 2068 export interface OpenDialogOptions { 2069 /** 2070 * The resource the dialog shows when opened. 2071 */ 2072 defaultUri?: Uri; 2073 2074 /** 2075 * A human-readable string for the open button. 2076 */ 2077 openLabel?: string; 2078 2079 /** 2080 * Allow to select files, defaults to `true`. 2081 */ 2082 canSelectFiles?: boolean; 2083 2084 /** 2085 * Allow to select folders, defaults to `false`. 2086 */ 2087 canSelectFolders?: boolean; 2088 2089 /** 2090 * Allow to select many files or folders. 2091 */ 2092 canSelectMany?: boolean; 2093 2094 /** 2095 * A set of file filters that are used by the dialog. Each entry is a human-readable label, 2096 * like "TypeScript", and an array of extensions, for example: 2097 * ```ts 2098 * { 2099 * 'Images': ['png', 'jpg'], 2100 * 'TypeScript': ['ts', 'tsx'] 2101 * } 2102 * ``` 2103 */ 2104 filters?: { [name: string]: string[] }; 2105 2106 /** 2107 * Dialog title. 2108 * 2109 * This parameter might be ignored, as not all operating systems display a title on open dialogs 2110 * (for example, macOS). 2111 */ 2112 title?: string; 2113 } 2114 2115 /** 2116 * Options to configure the behaviour of a file save dialog. 2117 */ 2118 export interface SaveDialogOptions { 2119 /** 2120 * The resource the dialog shows when opened. 2121 */ 2122 defaultUri?: Uri; 2123 2124 /** 2125 * A human-readable string for the save button. 2126 */ 2127 saveLabel?: string; 2128 2129 /** 2130 * A set of file filters that are used by the dialog. Each entry is a human-readable label, 2131 * like "TypeScript", and an array of extensions, for example: 2132 * ```ts 2133 * { 2134 * 'Images': ['png', 'jpg'], 2135 * 'TypeScript': ['ts', 'tsx'] 2136 * } 2137 * ``` 2138 */ 2139 filters?: { [name: string]: string[] }; 2140 2141 /** 2142 * Dialog title. 2143 * 2144 * This parameter might be ignored, as not all operating systems display a title on save dialogs 2145 * (for example, macOS). 2146 */ 2147 title?: string; 2148 } 2149 2150 /** 2151 * Represents an action that is shown with an information, warning, or 2152 * error message. 2153 * 2154 * @see {@link window.showInformationMessage showInformationMessage} 2155 * @see {@link window.showWarningMessage showWarningMessage} 2156 * @see {@link window.showErrorMessage showErrorMessage} 2157 */ 2158 export interface MessageItem { 2159 2160 /** 2161 * A short title like 'Retry', 'Open Log' etc. 2162 */ 2163 title: string; 2164 2165 /** 2166 * A hint for modal dialogs that the item should be triggered 2167 * when the user cancels the dialog (e.g. by pressing the ESC 2168 * key). 2169 * 2170 * Note: this option is ignored for non-modal messages. 2171 */ 2172 isCloseAffordance?: boolean; 2173 } 2174 2175 /** 2176 * Options to configure the behavior of the message. 2177 * 2178 * @see {@link window.showInformationMessage showInformationMessage} 2179 * @see {@link window.showWarningMessage showWarningMessage} 2180 * @see {@link window.showErrorMessage showErrorMessage} 2181 */ 2182 export interface MessageOptions { 2183 2184 /** 2185 * Indicates that this message should be modal. 2186 */ 2187 modal?: boolean; 2188 2189 /** 2190 * Human-readable detail message that is rendered less prominent. _Note_ that detail 2191 * is only shown for {@link MessageOptions.modal modal} messages. 2192 */ 2193 detail?: string; 2194 } 2195 2196 /** 2197 * Severity levels for input box validation messages. 2198 */ 2199 export enum InputBoxValidationSeverity { 2200 /** 2201 * Indicates an informational message that does not prevent input acceptance. 2202 */ 2203 Info = 1, 2204 /** 2205 * Indicates a warning message that does not prevent input acceptance. 2206 */ 2207 Warning = 2, 2208 /** 2209 * Indicates an error message that prevents the user from accepting the input. 2210 */ 2211 Error = 3 2212 } 2213 2214 /** 2215 * Represents a validation message for an {@link InputBox}. 2216 */ 2217 export interface InputBoxValidationMessage { 2218 /** 2219 * The validation message to display to the user. 2220 */ 2221 readonly message: string; 2222 2223 /** 2224 * The severity level of the validation message. 2225 * 2226 * **Note:** When using {@link InputBoxValidationSeverity.Error}, the user will not be able to accept 2227 * the input (e.g., by pressing Enter). {@link InputBoxValidationSeverity.Info Info} and 2228 * {@link InputBoxValidationSeverity.Warning Warning} severities will still allow the input to be accepted. 2229 */ 2230 readonly severity: InputBoxValidationSeverity; 2231 } 2232 2233 /** 2234 * Options to configure the behavior of the input box UI. 2235 */ 2236 export interface InputBoxOptions { 2237 2238 /** 2239 * An optional string that represents the title of the input box. 2240 */ 2241 title?: string; 2242 2243 /** 2244 * The value to pre-fill in the input box. 2245 */ 2246 value?: string; 2247 2248 /** 2249 * Selection of the pre-filled {@linkcode InputBoxOptions.value value}. Defined as tuple of two number where the 2250 * first is the inclusive start index and the second the exclusive end index. When `undefined` the whole 2251 * pre-filled value will be selected, when empty (start equals end) only the cursor will be set, 2252 * otherwise the defined range will be selected. 2253 */ 2254 valueSelection?: [number, number]; 2255 2256 /** 2257 * The text to display underneath the input box. 2258 */ 2259 prompt?: string; 2260 2261 /** 2262 * An optional string to show as placeholder in the input box to guide the user what to type. 2263 */ 2264 placeHolder?: string; 2265 2266 /** 2267 * Controls if a password input is shown. Password input hides the typed text. 2268 */ 2269 password?: boolean; 2270 2271 /** 2272 * Set to `true` to keep the input box open when focus moves to another part of the editor or to another window. 2273 * This setting is ignored on iPad and is always false. 2274 */ 2275 ignoreFocusOut?: boolean; 2276 2277 /** 2278 * An optional function that will be called to validate input and to give a hint 2279 * to the user. 2280 * 2281 * @param value The current value of the input box. 2282 * @returns Either a human-readable string which is presented as an error message or an {@link InputBoxValidationMessage} 2283 * which can provide a specific message severity. Return `undefined`, `null`, or the empty string when 'value' is valid. 2284 */ 2285 validateInput?(value: string): string | InputBoxValidationMessage | undefined | null | 2286 Thenable<string | InputBoxValidationMessage | undefined | null>; 2287 } 2288 2289 /** 2290 * A relative pattern is a helper to construct glob patterns that are matched 2291 * relatively to a base file path. The base path can either be an absolute file 2292 * path as string or uri or a {@link WorkspaceFolder workspace folder}, which is the 2293 * preferred way of creating the relative pattern. 2294 */ 2295 export class RelativePattern { 2296 2297 /** 2298 * A base file path to which this pattern will be matched against relatively. The 2299 * file path must be absolute, should not have any trailing path separators and 2300 * not include any relative segments (`.` or `..`). 2301 */ 2302 baseUri: Uri; 2303 2304 /** 2305 * A base file path to which this pattern will be matched against relatively. 2306 * 2307 * This matches the `fsPath` value of {@link RelativePattern.baseUri}. 2308 * 2309 * *Note:* updating this value will update {@link RelativePattern.baseUri} to 2310 * be a uri with `file` scheme. 2311 * 2312 * @deprecated This property is deprecated, please use {@link RelativePattern.baseUri} instead. 2313 */ 2314 base: string; 2315 2316 /** 2317 * A file glob pattern like `*.{ts,js}` that will be matched on file paths 2318 * relative to the base path. 2319 * 2320 * Example: Given a base of `/home/work/folder` and a file path of `/home/work/folder/index.js`, 2321 * the file glob pattern will match on `index.js`. 2322 */ 2323 pattern: string; 2324 2325 /** 2326 * Creates a new relative pattern object with a base file path and pattern to match. This pattern 2327 * will be matched on file paths relative to the base. 2328 * 2329 * Example: 2330 * ```ts 2331 * const folder = vscode.workspace.workspaceFolders?.[0]; 2332 * if (folder) { 2333 * 2334 * // Match any TypeScript file in the root of this workspace folder 2335 * const pattern1 = new vscode.RelativePattern(folder, '*.ts'); 2336 * 2337 * // Match any TypeScript file in `someFolder` inside this workspace folder 2338 * const pattern2 = new vscode.RelativePattern(folder, 'someFolder/*.ts'); 2339 * } 2340 * ``` 2341 * 2342 * @param base A base to which this pattern will be matched against relatively. It is recommended 2343 * to pass in a {@link WorkspaceFolder workspace folder} if the pattern should match inside the workspace. 2344 * Otherwise, a uri or string should only be used if the pattern is for a file path outside the workspace. 2345 * @param pattern A file glob pattern like `*.{ts,js}` that will be matched on paths relative to the base. 2346 */ 2347 constructor(base: WorkspaceFolder | Uri | string, pattern: string); 2348 } 2349 2350 /** 2351 * A file glob pattern to match file paths against. This can either be a glob pattern string 2352 * (like `**/*.{ts,js}` or `*.{ts,js}`) or a {@link RelativePattern relative pattern}. 2353 * 2354 * Glob patterns can have the following syntax: 2355 * * `*` to match zero or more characters in a path segment 2356 * * `?` to match on one character in a path segment 2357 * * `**` to match any number of path segments, including none 2358 * * `{}` to group conditions (e.g. `**/*.{ts,js}` matches all TypeScript and JavaScript files) 2359 * * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …) 2360 * * `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`) 2361 * 2362 * Note: a backslash (`\`) is not valid within a glob pattern. If you have an existing file 2363 * path to match against, consider to use the {@link RelativePattern relative pattern} support 2364 * that takes care of converting any backslash into slash. Otherwise, make sure to convert 2365 * any backslash to slash when creating the glob pattern. 2366 */ 2367 export type GlobPattern = string | RelativePattern; 2368 2369 /** 2370 * A document filter denotes a document by different properties like 2371 * the {@link TextDocument.languageId language}, the {@link Uri.scheme scheme} of 2372 * its resource, or a glob-pattern that is applied to the {@link TextDocument.fileName path}. 2373 * 2374 * @example <caption>A language filter that applies to typescript files on disk</caption> 2375 * { language: 'typescript', scheme: 'file' } 2376 * 2377 * @example <caption>A language filter that applies to all package.json paths</caption> 2378 * { language: 'json', pattern: '**/package.json' } 2379 */ 2380 export interface DocumentFilter { 2381 2382 /** 2383 * A language id, like `typescript`. 2384 */ 2385 readonly language?: string; 2386 2387 /** 2388 * The {@link NotebookDocument.notebookType type} of a notebook, like `jupyter-notebook`. This allows 2389 * to narrow down on the type of a notebook that a {@link NotebookCell.document cell document} belongs to. 2390 * 2391 * *Note* that setting the `notebookType`-property changes how `scheme` and `pattern` are interpreted. When set 2392 * they are evaluated against the {@link NotebookDocument.uri notebook uri}, not the document uri. 2393 * 2394 * @example <caption>Match python document inside jupyter notebook that aren't stored yet (`untitled`)</caption> 2395 * { language: 'python', notebookType: 'jupyter-notebook', scheme: 'untitled' } 2396 */ 2397 readonly notebookType?: string; 2398 2399 /** 2400 * A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. 2401 */ 2402 readonly scheme?: string; 2403 2404 /** 2405 * A {@link GlobPattern glob pattern} that is matched on the absolute path of the document. Use a {@link RelativePattern relative pattern} 2406 * to filter documents to a {@link WorkspaceFolder workspace folder}. 2407 */ 2408 readonly pattern?: GlobPattern; 2409 } 2410 2411 /** 2412 * A language selector is the combination of one or many language identifiers 2413 * and {@link DocumentFilter language filters}. 2414 * 2415 * *Note* that a document selector that is just a language identifier selects *all* 2416 * documents, even those that are not saved on disk. Only use such selectors when 2417 * a feature works without further context, e.g. without the need to resolve related 2418 * 'files'. 2419 * 2420 * @example 2421 * let sel:DocumentSelector = { scheme: 'file', language: 'typescript' }; 2422 */ 2423 export type DocumentSelector = DocumentFilter | string | ReadonlyArray<DocumentFilter | string>; 2424 2425 /** 2426 * A provider result represents the values a provider, like the {@linkcode HoverProvider}, 2427 * may return. For once this is the actual result type `T`, like `Hover`, or a thenable that resolves 2428 * to that type `T`. In addition, `null` and `undefined` can be returned - either directly or from a 2429 * thenable. 2430 * 2431 * The snippets below are all valid implementations of the {@linkcode HoverProvider}: 2432 * 2433 * ```ts 2434 * let a: HoverProvider = { 2435 * provideHover(doc, pos, token): ProviderResult<Hover> { 2436 * return new Hover('Hello World'); 2437 * } 2438 * } 2439 * 2440 * let b: HoverProvider = { 2441 * provideHover(doc, pos, token): ProviderResult<Hover> { 2442 * return new Promise(resolve => { 2443 * resolve(new Hover('Hello World')); 2444 * }); 2445 * } 2446 * } 2447 * 2448 * let c: HoverProvider = { 2449 * provideHover(doc, pos, token): ProviderResult<Hover> { 2450 * return; // undefined 2451 * } 2452 * } 2453 * ``` 2454 */ 2455 export type ProviderResult<T> = T | undefined | null | Thenable<T | undefined | null>; 2456 2457 /** 2458 * Kind of a code action. 2459 * 2460 * Kinds are a hierarchical list of identifiers separated by `.`, e.g. `"refactor.extract.function"`. 2461 * 2462 * Code action kinds are used by the editor for UI elements such as the refactoring context menu. Users 2463 * can also trigger code actions with a specific kind with the `editor.action.codeAction` command. 2464 */ 2465 export class CodeActionKind { 2466 /** 2467 * Empty kind. 2468 */ 2469 static readonly Empty: CodeActionKind; 2470 2471 /** 2472 * Base kind for quickfix actions: `quickfix`. 2473 * 2474 * Quick fix actions address a problem in the code and are shown in the normal code action context menu. 2475 */ 2476 static readonly QuickFix: CodeActionKind; 2477 2478 /** 2479 * Base kind for refactoring actions: `refactor` 2480 * 2481 * Refactoring actions are shown in the refactoring context menu. 2482 */ 2483 static readonly Refactor: CodeActionKind; 2484 2485 /** 2486 * Base kind for refactoring extraction actions: `refactor.extract` 2487 * 2488 * Example extract actions: 2489 * 2490 * - Extract method 2491 * - Extract function 2492 * - Extract variable 2493 * - Extract interface from class 2494 * - ... 2495 */ 2496 static readonly RefactorExtract: CodeActionKind; 2497 2498 /** 2499 * Base kind for refactoring inline actions: `refactor.inline` 2500 * 2501 * Example inline actions: 2502 * 2503 * - Inline function 2504 * - Inline variable 2505 * - Inline constant 2506 * - ... 2507 */ 2508 static readonly RefactorInline: CodeActionKind; 2509 2510 /** 2511 * Base kind for refactoring move actions: `refactor.move` 2512 * 2513 * Example move actions: 2514 * 2515 * - Move a function to a new file 2516 * - Move a property between classes 2517 * - Move method to base class 2518 * - ... 2519 */ 2520 static readonly RefactorMove: CodeActionKind; 2521 2522 /** 2523 * Base kind for refactoring rewrite actions: `refactor.rewrite` 2524 * 2525 * Example rewrite actions: 2526 * 2527 * - Convert JavaScript function to class 2528 * - Add or remove parameter 2529 * - Encapsulate field 2530 * - Make method static 2531 * - ... 2532 */ 2533 static readonly RefactorRewrite: CodeActionKind; 2534 2535 /** 2536 * Base kind for source actions: `source` 2537 * 2538 * Source code actions apply to the entire file. They must be explicitly requested and will not show in the 2539 * normal [lightbulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) menu. Source actions 2540 * can be run on save using `editor.codeActionsOnSave` and are also shown in the `source` context menu. 2541 */ 2542 static readonly Source: CodeActionKind; 2543 2544 /** 2545 * Base kind for an organize imports source action: `source.organizeImports`. 2546 */ 2547 static readonly SourceOrganizeImports: CodeActionKind; 2548 2549 /** 2550 * Base kind for auto-fix source actions: `source.fixAll`. 2551 * 2552 * Fix all actions automatically fix errors that have a clear fix that do not require user input. 2553 * They should not suppress errors or perform unsafe fixes such as generating new types or classes. 2554 */ 2555 static readonly SourceFixAll: CodeActionKind; 2556 2557 /** 2558 * Base kind for all code actions applying to the entire notebook's scope. CodeActionKinds using 2559 * this should always begin with `notebook.` 2560 * 2561 * This requires that new CodeActions be created for it and contributed via extensions. 2562 * Pre-existing kinds can not just have the new `notebook.` prefix added to them, as the functionality 2563 * is unique to the full-notebook scope. 2564 * 2565 * Notebook CodeActionKinds can be initialized as either of the following (both resulting in `notebook.source.xyz`): 2566 * - `const newKind = CodeActionKind.Notebook.append(CodeActionKind.Source.append('xyz').value)` 2567 * - `const newKind = CodeActionKind.Notebook.append('source.xyz')` 2568 * 2569 * Example Kinds/Actions: 2570 * - `notebook.source.organizeImports` (might move all imports to a new top cell) 2571 * - `notebook.source.normalizeVariableNames` (might rename all variables to a standardized casing format) 2572 */ 2573 static readonly Notebook: CodeActionKind; 2574 2575 /** 2576 * Private constructor, use static `CodeActionKind.XYZ` to derive from an existing code action kind. 2577 * 2578 * @param value The value of the kind, such as `refactor.extract.function`. 2579 */ 2580 private constructor(value: string); 2581 2582 /** 2583 * String value of the kind, e.g. `"refactor.extract.function"`. 2584 */ 2585 readonly value: string; 2586 2587 /** 2588 * Create a new kind by appending a more specific selector to the current kind. 2589 * 2590 * Does not modify the current kind. 2591 */ 2592 append(parts: string): CodeActionKind; 2593 2594 /** 2595 * Checks if this code action kind intersects `other`. 2596 * 2597 * The kind `"refactor.extract"` for example intersects `refactor`, `"refactor.extract"` and `"refactor.extract.function"`, 2598 * but not `"unicorn.refactor.extract"`, or `"refactor.extractAll"`. 2599 * 2600 * @param other Kind to check. 2601 */ 2602 intersects(other: CodeActionKind): boolean; 2603 2604 /** 2605 * Checks if `other` is a sub-kind of this `CodeActionKind`. 2606 * 2607 * The kind `"refactor.extract"` for example contains `"refactor.extract"` and ``"refactor.extract.function"`, 2608 * but not `"unicorn.refactor.extract"`, or `"refactor.extractAll"` or `refactor`. 2609 * 2610 * @param other Kind to check. 2611 */ 2612 contains(other: CodeActionKind): boolean; 2613 } 2614 2615 /** 2616 * The reason why code actions were requested. 2617 */ 2618 export enum CodeActionTriggerKind { 2619 /** 2620 * Code actions were explicitly requested by the user or by an extension. 2621 */ 2622 Invoke = 1, 2623 2624 /** 2625 * Code actions were requested automatically. 2626 * 2627 * This typically happens when current selection in a file changes, but can 2628 * also be triggered when file content changes. 2629 */ 2630 Automatic = 2, 2631 } 2632 2633 /** 2634 * Contains additional diagnostic information about the context in which 2635 * a {@link CodeActionProvider.provideCodeActions code action} is run. 2636 */ 2637 export interface CodeActionContext { 2638 /** 2639 * The reason why code actions were requested. 2640 */ 2641 readonly triggerKind: CodeActionTriggerKind; 2642 2643 /** 2644 * An array of diagnostics. 2645 */ 2646 readonly diagnostics: readonly Diagnostic[]; 2647 2648 /** 2649 * Requested kind of actions to return. 2650 * 2651 * Actions not of this kind are filtered out before being shown by the [lightbulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action). 2652 */ 2653 readonly only: CodeActionKind | undefined; 2654 } 2655 2656 /** 2657 * A code action represents a change that can be performed in code, e.g. to fix a problem or 2658 * to refactor code. 2659 * 2660 * A CodeAction must set either {@linkcode CodeAction.edit edit} and/or a {@linkcode CodeAction.command command}. If both are supplied, the `edit` is applied first, then the command is executed. 2661 */ 2662 export class CodeAction { 2663 2664 /** 2665 * A short, human-readable, title for this code action. 2666 */ 2667 title: string; 2668 2669 /** 2670 * A {@link WorkspaceEdit workspace edit} this code action performs. 2671 */ 2672 edit?: WorkspaceEdit; 2673 2674 /** 2675 * {@link Diagnostic Diagnostics} that this code action resolves. 2676 */ 2677 diagnostics?: Diagnostic[]; 2678 2679 /** 2680 * A {@link Command} this code action executes. 2681 * 2682 * If this command throws an exception, the editor displays the exception message to users in the editor at the 2683 * current cursor position. 2684 */ 2685 command?: Command; 2686 2687 /** 2688 * {@link CodeActionKind Kind} of the code action. 2689 * 2690 * Used to filter code actions. 2691 */ 2692 kind?: CodeActionKind; 2693 2694 /** 2695 * Marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted 2696 * by keybindings. 2697 * 2698 * A quick fix should be marked preferred if it properly addresses the underlying error. 2699 * A refactoring should be marked preferred if it is the most reasonable choice of actions to take. 2700 */ 2701 isPreferred?: boolean; 2702 2703 /** 2704 * Marks that the code action cannot currently be applied. 2705 * 2706 * - Disabled code actions are not shown in automatic [lightbulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) 2707 * code action menu. 2708 * 2709 * - Disabled actions are shown as faded out in the code action menu when the user request a more specific type 2710 * of code action, such as refactorings. 2711 * 2712 * - If the user has a [keybinding](https://code.visualstudio.com/docs/editor/refactoring#_keybindings-for-code-actions) 2713 * that auto applies a code action and only a disabled code actions are returned, the editor will show the user an 2714 * error message with `reason` in the editor. 2715 */ 2716 disabled?: { 2717 /** 2718 * Human readable description of why the code action is currently disabled. 2719 * 2720 * This is displayed in the code actions UI. 2721 */ 2722 readonly reason: string; 2723 }; 2724 2725 /** 2726 * Creates a new code action. 2727 * 2728 * A code action must have at least a {@link CodeAction.title title} and {@link CodeAction.edit edits} 2729 * and/or a {@link CodeAction.command command}. 2730 * 2731 * @param title The title of the code action. 2732 * @param kind The kind of the code action. 2733 */ 2734 constructor(title: string, kind?: CodeActionKind); 2735 } 2736 2737 /** 2738 * Provides contextual actions for code. Code actions typically either fix problems or beautify/refactor code. 2739 * 2740 * Code actions are surfaced to users in a few different ways: 2741 * 2742 * - The [lightbulb](https://code.visualstudio.com/docs/editor/editingevolved#_code-action) feature, which shows 2743 * a list of code actions at the current cursor position. The lightbulb's list of actions includes both quick fixes 2744 * and refactorings. 2745 * - As commands that users can run, such as `Refactor`. Users can run these from the command palette or with keybindings. 2746 * - As source actions, such `Organize Imports`. 2747 * - {@link CodeActionKind.QuickFix Quick fixes} are shown in the problems view. 2748 * - Change applied on save by the `editor.codeActionsOnSave` setting. 2749 */ 2750 export interface CodeActionProvider<T extends CodeAction = CodeAction> { 2751 /** 2752 * Get code actions for a given range in a document. 2753 * 2754 * Only return code actions that are relevant to user for the requested range. Also keep in mind how the 2755 * returned code actions will appear in the UI. The lightbulb widget and `Refactor` commands for instance show 2756 * returned code actions as a list, so do not return a large number of code actions that will overwhelm the user. 2757 * 2758 * @param document The document in which the command was invoked. 2759 * @param range The selector or range for which the command was invoked. This will always be a 2760 * {@link Selection selection} if the actions are being requested in the currently active editor. 2761 * @param context Provides additional information about what code actions are being requested. You can use this 2762 * to see what specific type of code actions are being requested by the editor in order to return more relevant 2763 * actions and avoid returning irrelevant code actions that the editor will discard. 2764 * @param token A cancellation token. 2765 * 2766 * @returns An array of code actions, such as quick fixes or refactorings. The lack of a result can be signaled 2767 * by returning `undefined`, `null`, or an empty array. 2768 * 2769 * We also support returning `Command` for legacy reasons, however all new extensions should return 2770 * `CodeAction` object instead. 2771 */ 2772 provideCodeActions(document: TextDocument, range: Range | Selection, context: CodeActionContext, token: CancellationToken): ProviderResult<Array<Command | T>>; 2773 2774 /** 2775 * Given a code action fill in its {@linkcode CodeAction.edit edit}-property. Changes to 2776 * all other properties, like title, are ignored. A code action that has an edit 2777 * will not be resolved. 2778 * 2779 * *Note* that a code action provider that returns commands, not code actions, cannot successfully 2780 * implement this function. Returning commands is deprecated and instead code actions should be 2781 * returned. 2782 * 2783 * @param codeAction A code action. 2784 * @param token A cancellation token. 2785 * @returns The resolved code action or a thenable that resolves to such. It is OK to return the given 2786 * `item`. When no result is returned, the given `item` will be used. 2787 */ 2788 resolveCodeAction?(codeAction: T, token: CancellationToken): ProviderResult<T>; 2789 } 2790 2791 /** 2792 * Metadata about the type of code actions that a {@link CodeActionProvider} provides. 2793 */ 2794 export interface CodeActionProviderMetadata { 2795 /** 2796 * List of {@link CodeActionKind CodeActionKinds} that a {@link CodeActionProvider} may return. 2797 * 2798 * This list is used to determine if a given `CodeActionProvider` should be invoked or not. 2799 * To avoid unnecessary computation, every `CodeActionProvider` should list use `providedCodeActionKinds`. The 2800 * list of kinds may either be generic, such as `[CodeActionKind.Refactor]`, or list out every kind provided, 2801 * such as `[CodeActionKind.Refactor.Extract.append('function'), CodeActionKind.Refactor.Extract.append('constant'), ...]`. 2802 */ 2803 readonly providedCodeActionKinds?: readonly CodeActionKind[]; 2804 2805 /** 2806 * Static documentation for a class of code actions. 2807 * 2808 * Documentation from the provider is shown in the code actions menu if either: 2809 * 2810 * - Code actions of `kind` are requested by the editor. In this case, the editor will show the documentation that 2811 * most closely matches the requested code action kind. For example, if a provider has documentation for 2812 * both `Refactor` and `RefactorExtract`, when the user requests code actions for `RefactorExtract`, 2813 * the editor will use the documentation for `RefactorExtract` instead of the documentation for `Refactor`. 2814 * 2815 * - Any code actions of `kind` are returned by the provider. 2816 * 2817 * At most one documentation entry will be shown per provider. 2818 */ 2819 readonly documentation?: ReadonlyArray<{ 2820 /** 2821 * The kind of the code action being documented. 2822 * 2823 * If the kind is generic, such as `CodeActionKind.Refactor`, the documentation will be shown whenever any 2824 * refactorings are returned. If the kind if more specific, such as `CodeActionKind.RefactorExtract`, the 2825 * documentation will only be shown when extract refactoring code actions are returned. 2826 */ 2827 readonly kind: CodeActionKind; 2828 2829 /** 2830 * Command that displays the documentation to the user. 2831 * 2832 * This can display the documentation directly in the editor or open a website using {@linkcode env.openExternal}; 2833 * 2834 * The title of this documentation code action is taken from {@linkcode Command.title} 2835 */ 2836 readonly command: Command; 2837 }>; 2838 } 2839 2840 /** 2841 * A code lens represents a {@link Command} that should be shown along with 2842 * source text, like the number of references, a way to run tests, etc. 2843 * 2844 * A code lens is _unresolved_ when no command is associated to it. For performance 2845 * reasons the creation of a code lens and resolving should be done to two stages. 2846 * 2847 * @see {@link CodeLensProvider.provideCodeLenses} 2848 * @see {@link CodeLensProvider.resolveCodeLens} 2849 */ 2850 export class CodeLens { 2851 2852 /** 2853 * The range in which this code lens is valid. Should only span a single line. 2854 */ 2855 range: Range; 2856 2857 /** 2858 * The command this code lens represents. 2859 */ 2860 command?: Command; 2861 2862 /** 2863 * `true` when there is a command associated. 2864 */ 2865 readonly isResolved: boolean; 2866 2867 /** 2868 * Creates a new code lens object. 2869 * 2870 * @param range The range to which this code lens applies. 2871 * @param command The command associated to this code lens. 2872 */ 2873 constructor(range: Range, command?: Command); 2874 } 2875 2876 /** 2877 * A code lens provider adds {@link Command commands} to source text. The commands will be shown 2878 * as dedicated horizontal lines in between the source text. 2879 */ 2880 export interface CodeLensProvider<T extends CodeLens = CodeLens> { 2881 2882 /** 2883 * An optional event to signal that the code lenses from this provider have changed. 2884 */ 2885 onDidChangeCodeLenses?: Event<void>; 2886 2887 /** 2888 * Compute a list of {@link CodeLens lenses}. This call should return as fast as possible and if 2889 * computing the commands is expensive implementors should only return code lens objects with the 2890 * range set and implement {@link CodeLensProvider.resolveCodeLens resolve}. 2891 * 2892 * @param document The document in which the command was invoked. 2893 * @param token A cancellation token. 2894 * @returns An array of code lenses or a thenable that resolves to such. The lack of a result can be 2895 * signaled by returning `undefined`, `null`, or an empty array. 2896 */ 2897 provideCodeLenses(document: TextDocument, token: CancellationToken): ProviderResult<T[]>; 2898 2899 /** 2900 * This function will be called for each visible code lens, usually when scrolling and after 2901 * calls to {@link CodeLensProvider.provideCodeLenses compute}-lenses. 2902 * 2903 * @param codeLens Code lens that must be resolved. 2904 * @param token A cancellation token. 2905 * @returns The given, resolved code lens or thenable that resolves to such. 2906 */ 2907 resolveCodeLens?(codeLens: T, token: CancellationToken): ProviderResult<T>; 2908 } 2909 2910 /** 2911 * Information about where a symbol is defined. 2912 * 2913 * Provides additional metadata over normal {@link Location} definitions, including the range of 2914 * the defining symbol 2915 */ 2916 export type DefinitionLink = LocationLink; 2917 2918 /** 2919 * The definition of a symbol represented as one or many {@link Location locations}. 2920 * For most programming languages there is only one location at which a symbol is 2921 * defined. 2922 */ 2923 export type Definition = Location | Location[]; 2924 2925 /** 2926 * The definition provider interface defines the contract between extensions and 2927 * the [go to definition](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-definition) 2928 * and peek definition features. 2929 */ 2930 export interface DefinitionProvider { 2931 2932 /** 2933 * Provide the definition of the symbol at the given position and document. 2934 * 2935 * @param document The document in which the command was invoked. 2936 * @param position The position at which the command was invoked. 2937 * @param token A cancellation token. 2938 * @returns A definition or a thenable that resolves to such. The lack of a result can be 2939 * signaled by returning `undefined` or `null`. 2940 */ 2941 provideDefinition(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>; 2942 } 2943 2944 /** 2945 * The implementation provider interface defines the contract between extensions and 2946 * the go to implementation feature. 2947 */ 2948 export interface ImplementationProvider { 2949 2950 /** 2951 * Provide the implementations of the symbol at the given position and document. 2952 * 2953 * @param document The document in which the command was invoked. 2954 * @param position The position at which the command was invoked. 2955 * @param token A cancellation token. 2956 * @returns A definition or a thenable that resolves to such. The lack of a result can be 2957 * signaled by returning `undefined` or `null`. 2958 */ 2959 provideImplementation(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>; 2960 } 2961 2962 /** 2963 * The type definition provider defines the contract between extensions and 2964 * the go to type definition feature. 2965 */ 2966 export interface TypeDefinitionProvider { 2967 2968 /** 2969 * Provide the type definition of the symbol at the given position and document. 2970 * 2971 * @param document The document in which the command was invoked. 2972 * @param position The position at which the command was invoked. 2973 * @param token A cancellation token. 2974 * @returns A definition or a thenable that resolves to such. The lack of a result can be 2975 * signaled by returning `undefined` or `null`. 2976 */ 2977 provideTypeDefinition(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Definition | DefinitionLink[]>; 2978 } 2979 2980 /** 2981 * The declaration of a symbol representation as one or many {@link Location locations} 2982 * or {@link LocationLink location links}. 2983 */ 2984 export type Declaration = Location | Location[] | LocationLink[]; 2985 2986 /** 2987 * The declaration provider interface defines the contract between extensions and 2988 * the go to declaration feature. 2989 */ 2990 export interface DeclarationProvider { 2991 2992 /** 2993 * Provide the declaration of the symbol at the given position and document. 2994 * 2995 * @param document The document in which the command was invoked. 2996 * @param position The position at which the command was invoked. 2997 * @param token A cancellation token. 2998 * @returns A declaration or a thenable that resolves to such. The lack of a result can be 2999 * signaled by returning `undefined` or `null`. 3000 */ 3001 provideDeclaration(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Declaration>; 3002 } 3003 3004 /** 3005 * Human-readable text that supports formatting via the [markdown syntax](https://commonmark.org). 3006 * 3007 * Rendering of {@link ThemeIcon theme icons} via the `$(<name>)`-syntax is supported 3008 * when the {@linkcode supportThemeIcons} is set to `true`. 3009 * 3010 * Rendering of embedded html is supported when {@linkcode supportHtml} is set to `true`. 3011 */ 3012 export class MarkdownString { 3013 3014 /** 3015 * The markdown string. 3016 */ 3017 value: string; 3018 3019 /** 3020 * Indicates that this markdown string is from a trusted source. Only *trusted* 3021 * markdown supports links that execute commands, e.g. `[Run it](command:myCommandId)`. 3022 * 3023 * Defaults to `false` (commands are disabled). 3024 */ 3025 isTrusted?: boolean | { 3026 /** 3027 * A set of commend ids that are allowed to be executed by this markdown string. 3028 */ 3029 readonly enabledCommands: readonly string[]; 3030 }; 3031 3032 /** 3033 * Indicates that this markdown string can contain {@link ThemeIcon ThemeIcons}, e.g. `$(zap)`. 3034 */ 3035 supportThemeIcons?: boolean; 3036 3037 /** 3038 * Indicates that this markdown string can contain raw html tags. Defaults to `false`. 3039 * 3040 * When `supportHtml` is false, the markdown renderer will strip out any raw html tags 3041 * that appear in the markdown text. This means you can only use markdown syntax for rendering. 3042 * 3043 * When `supportHtml` is true, the markdown render will also allow a safe subset of html tags 3044 * and attributes to be rendered. See https://github.com/microsoft/vscode/blob/6d2920473c6f13759c978dd89104c4270a83422d/src/vs/base/browser/markdownRenderer.ts#L296 3045 * for a list of all supported tags and attributes. 3046 */ 3047 supportHtml?: boolean; 3048 3049 /** 3050 * Uri that relative paths are resolved relative to. 3051 * 3052 * If the `baseUri` ends with `/`, it is considered a directory and relative paths in the markdown are resolved relative to that directory: 3053 * 3054 * ```ts 3055 * const md = new vscode.MarkdownString(`[link](./file.js)`); 3056 * md.baseUri = vscode.Uri.file('/path/to/dir/'); 3057 * // Here 'link' in the rendered markdown resolves to '/path/to/dir/file.js' 3058 * ``` 3059 * 3060 * If the `baseUri` is a file, relative paths in the markdown are resolved relative to the parent dir of that file: 3061 * 3062 * ```ts 3063 * const md = new vscode.MarkdownString(`[link](./file.js)`); 3064 * md.baseUri = vscode.Uri.file('/path/to/otherFile.js'); 3065 * // Here 'link' in the rendered markdown resolves to '/path/to/file.js' 3066 * ``` 3067 */ 3068 baseUri?: Uri; 3069 3070 /** 3071 * Creates a new markdown string with the given value. 3072 * 3073 * @param value Optional, initial value. 3074 * @param supportThemeIcons Optional, Specifies whether {@link ThemeIcon ThemeIcons} are supported within the {@linkcode MarkdownString}. 3075 */ 3076 constructor(value?: string, supportThemeIcons?: boolean); 3077 3078 /** 3079 * Appends and escapes the given string to this markdown string. 3080 * @param value Plain text. 3081 */ 3082 appendText(value: string): MarkdownString; 3083 3084 /** 3085 * Appends the given string 'as is' to this markdown string. When {@linkcode MarkdownString.supportThemeIcons supportThemeIcons} is `true`, {@link ThemeIcon ThemeIcons} in the `value` will be iconified. 3086 * @param value Markdown string. 3087 */ 3088 appendMarkdown(value: string): MarkdownString; 3089 3090 /** 3091 * Appends the given string as codeblock using the provided language. 3092 * @param value A code snippet. 3093 * @param language An optional {@link languages.getLanguages language identifier}. 3094 */ 3095 appendCodeblock(value: string, language?: string): MarkdownString; 3096 } 3097 3098 /** 3099 * MarkedString can be used to render human-readable text. It is either a markdown string 3100 * or a code-block that provides a language and a code snippet. Note that 3101 * markdown strings will be sanitized - that means html will be escaped. 3102 * 3103 * @deprecated This type is deprecated, please use {@linkcode MarkdownString} instead. 3104 */ 3105 export type MarkedString = string | { 3106 /** 3107 * The language of a markdown code block 3108 * @deprecated please use {@linkcode MarkdownString} instead 3109 */ 3110 language: string; 3111 /** 3112 * The code snippet of a markdown code block. 3113 * @deprecated please use {@linkcode MarkdownString} instead 3114 */ 3115 value: string; 3116 }; 3117 3118 /** 3119 * A hover represents additional information for a symbol or word. Hovers are 3120 * rendered in a tooltip-like widget. 3121 */ 3122 export class Hover { 3123 3124 /** 3125 * The contents of this hover. 3126 */ 3127 contents: Array<MarkdownString | MarkedString>; 3128 3129 /** 3130 * The range to which this hover applies. When missing, the 3131 * editor will use the range at the current position or the 3132 * current position itself. 3133 */ 3134 range?: Range; 3135 3136 /** 3137 * Creates a new hover object. 3138 * 3139 * @param contents The contents of the hover. 3140 * @param range The range to which the hover applies. 3141 */ 3142 constructor(contents: MarkdownString | MarkedString | Array<MarkdownString | MarkedString>, range?: Range); 3143 } 3144 3145 /** 3146 * The hover provider interface defines the contract between extensions and 3147 * the [hover](https://code.visualstudio.com/docs/editor/intellisense)-feature. 3148 */ 3149 export interface HoverProvider { 3150 3151 /** 3152 * Provide a hover for the given position and document. Multiple hovers at the same 3153 * position will be merged by the editor. A hover can have a range which defaults 3154 * to the word range at the position when omitted. 3155 * 3156 * @param document The document in which the command was invoked. 3157 * @param position The position at which the command was invoked. 3158 * @param token A cancellation token. 3159 * @returns A hover or a thenable that resolves to such. The lack of a result can be 3160 * signaled by returning `undefined` or `null`. 3161 */ 3162 provideHover(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Hover>; 3163 } 3164 3165 /** 3166 * An EvaluatableExpression represents an expression in a document that can be evaluated by an active debugger or runtime. 3167 * The result of this evaluation is shown in a tooltip-like widget. 3168 * If only a range is specified, the expression will be extracted from the underlying document. 3169 * An optional expression can be used to override the extracted expression. 3170 * In this case the range is still used to highlight the range in the document. 3171 */ 3172 export class EvaluatableExpression { 3173 3174 /** 3175 * The range is used to extract the evaluatable expression from the underlying document and to highlight it. 3176 */ 3177 readonly range: Range; 3178 3179 /** 3180 * If specified the expression overrides the extracted expression. 3181 */ 3182 readonly expression?: string | undefined; 3183 3184 /** 3185 * Creates a new evaluatable expression object. 3186 * 3187 * @param range The range in the underlying document from which the evaluatable expression is extracted. 3188 * @param expression If specified overrides the extracted expression. 3189 */ 3190 constructor(range: Range, expression?: string); 3191 } 3192 3193 /** 3194 * The evaluatable expression provider interface defines the contract between extensions and 3195 * the debug hover. In this contract the provider returns an evaluatable expression for a given position 3196 * in a document and the editor evaluates this expression in the active debug session and shows the result in a debug hover. 3197 */ 3198 export interface EvaluatableExpressionProvider { 3199 3200 /** 3201 * Provide an evaluatable expression for the given document and position. 3202 * The editor will evaluate this expression in the active debug session and will show the result in the debug hover. 3203 * The expression can be implicitly specified by the range in the underlying document or by explicitly returning an expression. 3204 * 3205 * @param document The document for which the debug hover is about to appear. 3206 * @param position The line and character position in the document where the debug hover is about to appear. 3207 * @param token A cancellation token. 3208 * @returns An EvaluatableExpression or a thenable that resolves to such. The lack of a result can be 3209 * signaled by returning `undefined` or `null`. 3210 */ 3211 provideEvaluatableExpression(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<EvaluatableExpression>; 3212 } 3213 3214 /** 3215 * Provide inline value as text. 3216 */ 3217 export class InlineValueText { 3218 /** 3219 * The document range for which the inline value applies. 3220 */ 3221 readonly range: Range; 3222 /** 3223 * The text of the inline value. 3224 */ 3225 readonly text: string; 3226 /** 3227 * Creates a new InlineValueText object. 3228 * 3229 * @param range The document line where to show the inline value. 3230 * @param text The value to be shown for the line. 3231 */ 3232 constructor(range: Range, text: string); 3233 } 3234 3235 /** 3236 * Provide inline value through a variable lookup. 3237 * If only a range is specified, the variable name will be extracted from the underlying document. 3238 * An optional variable name can be used to override the extracted name. 3239 */ 3240 export class InlineValueVariableLookup { 3241 /** 3242 * The document range for which the inline value applies. 3243 * The range is used to extract the variable name from the underlying document. 3244 */ 3245 readonly range: Range; 3246 /** 3247 * If specified the name of the variable to look up. 3248 */ 3249 readonly variableName?: string | undefined; 3250 /** 3251 * How to perform the lookup. 3252 */ 3253 readonly caseSensitiveLookup: boolean; 3254 /** 3255 * Creates a new InlineValueVariableLookup object. 3256 * 3257 * @param range The document line where to show the inline value. 3258 * @param variableName The name of the variable to look up. 3259 * @param caseSensitiveLookup How to perform the lookup. If missing lookup is case sensitive. 3260 */ 3261 constructor(range: Range, variableName?: string, caseSensitiveLookup?: boolean); 3262 } 3263 3264 /** 3265 * Provide an inline value through an expression evaluation. 3266 * If only a range is specified, the expression will be extracted from the underlying document. 3267 * An optional expression can be used to override the extracted expression. 3268 */ 3269 export class InlineValueEvaluatableExpression { 3270 /** 3271 * The document range for which the inline value applies. 3272 * The range is used to extract the evaluatable expression from the underlying document. 3273 */ 3274 readonly range: Range; 3275 /** 3276 * If specified the expression overrides the extracted expression. 3277 */ 3278 readonly expression?: string | undefined; 3279 /** 3280 * Creates a new InlineValueEvaluatableExpression object. 3281 * 3282 * @param range The range in the underlying document from which the evaluatable expression is extracted. 3283 * @param expression If specified overrides the extracted expression. 3284 */ 3285 constructor(range: Range, expression?: string); 3286 } 3287 3288 /** 3289 * Inline value information can be provided by different means: 3290 * - directly as a text value (class InlineValueText). 3291 * - as a name to use for a variable lookup (class InlineValueVariableLookup) 3292 * - as an evaluatable expression (class InlineValueEvaluatableExpression) 3293 * The InlineValue types combines all inline value types into one type. 3294 */ 3295 export type InlineValue = InlineValueText | InlineValueVariableLookup | InlineValueEvaluatableExpression; 3296 3297 /** 3298 * A value-object that contains contextual information when requesting inline values from a InlineValuesProvider. 3299 */ 3300 export interface InlineValueContext { 3301 3302 /** 3303 * The stack frame (as a DAP Id) where the execution has stopped. 3304 */ 3305 readonly frameId: number; 3306 3307 /** 3308 * The document range where execution has stopped. 3309 * Typically the end position of the range denotes the line where the inline values are shown. 3310 */ 3311 readonly stoppedLocation: Range; 3312 } 3313 3314 /** 3315 * The inline values provider interface defines the contract between extensions and the editor's debugger inline values feature. 3316 * In this contract the provider returns inline value information for a given document range 3317 * and the editor shows this information in the editor at the end of lines. 3318 */ 3319 export interface InlineValuesProvider { 3320 3321 /** 3322 * An optional event to signal that inline values have changed. 3323 * @see {@link EventEmitter} 3324 */ 3325 onDidChangeInlineValues?: Event<void> | undefined; 3326 3327 /** 3328 * Provide "inline value" information for a given document and range. 3329 * The editor calls this method whenever debugging stops in the given document. 3330 * The returned inline values information is rendered in the editor at the end of lines. 3331 * 3332 * @param document The document for which the inline values information is needed. 3333 * @param viewPort The visible document range for which inline values should be computed. 3334 * @param context A bag containing contextual information like the current location. 3335 * @param token A cancellation token. 3336 * @returns An array of InlineValueDescriptors or a thenable that resolves to such. The lack of a result can be 3337 * signaled by returning `undefined` or `null`. 3338 */ 3339 provideInlineValues(document: TextDocument, viewPort: Range, context: InlineValueContext, token: CancellationToken): ProviderResult<InlineValue[]>; 3340 } 3341 3342 /** 3343 * A document highlight kind. 3344 */ 3345 export enum DocumentHighlightKind { 3346 3347 /** 3348 * A textual occurrence. 3349 */ 3350 Text = 0, 3351 3352 /** 3353 * Read-access of a symbol, like reading a variable. 3354 */ 3355 Read = 1, 3356 3357 /** 3358 * Write-access of a symbol, like writing to a variable. 3359 */ 3360 Write = 2 3361 } 3362 3363 /** 3364 * A document highlight is a range inside a text document which deserves 3365 * special attention. Usually a document highlight is visualized by changing 3366 * the background color of its range. 3367 */ 3368 export class DocumentHighlight { 3369 3370 /** 3371 * The range this highlight applies to. 3372 */ 3373 range: Range; 3374 3375 /** 3376 * The highlight kind, default is {@link DocumentHighlightKind.Text text}. 3377 */ 3378 kind?: DocumentHighlightKind; 3379 3380 /** 3381 * Creates a new document highlight object. 3382 * 3383 * @param range The range the highlight applies to. 3384 * @param kind The highlight kind, default is {@link DocumentHighlightKind.Text text}. 3385 */ 3386 constructor(range: Range, kind?: DocumentHighlightKind); 3387 } 3388 3389 /** 3390 * The document highlight provider interface defines the contract between extensions and 3391 * the word-highlight-feature. 3392 */ 3393 export interface DocumentHighlightProvider { 3394 3395 /** 3396 * Provide a set of document highlights, like all occurrences of a variable or 3397 * all exit-points of a function. 3398 * 3399 * @param document The document in which the command was invoked. 3400 * @param position The position at which the command was invoked. 3401 * @param token A cancellation token. 3402 * @returns An array of document highlights or a thenable that resolves to such. The lack of a result can be 3403 * signaled by returning `undefined`, `null`, or an empty array. 3404 */ 3405 provideDocumentHighlights(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<DocumentHighlight[]>; 3406 } 3407 3408 /** 3409 * A symbol kind. 3410 */ 3411 export enum SymbolKind { 3412 /** 3413 * The `File` symbol kind. 3414 */ 3415 File = 0, 3416 /** 3417 * The `Module` symbol kind. 3418 */ 3419 Module = 1, 3420 /** 3421 * The `Namespace` symbol kind. 3422 */ 3423 Namespace = 2, 3424 /** 3425 * The `Package` symbol kind. 3426 */ 3427 Package = 3, 3428 /** 3429 * The `Class` symbol kind. 3430 */ 3431 Class = 4, 3432 /** 3433 * The `Method` symbol kind. 3434 */ 3435 Method = 5, 3436 /** 3437 * The `Property` symbol kind. 3438 */ 3439 Property = 6, 3440 /** 3441 * The `Field` symbol kind. 3442 */ 3443 Field = 7, 3444 /** 3445 * The `Constructor` symbol kind. 3446 */ 3447 Constructor = 8, 3448 /** 3449 * The `Enum` symbol kind. 3450 */ 3451 Enum = 9, 3452 /** 3453 * The `Interface` symbol kind. 3454 */ 3455 Interface = 10, 3456 /** 3457 * The `Function` symbol kind. 3458 */ 3459 Function = 11, 3460 /** 3461 * The `Variable` symbol kind. 3462 */ 3463 Variable = 12, 3464 /** 3465 * The `Constant` symbol kind. 3466 */ 3467 Constant = 13, 3468 /** 3469 * The `String` symbol kind. 3470 */ 3471 String = 14, 3472 /** 3473 * The `Number` symbol kind. 3474 */ 3475 Number = 15, 3476 /** 3477 * The `Boolean` symbol kind. 3478 */ 3479 Boolean = 16, 3480 /** 3481 * The `Array` symbol kind. 3482 */ 3483 Array = 17, 3484 /** 3485 * The `Object` symbol kind. 3486 */ 3487 Object = 18, 3488 /** 3489 * The `Key` symbol kind. 3490 */ 3491 Key = 19, 3492 /** 3493 * The `Null` symbol kind. 3494 */ 3495 Null = 20, 3496 /** 3497 * The `EnumMember` symbol kind. 3498 */ 3499 EnumMember = 21, 3500 /** 3501 * The `Struct` symbol kind. 3502 */ 3503 Struct = 22, 3504 /** 3505 * The `Event` symbol kind. 3506 */ 3507 Event = 23, 3508 /** 3509 * The `Operator` symbol kind. 3510 */ 3511 Operator = 24, 3512 /** 3513 * The `TypeParameter` symbol kind. 3514 */ 3515 TypeParameter = 25 3516 } 3517 3518 /** 3519 * Symbol tags are extra annotations that tweak the rendering of a symbol. 3520 */ 3521 export enum SymbolTag { 3522 3523 /** 3524 * Render a symbol as obsolete, usually using a strike-out. 3525 */ 3526 Deprecated = 1 3527 } 3528 3529 /** 3530 * Represents information about programming constructs like variables, classes, 3531 * interfaces etc. 3532 */ 3533 export class SymbolInformation { 3534 3535 /** 3536 * The name of this symbol. 3537 */ 3538 name: string; 3539 3540 /** 3541 * The name of the symbol containing this symbol. 3542 */ 3543 containerName: string; 3544 3545 /** 3546 * The kind of this symbol. 3547 */ 3548 kind: SymbolKind; 3549 3550 /** 3551 * Tags for this symbol. 3552 */ 3553 tags?: readonly SymbolTag[]; 3554 3555 /** 3556 * The location of this symbol. 3557 */ 3558 location: Location; 3559 3560 /** 3561 * Creates a new symbol information object. 3562 * 3563 * @param name The name of the symbol. 3564 * @param kind The kind of the symbol. 3565 * @param containerName The name of the symbol containing the symbol. 3566 * @param location The location of the symbol. 3567 */ 3568 constructor(name: string, kind: SymbolKind, containerName: string, location: Location); 3569 3570 /** 3571 * Creates a new symbol information object. 3572 * 3573 * @deprecated Please use the constructor taking a {@link Location} object. 3574 * 3575 * @param name The name of the symbol. 3576 * @param kind The kind of the symbol. 3577 * @param range The range of the location of the symbol. 3578 * @param uri The resource of the location of symbol, defaults to the current document. 3579 * @param containerName The name of the symbol containing the symbol. 3580 */ 3581 constructor(name: string, kind: SymbolKind, range: Range, uri?: Uri, containerName?: string); 3582 } 3583 3584 /** 3585 * Represents programming constructs like variables, classes, interfaces etc. that appear in a document. Document 3586 * symbols can be hierarchical and they have two ranges: one that encloses its definition and one that points to 3587 * its most interesting range, e.g. the range of an identifier. 3588 */ 3589 export class DocumentSymbol { 3590 3591 /** 3592 * The name of this symbol. 3593 */ 3594 name: string; 3595 3596 /** 3597 * More detail for this symbol, e.g. the signature of a function. 3598 */ 3599 detail: string; 3600 3601 /** 3602 * The kind of this symbol. 3603 */ 3604 kind: SymbolKind; 3605 3606 /** 3607 * Tags for this symbol. 3608 */ 3609 tags?: readonly SymbolTag[]; 3610 3611 /** 3612 * The range enclosing this symbol not including leading/trailing whitespace but everything else, e.g. comments and code. 3613 */ 3614 range: Range; 3615 3616 /** 3617 * The range that should be selected and reveal when this symbol is being picked, e.g. the name of a function. 3618 * Must be contained by the {@linkcode DocumentSymbol.range range}. 3619 */ 3620 selectionRange: Range; 3621 3622 /** 3623 * Children of this symbol, e.g. properties of a class. 3624 */ 3625 children: DocumentSymbol[]; 3626 3627 /** 3628 * Creates a new document symbol. 3629 * 3630 * @param name The name of the symbol. 3631 * @param detail Details for the symbol. 3632 * @param kind The kind of the symbol. 3633 * @param range The full range of the symbol. 3634 * @param selectionRange The range that should be reveal. 3635 */ 3636 constructor(name: string, detail: string, kind: SymbolKind, range: Range, selectionRange: Range); 3637 } 3638 3639 /** 3640 * The document symbol provider interface defines the contract between extensions and 3641 * the [go to symbol](https://code.visualstudio.com/docs/editor/editingevolved#_go-to-symbol)-feature. 3642 */ 3643 export interface DocumentSymbolProvider { 3644 3645 /** 3646 * Provide symbol information for the given document. 3647 * 3648 * @param document The document in which the command was invoked. 3649 * @param token A cancellation token. 3650 * @returns An array of document highlights or a thenable that resolves to such. The lack of a result can be 3651 * signaled by returning `undefined`, `null`, or an empty array. 3652 */ 3653 provideDocumentSymbols(document: TextDocument, token: CancellationToken): ProviderResult<SymbolInformation[] | DocumentSymbol[]>; 3654 } 3655 3656 /** 3657 * Metadata about a document symbol provider. 3658 */ 3659 export interface DocumentSymbolProviderMetadata { 3660 /** 3661 * A human-readable string that is shown when multiple outlines trees show for one document. 3662 */ 3663 label?: string; 3664 } 3665 3666 /** 3667 * The workspace symbol provider interface defines the contract between extensions and 3668 * the [symbol search](https://code.visualstudio.com/docs/editor/editingevolved#_open-symbol-by-name)-feature. 3669 */ 3670 export interface WorkspaceSymbolProvider<T extends SymbolInformation = SymbolInformation> { 3671 3672 /** 3673 * Project-wide search for a symbol matching the given query string. 3674 * 3675 * The `query`-parameter should be interpreted in a *relaxed way* as the editor will apply its own highlighting 3676 * and scoring on the results. A good rule of thumb is to match case-insensitive and to simply check that the 3677 * characters of *query* appear in their order in a candidate symbol. Don't use prefix, substring, or similar 3678 * strict matching. 3679 * 3680 * To improve performance implementors can implement `resolveWorkspaceSymbol` and then provide symbols with partial 3681 * {@link SymbolInformation.location location}-objects, without a `range` defined. The editor will then call 3682 * `resolveWorkspaceSymbol` for selected symbols only, e.g. when opening a workspace symbol. 3683 * 3684 * @param query A query string, can be the empty string in which case all symbols should be returned. 3685 * @param token A cancellation token. 3686 * @returns An array of document highlights or a thenable that resolves to such. The lack of a result can be 3687 * signaled by returning `undefined`, `null`, or an empty array. 3688 */ 3689 provideWorkspaceSymbols(query: string, token: CancellationToken): ProviderResult<T[]>; 3690 3691 /** 3692 * Given a symbol fill in its {@link SymbolInformation.location location}. This method is called whenever a symbol 3693 * is selected in the UI. Providers can implement this method and return incomplete symbols from 3694 * {@linkcode WorkspaceSymbolProvider.provideWorkspaceSymbols provideWorkspaceSymbols} which often helps to improve 3695 * performance. 3696 * 3697 * @param symbol The symbol that is to be resolved. Guaranteed to be an instance of an object returned from an 3698 * earlier call to `provideWorkspaceSymbols`. 3699 * @param token A cancellation token. 3700 * @returns The resolved symbol or a thenable that resolves to that. When no result is returned, 3701 * the given `symbol` is used. 3702 */ 3703 resolveWorkspaceSymbol?(symbol: T, token: CancellationToken): ProviderResult<T>; 3704 } 3705 3706 /** 3707 * Value-object that contains additional information when 3708 * requesting references. 3709 */ 3710 export interface ReferenceContext { 3711 3712 /** 3713 * Include the declaration of the current symbol. 3714 */ 3715 readonly includeDeclaration: boolean; 3716 } 3717 3718 /** 3719 * The reference provider interface defines the contract between extensions and 3720 * the [find references](https://code.visualstudio.com/docs/editor/editingevolved#_peek)-feature. 3721 */ 3722 export interface ReferenceProvider { 3723 3724 /** 3725 * Provide a set of project-wide references for the given position and document. 3726 * 3727 * @param document The document in which the command was invoked. 3728 * @param position The position at which the command was invoked. 3729 * @param context Additional information about the references request. 3730 * @param token A cancellation token. 3731 * 3732 * @returns An array of locations or a thenable that resolves to such. The lack of a result can be 3733 * signaled by returning `undefined`, `null`, or an empty array. 3734 */ 3735 provideReferences(document: TextDocument, position: Position, context: ReferenceContext, token: CancellationToken): ProviderResult<Location[]>; 3736 } 3737 3738 /** 3739 * A text edit represents edits that should be applied 3740 * to a document. 3741 */ 3742 export class TextEdit { 3743 3744 /** 3745 * Utility to create a replace edit. 3746 * 3747 * @param range A range. 3748 * @param newText A string. 3749 * @returns A new text edit object. 3750 */ 3751 static replace(range: Range, newText: string): TextEdit; 3752 3753 /** 3754 * Utility to create an insert edit. 3755 * 3756 * @param position A position, will become an empty range. 3757 * @param newText A string. 3758 * @returns A new text edit object. 3759 */ 3760 static insert(position: Position, newText: string): TextEdit; 3761 3762 /** 3763 * Utility to create a delete edit. 3764 * 3765 * @param range A range. 3766 * @returns A new text edit object. 3767 */ 3768 static delete(range: Range): TextEdit; 3769 3770 /** 3771 * Utility to create an eol-edit. 3772 * 3773 * @param eol An eol-sequence 3774 * @returns A new text edit object. 3775 */ 3776 static setEndOfLine(eol: EndOfLine): TextEdit; 3777 3778 /** 3779 * The range this edit applies to. 3780 */ 3781 range: Range; 3782 3783 /** 3784 * The string this edit will insert. 3785 */ 3786 newText: string; 3787 3788 /** 3789 * The eol-sequence used in the document. 3790 * 3791 * *Note* that the eol-sequence will be applied to the 3792 * whole document. 3793 */ 3794 newEol?: EndOfLine; 3795 3796 /** 3797 * Create a new TextEdit. 3798 * 3799 * @param range A range. 3800 * @param newText A string. 3801 */ 3802 constructor(range: Range, newText: string); 3803 } 3804 3805 /** 3806 * A snippet edit represents an interactive edit that is performed by 3807 * the editor. 3808 * 3809 * *Note* that a snippet edit can always be performed as a normal {@link TextEdit text edit}. 3810 * This will happen when no matching editor is open or when a {@link WorkspaceEdit workspace edit} 3811 * contains snippet edits for multiple files. In that case only those that match the active editor 3812 * will be performed as snippet edits and the others as normal text edits. 3813 */ 3814 export class SnippetTextEdit { 3815 3816 /** 3817 * Utility to create a replace snippet edit. 3818 * 3819 * @param range A range. 3820 * @param snippet A snippet string. 3821 * @returns A new snippet edit object. 3822 */ 3823 static replace(range: Range, snippet: SnippetString): SnippetTextEdit; 3824 3825 /** 3826 * Utility to create an insert snippet edit. 3827 * 3828 * @param position A position, will become an empty range. 3829 * @param snippet A snippet string. 3830 * @returns A new snippet edit object. 3831 */ 3832 static insert(position: Position, snippet: SnippetString): SnippetTextEdit; 3833 3834 /** 3835 * The range this edit applies to. 3836 */ 3837 range: Range; 3838 3839 /** 3840 * The {@link SnippetString snippet} this edit will perform. 3841 */ 3842 snippet: SnippetString; 3843 3844 /** 3845 * Whether the snippet edit should be applied with existing whitespace preserved. 3846 */ 3847 keepWhitespace?: boolean; 3848 3849 /** 3850 * Create a new snippet edit. 3851 * 3852 * @param range A range. 3853 * @param snippet A snippet string. 3854 */ 3855 constructor(range: Range, snippet: SnippetString); 3856 } 3857 3858 /** 3859 * A notebook edit represents edits that should be applied to the contents of a notebook. 3860 */ 3861 export class NotebookEdit { 3862 3863 /** 3864 * Utility to create a edit that replaces cells in a notebook. 3865 * 3866 * @param range The range of cells to replace 3867 * @param newCells The new notebook cells. 3868 */ 3869 static replaceCells(range: NotebookRange, newCells: NotebookCellData[]): NotebookEdit; 3870 3871 /** 3872 * Utility to create an edit that replaces cells in a notebook. 3873 * 3874 * @param index The index to insert cells at. 3875 * @param newCells The new notebook cells. 3876 */ 3877 static insertCells(index: number, newCells: NotebookCellData[]): NotebookEdit; 3878 3879 /** 3880 * Utility to create an edit that deletes cells in a notebook. 3881 * 3882 * @param range The range of cells to delete. 3883 */ 3884 static deleteCells(range: NotebookRange): NotebookEdit; 3885 3886 /** 3887 * Utility to create an edit that update a cell's metadata. 3888 * 3889 * @param index The index of the cell to update. 3890 * @param newCellMetadata The new metadata for the cell. 3891 */ 3892 static updateCellMetadata(index: number, newCellMetadata: { [key: string]: any }): NotebookEdit; 3893 3894 /** 3895 * Utility to create an edit that updates the notebook's metadata. 3896 * 3897 * @param newNotebookMetadata The new metadata for the notebook. 3898 */ 3899 static updateNotebookMetadata(newNotebookMetadata: { [key: string]: any }): NotebookEdit; 3900 3901 /** 3902 * Range of the cells being edited. May be empty. 3903 */ 3904 range: NotebookRange; 3905 3906 /** 3907 * New cells being inserted. May be empty. 3908 */ 3909 newCells: NotebookCellData[]; 3910 3911 /** 3912 * Optional new metadata for the cells. 3913 */ 3914 newCellMetadata?: { [key: string]: any }; 3915 3916 /** 3917 * Optional new metadata for the notebook. 3918 */ 3919 newNotebookMetadata?: { [key: string]: any }; 3920 3921 /** 3922 * Create a new notebook edit. 3923 * 3924 * @param range A notebook range. 3925 * @param newCells An array of new cell data. 3926 */ 3927 constructor(range: NotebookRange, newCells: NotebookCellData[]); 3928 } 3929 3930 /** 3931 * Additional data for entries of a workspace edit. Supports to label entries and marks entries 3932 * as needing confirmation by the user. The editor groups edits with equal labels into tree nodes, 3933 * for instance all edits labelled with "Changes in Strings" would be a tree node. 3934 */ 3935 export interface WorkspaceEditEntryMetadata { 3936 3937 /** 3938 * A flag which indicates that user confirmation is needed. 3939 */ 3940 needsConfirmation: boolean; 3941 3942 /** 3943 * A human-readable string which is rendered prominent. 3944 */ 3945 label: string; 3946 3947 /** 3948 * A human-readable string which is rendered less prominent on the same line. 3949 */ 3950 description?: string; 3951 3952 /** 3953 * The icon path or {@link ThemeIcon} for the edit. 3954 */ 3955 iconPath?: IconPath; 3956 } 3957 3958 /** 3959 * Additional data about a workspace edit. 3960 */ 3961 export interface WorkspaceEditMetadata { 3962 /** 3963 * Signal to the editor that this edit is a refactoring. 3964 */ 3965 isRefactoring?: boolean; 3966 } 3967 3968 /** 3969 * A workspace edit is a collection of textual and files changes for 3970 * multiple resources and documents. 3971 * 3972 * Use the {@link workspace.applyEdit applyEdit}-function to apply a workspace edit. 3973 */ 3974 export class WorkspaceEdit { 3975 3976 /** 3977 * The number of affected resources of textual or resource changes. 3978 */ 3979 readonly size: number; 3980 3981 /** 3982 * Replace the given range with given text for the given resource. 3983 * 3984 * @param uri A resource identifier. 3985 * @param range A range. 3986 * @param newText A string. 3987 * @param metadata Optional metadata for the entry. 3988 */ 3989 replace(uri: Uri, range: Range, newText: string, metadata?: WorkspaceEditEntryMetadata): void; 3990 3991 /** 3992 * Insert the given text at the given position. 3993 * 3994 * @param uri A resource identifier. 3995 * @param position A position. 3996 * @param newText A string. 3997 * @param metadata Optional metadata for the entry. 3998 */ 3999 insert(uri: Uri, position: Position, newText: string, metadata?: WorkspaceEditEntryMetadata): void; 4000 4001 /** 4002 * Delete the text at the given range. 4003 * 4004 * @param uri A resource identifier. 4005 * @param range A range. 4006 * @param metadata Optional metadata for the entry. 4007 */ 4008 delete(uri: Uri, range: Range, metadata?: WorkspaceEditEntryMetadata): void; 4009 4010 /** 4011 * Check if a text edit for a resource exists. 4012 * 4013 * @param uri A resource identifier. 4014 * @returns `true` if the given resource will be touched by this edit. 4015 */ 4016 has(uri: Uri): boolean; 4017 4018 /** 4019 * Set (and replace) text edits or snippet edits for a resource. 4020 * 4021 * @param uri A resource identifier. 4022 * @param edits An array of edits. 4023 */ 4024 set(uri: Uri, edits: ReadonlyArray<TextEdit | SnippetTextEdit>): void; 4025 4026 /** 4027 * Set (and replace) text edits or snippet edits with metadata for a resource. 4028 * 4029 * @param uri A resource identifier. 4030 * @param edits An array of edits. 4031 */ 4032 set(uri: Uri, edits: ReadonlyArray<[TextEdit | SnippetTextEdit, WorkspaceEditEntryMetadata | undefined]>): void; 4033 4034 /** 4035 * Set (and replace) notebook edits for a resource. 4036 * 4037 * @param uri A resource identifier. 4038 * @param edits An array of edits. 4039 */ 4040 set(uri: Uri, edits: readonly NotebookEdit[]): void; 4041 4042 /** 4043 * Set (and replace) notebook edits with metadata for a resource. 4044 * 4045 * @param uri A resource identifier. 4046 * @param edits An array of edits. 4047 */ 4048 set(uri: Uri, edits: ReadonlyArray<[NotebookEdit, WorkspaceEditEntryMetadata | undefined]>): void; 4049 4050 /** 4051 * Get the text edits for a resource. 4052 * 4053 * @param uri A resource identifier. 4054 * @returns An array of text edits. 4055 */ 4056 get(uri: Uri): TextEdit[]; 4057 4058 /** 4059 * Create a regular file. 4060 * 4061 * @param uri Uri of the new file. 4062 * @param options Defines if an existing file should be overwritten or be 4063 * ignored. When `overwrite` and `ignoreIfExists` are both set `overwrite` wins. 4064 * When both are unset and when the file already exists then the edit cannot 4065 * be applied successfully. The `content`-property allows to set the initial contents 4066 * the file is being created with. 4067 * @param metadata Optional metadata for the entry. 4068 */ 4069 createFile(uri: Uri, options?: { 4070 /** 4071 * Overwrite existing file. Overwrite wins over `ignoreIfExists` 4072 */ 4073 readonly overwrite?: boolean; 4074 /** 4075 * Do nothing if a file with `uri` exists already. 4076 */ 4077 readonly ignoreIfExists?: boolean; 4078 /** 4079 * The initial contents of the new file. 4080 * 4081 * If creating a file from a {@link DocumentDropEditProvider drop operation}, you can 4082 * pass in a {@link DataTransferFile} to improve performance by avoiding extra data copying. 4083 */ 4084 readonly contents?: Uint8Array | DataTransferFile; 4085 }, metadata?: WorkspaceEditEntryMetadata): void; 4086 4087 /** 4088 * Delete a file or folder. 4089 * 4090 * @param uri The uri of the file that is to be deleted. 4091 * @param metadata Optional metadata for the entry. 4092 */ 4093 deleteFile(uri: Uri, options?: { 4094 /** 4095 * Delete the content recursively if a folder is denoted. 4096 */ 4097 readonly recursive?: boolean; 4098 /** 4099 * Do nothing if a file with `uri` exists already. 4100 */ 4101 readonly ignoreIfNotExists?: boolean; 4102 }, metadata?: WorkspaceEditEntryMetadata): void; 4103 4104 /** 4105 * Rename a file or folder. 4106 * 4107 * @param oldUri The existing file. 4108 * @param newUri The new location. 4109 * @param options Defines if existing files should be overwritten or be 4110 * ignored. When overwrite and ignoreIfExists are both set overwrite wins. 4111 * @param metadata Optional metadata for the entry. 4112 */ 4113 renameFile(oldUri: Uri, newUri: Uri, options?: { 4114 /** 4115 * Overwrite existing file. Overwrite wins over `ignoreIfExists` 4116 */ 4117 readonly overwrite?: boolean; 4118 /** 4119 * Do nothing if a file with `uri` exists already. 4120 */ 4121 readonly ignoreIfExists?: boolean; 4122 }, metadata?: WorkspaceEditEntryMetadata): void; 4123 4124 /** 4125 * Get all text edits grouped by resource. 4126 * 4127 * @returns A shallow copy of `[Uri, TextEdit[]]`-tuples. 4128 */ 4129 entries(): [Uri, TextEdit[]][]; 4130 } 4131 4132 /** 4133 * A snippet string is a template which allows to insert text 4134 * and to control the editor cursor when insertion happens. 4135 * 4136 * A snippet can define tab stops and placeholders with `$1`, `$2` 4137 * and `${3:foo}`. `$0` defines the final tab stop, it defaults to 4138 * the end of the snippet. Variables are defined with `$name` and 4139 * `${name:default value}`. Also see 4140 * [the full snippet syntax](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets). 4141 */ 4142 export class SnippetString { 4143 4144 /** 4145 * The snippet string. 4146 */ 4147 value: string; 4148 4149 /** 4150 * Create a new snippet string. 4151 * 4152 * @param value A snippet string. 4153 */ 4154 constructor(value?: string); 4155 4156 /** 4157 * Builder-function that appends the given string to 4158 * the {@linkcode SnippetString.value value} of this snippet string. 4159 * 4160 * @param string A value to append 'as given'. The string will be escaped. 4161 * @returns This snippet string. 4162 */ 4163 appendText(string: string): SnippetString; 4164 4165 /** 4166 * Builder-function that appends a tabstop (`$1`, `$2` etc) to 4167 * the {@linkcode SnippetString.value value} of this snippet string. 4168 * 4169 * @param number The number of this tabstop, defaults to an auto-increment 4170 * value starting at 1. 4171 * @returns This snippet string. 4172 */ 4173 appendTabstop(number?: number): SnippetString; 4174 4175 /** 4176 * Builder-function that appends a placeholder (`${1:value}`) to 4177 * the {@linkcode SnippetString.value value} of this snippet string. 4178 * 4179 * @param value The value of this placeholder - either a string or a function 4180 * with which a nested snippet can be created. 4181 * @param number The number of this tabstop, defaults to an auto-increment 4182 * value starting at 1. 4183 * @returns This snippet string. 4184 */ 4185 appendPlaceholder(value: string | ((snippet: SnippetString) => any), number?: number): SnippetString; 4186 4187 /** 4188 * Builder-function that appends a choice (`${1|a,b,c|}`) to 4189 * the {@linkcode SnippetString.value value} of this snippet string. 4190 * 4191 * @param values The values for choices - the array of strings 4192 * @param number The number of this tabstop, defaults to an auto-increment 4193 * value starting at 1. 4194 * @returns This snippet string. 4195 */ 4196 appendChoice(values: readonly string[], number?: number): SnippetString; 4197 4198 /** 4199 * Builder-function that appends a variable (`${VAR}`) to 4200 * the {@linkcode SnippetString.value value} of this snippet string. 4201 * 4202 * @param name The name of the variable - excluding the `$`. 4203 * @param defaultValue The default value which is used when the variable name cannot 4204 * be resolved - either a string or a function with which a nested snippet can be created. 4205 * @returns This snippet string. 4206 */ 4207 appendVariable(name: string, defaultValue: string | ((snippet: SnippetString) => any)): SnippetString; 4208 } 4209 4210 /** 4211 * The rename provider interface defines the contract between extensions and 4212 * the [rename](https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol)-feature. 4213 */ 4214 export interface RenameProvider { 4215 4216 /** 4217 * Provide an edit that describes changes that have to be made to one 4218 * or many resources to rename a symbol to a different name. 4219 * 4220 * @param document The document in which the command was invoked. 4221 * @param position The position at which the command was invoked. 4222 * @param newName The new name of the symbol. If the given name is not valid, the provider must return a rejected promise. 4223 * @param token A cancellation token. 4224 * @returns A workspace edit or a thenable that resolves to such. The lack of a result can be 4225 * signaled by returning `undefined` or `null`. 4226 */ 4227 provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult<WorkspaceEdit>; 4228 4229 /** 4230 * Optional function for resolving and validating a position *before* running rename. The result can 4231 * be a range or a range and a placeholder text. The placeholder text should be the identifier of the symbol 4232 * which is being renamed - when omitted the text in the returned range is used. 4233 * 4234 * *Note:* This function should throw an error or return a rejected thenable when the provided location 4235 * doesn't allow for a rename. 4236 * 4237 * @param document The document in which rename will be invoked. 4238 * @param position The position at which rename will be invoked. 4239 * @param token A cancellation token. 4240 * @returns The range or range and placeholder text of the identifier that is to be renamed. The lack of a result can signaled by returning `undefined` or `null`. 4241 */ 4242 prepareRename?(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<Range | { 4243 /** 4244 * The range of the identifier that can be renamed. 4245 */ 4246 range: Range; 4247 /** 4248 * The placeholder of the editors rename input box. 4249 */ 4250 placeholder: string; 4251 }>; 4252 } 4253 4254 /** 4255 * A semantic tokens legend contains the needed information to decipher 4256 * the integer encoded representation of semantic tokens. 4257 */ 4258 export class SemanticTokensLegend { 4259 /** 4260 * The possible token types. 4261 */ 4262 readonly tokenTypes: string[]; 4263 /** 4264 * The possible token modifiers. 4265 */ 4266 readonly tokenModifiers: string[]; 4267 4268 /** 4269 * Creates a semantic tokens legend. 4270 * 4271 * @param tokenTypes An array of token types. 4272 * @param tokenModifiers An array of token modifiers. 4273 */ 4274 constructor(tokenTypes: string[], tokenModifiers?: string[]); 4275 } 4276 4277 /** 4278 * A semantic tokens builder can help with creating a `SemanticTokens` instance 4279 * which contains delta encoded semantic tokens. 4280 */ 4281 export class SemanticTokensBuilder { 4282 4283 /** 4284 * Creates a semantic tokens builder. 4285 * 4286 * @param legend A semantic tokens legend. 4287 */ 4288 constructor(legend?: SemanticTokensLegend); 4289 4290 /** 4291 * Add another token. 4292 * 4293 * @param line The token start line number (absolute value). 4294 * @param char The token start character (absolute value). 4295 * @param length The token length in characters. 4296 * @param tokenType The encoded token type. 4297 * @param tokenModifiers The encoded token modifiers. 4298 */ 4299 push(line: number, char: number, length: number, tokenType: number, tokenModifiers?: number): void; 4300 4301 /** 4302 * Add another token. Use only when providing a legend. 4303 * 4304 * @param range The range of the token. Must be single-line. 4305 * @param tokenType The token type. 4306 * @param tokenModifiers The token modifiers. 4307 */ 4308 push(range: Range, tokenType: string, tokenModifiers?: readonly string[]): void; 4309 4310 /** 4311 * Finish and create a `SemanticTokens` instance. 4312 */ 4313 build(resultId?: string): SemanticTokens; 4314 } 4315 4316 /** 4317 * Represents semantic tokens, either in a range or in an entire document. 4318 * @see {@link DocumentSemanticTokensProvider.provideDocumentSemanticTokens provideDocumentSemanticTokens} for an explanation of the format. 4319 * @see {@link SemanticTokensBuilder} for a helper to create an instance. 4320 */ 4321 export class SemanticTokens { 4322 /** 4323 * The result id of the tokens. 4324 * 4325 * This is the id that will be passed to `DocumentSemanticTokensProvider.provideDocumentSemanticTokensEdits` (if implemented). 4326 */ 4327 readonly resultId: string | undefined; 4328 /** 4329 * The actual tokens data. 4330 * @see {@link DocumentSemanticTokensProvider.provideDocumentSemanticTokens provideDocumentSemanticTokens} for an explanation of the format. 4331 */ 4332 readonly data: Uint32Array; 4333 4334 /** 4335 * Create new semantic tokens. 4336 * 4337 * @param data Token data. 4338 * @param resultId Result identifier. 4339 */ 4340 constructor(data: Uint32Array, resultId?: string); 4341 } 4342 4343 /** 4344 * Represents edits to semantic tokens. 4345 * @see {@link DocumentSemanticTokensProvider.provideDocumentSemanticTokensEdits provideDocumentSemanticTokensEdits} for an explanation of the format. 4346 */ 4347 export class SemanticTokensEdits { 4348 /** 4349 * The result id of the tokens. 4350 * 4351 * This is the id that will be passed to `DocumentSemanticTokensProvider.provideDocumentSemanticTokensEdits` (if implemented). 4352 */ 4353 readonly resultId: string | undefined; 4354 /** 4355 * The edits to the tokens data. 4356 * All edits refer to the initial data state. 4357 */ 4358 readonly edits: SemanticTokensEdit[]; 4359 4360 /** 4361 * Create new semantic tokens edits. 4362 * 4363 * @param edits An array of semantic token edits 4364 * @param resultId Result identifier. 4365 */ 4366 constructor(edits: SemanticTokensEdit[], resultId?: string); 4367 } 4368 4369 /** 4370 * Represents an edit to semantic tokens. 4371 * @see {@link DocumentSemanticTokensProvider.provideDocumentSemanticTokensEdits provideDocumentSemanticTokensEdits} for an explanation of the format. 4372 */ 4373 export class SemanticTokensEdit { 4374 /** 4375 * The start offset of the edit. 4376 */ 4377 readonly start: number; 4378 /** 4379 * The count of elements to remove. 4380 */ 4381 readonly deleteCount: number; 4382 /** 4383 * The elements to insert. 4384 */ 4385 readonly data: Uint32Array | undefined; 4386 4387 /** 4388 * Create a semantic token edit. 4389 * 4390 * @param start Start offset 4391 * @param deleteCount Number of elements to remove. 4392 * @param data Elements to insert 4393 */ 4394 constructor(start: number, deleteCount: number, data?: Uint32Array); 4395 } 4396 4397 /** 4398 * The document semantic tokens provider interface defines the contract between extensions and 4399 * semantic tokens. 4400 */ 4401 export interface DocumentSemanticTokensProvider { 4402 /** 4403 * An optional event to signal that the semantic tokens from this provider have changed. 4404 */ 4405 onDidChangeSemanticTokens?: Event<void>; 4406 4407 /** 4408 * Tokens in a file are represented as an array of integers. The position of each token is expressed relative to 4409 * the token before it, because most tokens remain stable relative to each other when edits are made in a file. 4410 * 4411 * --- 4412 * In short, each token takes 5 integers to represent, so a specific token `i` in the file consists of the following array indices: 4413 * - at index `5*i` - `deltaLine`: token line number, relative to the previous token 4414 * - at index `5*i+1` - `deltaStart`: token start character, relative to the previous token (relative to 0 or the previous token's start if they are on the same line) 4415 * - at index `5*i+2` - `length`: the length of the token. A token cannot be multiline. 4416 * - at index `5*i+3` - `tokenType`: will be looked up in `SemanticTokensLegend.tokenTypes`. We currently ask that `tokenType` < 65536. 4417 * - at index `5*i+4` - `tokenModifiers`: each set bit will be looked up in `SemanticTokensLegend.tokenModifiers` 4418 * 4419 * --- 4420 * ### How to encode tokens 4421 * 4422 * Here is an example for encoding a file with 3 tokens in a uint32 array: 4423 * ``` 4424 * { line: 2, startChar: 5, length: 3, tokenType: "property", tokenModifiers: ["private", "static"] }, 4425 * { line: 2, startChar: 10, length: 4, tokenType: "type", tokenModifiers: [] }, 4426 * { line: 5, startChar: 2, length: 7, tokenType: "class", tokenModifiers: [] } 4427 * ``` 4428 * 4429 * 1. First of all, a legend must be devised. This legend must be provided up-front and capture all possible token types. 4430 * For this example, we will choose the following legend which must be passed in when registering the provider: 4431 * ``` 4432 * tokenTypes: ['property', 'type', 'class'], 4433 * tokenModifiers: ['private', 'static'] 4434 * ``` 4435 * 4436 * 2. The first transformation step is to encode `tokenType` and `tokenModifiers` as integers using the legend. Token types are looked 4437 * up by index, so a `tokenType` value of `1` means `tokenTypes[1]`. Multiple token modifiers can be set by using bit flags, 4438 * so a `tokenModifier` value of `3` is first viewed as binary `0b00000011`, which means `[tokenModifiers[0], tokenModifiers[1]]` because 4439 * bits 0 and 1 are set. Using this legend, the tokens now are: 4440 * ``` 4441 * { line: 2, startChar: 5, length: 3, tokenType: 0, tokenModifiers: 3 }, 4442 * { line: 2, startChar: 10, length: 4, tokenType: 1, tokenModifiers: 0 }, 4443 * { line: 5, startChar: 2, length: 7, tokenType: 2, tokenModifiers: 0 } 4444 * ``` 4445 * 4446 * 3. The next step is to represent each token relative to the previous token in the file. In this case, the second token 4447 * is on the same line as the first token, so the `startChar` of the second token is made relative to the `startChar` 4448 * of the first token, so it will be `10 - 5`. The third token is on a different line than the second token, so the 4449 * `startChar` of the third token will not be altered: 4450 * ``` 4451 * { deltaLine: 2, deltaStartChar: 5, length: 3, tokenType: 0, tokenModifiers: 3 }, 4452 * { deltaLine: 0, deltaStartChar: 5, length: 4, tokenType: 1, tokenModifiers: 0 }, 4453 * { deltaLine: 3, deltaStartChar: 2, length: 7, tokenType: 2, tokenModifiers: 0 } 4454 * ``` 4455 * 4456 * 4. Finally, the last step is to inline each of the 5 fields for a token in a single array, which is a memory friendly representation: 4457 * ``` 4458 * // 1st token, 2nd token, 3rd token 4459 * [ 2,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ] 4460 * ``` 4461 * 4462 * @see {@link SemanticTokensBuilder} for a helper to encode tokens as integers. 4463 * *NOTE*: When doing edits, it is possible that multiple edits occur until the editor decides to invoke the semantic tokens provider. 4464 * *NOTE*: If the provider cannot temporarily compute semantic tokens, it can indicate this by throwing an error with the message 'Busy'. 4465 */ 4466 provideDocumentSemanticTokens(document: TextDocument, token: CancellationToken): ProviderResult<SemanticTokens>; 4467 4468 /** 4469 * Instead of always returning all the tokens in a file, it is possible for a `DocumentSemanticTokensProvider` to implement 4470 * this method (`provideDocumentSemanticTokensEdits`) and then return incremental updates to the previously provided semantic tokens. 4471 * 4472 * --- 4473 * ### How tokens change when the document changes 4474 * 4475 * Suppose that `provideDocumentSemanticTokens` has previously returned the following semantic tokens: 4476 * ``` 4477 * // 1st token, 2nd token, 3rd token 4478 * [ 2,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ] 4479 * ``` 4480 * 4481 * Also suppose that after some edits, the new semantic tokens in a file are: 4482 * ``` 4483 * // 1st token, 2nd token, 3rd token 4484 * [ 3,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ] 4485 * ``` 4486 * It is possible to express these new tokens in terms of an edit applied to the previous tokens: 4487 * ``` 4488 * [ 2,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ] // old tokens 4489 * [ 3,5,3,0,3, 0,5,4,1,0, 3,2,7,2,0 ] // new tokens 4490 * 4491 * edit: { start: 0, deleteCount: 1, data: [3] } // replace integer at offset 0 with 3 4492 * ``` 4493 * 4494 * *NOTE*: If the provider cannot compute `SemanticTokensEdits`, it can "give up" and return all the tokens in the document again. 4495 * *NOTE*: All edits in `SemanticTokensEdits` contain indices in the old integers array, so they all refer to the previous result state. 4496 */ 4497 provideDocumentSemanticTokensEdits?(document: TextDocument, previousResultId: string, token: CancellationToken): ProviderResult<SemanticTokens | SemanticTokensEdits>; 4498 } 4499 4500 /** 4501 * The document range semantic tokens provider interface defines the contract between extensions and 4502 * semantic tokens. 4503 */ 4504 export interface DocumentRangeSemanticTokensProvider { 4505 4506 /** 4507 * An optional event to signal that the semantic tokens from this provider have changed. 4508 */ 4509 onDidChangeSemanticTokens?: Event<void>; 4510 4511 /** 4512 * @see {@link DocumentSemanticTokensProvider.provideDocumentSemanticTokens provideDocumentSemanticTokens}. 4513 */ 4514 provideDocumentRangeSemanticTokens(document: TextDocument, range: Range, token: CancellationToken): ProviderResult<SemanticTokens>; 4515 } 4516 4517 /** 4518 * Value-object describing what options formatting should use. 4519 */ 4520 export interface FormattingOptions { 4521 4522 /** 4523 * Size of a tab in spaces. 4524 */ 4525 tabSize: number; 4526 4527 /** 4528 * Prefer spaces over tabs. 4529 */ 4530 insertSpaces: boolean; 4531 4532 /** 4533 * Signature for further properties. 4534 */ 4535 [key: string]: boolean | number | string; 4536 } 4537 4538 /** 4539 * The document formatting provider interface defines the contract between extensions and 4540 * the formatting-feature. 4541 */ 4542 export interface DocumentFormattingEditProvider { 4543 4544 /** 4545 * Provide formatting edits for a whole document. 4546 * 4547 * @param document The document in which the command was invoked. 4548 * @param options Options controlling formatting. 4549 * @param token A cancellation token. 4550 * @returns A set of text edits or a thenable that resolves to such. The lack of a result can be 4551 * signaled by returning `undefined`, `null`, or an empty array. 4552 */ 4553 provideDocumentFormattingEdits(document: TextDocument, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>; 4554 } 4555 4556 /** 4557 * The document formatting provider interface defines the contract between extensions and 4558 * the formatting-feature. 4559 */ 4560 export interface DocumentRangeFormattingEditProvider { 4561 4562 /** 4563 * Provide formatting edits for a range in a document. 4564 * 4565 * The given range is a hint and providers can decide to format a smaller 4566 * or larger range. Often this is done by adjusting the start and end 4567 * of the range to full syntax nodes. 4568 * 4569 * @param document The document in which the command was invoked. 4570 * @param range The range which should be formatted. 4571 * @param options Options controlling formatting. 4572 * @param token A cancellation token. 4573 * @returns A set of text edits or a thenable that resolves to such. The lack of a result can be 4574 * signaled by returning `undefined`, `null`, or an empty array. 4575 */ 4576 provideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>; 4577 4578 4579 /** 4580 * Provide formatting edits for multiple ranges in a document. 4581 * 4582 * This function is optional but allows a formatter to perform faster when formatting only modified ranges or when 4583 * formatting a large number of selections. 4584 * 4585 * The given ranges are hints and providers can decide to format a smaller 4586 * or larger range. Often this is done by adjusting the start and end 4587 * of the range to full syntax nodes. 4588 * 4589 * @param document The document in which the command was invoked. 4590 * @param ranges The ranges which should be formatted. 4591 * @param options Options controlling formatting. 4592 * @param token A cancellation token. 4593 * @returns A set of text edits or a thenable that resolves to such. The lack of a result can be 4594 * signaled by returning `undefined`, `null`, or an empty array. 4595 */ 4596 provideDocumentRangesFormattingEdits?(document: TextDocument, ranges: Range[], options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>; 4597 } 4598 4599 /** 4600 * The document formatting provider interface defines the contract between extensions and 4601 * the formatting-feature. 4602 */ 4603 export interface OnTypeFormattingEditProvider { 4604 4605 /** 4606 * Provide formatting edits after a character has been typed. 4607 * 4608 * The given position and character should hint to the provider 4609 * what range the position to expand to, like find the matching `{` 4610 * when `}` has been entered. 4611 * 4612 * @param document The document in which the command was invoked. 4613 * @param position The position at which the command was invoked. 4614 * @param ch The character that has been typed. 4615 * @param options Options controlling formatting. 4616 * @param token A cancellation token. 4617 * @returns A set of text edits or a thenable that resolves to such. The lack of a result can be 4618 * signaled by returning `undefined`, `null`, or an empty array. 4619 */ 4620 provideOnTypeFormattingEdits(document: TextDocument, position: Position, ch: string, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>; 4621 } 4622 4623 /** 4624 * Represents a parameter of a callable-signature. A parameter can 4625 * have a label and a doc-comment. 4626 */ 4627 export class ParameterInformation { 4628 4629 /** 4630 * The label of this signature. 4631 * 4632 * Either a string or inclusive start and exclusive end offsets within its containing 4633 * {@link SignatureInformation.label signature label}. *Note*: A label of type string must be 4634 * a substring of its containing signature information's {@link SignatureInformation.label label}. 4635 */ 4636 label: string | [number, number]; 4637 4638 /** 4639 * The human-readable doc-comment of this signature. Will be shown 4640 * in the UI but can be omitted. 4641 */ 4642 documentation?: string | MarkdownString; 4643 4644 /** 4645 * Creates a new parameter information object. 4646 * 4647 * @param label A label string or inclusive start and exclusive end offsets within its containing signature label. 4648 * @param documentation A doc string. 4649 */ 4650 constructor(label: string | [number, number], documentation?: string | MarkdownString); 4651 } 4652 4653 /** 4654 * Represents the signature of something callable. A signature 4655 * can have a label, like a function-name, a doc-comment, and 4656 * a set of parameters. 4657 */ 4658 export class SignatureInformation { 4659 4660 /** 4661 * The label of this signature. Will be shown in 4662 * the UI. 4663 */ 4664 label: string; 4665 4666 /** 4667 * The human-readable doc-comment of this signature. Will be shown 4668 * in the UI but can be omitted. 4669 */ 4670 documentation?: string | MarkdownString; 4671 4672 /** 4673 * The parameters of this signature. 4674 */ 4675 parameters: ParameterInformation[]; 4676 4677 /** 4678 * The index of the active parameter. 4679 * 4680 * If provided, this is used in place of {@linkcode SignatureHelp.activeParameter}. 4681 */ 4682 activeParameter?: number; 4683 4684 /** 4685 * Creates a new signature information object. 4686 * 4687 * @param label A label string. 4688 * @param documentation A doc string. 4689 */ 4690 constructor(label: string, documentation?: string | MarkdownString); 4691 } 4692 4693 /** 4694 * Signature help represents the signature of something 4695 * callable. There can be multiple signatures but only one 4696 * active and only one active parameter. 4697 */ 4698 export class SignatureHelp { 4699 4700 /** 4701 * One or more signatures. 4702 */ 4703 signatures: SignatureInformation[]; 4704 4705 /** 4706 * The active signature. 4707 */ 4708 activeSignature: number; 4709 4710 /** 4711 * The active parameter of the active signature. 4712 */ 4713 activeParameter: number; 4714 } 4715 4716 /** 4717 * How a {@linkcode SignatureHelpProvider} was triggered. 4718 */ 4719 export enum SignatureHelpTriggerKind { 4720 /** 4721 * Signature help was invoked manually by the user or by a command. 4722 */ 4723 Invoke = 1, 4724 4725 /** 4726 * Signature help was triggered by a trigger character. 4727 */ 4728 TriggerCharacter = 2, 4729 4730 /** 4731 * Signature help was triggered by the cursor moving or by the document content changing. 4732 */ 4733 ContentChange = 3, 4734 } 4735 4736 /** 4737 * Additional information about the context in which a 4738 * {@linkcode SignatureHelpProvider.provideSignatureHelp SignatureHelpProvider} was triggered. 4739 */ 4740 export interface SignatureHelpContext { 4741 /** 4742 * Action that caused signature help to be triggered. 4743 */ 4744 readonly triggerKind: SignatureHelpTriggerKind; 4745 4746 /** 4747 * Character that caused signature help to be triggered. 4748 * 4749 * This is `undefined` when signature help is not triggered by typing, such as when manually invoking 4750 * signature help or when moving the cursor. 4751 */ 4752 readonly triggerCharacter: string | undefined; 4753 4754 /** 4755 * `true` if signature help was already showing when it was triggered. 4756 * 4757 * Retriggers occur when the signature help is already active and can be caused by actions such as 4758 * typing a trigger character, a cursor move, or document content changes. 4759 */ 4760 readonly isRetrigger: boolean; 4761 4762 /** 4763 * The currently active {@linkcode SignatureHelp}. 4764 * 4765 * The `activeSignatureHelp` has its {@linkcode SignatureHelp.activeSignature activeSignature} field updated based on 4766 * the user arrowing through available signatures. 4767 */ 4768 readonly activeSignatureHelp: SignatureHelp | undefined; 4769 } 4770 4771 /** 4772 * The signature help provider interface defines the contract between extensions and 4773 * the [parameter hints](https://code.visualstudio.com/docs/editor/intellisense)-feature. 4774 */ 4775 export interface SignatureHelpProvider { 4776 4777 /** 4778 * Provide help for the signature at the given position and document. 4779 * 4780 * @param document The document in which the command was invoked. 4781 * @param position The position at which the command was invoked. 4782 * @param token A cancellation token. 4783 * @param context Information about how signature help was triggered. 4784 * 4785 * @returns Signature help or a thenable that resolves to such. The lack of a result can be 4786 * signaled by returning `undefined` or `null`. 4787 */ 4788 provideSignatureHelp(document: TextDocument, position: Position, token: CancellationToken, context: SignatureHelpContext): ProviderResult<SignatureHelp>; 4789 } 4790 4791 /** 4792 * Metadata about a registered {@linkcode SignatureHelpProvider}. 4793 */ 4794 export interface SignatureHelpProviderMetadata { 4795 /** 4796 * List of characters that trigger signature help. 4797 */ 4798 readonly triggerCharacters: readonly string[]; 4799 4800 /** 4801 * List of characters that re-trigger signature help. 4802 * 4803 * These trigger characters are only active when signature help is already showing. All trigger characters 4804 * are also counted as re-trigger characters. 4805 */ 4806 readonly retriggerCharacters: readonly string[]; 4807 } 4808 4809 /** 4810 * A structured label for a {@link CompletionItem completion item}. 4811 */ 4812 export interface CompletionItemLabel { 4813 4814 /** 4815 * The label of this completion item. 4816 * 4817 * By default this is also the text that is inserted when this completion is selected. 4818 */ 4819 label: string; 4820 4821 /** 4822 * An optional string which is rendered less prominently directly after {@link CompletionItemLabel.label label}, 4823 * without any spacing. Should be used for function signatures or type annotations. 4824 */ 4825 detail?: string; 4826 4827 /** 4828 * An optional string which is rendered less prominently after {@link CompletionItemLabel.detail}. Should be used 4829 * for fully qualified names or file path. 4830 */ 4831 description?: string; 4832 } 4833 4834 /** 4835 * Completion item kinds. 4836 */ 4837 export enum CompletionItemKind { 4838 /** 4839 * The `Text` completion item kind. 4840 */ 4841 Text = 0, 4842 /** 4843 * The `Method` completion item kind. 4844 */ 4845 Method = 1, 4846 /** 4847 * The `Function` completion item kind. 4848 */ 4849 Function = 2, 4850 /** 4851 * The `Constructor` completion item kind. 4852 */ 4853 Constructor = 3, 4854 /** 4855 * The `Field` completion item kind. 4856 */ 4857 Field = 4, 4858 /** 4859 * The `Variable` completion item kind. 4860 */ 4861 Variable = 5, 4862 /** 4863 * The `Class` completion item kind. 4864 */ 4865 Class = 6, 4866 /** 4867 * The `Interface` completion item kind. 4868 */ 4869 Interface = 7, 4870 /** 4871 * The `Module` completion item kind. 4872 */ 4873 Module = 8, 4874 /** 4875 * The `Property` completion item kind. 4876 */ 4877 Property = 9, 4878 /** 4879 * The `Unit` completion item kind. 4880 */ 4881 Unit = 10, 4882 /** 4883 * The `Value` completion item kind. 4884 */ 4885 Value = 11, 4886 /** 4887 * The `Enum` completion item kind. 4888 */ 4889 Enum = 12, 4890 /** 4891 * The `Keyword` completion item kind. 4892 */ 4893 Keyword = 13, 4894 /** 4895 * The `Snippet` completion item kind. 4896 */ 4897 Snippet = 14, 4898 /** 4899 * The `Color` completion item kind. 4900 */ 4901 Color = 15, 4902 /** 4903 * The `Reference` completion item kind. 4904 */ 4905 Reference = 17, 4906 /** 4907 * The `File` completion item kind. 4908 */ 4909 File = 16, 4910 /** 4911 * The `Folder` completion item kind. 4912 */ 4913 Folder = 18, 4914 /** 4915 * The `EnumMember` completion item kind. 4916 */ 4917 EnumMember = 19, 4918 /** 4919 * The `Constant` completion item kind. 4920 */ 4921 Constant = 20, 4922 /** 4923 * The `Struct` completion item kind. 4924 */ 4925 Struct = 21, 4926 /** 4927 * The `Event` completion item kind. 4928 */ 4929 Event = 22, 4930 /** 4931 * The `Operator` completion item kind. 4932 */ 4933 Operator = 23, 4934 /** 4935 * The `TypeParameter` completion item kind. 4936 */ 4937 TypeParameter = 24, 4938 /** 4939 * The `User` completion item kind. 4940 */ 4941 User = 25, 4942 /** 4943 * The `Issue` completion item kind. 4944 */ 4945 Issue = 26, 4946 } 4947 4948 /** 4949 * Completion item tags are extra annotations that tweak the rendering of a completion 4950 * item. 4951 */ 4952 export enum CompletionItemTag { 4953 /** 4954 * Render a completion as obsolete, usually using a strike-out. 4955 */ 4956 Deprecated = 1 4957 } 4958 4959 /** 4960 * A completion item represents a text snippet that is proposed to complete text that is being typed. 4961 * 4962 * It is sufficient to create a completion item from just a {@link CompletionItem.label label}. In that 4963 * case the completion item will replace the {@link TextDocument.getWordRangeAtPosition word} 4964 * until the cursor with the given label or {@link CompletionItem.insertText insertText}. Otherwise the 4965 * given {@link CompletionItem.textEdit edit} is used. 4966 * 4967 * When selecting a completion item in the editor its defined or synthesized text edit will be applied 4968 * to *all* cursors/selections whereas {@link CompletionItem.additionalTextEdits additionalTextEdits} will be 4969 * applied as provided. 4970 * 4971 * @see {@link CompletionItemProvider.provideCompletionItems} 4972 * @see {@link CompletionItemProvider.resolveCompletionItem} 4973 */ 4974 export class CompletionItem { 4975 4976 /** 4977 * The label of this completion item. By default 4978 * this is also the text that is inserted when selecting 4979 * this completion. 4980 */ 4981 label: string | CompletionItemLabel; 4982 4983 /** 4984 * The kind of this completion item. Based on the kind 4985 * an icon is chosen by the editor. 4986 */ 4987 kind?: CompletionItemKind; 4988 4989 /** 4990 * Tags for this completion item. 4991 */ 4992 tags?: readonly CompletionItemTag[]; 4993 4994 /** 4995 * A human-readable string with additional information 4996 * about this item, like type or symbol information. 4997 */ 4998 detail?: string; 4999 5000 /** 5001 * A human-readable string that represents a doc-comment. 5002 */ 5003 documentation?: string | MarkdownString; 5004 5005 /** 5006 * A string that should be used when comparing this item 5007 * with other items. When `falsy` the {@link CompletionItem.label label} 5008 * is used. 5009 * 5010 * Note that `sortText` is only used for the initial ordering of completion 5011 * items. When having a leading word (prefix) ordering is based on how 5012 * well completions match that prefix and the initial ordering is only used 5013 * when completions match equally well. The prefix is defined by the 5014 * {@linkcode CompletionItem.range range}-property and can therefore be different 5015 * for each completion. 5016 */ 5017 sortText?: string; 5018 5019 /** 5020 * A string that should be used when filtering a set of 5021 * completion items. When `falsy` the {@link CompletionItem.label label} 5022 * is used. 5023 * 5024 * Note that the filter text is matched against the leading word (prefix) which is defined 5025 * by the {@linkcode CompletionItem.range range}-property. 5026 */ 5027 filterText?: string; 5028 5029 /** 5030 * Select this item when showing. *Note* that only one completion item can be selected and 5031 * that the editor decides which item that is. The rule is that the *first* item of those 5032 * that match best is selected. 5033 */ 5034 preselect?: boolean; 5035 5036 /** 5037 * A string or snippet that should be inserted in a document when selecting 5038 * this completion. When `falsy` the {@link CompletionItem.label label} 5039 * is used. 5040 */ 5041 insertText?: string | SnippetString; 5042 5043 /** 5044 * A range or a insert and replace range selecting the text that should be replaced by this completion item. 5045 * 5046 * When omitted, the range of the {@link TextDocument.getWordRangeAtPosition current word} is used as replace-range 5047 * and as insert-range the start of the {@link TextDocument.getWordRangeAtPosition current word} to the 5048 * current position is used. 5049 * 5050 * *Note 1:* A range must be a {@link Range.isSingleLine single line} and it must 5051 * {@link Range.contains contain} the position at which completion has been {@link CompletionItemProvider.provideCompletionItems requested}. 5052 * *Note 2:* A insert range must be a prefix of a replace range, that means it must be contained and starting at the same position. 5053 */ 5054 range?: Range | { 5055 /** 5056 * The range that should be used when insert-accepting a completion. Must be a prefix of `replaceRange`. 5057 */ 5058 inserting: Range; 5059 /** 5060 * The range that should be used when replace-accepting a completion. 5061 */ 5062 replacing: Range; 5063 }; 5064 5065 /** 5066 * An optional set of characters that when pressed while this completion is active will accept it first and 5067 * then type that character. *Note* that all commit characters should have `length=1` and that superfluous 5068 * characters will be ignored. 5069 */ 5070 commitCharacters?: string[]; 5071 5072 /** 5073 * Keep whitespace of the {@link CompletionItem.insertText insertText} as is. By default, the editor adjusts leading 5074 * whitespace of new lines so that they match the indentation of the line for which the item is accepted - setting 5075 * this to `true` will prevent that. 5076 */ 5077 keepWhitespace?: boolean; 5078 5079 /** 5080 * @deprecated Use `CompletionItem.insertText` and `CompletionItem.range` instead. 5081 * 5082 * An {@link TextEdit edit} which is applied to a document when selecting 5083 * this completion. When an edit is provided the value of 5084 * {@link CompletionItem.insertText insertText} is ignored. 5085 * 5086 * The {@link Range} of the edit must be single-line and on the same 5087 * line completions were {@link CompletionItemProvider.provideCompletionItems requested} at. 5088 */ 5089 textEdit?: TextEdit; 5090 5091 /** 5092 * An optional array of additional {@link TextEdit text edits} that are applied when 5093 * selecting this completion. Edits must not overlap with the main {@link CompletionItem.textEdit edit} 5094 * nor with themselves. 5095 */ 5096 additionalTextEdits?: TextEdit[]; 5097 5098 /** 5099 * An optional {@link Command} that is executed *after* inserting this completion. *Note* that 5100 * additional modifications to the current document should be described with the 5101 * {@link CompletionItem.additionalTextEdits additionalTextEdits}-property. 5102 */ 5103 command?: Command; 5104 5105 /** 5106 * Creates a new completion item. 5107 * 5108 * Completion items must have at least a {@link CompletionItem.label label} which then 5109 * will be used as insert text as well as for sorting and filtering. 5110 * 5111 * @param label The label of the completion. 5112 * @param kind The {@link CompletionItemKind kind} of the completion. 5113 */ 5114 constructor(label: string | CompletionItemLabel, kind?: CompletionItemKind); 5115 } 5116 5117 /** 5118 * Represents a collection of {@link CompletionItem completion items} to be presented 5119 * in the editor. 5120 */ 5121 export class CompletionList<T extends CompletionItem = CompletionItem> { 5122 5123 /** 5124 * This list is not complete. Further typing should result in recomputing 5125 * this list. 5126 */ 5127 isIncomplete?: boolean; 5128 5129 /** 5130 * The completion items. 5131 */ 5132 items: T[]; 5133 5134 /** 5135 * Creates a new completion list. 5136 * 5137 * @param items The completion items. 5138 * @param isIncomplete The list is not complete. 5139 */ 5140 constructor(items?: T[], isIncomplete?: boolean); 5141 } 5142 5143 /** 5144 * How a {@link CompletionItemProvider completion provider} was triggered 5145 */ 5146 export enum CompletionTriggerKind { 5147 /** 5148 * Completion was triggered normally. 5149 */ 5150 Invoke = 0, 5151 /** 5152 * Completion was triggered by a trigger character. 5153 */ 5154 TriggerCharacter = 1, 5155 /** 5156 * Completion was re-triggered as current completion list is incomplete 5157 */ 5158 TriggerForIncompleteCompletions = 2 5159 } 5160 5161 /** 5162 * Contains additional information about the context in which 5163 * {@link CompletionItemProvider.provideCompletionItems completion provider} is triggered. 5164 */ 5165 export interface CompletionContext { 5166 /** 5167 * How the completion was triggered. 5168 */ 5169 readonly triggerKind: CompletionTriggerKind; 5170 5171 /** 5172 * Character that triggered the completion item provider. 5173 * 5174 * `undefined` if the provider was not triggered by a character. 5175 * 5176 * The trigger character is already in the document when the completion provider is triggered. 5177 */ 5178 readonly triggerCharacter: string | undefined; 5179 } 5180 5181 /** 5182 * The completion item provider interface defines the contract between extensions and 5183 * [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense). 5184 * 5185 * Providers can delay the computation of the {@linkcode CompletionItem.detail detail} 5186 * and {@linkcode CompletionItem.documentation documentation} properties by implementing the 5187 * {@linkcode CompletionItemProvider.resolveCompletionItem resolveCompletionItem}-function. However, properties that 5188 * are needed for the initial sorting and filtering, like `sortText`, `filterText`, `insertText`, and `range`, must 5189 * not be changed during resolve. 5190 * 5191 * Providers are asked for completions either explicitly by a user gesture or -depending on the configuration- 5192 * implicitly when typing words or trigger characters. 5193 */ 5194 export interface CompletionItemProvider<T extends CompletionItem = CompletionItem> { 5195 5196 /** 5197 * Provide completion items for the given position and document. 5198 * 5199 * @param document The document in which the command was invoked. 5200 * @param position The position at which the command was invoked. 5201 * @param token A cancellation token. 5202 * @param context How the completion was triggered. 5203 * 5204 * @returns An array of completions, a {@link CompletionList completion list}, or a thenable that resolves to either. 5205 * The lack of a result can be signaled by returning `undefined`, `null`, or an empty array. 5206 */ 5207 provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken, context: CompletionContext): ProviderResult<T[] | CompletionList<T>>; 5208 5209 /** 5210 * Given a completion item fill in more data, like {@link CompletionItem.documentation doc-comment} 5211 * or {@link CompletionItem.detail details}. 5212 * 5213 * The editor will only resolve a completion item once. 5214 * 5215 * *Note* that this function is called when completion items are already showing in the UI or when an item has been 5216 * selected for insertion. Because of that, no property that changes the presentation (label, sorting, filtering etc) 5217 * or the (primary) insert behaviour ({@link CompletionItem.insertText insertText}) can be changed. 5218 * 5219 * This function may fill in {@link CompletionItem.additionalTextEdits additionalTextEdits}. However, that means an item might be 5220 * inserted *before* resolving is done and in that case the editor will do a best effort to still apply those additional 5221 * text edits. 5222 * 5223 * @param item A completion item currently active in the UI. 5224 * @param token A cancellation token. 5225 * @returns The resolved completion item or a thenable that resolves to of such. It is OK to return the given 5226 * `item`. When no result is returned, the given `item` will be used. 5227 */ 5228 resolveCompletionItem?(item: T, token: CancellationToken): ProviderResult<T>; 5229 } 5230 5231 5232 /** 5233 * The inline completion item provider interface defines the contract between extensions and 5234 * the inline completion feature. 5235 * 5236 * Providers are asked for completions either explicitly by a user gesture or implicitly when typing. 5237 */ 5238 export interface InlineCompletionItemProvider { 5239 5240 /** 5241 * Provides inline completion items for the given position and document. 5242 * If inline completions are enabled, this method will be called whenever the user stopped typing. 5243 * It will also be called when the user explicitly triggers inline completions or explicitly asks for the next or previous inline completion. 5244 * In that case, all available inline completions should be returned. 5245 * `context.triggerKind` can be used to distinguish between these scenarios. 5246 * 5247 * @param document The document inline completions are requested for. 5248 * @param position The position inline completions are requested for. 5249 * @param context A context object with additional information. 5250 * @param token A cancellation token. 5251 * @returns An array of completion items or a thenable that resolves to an array of completion items. 5252 */ 5253 provideInlineCompletionItems(document: TextDocument, position: Position, context: InlineCompletionContext, token: CancellationToken): ProviderResult<InlineCompletionItem[] | InlineCompletionList>; 5254 } 5255 5256 /** 5257 * Represents a collection of {@link InlineCompletionItem inline completion items} to be presented 5258 * in the editor. 5259 */ 5260 export class InlineCompletionList { 5261 /** 5262 * The inline completion items. 5263 */ 5264 items: InlineCompletionItem[]; 5265 5266 /** 5267 * Creates a new list of inline completion items. 5268 */ 5269 constructor(items: InlineCompletionItem[]); 5270 } 5271 5272 /** 5273 * Provides information about the context in which an inline completion was requested. 5274 */ 5275 export interface InlineCompletionContext { 5276 /** 5277 * Describes how the inline completion was triggered. 5278 */ 5279 readonly triggerKind: InlineCompletionTriggerKind; 5280 5281 /** 5282 * Provides information about the currently selected item in the autocomplete widget if it is visible. 5283 * 5284 * If set, provided inline completions must extend the text of the selected item 5285 * and use the same range, otherwise they are not shown as preview. 5286 * As an example, if the document text is `console.` and the selected item is `.log` replacing the `.` in the document, 5287 * the inline completion must also replace `.` and start with `.log`, for example `.log()`. 5288 * 5289 * Inline completion providers are requested again whenever the selected item changes. 5290 */ 5291 readonly selectedCompletionInfo: SelectedCompletionInfo | undefined; 5292 } 5293 5294 /** 5295 * Describes the currently selected completion item. 5296 */ 5297 export interface SelectedCompletionInfo { 5298 /** 5299 * The range that will be replaced if this completion item is accepted. 5300 */ 5301 readonly range: Range; 5302 5303 /** 5304 * The text the range will be replaced with if this completion is accepted. 5305 */ 5306 readonly text: string; 5307 } 5308 5309 /** 5310 * Describes how an {@link InlineCompletionItemProvider inline completion provider} was triggered. 5311 */ 5312 export enum InlineCompletionTriggerKind { 5313 /** 5314 * Completion was triggered explicitly by a user gesture. 5315 * Return multiple completion items to enable cycling through them. 5316 */ 5317 Invoke = 0, 5318 5319 /** 5320 * Completion was triggered automatically while editing. 5321 * It is sufficient to return a single completion item in this case. 5322 */ 5323 Automatic = 1, 5324 } 5325 5326 /** 5327 * An inline completion item represents a text snippet that is proposed inline to complete text that is being typed. 5328 * 5329 * @see {@link InlineCompletionItemProvider.provideInlineCompletionItems} 5330 */ 5331 export class InlineCompletionItem { 5332 /** 5333 * The text to replace the range with. Must be set. 5334 * Is used both for the preview and the accept operation. 5335 */ 5336 insertText: string | SnippetString; 5337 5338 /** 5339 * A text that is used to decide if this inline completion should be shown. When `falsy` 5340 * the {@link InlineCompletionItem.insertText} is used. 5341 * 5342 * An inline completion is shown if the text to replace is a prefix of the filter text. 5343 */ 5344 filterText?: string; 5345 5346 /** 5347 * The range to replace. 5348 * Must begin and end on the same line. 5349 * 5350 * Prefer replacements over insertions to provide a better experience when the user deletes typed text. 5351 */ 5352 range?: Range; 5353 5354 /** 5355 * An optional {@link Command} that is executed *after* inserting this completion. 5356 */ 5357 command?: Command; 5358 5359 /** 5360 * Creates a new inline completion item. 5361 * 5362 * @param insertText The text to replace the range with. 5363 * @param range The range to replace. If not set, the word at the requested position will be used. 5364 * @param command An optional {@link Command} that is executed *after* inserting this completion. 5365 */ 5366 constructor(insertText: string | SnippetString, range?: Range, command?: Command); 5367 } 5368 5369 /** 5370 * A document link is a range in a text document that links to an internal or external resource, like another 5371 * text document or a web site. 5372 */ 5373 export class DocumentLink { 5374 5375 /** 5376 * The range this link applies to. 5377 */ 5378 range: Range; 5379 5380 /** 5381 * The uri this link points to. 5382 */ 5383 target?: Uri; 5384 5385 /** 5386 * The tooltip text when you hover over this link. 5387 * 5388 * If a tooltip is provided, is will be displayed in a string that includes instructions on how to 5389 * trigger the link, such as `{0} (ctrl + click)`. The specific instructions vary depending on OS, 5390 * user settings, and localization. 5391 */ 5392 tooltip?: string; 5393 5394 /** 5395 * Creates a new document link. 5396 * 5397 * @param range The range the document link applies to. Must not be empty. 5398 * @param target The uri the document link points to. 5399 */ 5400 constructor(range: Range, target?: Uri); 5401 } 5402 5403 /** 5404 * The document link provider defines the contract between extensions and feature of showing 5405 * links in the editor. 5406 */ 5407 export interface DocumentLinkProvider<T extends DocumentLink = DocumentLink> { 5408 5409 /** 5410 * Provide links for the given document. Note that the editor ships with a default provider that detects 5411 * `http(s)` and `file` links. 5412 * 5413 * @param document The document in which the command was invoked. 5414 * @param token A cancellation token. 5415 * @returns An array of {@link DocumentLink document links} or a thenable that resolves to such. The lack of a result 5416 * can be signaled by returning `undefined`, `null`, or an empty array. 5417 */ 5418 provideDocumentLinks(document: TextDocument, token: CancellationToken): ProviderResult<T[]>; 5419 5420 /** 5421 * Given a link fill in its {@link DocumentLink.target target}. This method is called when an incomplete 5422 * link is selected in the UI. Providers can implement this method and return incomplete links 5423 * (without target) from the {@linkcode DocumentLinkProvider.provideDocumentLinks provideDocumentLinks} method which 5424 * often helps to improve performance. 5425 * 5426 * @param link The link that is to be resolved. 5427 * @param token A cancellation token. 5428 */ 5429 resolveDocumentLink?(link: T, token: CancellationToken): ProviderResult<T>; 5430 } 5431 5432 /** 5433 * Represents a color in RGBA space. 5434 */ 5435 export class Color { 5436 5437 /** 5438 * The red component of this color in the range `[0-1]`. 5439 */ 5440 readonly red: number; 5441 5442 /** 5443 * The green component of this color in the range `[0-1]`. 5444 */ 5445 readonly green: number; 5446 5447 /** 5448 * The blue component of this color in the range `[0-1]`. 5449 */ 5450 readonly blue: number; 5451 5452 /** 5453 * The alpha component of this color in the range `[0-1]`. 5454 */ 5455 readonly alpha: number; 5456 5457 /** 5458 * Creates a new color instance. 5459 * 5460 * @param red The red component. 5461 * @param green The green component. 5462 * @param blue The blue component. 5463 * @param alpha The alpha component. 5464 */ 5465 constructor(red: number, green: number, blue: number, alpha: number); 5466 } 5467 5468 /** 5469 * Represents a color range from a document. 5470 */ 5471 export class ColorInformation { 5472 5473 /** 5474 * The range in the document where this color appears. 5475 */ 5476 range: Range; 5477 5478 /** 5479 * The actual color value for this color range. 5480 */ 5481 color: Color; 5482 5483 /** 5484 * Creates a new color range. 5485 * 5486 * @param range The range the color appears in. Must not be empty. 5487 * @param color The value of the color. 5488 */ 5489 constructor(range: Range, color: Color); 5490 } 5491 5492 /** 5493 * A color presentation object describes how a {@linkcode Color} should be represented as text and what 5494 * edits are required to refer to it from source code. 5495 * 5496 * For some languages one color can have multiple presentations, e.g. css can represent the color red with 5497 * the constant `Red`, the hex-value `#ff0000`, or in rgba and hsla forms. In csharp other representations 5498 * apply, e.g. `System.Drawing.Color.Red`. 5499 */ 5500 export class ColorPresentation { 5501 5502 /** 5503 * The label of this color presentation. It will be shown on the color 5504 * picker header. By default this is also the text that is inserted when selecting 5505 * this color presentation. 5506 */ 5507 label: string; 5508 5509 /** 5510 * An {@link TextEdit edit} which is applied to a document when selecting 5511 * this presentation for the color. When `falsy` the {@link ColorPresentation.label label} 5512 * is used. 5513 */ 5514 textEdit?: TextEdit; 5515 5516 /** 5517 * An optional array of additional {@link TextEdit text edits} that are applied when 5518 * selecting this color presentation. Edits must not overlap with the main {@link ColorPresentation.textEdit edit} nor with themselves. 5519 */ 5520 additionalTextEdits?: TextEdit[]; 5521 5522 /** 5523 * Creates a new color presentation. 5524 * 5525 * @param label The label of this color presentation. 5526 */ 5527 constructor(label: string); 5528 } 5529 5530 /** 5531 * The document color provider defines the contract between extensions and feature of 5532 * picking and modifying colors in the editor. 5533 */ 5534 export interface DocumentColorProvider { 5535 5536 /** 5537 * Provide colors for the given document. 5538 * 5539 * @param document The document in which the command was invoked. 5540 * @param token A cancellation token. 5541 * @returns An array of {@link ColorInformation color information} or a thenable that resolves to such. The lack of a result 5542 * can be signaled by returning `undefined`, `null`, or an empty array. 5543 */ 5544 provideDocumentColors(document: TextDocument, token: CancellationToken): ProviderResult<ColorInformation[]>; 5545 5546 /** 5547 * Provide {@link ColorPresentation representations} for a color. 5548 * 5549 * @param color The color to show and insert. 5550 * @param context A context object with additional information 5551 * @param token A cancellation token. 5552 * @returns An array of color presentations or a thenable that resolves to such. The lack of a result 5553 * can be signaled by returning `undefined`, `null`, or an empty array. 5554 */ 5555 provideColorPresentations(color: Color, context: { 5556 /** 5557 * The text document that contains the color 5558 */ 5559 readonly document: TextDocument; 5560 /** 5561 * The range in the document where the color is located. 5562 */ 5563 readonly range: Range; 5564 }, token: CancellationToken): ProviderResult<ColorPresentation[]>; 5565 } 5566 5567 /** 5568 * Inlay hint kinds. 5569 * 5570 * The kind of an inline hint defines its appearance, e.g the corresponding foreground and background colors are being 5571 * used. 5572 */ 5573 export enum InlayHintKind { 5574 /** 5575 * An inlay hint that is for a type annotation. 5576 */ 5577 Type = 1, 5578 /** 5579 * An inlay hint that is for a parameter. 5580 */ 5581 Parameter = 2, 5582 } 5583 5584 /** 5585 * An inlay hint label part allows for interactive and composite labels of inlay hints. 5586 */ 5587 export class InlayHintLabelPart { 5588 5589 /** 5590 * The value of this label part. 5591 */ 5592 value: string; 5593 5594 /** 5595 * The tooltip text when you hover over this label part. 5596 * 5597 * *Note* that this property can be set late during 5598 * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. 5599 */ 5600 tooltip?: string | MarkdownString | undefined; 5601 5602 /** 5603 * An optional {@link Location source code location} that represents this label 5604 * part. 5605 * 5606 * The editor will use this location for the hover and for code navigation features: This 5607 * part will become a clickable link that resolves to the definition of the symbol at the 5608 * given location (not necessarily the location itself), it shows the hover that shows at 5609 * the given location, and it shows a context menu with further code navigation commands. 5610 * 5611 * *Note* that this property can be set late during 5612 * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. 5613 */ 5614 location?: Location | undefined; 5615 5616 /** 5617 * An optional command for this label part. 5618 * 5619 * The editor renders parts with commands as clickable links. The command is added to the context menu 5620 * when a label part defines {@link InlayHintLabelPart.location location} and {@link InlayHintLabelPart.command command} . 5621 * 5622 * *Note* that this property can be set late during 5623 * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. 5624 */ 5625 command?: Command | undefined; 5626 5627 /** 5628 * Creates a new inlay hint label part. 5629 * 5630 * @param value The value of the part. 5631 */ 5632 constructor(value: string); 5633 } 5634 5635 /** 5636 * Inlay hint information. 5637 */ 5638 export class InlayHint { 5639 5640 /** 5641 * The position of this hint. 5642 */ 5643 position: Position; 5644 5645 /** 5646 * The label of this hint. A human readable string or an array of {@link InlayHintLabelPart label parts}. 5647 * 5648 * *Note* that neither the string nor the label part can be empty. 5649 */ 5650 label: string | InlayHintLabelPart[]; 5651 5652 /** 5653 * The tooltip text when you hover over this item. 5654 * 5655 * *Note* that this property can be set late during 5656 * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. 5657 */ 5658 tooltip?: string | MarkdownString | undefined; 5659 5660 /** 5661 * The kind of this hint. The inlay hint kind defines the appearance of this inlay hint. 5662 */ 5663 kind?: InlayHintKind; 5664 5665 /** 5666 * Optional {@link TextEdit text edits} that are performed when accepting this inlay hint. The default 5667 * gesture for accepting an inlay hint is the double click. 5668 * 5669 * *Note* that edits are expected to change the document so that the inlay hint (or its nearest variant) is 5670 * now part of the document and the inlay hint itself is now obsolete. 5671 * 5672 * *Note* that this property can be set late during 5673 * {@link InlayHintsProvider.resolveInlayHint resolving} of inlay hints. 5674 */ 5675 textEdits?: TextEdit[]; 5676 5677 /** 5678 * Render padding before the hint. Padding will use the editor's background color, 5679 * not the background color of the hint itself. That means padding can be used to visually 5680 * align/separate an inlay hint. 5681 */ 5682 paddingLeft?: boolean; 5683 5684 /** 5685 * Render padding after the hint. Padding will use the editor's background color, 5686 * not the background color of the hint itself. That means padding can be used to visually 5687 * align/separate an inlay hint. 5688 */ 5689 paddingRight?: boolean; 5690 5691 /** 5692 * Creates a new inlay hint. 5693 * 5694 * @param position The position of the hint. 5695 * @param label The label of the hint. 5696 * @param kind The {@link InlayHintKind kind} of the hint. 5697 */ 5698 constructor(position: Position, label: string | InlayHintLabelPart[], kind?: InlayHintKind); 5699 } 5700 5701 /** 5702 * The inlay hints provider interface defines the contract between extensions and 5703 * the inlay hints feature. 5704 */ 5705 export interface InlayHintsProvider<T extends InlayHint = InlayHint> { 5706 5707 /** 5708 * An optional event to signal that inlay hints from this provider have changed. 5709 */ 5710 onDidChangeInlayHints?: Event<void>; 5711 5712 /** 5713 * Provide inlay hints for the given range and document. 5714 * 5715 * *Note* that inlay hints that are not {@link Range.contains contained} by the given range are ignored. 5716 * 5717 * @param document The document in which the command was invoked. 5718 * @param range The range for which inlay hints should be computed. 5719 * @param token A cancellation token. 5720 * @returns An array of inlay hints or a thenable that resolves to such. 5721 */ 5722 provideInlayHints(document: TextDocument, range: Range, token: CancellationToken): ProviderResult<T[]>; 5723 5724 /** 5725 * Given an inlay hint fill in {@link InlayHint.tooltip tooltip}, {@link InlayHint.textEdits text edits}, 5726 * or complete label {@link InlayHintLabelPart parts}. 5727 * 5728 * *Note* that the editor will resolve an inlay hint at most once. 5729 * 5730 * @param hint An inlay hint. 5731 * @param token A cancellation token. 5732 * @returns The resolved inlay hint or a thenable that resolves to such. It is OK to return the given `item`. When no result is returned, the given `item` will be used. 5733 */ 5734 resolveInlayHint?(hint: T, token: CancellationToken): ProviderResult<T>; 5735 } 5736 5737 /** 5738 * A line based folding range. To be valid, start and end line must be bigger than zero and smaller than the number of lines in the document. 5739 * Invalid ranges will be ignored. 5740 */ 5741 export class FoldingRange { 5742 5743 /** 5744 * The zero-based start line of the range to fold. The folded area starts after the line's last character. 5745 * To be valid, the end must be zero or larger and smaller than the number of lines in the document. 5746 */ 5747 start: number; 5748 5749 /** 5750 * The zero-based end line of the range to fold. The folded area ends with the line's last character. 5751 * To be valid, the end must be zero or larger and smaller than the number of lines in the document. 5752 */ 5753 end: number; 5754 5755 /** 5756 * Describes the {@link FoldingRangeKind Kind} of the folding range such as {@link FoldingRangeKind.Comment Comment} or 5757 * {@link FoldingRangeKind.Region Region}. The kind is used to categorize folding ranges and used by commands 5758 * like 'Fold all comments'. See 5759 * {@link FoldingRangeKind} for an enumeration of all kinds. 5760 * If not set, the range is originated from a syntax element. 5761 */ 5762 kind?: FoldingRangeKind; 5763 5764 /** 5765 * Creates a new folding range. 5766 * 5767 * @param start The start line of the folded range. 5768 * @param end The end line of the folded range. 5769 * @param kind The kind of the folding range. 5770 */ 5771 constructor(start: number, end: number, kind?: FoldingRangeKind); 5772 } 5773 5774 /** 5775 * An enumeration of specific folding range kinds. The kind is an optional field of a {@link FoldingRange} 5776 * and is used to distinguish specific folding ranges such as ranges originated from comments. The kind is used by commands like 5777 * `Fold all comments` or `Fold all regions`. 5778 * If the kind is not set on the range, the range originated from a syntax element other than comments, imports or region markers. 5779 */ 5780 export enum FoldingRangeKind { 5781 /** 5782 * Kind for folding range representing a comment. 5783 */ 5784 Comment = 1, 5785 /** 5786 * Kind for folding range representing a import. 5787 */ 5788 Imports = 2, 5789 /** 5790 * Kind for folding range representing regions originating from folding markers like `#region` and `#endregion`. 5791 */ 5792 Region = 3 5793 } 5794 5795 /** 5796 * Folding context (for future use) 5797 */ 5798 export interface FoldingContext { 5799 } 5800 5801 /** 5802 * The folding range provider interface defines the contract between extensions and 5803 * [Folding](https://code.visualstudio.com/docs/editor/codebasics#_folding) in the editor. 5804 */ 5805 export interface FoldingRangeProvider { 5806 5807 /** 5808 * An optional event to signal that the folding ranges from this provider have changed. 5809 */ 5810 onDidChangeFoldingRanges?: Event<void>; 5811 5812 /** 5813 * Returns a list of folding ranges or null and undefined if the provider 5814 * does not want to participate or was cancelled. 5815 * @param document The document in which the command was invoked. 5816 * @param context Additional context information (for future use) 5817 * @param token A cancellation token. 5818 */ 5819 provideFoldingRanges(document: TextDocument, context: FoldingContext, token: CancellationToken): ProviderResult<FoldingRange[]>; 5820 } 5821 5822 /** 5823 * A selection range represents a part of a selection hierarchy. A selection range 5824 * may have a parent selection range that contains it. 5825 */ 5826 export class SelectionRange { 5827 5828 /** 5829 * The {@link Range} of this selection range. 5830 */ 5831 range: Range; 5832 5833 /** 5834 * The parent selection range containing this range. 5835 */ 5836 parent?: SelectionRange; 5837 5838 /** 5839 * Creates a new selection range. 5840 * 5841 * @param range The range of the selection range. 5842 * @param parent The parent of the selection range. 5843 */ 5844 constructor(range: Range, parent?: SelectionRange); 5845 } 5846 5847 /** 5848 * The selection range provider interface defines the contract between extensions and the "Expand and Shrink Selection" feature. 5849 */ 5850 export interface SelectionRangeProvider { 5851 /** 5852 * Provide selection ranges for the given positions. 5853 * 5854 * Selection ranges should be computed individually and independent for each position. The editor will merge 5855 * and deduplicate ranges but providers must return hierarchies of selection ranges so that a range 5856 * is {@link Range.contains contained} by its parent. 5857 * 5858 * @param document The document in which the command was invoked. 5859 * @param positions The positions at which the command was invoked. 5860 * @param token A cancellation token. 5861 * @returns Selection ranges or a thenable that resolves to such. The lack of a result can be 5862 * signaled by returning `undefined` or `null`. 5863 */ 5864 provideSelectionRanges(document: TextDocument, positions: readonly Position[], token: CancellationToken): ProviderResult<SelectionRange[]>; 5865 } 5866 5867 /** 5868 * Represents programming constructs like functions or constructors in the context 5869 * of call hierarchy. 5870 */ 5871 export class CallHierarchyItem { 5872 /** 5873 * The name of this item. 5874 */ 5875 name: string; 5876 5877 /** 5878 * The kind of this item. 5879 */ 5880 kind: SymbolKind; 5881 5882 /** 5883 * Tags for this item. 5884 */ 5885 tags?: readonly SymbolTag[]; 5886 5887 /** 5888 * More detail for this item, e.g. the signature of a function. 5889 */ 5890 detail?: string; 5891 5892 /** 5893 * The resource identifier of this item. 5894 */ 5895 uri: Uri; 5896 5897 /** 5898 * The range enclosing this symbol not including leading/trailing whitespace but everything else, e.g. comments and code. 5899 */ 5900 range: Range; 5901 5902 /** 5903 * The range that should be selected and revealed when this symbol is being picked, e.g. the name of a function. 5904 * Must be contained by the {@linkcode CallHierarchyItem.range range}. 5905 */ 5906 selectionRange: Range; 5907 5908 /** 5909 * Creates a new call hierarchy item. 5910 */ 5911 constructor(kind: SymbolKind, name: string, detail: string, uri: Uri, range: Range, selectionRange: Range); 5912 } 5913 5914 /** 5915 * Represents an incoming call, e.g. a caller of a method or constructor. 5916 */ 5917 export class CallHierarchyIncomingCall { 5918 5919 /** 5920 * The item that makes the call. 5921 */ 5922 from: CallHierarchyItem; 5923 5924 /** 5925 * The range at which at which the calls appears. This is relative to the caller 5926 * denoted by {@linkcode CallHierarchyIncomingCall.from this.from}. 5927 */ 5928 fromRanges: Range[]; 5929 5930 /** 5931 * Create a new call object. 5932 * 5933 * @param item The item making the call. 5934 * @param fromRanges The ranges at which the calls appear. 5935 */ 5936 constructor(item: CallHierarchyItem, fromRanges: Range[]); 5937 } 5938 5939 /** 5940 * Represents an outgoing call, e.g. calling a getter from a method or a method from a constructor etc. 5941 */ 5942 export class CallHierarchyOutgoingCall { 5943 5944 /** 5945 * The item that is called. 5946 */ 5947 to: CallHierarchyItem; 5948 5949 /** 5950 * The range at which this item is called. This is the range relative to the caller, e.g the item 5951 * passed to {@linkcode CallHierarchyProvider.provideCallHierarchyOutgoingCalls provideCallHierarchyOutgoingCalls} 5952 * and not {@linkcode CallHierarchyOutgoingCall.to this.to}. 5953 */ 5954 fromRanges: Range[]; 5955 5956 /** 5957 * Create a new call object. 5958 * 5959 * @param item The item being called 5960 * @param fromRanges The ranges at which the calls appear. 5961 */ 5962 constructor(item: CallHierarchyItem, fromRanges: Range[]); 5963 } 5964 5965 /** 5966 * The call hierarchy provider interface describes the contract between extensions 5967 * and the call hierarchy feature which allows to browse calls and caller of function, 5968 * methods, constructor etc. 5969 */ 5970 export interface CallHierarchyProvider { 5971 5972 /** 5973 * Bootstraps call hierarchy by returning the item that is denoted by the given document 5974 * and position. This item will be used as entry into the call graph. Providers should 5975 * return `undefined` or `null` when there is no item at the given location. 5976 * 5977 * @param document The document in which the command was invoked. 5978 * @param position The position at which the command was invoked. 5979 * @param token A cancellation token. 5980 * @returns One or multiple call hierarchy items or a thenable that resolves to such. The lack of a result can be 5981 * signaled by returning `undefined`, `null`, or an empty array. 5982 */ 5983 prepareCallHierarchy(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<CallHierarchyItem | CallHierarchyItem[]>; 5984 5985 /** 5986 * Provide all incoming calls for an item, e.g all callers for a method. In graph terms this describes directed 5987 * and annotated edges inside the call graph, e.g the given item is the starting node and the result is the nodes 5988 * that can be reached. 5989 * 5990 * @param item The hierarchy item for which incoming calls should be computed. 5991 * @param token A cancellation token. 5992 * @returns A set of incoming calls or a thenable that resolves to such. The lack of a result can be 5993 * signaled by returning `undefined` or `null`. 5994 */ 5995 provideCallHierarchyIncomingCalls(item: CallHierarchyItem, token: CancellationToken): ProviderResult<CallHierarchyIncomingCall[]>; 5996 5997 /** 5998 * Provide all outgoing calls for an item, e.g call calls to functions, methods, or constructors from the given item. In 5999 * graph terms this describes directed and annotated edges inside the call graph, e.g the given item is the starting 6000 * node and the result is the nodes that can be reached. 6001 * 6002 * @param item The hierarchy item for which outgoing calls should be computed. 6003 * @param token A cancellation token. 6004 * @returns A set of outgoing calls or a thenable that resolves to such. The lack of a result can be 6005 * signaled by returning `undefined` or `null`. 6006 */ 6007 provideCallHierarchyOutgoingCalls(item: CallHierarchyItem, token: CancellationToken): ProviderResult<CallHierarchyOutgoingCall[]>; 6008 } 6009 6010 /** 6011 * Represents an item of a type hierarchy, like a class or an interface. 6012 */ 6013 export class TypeHierarchyItem { 6014 /** 6015 * The name of this item. 6016 */ 6017 name: string; 6018 6019 /** 6020 * The kind of this item. 6021 */ 6022 kind: SymbolKind; 6023 6024 /** 6025 * Tags for this item. 6026 */ 6027 tags?: ReadonlyArray<SymbolTag>; 6028 6029 /** 6030 * More detail for this item, e.g. the signature of a function. 6031 */ 6032 detail?: string; 6033 6034 /** 6035 * The resource identifier of this item. 6036 */ 6037 uri: Uri; 6038 6039 /** 6040 * The range enclosing this symbol not including leading/trailing whitespace 6041 * but everything else, e.g. comments and code. 6042 */ 6043 range: Range; 6044 6045 /** 6046 * The range that should be selected and revealed when this symbol is being 6047 * picked, e.g. the name of a class. Must be contained by the {@link TypeHierarchyItem.range range}-property. 6048 */ 6049 selectionRange: Range; 6050 6051 /** 6052 * Creates a new type hierarchy item. 6053 * 6054 * @param kind The kind of the item. 6055 * @param name The name of the item. 6056 * @param detail The details of the item. 6057 * @param uri The Uri of the item. 6058 * @param range The whole range of the item. 6059 * @param selectionRange The selection range of the item. 6060 */ 6061 constructor(kind: SymbolKind, name: string, detail: string, uri: Uri, range: Range, selectionRange: Range); 6062 } 6063 6064 /** 6065 * The type hierarchy provider interface describes the contract between extensions 6066 * and the type hierarchy feature. 6067 */ 6068 export interface TypeHierarchyProvider { 6069 6070 /** 6071 * Bootstraps type hierarchy by returning the item that is denoted by the given document 6072 * and position. This item will be used as entry into the type graph. Providers should 6073 * return `undefined` or `null` when there is no item at the given location. 6074 * 6075 * @param document The document in which the command was invoked. 6076 * @param position The position at which the command was invoked. 6077 * @param token A cancellation token. 6078 * @returns One or multiple type hierarchy items or a thenable that resolves to such. The lack of a result can be 6079 * signaled by returning `undefined`, `null`, or an empty array. 6080 */ 6081 prepareTypeHierarchy(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<TypeHierarchyItem | TypeHierarchyItem[]>; 6082 6083 /** 6084 * Provide all supertypes for an item, e.g all types from which a type is derived/inherited. In graph terms this describes directed 6085 * and annotated edges inside the type graph, e.g the given item is the starting node and the result is the nodes 6086 * that can be reached. 6087 * 6088 * @param item The hierarchy item for which super types should be computed. 6089 * @param token A cancellation token. 6090 * @returns A set of direct supertypes or a thenable that resolves to such. The lack of a result can be 6091 * signaled by returning `undefined` or `null`. 6092 */ 6093 provideTypeHierarchySupertypes(item: TypeHierarchyItem, token: CancellationToken): ProviderResult<TypeHierarchyItem[]>; 6094 6095 /** 6096 * Provide all subtypes for an item, e.g all types which are derived/inherited from the given item. In 6097 * graph terms this describes directed and annotated edges inside the type graph, e.g the given item is the starting 6098 * node and the result is the nodes that can be reached. 6099 * 6100 * @param item The hierarchy item for which subtypes should be computed. 6101 * @param token A cancellation token. 6102 * @returns A set of direct subtypes or a thenable that resolves to such. The lack of a result can be 6103 * signaled by returning `undefined` or `null`. 6104 */ 6105 provideTypeHierarchySubtypes(item: TypeHierarchyItem, token: CancellationToken): ProviderResult<TypeHierarchyItem[]>; 6106 } 6107 6108 /** 6109 * Represents a list of ranges that can be edited together along with a word pattern to describe valid range contents. 6110 */ 6111 export class LinkedEditingRanges { 6112 /** 6113 * Create a new linked editing ranges object. 6114 * 6115 * @param ranges A list of ranges that can be edited together 6116 * @param wordPattern An optional word pattern that describes valid contents for the given ranges 6117 */ 6118 constructor(ranges: Range[], wordPattern?: RegExp); 6119 6120 /** 6121 * A list of ranges that can be edited together. The ranges must have 6122 * identical length and text content. The ranges cannot overlap. 6123 */ 6124 readonly ranges: Range[]; 6125 6126 /** 6127 * An optional word pattern that describes valid contents for the given ranges. 6128 * If no pattern is provided, the language configuration's word pattern will be used. 6129 */ 6130 readonly wordPattern: RegExp | undefined; 6131 } 6132 6133 /** 6134 * The linked editing range provider interface defines the contract between extensions and 6135 * the linked editing feature. 6136 */ 6137 export interface LinkedEditingRangeProvider { 6138 /** 6139 * For a given position in a document, returns the range of the symbol at the position and all ranges 6140 * that have the same content. A change to one of the ranges can be applied to all other ranges if the new content 6141 * is valid. An optional word pattern can be returned with the result to describe valid contents. 6142 * If no result-specific word pattern is provided, the word pattern from the language configuration is used. 6143 * 6144 * @param document The document in which the provider was invoked. 6145 * @param position The position at which the provider was invoked. 6146 * @param token A cancellation token. 6147 * @returns A list of ranges that can be edited together 6148 */ 6149 provideLinkedEditingRanges(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<LinkedEditingRanges>; 6150 } 6151 6152 /** 6153 * Identifies a {@linkcode DocumentDropEdit} or {@linkcode DocumentPasteEdit} 6154 */ 6155 export class DocumentDropOrPasteEditKind { 6156 static readonly Empty: DocumentDropOrPasteEditKind; 6157 6158 /** 6159 * The root kind for basic text edits. 6160 * 6161 * This kind should be used for edits that insert basic text into the document. A good example of this is 6162 * an edit that pastes the clipboard text while also updating imports in the file based on the pasted text. 6163 * For this we could use a kind such as `text.updateImports.someLanguageId`. 6164 * 6165 * Even though most drop/paste edits ultimately insert text, you should not use {@linkcode Text} as the base kind 6166 * for every edit as this is redundant. Instead a more specific kind that describes the type of content being 6167 * inserted should be used instead. For example, if the edit adds a Markdown link, use `markdown.link` since even 6168 * though the content being inserted is text, it's more important to know that the edit inserts Markdown syntax. 6169 */ 6170 static readonly Text: DocumentDropOrPasteEditKind; 6171 6172 /** 6173 * Root kind for edits that update imports in a document in addition to inserting text. 6174 */ 6175 static readonly TextUpdateImports: DocumentDropOrPasteEditKind; 6176 6177 /** 6178 * Use {@linkcode DocumentDropOrPasteEditKind.Empty} instead. 6179 */ 6180 private constructor(value: string); 6181 6182 /** 6183 * The raw string value of the kind. 6184 */ 6185 readonly value: string; 6186 6187 /** 6188 * Create a new kind by appending additional scopes to the current kind. 6189 * 6190 * Does not modify the current kind. 6191 */ 6192 append(...parts: string[]): DocumentDropOrPasteEditKind; 6193 6194 /** 6195 * Checks if this kind intersects `other`. 6196 * 6197 * The kind `"text.plain"` for example intersects `text`, `"text.plain"` and `"text.plain.list"`, 6198 * but not `"unicorn"`, or `"textUnicorn.plain"`. 6199 * 6200 * @param other Kind to check. 6201 */ 6202 intersects(other: DocumentDropOrPasteEditKind): boolean; 6203 6204 /** 6205 * Checks if `other` is a sub-kind of this `DocumentDropOrPasteEditKind`. 6206 * 6207 * The kind `"text.plain"` for example contains `"text.plain"` and `"text.plain.list"`, 6208 * but not `"text"` or `"unicorn.text.plain"`. 6209 * 6210 * @param other Kind to check. 6211 */ 6212 contains(other: DocumentDropOrPasteEditKind): boolean; 6213 } 6214 6215 /** 6216 * An edit operation applied {@link DocumentDropEditProvider on drop}. 6217 */ 6218 export class DocumentDropEdit { 6219 /** 6220 * Human readable label that describes the edit. 6221 */ 6222 title?: string; 6223 6224 /** 6225 * {@link DocumentDropOrPasteEditKind Kind} of the edit. 6226 */ 6227 kind?: DocumentDropOrPasteEditKind; 6228 6229 /** 6230 * Controls the ordering or multiple edits. If this provider yield to edits, it will be shown lower in the list. 6231 */ 6232 yieldTo?: readonly DocumentDropOrPasteEditKind[]; 6233 6234 /** 6235 * The text or snippet to insert at the drop location. 6236 */ 6237 insertText: string | SnippetString; 6238 6239 /** 6240 * An optional additional edit to apply on drop. 6241 */ 6242 additionalEdit?: WorkspaceEdit; 6243 6244 /** 6245 * @param insertText The text or snippet to insert at the drop location. 6246 * @param title Human readable label that describes the edit. 6247 * @param kind {@link DocumentDropOrPasteEditKind Kind} of the edit. 6248 */ 6249 constructor(insertText: string | SnippetString, title?: string, kind?: DocumentDropOrPasteEditKind); 6250 } 6251 6252 /** 6253 * Provider which handles dropping of resources into a text editor. 6254 * 6255 * This allows users to drag and drop resources (including resources from external apps) into the editor. While dragging 6256 * and dropping files, users can hold down `shift` to drop the file into the editor instead of opening it. 6257 * Requires `editor.dropIntoEditor.enabled` to be on. 6258 */ 6259 export interface DocumentDropEditProvider<T extends DocumentDropEdit = DocumentDropEdit> { 6260 /** 6261 * Provide edits which inserts the content being dragged and dropped into the document. 6262 * 6263 * @param document The document in which the drop occurred. 6264 * @param position The position in the document where the drop occurred. 6265 * @param dataTransfer A {@link DataTransfer} object that holds data about what is being dragged and dropped. 6266 * @param token A cancellation token. 6267 * 6268 * @returns A {@link DocumentDropEdit} or a thenable that resolves to such. The lack of a result can be 6269 * signaled by returning `undefined` or `null`. 6270 */ 6271 provideDocumentDropEdits(document: TextDocument, position: Position, dataTransfer: DataTransfer, token: CancellationToken): ProviderResult<T | T[]>; 6272 6273 /** 6274 * Optional method which fills in the {@linkcode DocumentDropEdit.additionalEdit} before the edit is applied. 6275 * 6276 * This is called once per edit and should be used if generating the complete edit may take a long time. 6277 * Resolve can only be used to change {@link DocumentDropEdit.additionalEdit}. 6278 * 6279 * @param edit The {@linkcode DocumentDropEdit} to resolve. 6280 * @param token A cancellation token. 6281 * 6282 * @returns The resolved edit or a thenable that resolves to such. It is OK to return the given 6283 * `edit`. If no result is returned, the given `edit` is used. 6284 */ 6285 resolveDocumentDropEdit?(edit: T, token: CancellationToken): ProviderResult<T>; 6286 } 6287 6288 /** 6289 * Provides additional metadata about how a {@linkcode DocumentDropEditProvider} works. 6290 */ 6291 export interface DocumentDropEditProviderMetadata { 6292 /** 6293 * List of {@link DocumentDropOrPasteEditKind kinds} that the provider may return in {@linkcode DocumentDropEditProvider.provideDocumentDropEdits provideDocumentDropEdits}. 6294 * 6295 * This is used to filter out providers when a specific {@link DocumentDropOrPasteEditKind kind} of edit is requested. 6296 */ 6297 readonly providedDropEditKinds?: readonly DocumentDropOrPasteEditKind[]; 6298 6299 /** 6300 * List of {@link DataTransfer} mime types that the provider can handle. 6301 * 6302 * This can either be an exact mime type such as `image/png`, or a wildcard pattern such as `image/*`. 6303 * 6304 * Use `text/uri-list` for resources dropped from the explorer or other tree views in the workbench. 6305 * 6306 * Use `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@link DataTransfer}. 6307 * Note that {@link DataTransferFile} entries are only created when dropping content from outside the editor, such as 6308 * from the operating system. 6309 */ 6310 readonly dropMimeTypes: readonly string[]; 6311 } 6312 6313 6314 /** 6315 * The reason why paste edits were requested. 6316 */ 6317 export enum DocumentPasteTriggerKind { 6318 /** 6319 * Pasting was requested as part of a normal paste operation. 6320 */ 6321 Automatic = 0, 6322 6323 /** 6324 * Pasting was requested by the user with the `paste as` command. 6325 */ 6326 PasteAs = 1, 6327 } 6328 6329 /** 6330 * Additional information about the paste operation. 6331 */ 6332 export interface DocumentPasteEditContext { 6333 6334 /** 6335 * Requested kind of paste edits to return. 6336 * 6337 * When a explicit kind if requested by {@linkcode DocumentPasteTriggerKind.PasteAs PasteAs}, providers are 6338 * encourage to be more flexible when generating an edit of the requested kind. 6339 */ 6340 readonly only: DocumentDropOrPasteEditKind | undefined; 6341 6342 /** 6343 * The reason why paste edits were requested. 6344 */ 6345 readonly triggerKind: DocumentPasteTriggerKind; 6346 } 6347 6348 /** 6349 * Provider invoked when the user copies or pastes in a {@linkcode TextDocument}. 6350 */ 6351 export interface DocumentPasteEditProvider<T extends DocumentPasteEdit = DocumentPasteEdit> { 6352 6353 /** 6354 * Optional method invoked after the user copies from a {@link TextEditor text editor}. 6355 * 6356 * This allows the provider to attach metadata about the copied text to the {@link DataTransfer}. This data 6357 * transfer is then passed back to providers in {@linkcode provideDocumentPasteEdits}. 6358 * 6359 * Note that currently any changes to the {@linkcode DataTransfer} are isolated to the current editor window. 6360 * This means that any added metadata cannot be seen by other editor windows or by other applications. 6361 * 6362 * @param document Text document where the copy took place. 6363 * @param ranges Ranges being copied in {@linkcode document}. 6364 * @param dataTransfer The data transfer associated with the copy. You can store additional values on this for 6365 * later use in {@linkcode provideDocumentPasteEdits}. This object is only valid for the duration of this method. 6366 * @param token A cancellation token. 6367 * 6368 * @return Optional thenable that resolves when all changes to the `dataTransfer` are complete. 6369 */ 6370 prepareDocumentPaste?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, token: CancellationToken): void | Thenable<void>; 6371 6372 /** 6373 * Invoked before the user pastes into a {@link TextEditor text editor}. 6374 * 6375 * Returned edits can replace the standard pasting behavior. 6376 * 6377 * @param document Document being pasted into 6378 * @param ranges Range in the {@linkcode document} to paste into. 6379 * @param dataTransfer The {@link DataTransfer data transfer} associated with the paste. This object is only 6380 * valid for the duration of the paste operation. 6381 * @param context Additional context for the paste. 6382 * @param token A cancellation token. 6383 * 6384 * @return Set of potential {@link DocumentPasteEdit edits} that can apply the paste. Only a single returned 6385 * {@linkcode DocumentPasteEdit} is applied at a time. If multiple edits are returned from all providers, then 6386 * the first is automatically applied and a widget is shown that lets the user switch to the other edits. 6387 */ 6388 provideDocumentPasteEdits?(document: TextDocument, ranges: readonly Range[], dataTransfer: DataTransfer, context: DocumentPasteEditContext, token: CancellationToken): ProviderResult<T[]>; 6389 6390 /** 6391 * Optional method which fills in the {@linkcode DocumentPasteEdit.additionalEdit} before the edit is applied. 6392 * 6393 * This is called once per edit and should be used if generating the complete edit may take a long time. 6394 * Resolve can only be used to change {@linkcode DocumentPasteEdit.insertText} or {@linkcode DocumentPasteEdit.additionalEdit}. 6395 * 6396 * @param pasteEdit The {@linkcode DocumentPasteEdit} to resolve. 6397 * @param token A cancellation token. 6398 * 6399 * @returns The resolved paste edit or a thenable that resolves to such. It is OK to return the given 6400 * `pasteEdit`. If no result is returned, the given `pasteEdit` is used. 6401 */ 6402 resolveDocumentPasteEdit?(pasteEdit: T, token: CancellationToken): ProviderResult<T>; 6403 } 6404 6405 /** 6406 * An edit the applies a paste operation. 6407 */ 6408 export class DocumentPasteEdit { 6409 6410 /** 6411 * Human readable label that describes the edit. 6412 */ 6413 title: string; 6414 6415 /** 6416 * {@link DocumentDropOrPasteEditKind Kind} of the edit. 6417 */ 6418 kind: DocumentDropOrPasteEditKind; 6419 6420 /** 6421 * The text or snippet to insert at the pasted locations. 6422 * 6423 * If your edit requires more advanced insertion logic, set this to an empty string and provide an {@link DocumentPasteEdit.additionalEdit additional edit} instead. 6424 */ 6425 insertText: string | SnippetString; 6426 6427 /** 6428 * An optional additional edit to apply on paste. 6429 */ 6430 additionalEdit?: WorkspaceEdit; 6431 6432 /** 6433 * Controls ordering when multiple paste edits can potentially be applied. 6434 * 6435 * If this edit yields to another, it will be shown lower in the list of possible paste edits shown to the user. 6436 */ 6437 yieldTo?: readonly DocumentDropOrPasteEditKind[]; 6438 6439 /** 6440 * Create a new paste edit. 6441 * 6442 * @param insertText The text or snippet to insert at the pasted locations. 6443 * @param title Human readable label that describes the edit. 6444 * @param kind {@link DocumentDropOrPasteEditKind Kind} of the edit. 6445 */ 6446 constructor(insertText: string | SnippetString, title: string, kind: DocumentDropOrPasteEditKind); 6447 } 6448 6449 /** 6450 * Provides additional metadata about how a {@linkcode DocumentPasteEditProvider} works. 6451 */ 6452 export interface DocumentPasteProviderMetadata { 6453 /** 6454 * List of {@link DocumentDropOrPasteEditKind kinds} that the provider may return in {@linkcode DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits}. 6455 * 6456 * This is used to filter out providers when a specific {@link DocumentDropOrPasteEditKind kind} of edit is requested. 6457 */ 6458 readonly providedPasteEditKinds: readonly DocumentDropOrPasteEditKind[]; 6459 6460 /** 6461 * Mime types that {@linkcode DocumentPasteEditProvider.prepareDocumentPaste prepareDocumentPaste} may add on copy. 6462 */ 6463 readonly copyMimeTypes?: readonly string[]; 6464 6465 /** 6466 * Mime types that {@linkcode DocumentPasteEditProvider.provideDocumentPasteEdits provideDocumentPasteEdits} should be invoked for. 6467 * 6468 * This can either be an exact mime type such as `image/png`, or a wildcard pattern such as `image/*`. 6469 * 6470 * Use `text/uri-list` for resources dropped from the explorer or other tree views in the workbench. 6471 * 6472 * Use `files` to indicate that the provider should be invoked if any {@link DataTransferFile files} are present in the {@linkcode DataTransfer}. 6473 * Note that {@linkcode DataTransferFile} entries are only created when pasting content from outside the editor, such as 6474 * from the operating system. 6475 */ 6476 readonly pasteMimeTypes?: readonly string[]; 6477 } 6478 6479 /** 6480 * A tuple of two characters, like a pair of 6481 * opening and closing brackets. 6482 */ 6483 export type CharacterPair = [string, string]; 6484 6485 /** 6486 * Describes how comments for a language work. 6487 */ 6488 export interface CommentRule { 6489 6490 /** 6491 * The line comment token, like `// this is a comment` 6492 */ 6493 lineComment?: string; 6494 6495 /** 6496 * The block comment character pair, like `/* block comment */` 6497 */ 6498 blockComment?: CharacterPair; 6499 } 6500 6501 /** 6502 * Describes indentation rules for a language. 6503 */ 6504 export interface IndentationRule { 6505 /** 6506 * If a line matches this pattern, then all the lines after it should be unindented once (until another rule matches). 6507 */ 6508 decreaseIndentPattern: RegExp; 6509 /** 6510 * If a line matches this pattern, then all the lines after it should be indented once (until another rule matches). 6511 */ 6512 increaseIndentPattern: RegExp; 6513 /** 6514 * If a line matches this pattern, then **only the next line** after it should be indented once. 6515 */ 6516 indentNextLinePattern?: RegExp; 6517 /** 6518 * If a line matches this pattern, then its indentation should not be changed and it should not be evaluated against the other rules. 6519 */ 6520 unIndentedLinePattern?: RegExp; 6521 } 6522 6523 /** 6524 * Describes what to do with the indentation when pressing Enter. 6525 */ 6526 export enum IndentAction { 6527 /** 6528 * Insert new line and copy the previous line's indentation. 6529 */ 6530 None = 0, 6531 /** 6532 * Insert new line and indent once (relative to the previous line's indentation). 6533 */ 6534 Indent = 1, 6535 /** 6536 * Insert two new lines: 6537 * - the first one indented which will hold the cursor 6538 * - the second one at the same indentation level 6539 */ 6540 IndentOutdent = 2, 6541 /** 6542 * Insert new line and outdent once (relative to the previous line's indentation). 6543 */ 6544 Outdent = 3 6545 } 6546 6547 /** 6548 * Describes what to do when pressing Enter. 6549 */ 6550 export interface EnterAction { 6551 /** 6552 * Describe what to do with the indentation. 6553 */ 6554 indentAction: IndentAction; 6555 /** 6556 * Describes text to be appended after the new line and after the indentation. 6557 */ 6558 appendText?: string; 6559 /** 6560 * Describes the number of characters to remove from the new line's indentation. 6561 */ 6562 removeText?: number; 6563 } 6564 6565 /** 6566 * Describes a rule to be evaluated when pressing Enter. 6567 */ 6568 export interface OnEnterRule { 6569 /** 6570 * This rule will only execute if the text before the cursor matches this regular expression. 6571 */ 6572 beforeText: RegExp; 6573 /** 6574 * This rule will only execute if the text after the cursor matches this regular expression. 6575 */ 6576 afterText?: RegExp; 6577 /** 6578 * This rule will only execute if the text above the current line matches this regular expression. 6579 */ 6580 previousLineText?: RegExp; 6581 /** 6582 * The action to execute. 6583 */ 6584 action: EnterAction; 6585 } 6586 6587 /** 6588 * Enumeration of commonly encountered syntax token types. 6589 */ 6590 export enum SyntaxTokenType { 6591 /** 6592 * Everything except tokens that are part of comments, string literals and regular expressions. 6593 */ 6594 Other = 0, 6595 /** 6596 * A comment. 6597 */ 6598 Comment = 1, 6599 /** 6600 * A string literal. 6601 */ 6602 String = 2, 6603 /** 6604 * A regular expression. 6605 */ 6606 RegEx = 3 6607 } 6608 6609 /** 6610 * Describes pairs of strings where the close string will be automatically inserted when typing the opening string. 6611 */ 6612 export interface AutoClosingPair { 6613 /** 6614 * The string that will trigger the automatic insertion of the closing string. 6615 */ 6616 open: string; 6617 /** 6618 * The closing string that will be automatically inserted when typing the opening string. 6619 */ 6620 close: string; 6621 /** 6622 * A set of tokens where the pair should not be auto closed. 6623 */ 6624 notIn?: SyntaxTokenType[]; 6625 } 6626 6627 /** 6628 * The language configuration interfaces defines the contract between extensions 6629 * and various editor features, like automatic bracket insertion, automatic indentation etc. 6630 */ 6631 export interface LanguageConfiguration { 6632 /** 6633 * The language's comment settings. 6634 */ 6635 comments?: CommentRule; 6636 /** 6637 * The language's brackets. 6638 * This configuration implicitly affects pressing Enter around these brackets. 6639 */ 6640 brackets?: CharacterPair[]; 6641 /** 6642 * The language's word definition. 6643 * If the language supports Unicode identifiers (e.g. JavaScript), it is preferable 6644 * to provide a word definition that uses exclusion of known separators. 6645 * e.g.: A regex that matches anything except known separators (and dot is allowed to occur in a floating point number): 6646 * ``` 6647 * /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g 6648 * ``` 6649 */ 6650 wordPattern?: RegExp; 6651 /** 6652 * The language's indentation settings. 6653 */ 6654 indentationRules?: IndentationRule; 6655 /** 6656 * The language's rules to be evaluated when pressing Enter. 6657 */ 6658 onEnterRules?: OnEnterRule[]; 6659 /** 6660 * The language's auto closing pairs. 6661 */ 6662 autoClosingPairs?: AutoClosingPair[]; 6663 6664 /** 6665 * **Deprecated** Do not use. 6666 * 6667 * @deprecated Will be replaced by a better API soon. 6668 */ 6669 __electricCharacterSupport?: { 6670 /** 6671 * This property is deprecated and will be **ignored** from 6672 * the editor. 6673 * @deprecated 6674 */ 6675 brackets?: any; 6676 /** 6677 * This property is deprecated and not fully supported anymore by 6678 * the editor (scope and lineStart are ignored). 6679 * Use the autoClosingPairs property in the language configuration file instead. 6680 * @deprecated 6681 */ 6682 docComment?: { 6683 /** 6684 * @deprecated 6685 */ 6686 scope: string; 6687 /** 6688 * @deprecated 6689 */ 6690 open: string; 6691 /** 6692 * @deprecated 6693 */ 6694 lineStart: string; 6695 /** 6696 * @deprecated 6697 */ 6698 close?: string; 6699 }; 6700 }; 6701 6702 /** 6703 * **Deprecated** Do not use. 6704 * 6705 * @deprecated * Use the autoClosingPairs property in the language configuration file instead. 6706 */ 6707 __characterPairSupport?: { 6708 /** 6709 * @deprecated 6710 */ 6711 autoClosingPairs: { 6712 /** 6713 * @deprecated 6714 */ 6715 open: string; 6716 /** 6717 * @deprecated 6718 */ 6719 close: string; 6720 /** 6721 * @deprecated 6722 */ 6723 notIn?: string[]; 6724 }[]; 6725 }; 6726 } 6727 6728 /** 6729 * The configuration target 6730 */ 6731 export enum ConfigurationTarget { 6732 /** 6733 * Global configuration 6734 */ 6735 Global = 1, 6736 6737 /** 6738 * Workspace configuration 6739 */ 6740 Workspace = 2, 6741 6742 /** 6743 * Workspace folder configuration 6744 */ 6745 WorkspaceFolder = 3 6746 } 6747 6748 /** 6749 * Represents the configuration. It is a merged view of 6750 * 6751 * - *Default Settings* 6752 * - *Global (User) Settings* 6753 * - *Workspace settings* 6754 * - *Workspace Folder settings* - From one of the {@link workspace.workspaceFolders Workspace Folders} under which requested resource belongs to. 6755 * - *Language settings* - Settings defined under requested language. 6756 * 6757 * The *effective* value (returned by {@linkcode WorkspaceConfiguration.get get}) is computed by overriding or merging the values in the following order: 6758 * 6759 * 1. `defaultValue` (if defined in `package.json` otherwise derived from the value's type) 6760 * 1. `globalValue` (if defined) 6761 * 1. `workspaceValue` (if defined) 6762 * 1. `workspaceFolderValue` (if defined) 6763 * 1. `defaultLanguageValue` (if defined) 6764 * 1. `globalLanguageValue` (if defined) 6765 * 1. `workspaceLanguageValue` (if defined) 6766 * 1. `workspaceFolderLanguageValue` (if defined) 6767 * 6768 * **Note:** Only `object` value types are merged and all other value types are overridden. 6769 * 6770 * Example 1: Overriding 6771 * 6772 * ```ts 6773 * defaultValue = 'on'; 6774 * globalValue = 'relative' 6775 * workspaceFolderValue = 'off' 6776 * value = 'off' 6777 * ``` 6778 * 6779 * Example 2: Language Values 6780 * 6781 * ```ts 6782 * defaultValue = 'on'; 6783 * globalValue = 'relative' 6784 * workspaceFolderValue = 'off' 6785 * globalLanguageValue = 'on' 6786 * value = 'on' 6787 * ``` 6788 * 6789 * Example 3: Object Values 6790 * 6791 * ```ts 6792 * defaultValue = { "a": 1, "b": 2 }; 6793 * globalValue = { "b": 3, "c": 4 }; 6794 * value = { "a": 1, "b": 3, "c": 4 }; 6795 * ``` 6796 * 6797 * *Note:* Workspace and Workspace Folder configurations contains `launch` and `tasks` settings. Their basename will be 6798 * part of the section identifier. The following snippets shows how to retrieve all configurations 6799 * from `launch.json`: 6800 * 6801 * ```ts 6802 * // launch.json configuration 6803 * const config = workspace.getConfiguration('launch', vscode.workspace.workspaceFolders[0].uri); 6804 * 6805 * // retrieve values 6806 * const values = config.get('configurations'); 6807 * ``` 6808 * 6809 * Refer to [Settings](https://code.visualstudio.com/docs/getstarted/settings) for more information. 6810 */ 6811 export interface WorkspaceConfiguration { 6812 6813 /** 6814 * Return a value from this configuration. 6815 * 6816 * @param section Configuration name, supports _dotted_ names. 6817 * @returns The value `section` denotes or `undefined`. 6818 */ 6819 get<T>(section: string): T | undefined; 6820 6821 /** 6822 * Return a value from this configuration. 6823 * 6824 * @param section Configuration name, supports _dotted_ names. 6825 * @param defaultValue A value should be returned when no value could be found, is `undefined`. 6826 * @returns The value `section` denotes or the default. 6827 */ 6828 get<T>(section: string, defaultValue: T): T; 6829 6830 /** 6831 * Check if this configuration has a certain value. 6832 * 6833 * @param section Configuration name, supports _dotted_ names. 6834 * @returns `true` if the section doesn't resolve to `undefined`. 6835 */ 6836 has(section: string): boolean; 6837 6838 /** 6839 * Retrieve all information about a configuration setting. A configuration value 6840 * often consists of a *default* value, a global or installation-wide value, 6841 * a workspace-specific value, folder-specific value 6842 * and language-specific values (if {@link WorkspaceConfiguration} is scoped to a language). 6843 * 6844 * Also provides all language ids under which the given configuration setting is defined. 6845 * 6846 * *Note:* The configuration name must denote a leaf in the configuration tree 6847 * (`editor.fontSize` vs `editor`) otherwise no result is returned. 6848 * 6849 * @param section Configuration name, supports _dotted_ names. 6850 * @returns Information about a configuration setting or `undefined`. 6851 */ 6852 inspect<T>(section: string): { 6853 6854 /** 6855 * The fully qualified key of the configuration value 6856 */ 6857 key: string; 6858 6859 /** 6860 * The default value which is used when no other value is defined 6861 */ 6862 defaultValue?: T; 6863 6864 /** 6865 * The global or installation-wide value. 6866 */ 6867 globalValue?: T; 6868 6869 /** 6870 * The workspace-specific value. 6871 */ 6872 workspaceValue?: T; 6873 6874 /** 6875 * The workspace-folder-specific value. 6876 */ 6877 workspaceFolderValue?: T; 6878 6879 /** 6880 * Language specific default value when this configuration value is created for a {@link ConfigurationScope language scope}. 6881 */ 6882 defaultLanguageValue?: T; 6883 6884 /** 6885 * Language specific global value when this configuration value is created for a {@link ConfigurationScope language scope}. 6886 */ 6887 globalLanguageValue?: T; 6888 6889 /** 6890 * Language specific workspace value when this configuration value is created for a {@link ConfigurationScope language scope}. 6891 */ 6892 workspaceLanguageValue?: T; 6893 6894 /** 6895 * Language specific workspace-folder value when this configuration value is created for a {@link ConfigurationScope language scope}. 6896 */ 6897 workspaceFolderLanguageValue?: T; 6898 6899 /** 6900 * All language identifiers for which this configuration is defined. 6901 */ 6902 languageIds?: string[]; 6903 6904 } | undefined; 6905 6906 /** 6907 * Update a configuration value. The updated configuration values are persisted. 6908 * 6909 * A value can be changed in 6910 * 6911 * - {@link ConfigurationTarget.Global Global settings}: Changes the value for all instances of the editor. 6912 * - {@link ConfigurationTarget.Workspace Workspace settings}: Changes the value for current workspace, if available. 6913 * - {@link ConfigurationTarget.WorkspaceFolder Workspace folder settings}: Changes the value for settings from one of the {@link workspace.workspaceFolders Workspace Folders} under which the requested resource belongs to. 6914 * - Language settings: Changes the value for the requested languageId. 6915 * 6916 * *Note:* To remove a configuration value use `undefined`, like so: `config.update('somekey', undefined)` 6917 * 6918 * @param section Configuration name, supports _dotted_ names. 6919 * @param value The new value. 6920 * @param configurationTarget The {@link ConfigurationTarget configuration target} or a boolean value. 6921 * - If `true` updates {@link ConfigurationTarget.Global Global settings}. 6922 * - If `false` updates {@link ConfigurationTarget.Workspace Workspace settings}. 6923 * - If `undefined` or `null` updates to {@link ConfigurationTarget.WorkspaceFolder Workspace folder settings} if configuration is resource specific, 6924 * otherwise to {@link ConfigurationTarget.Workspace Workspace settings}. 6925 * @param overrideInLanguage Whether to update the value in the scope of requested languageId or not. 6926 * - If `true` updates the value under the requested languageId. 6927 * - If `undefined` updates the value under the requested languageId only if the configuration is defined for the language. 6928 * @throws error while updating 6929 * - configuration which is not registered. 6930 * - window configuration to workspace folder 6931 * - configuration to workspace or workspace folder when no workspace is opened. 6932 * - configuration to workspace folder when there is no workspace folder settings. 6933 * - configuration to workspace folder when {@link WorkspaceConfiguration} is not scoped to a resource. 6934 */ 6935 update(section: string, value: any, configurationTarget?: ConfigurationTarget | boolean | null, overrideInLanguage?: boolean): Thenable<void>; 6936 6937 /** 6938 * Readable dictionary that backs this configuration. 6939 */ 6940 readonly [key: string]: any; 6941 } 6942 6943 /** 6944 * Represents a location inside a resource, such as a line 6945 * inside a text file. 6946 */ 6947 export class Location { 6948 6949 /** 6950 * The resource identifier of this location. 6951 */ 6952 uri: Uri; 6953 6954 /** 6955 * The document range of this location. 6956 */ 6957 range: Range; 6958 6959 /** 6960 * Creates a new location object. 6961 * 6962 * @param uri The resource identifier. 6963 * @param rangeOrPosition The range or position. Positions will be converted to an empty range. 6964 */ 6965 constructor(uri: Uri, rangeOrPosition: Range | Position); 6966 } 6967 6968 /** 6969 * Represents the connection of two locations. Provides additional metadata over normal {@link Location locations}, 6970 * including an origin range. 6971 */ 6972 export interface LocationLink { 6973 /** 6974 * Span of the origin of this link. 6975 * 6976 * Used as the underlined span for mouse definition hover. Defaults to the word range at 6977 * the definition position. 6978 */ 6979 originSelectionRange?: Range; 6980 6981 /** 6982 * The target resource identifier of this link. 6983 */ 6984 targetUri: Uri; 6985 6986 /** 6987 * The full target range of this link. 6988 */ 6989 targetRange: Range; 6990 6991 /** 6992 * The span of this link. 6993 */ 6994 targetSelectionRange?: Range; 6995 } 6996 6997 /** 6998 * The event that is fired when diagnostics change. 6999 */ 7000 export interface DiagnosticChangeEvent { 7001 7002 /** 7003 * An array of resources for which diagnostics have changed. 7004 */ 7005 readonly uris: readonly Uri[]; 7006 } 7007 7008 /** 7009 * Represents the severity of diagnostics. 7010 */ 7011 export enum DiagnosticSeverity { 7012 7013 /** 7014 * Something not allowed by the rules of a language or other means. 7015 */ 7016 Error = 0, 7017 7018 /** 7019 * Something suspicious but allowed. 7020 */ 7021 Warning = 1, 7022 7023 /** 7024 * Something to inform about but not a problem. 7025 */ 7026 Information = 2, 7027 7028 /** 7029 * Something to hint to a better way of doing it, like proposing 7030 * a refactoring. 7031 */ 7032 Hint = 3 7033 } 7034 7035 /** 7036 * Represents a related message and source code location for a diagnostic. This should be 7037 * used to point to code locations that cause or related to a diagnostics, e.g. when duplicating 7038 * a symbol in a scope. 7039 */ 7040 export class DiagnosticRelatedInformation { 7041 7042 /** 7043 * The location of this related diagnostic information. 7044 */ 7045 location: Location; 7046 7047 /** 7048 * The message of this related diagnostic information. 7049 */ 7050 message: string; 7051 7052 /** 7053 * Creates a new related diagnostic information object. 7054 * 7055 * @param location The location. 7056 * @param message The message. 7057 */ 7058 constructor(location: Location, message: string); 7059 } 7060 7061 /** 7062 * Additional metadata about the type of a diagnostic. 7063 */ 7064 export enum DiagnosticTag { 7065 /** 7066 * Unused or unnecessary code. 7067 * 7068 * Diagnostics with this tag are rendered faded out. The amount of fading 7069 * is controlled by the `"editorUnnecessaryCode.opacity"` theme color. For 7070 * example, `"editorUnnecessaryCode.opacity": "#000000c0"` will render the 7071 * code with 75% opacity. For high contrast themes, use the 7072 * `"editorUnnecessaryCode.border"` theme color to underline unnecessary code 7073 * instead of fading it out. 7074 */ 7075 Unnecessary = 1, 7076 7077 /** 7078 * Deprecated or obsolete code. 7079 * 7080 * Diagnostics with this tag are rendered with a strike through. 7081 */ 7082 Deprecated = 2, 7083 } 7084 7085 /** 7086 * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects 7087 * are only valid in the scope of a file. 7088 */ 7089 export class Diagnostic { 7090 7091 /** 7092 * The range to which this diagnostic applies. 7093 */ 7094 range: Range; 7095 7096 /** 7097 * The human-readable message. 7098 */ 7099 message: string; 7100 7101 /** 7102 * The severity, default is {@link DiagnosticSeverity.Error error}. 7103 */ 7104 severity: DiagnosticSeverity; 7105 7106 /** 7107 * A human-readable string describing the source of this 7108 * diagnostic, e.g. 'typescript' or 'super lint'. 7109 */ 7110 source?: string; 7111 7112 /** 7113 * A code or identifier for this diagnostic. 7114 * Should be used for later processing, e.g. when providing {@link CodeActionContext code actions}. 7115 */ 7116 code?: string | number | { 7117 /** 7118 * A code or identifier for this diagnostic. 7119 * Should be used for later processing, e.g. when providing {@link CodeActionContext code actions}. 7120 */ 7121 value: string | number; 7122 7123 /** 7124 * A target URI to open with more information about the diagnostic error. 7125 */ 7126 target: Uri; 7127 }; 7128 7129 /** 7130 * An array of related diagnostic information, e.g. when symbol-names within 7131 * a scope collide all definitions can be marked via this property. 7132 */ 7133 relatedInformation?: DiagnosticRelatedInformation[]; 7134 7135 /** 7136 * Additional metadata about the diagnostic. 7137 */ 7138 tags?: DiagnosticTag[]; 7139 7140 /** 7141 * Creates a new diagnostic object. 7142 * 7143 * @param range The range to which this diagnostic applies. 7144 * @param message The human-readable message. 7145 * @param severity The severity, default is {@link DiagnosticSeverity.Error error}. 7146 */ 7147 constructor(range: Range, message: string, severity?: DiagnosticSeverity); 7148 } 7149 7150 /** 7151 * A diagnostics collection is a container that manages a set of 7152 * {@link Diagnostic diagnostics}. Diagnostics are always scopes to a 7153 * diagnostics collection and a resource. 7154 * 7155 * To get an instance of a `DiagnosticCollection` use 7156 * {@link languages.createDiagnosticCollection createDiagnosticCollection}. 7157 */ 7158 export interface DiagnosticCollection extends Iterable<[uri: Uri, diagnostics: readonly Diagnostic[]]> { 7159 7160 /** 7161 * The name of this diagnostic collection, for instance `typescript`. Every diagnostic 7162 * from this collection will be associated with this name. Also, the task framework uses this 7163 * name when defining [problem matchers](https://code.visualstudio.com/docs/editor/tasks#_defining-a-problem-matcher). 7164 */ 7165 readonly name: string; 7166 7167 /** 7168 * Assign diagnostics for given resource. Will replace 7169 * existing diagnostics for that resource. 7170 * 7171 * @param uri A resource identifier. 7172 * @param diagnostics Array of diagnostics or `undefined` 7173 */ 7174 set(uri: Uri, diagnostics: readonly Diagnostic[] | undefined): void; 7175 7176 /** 7177 * Replace diagnostics for multiple resources in this collection. 7178 * 7179 * _Note_ that multiple tuples of the same uri will be merged, e.g 7180 * `[[file1, [d1]], [file1, [d2]]]` is equivalent to `[[file1, [d1, d2]]]`. 7181 * If a diagnostics item is `undefined` as in `[file1, undefined]` 7182 * all previous but not subsequent diagnostics are removed. 7183 * 7184 * @param entries An array of tuples, like `[[file1, [d1, d2]], [file2, [d3, d4, d5]]]`, or `undefined`. 7185 */ 7186 set(entries: ReadonlyArray<[Uri, readonly Diagnostic[] | undefined]>): void; 7187 7188 /** 7189 * Remove all diagnostics from this collection that belong 7190 * to the provided `uri`. The same as `#set(uri, undefined)`. 7191 * 7192 * @param uri A resource identifier. 7193 */ 7194 delete(uri: Uri): void; 7195 7196 /** 7197 * Remove all diagnostics from this collection. The same 7198 * as calling `#set(undefined)`; 7199 */ 7200 clear(): void; 7201 7202 /** 7203 * Iterate over each entry in this collection. 7204 * 7205 * @param callback Function to execute for each entry. 7206 * @param thisArg The `this` context used when invoking the handler function. 7207 */ 7208 forEach(callback: (uri: Uri, diagnostics: readonly Diagnostic[], collection: DiagnosticCollection) => any, thisArg?: any): void; 7209 7210 /** 7211 * Get the diagnostics for a given resource. *Note* that you cannot 7212 * modify the diagnostics-array returned from this call. 7213 * 7214 * @param uri A resource identifier. 7215 * @returns An immutable array of {@link Diagnostic diagnostics} or `undefined`. 7216 */ 7217 get(uri: Uri): readonly Diagnostic[] | undefined; 7218 7219 /** 7220 * Check if this collection contains diagnostics for a 7221 * given resource. 7222 * 7223 * @param uri A resource identifier. 7224 * @returns `true` if this collection has diagnostic for the given resource. 7225 */ 7226 has(uri: Uri): boolean; 7227 7228 /** 7229 * Dispose and free associated resources. Calls 7230 * {@link DiagnosticCollection.clear clear}. 7231 */ 7232 dispose(): void; 7233 } 7234 7235 /** 7236 * Represents the severity of a language status item. 7237 */ 7238 /** 7239 * Represents the severity level of a language status. 7240 */ 7241 export enum LanguageStatusSeverity { 7242 /** 7243 * Informational severity level. 7244 */ 7245 Information = 0, 7246 /** 7247 * Warning severity level. 7248 */ 7249 Warning = 1, 7250 /** 7251 * Error severity level. 7252 */ 7253 Error = 2 7254 } 7255 7256 /** 7257 * A language status item is the preferred way to present language status reports for the active text editors, 7258 * such as selected linter or notifying about a configuration problem. 7259 */ 7260 export interface LanguageStatusItem { 7261 7262 /** 7263 * The identifier of this item. 7264 */ 7265 readonly id: string; 7266 7267 /** 7268 * The short name of this item, like 'Java Language Status', etc. 7269 */ 7270 name: string | undefined; 7271 7272 /** 7273 * A {@link DocumentSelector selector} that defines for what editors 7274 * this item shows. 7275 */ 7276 selector: DocumentSelector; 7277 7278 /** 7279 * The severity of this item. 7280 * 7281 * Defaults to {@link LanguageStatusSeverity.Information information}. You can use this property to 7282 * signal to users that there is a problem that needs attention, like a missing executable or an 7283 * invalid configuration. 7284 */ 7285 severity: LanguageStatusSeverity; 7286 7287 /** 7288 * The text to show for the entry. You can embed icons in the text by leveraging the syntax: 7289 * 7290 * `My text $(icon-name) contains icons like $(icon-name) this one.` 7291 * 7292 * Where the icon-name is taken from the ThemeIcon [icon set](https://code.visualstudio.com/api/references/icons-in-labels#icon-listing), e.g. 7293 * `light-bulb`, `thumbsup`, `zap` etc. 7294 */ 7295 text: string; 7296 7297 /** 7298 * Optional, human-readable details for this item. 7299 */ 7300 detail?: string; 7301 7302 /** 7303 * Controls whether the item is shown as "busy". Defaults to `false`. 7304 */ 7305 busy: boolean; 7306 7307 /** 7308 * A {@linkcode Command command} for this item. 7309 */ 7310 command: Command | undefined; 7311 7312 /** 7313 * Accessibility information used when a screen reader interacts with this item 7314 */ 7315 accessibilityInformation?: AccessibilityInformation; 7316 7317 /** 7318 * Dispose and free associated resources. 7319 */ 7320 dispose(): void; 7321 } 7322 7323 /** 7324 * Denotes a location of an editor in the window. Editors can be arranged in a grid 7325 * and each column represents one editor location in that grid by counting the editors 7326 * in order of their appearance. 7327 */ 7328 export enum ViewColumn { 7329 /** 7330 * A *symbolic* editor column representing the currently active column. This value 7331 * can be used when opening editors, but the *resolved* {@link TextEditor.viewColumn viewColumn}-value 7332 * of editors will always be `One`, `Two`, `Three`,... or `undefined` but never `Active`. 7333 */ 7334 Active = -1, 7335 /** 7336 * A *symbolic* editor column representing the column to the side of the active one. This value 7337 * can be used when opening editors, but the *resolved* {@link TextEditor.viewColumn viewColumn}-value 7338 * of editors will always be `One`, `Two`, `Three`,... or `undefined` but never `Beside`. 7339 */ 7340 Beside = -2, 7341 /** 7342 * The first editor column. 7343 */ 7344 One = 1, 7345 /** 7346 * The second editor column. 7347 */ 7348 Two = 2, 7349 /** 7350 * The third editor column. 7351 */ 7352 Three = 3, 7353 /** 7354 * The fourth editor column. 7355 */ 7356 Four = 4, 7357 /** 7358 * The fifth editor column. 7359 */ 7360 Five = 5, 7361 /** 7362 * The sixth editor column. 7363 */ 7364 Six = 6, 7365 /** 7366 * The seventh editor column. 7367 */ 7368 Seven = 7, 7369 /** 7370 * The eighth editor column. 7371 */ 7372 Eight = 8, 7373 /** 7374 * The ninth editor column. 7375 */ 7376 Nine = 9 7377 } 7378 7379 /** 7380 * An output channel is a container for readonly textual information. 7381 * 7382 * To get an instance of an `OutputChannel` use 7383 * {@link window.createOutputChannel createOutputChannel}. 7384 */ 7385 export interface OutputChannel { 7386 7387 /** 7388 * The human-readable name of this output channel. 7389 */ 7390 readonly name: string; 7391 7392 /** 7393 * Append the given value to the channel. 7394 * 7395 * @param value A string, falsy values will not be printed. 7396 */ 7397 append(value: string): void; 7398 7399 /** 7400 * Append the given value and a line feed character 7401 * to the channel. 7402 * 7403 * @param value A string, falsy values will be printed. 7404 */ 7405 appendLine(value: string): void; 7406 7407 /** 7408 * Replaces all output from the channel with the given value. 7409 * 7410 * @param value A string, falsy values will not be printed. 7411 */ 7412 replace(value: string): void; 7413 7414 /** 7415 * Removes all output from the channel. 7416 */ 7417 clear(): void; 7418 7419 /** 7420 * Reveal this channel in the UI. 7421 * 7422 * @param preserveFocus When `true` the channel will not take focus. 7423 */ 7424 show(preserveFocus?: boolean): void; 7425 7426 /** 7427 * Reveal this channel in the UI. 7428 * 7429 * @deprecated Use the overload with just one parameter (`show(preserveFocus?: boolean): void`). 7430 * 7431 * @param column This argument is **deprecated** and will be ignored. 7432 * @param preserveFocus When `true` the channel will not take focus. 7433 */ 7434 show(column?: ViewColumn, preserveFocus?: boolean): void; 7435 7436 /** 7437 * Hide this channel from the UI. 7438 */ 7439 hide(): void; 7440 7441 /** 7442 * Dispose and free associated resources. 7443 */ 7444 dispose(): void; 7445 } 7446 7447 /** 7448 * A channel for containing log output. 7449 * 7450 * To get an instance of a `LogOutputChannel` use 7451 * {@link window.createOutputChannel createOutputChannel}. 7452 */ 7453 export interface LogOutputChannel extends OutputChannel { 7454 7455 /** 7456 * The current log level of the channel. Defaults to {@link env.logLevel editor log level}. 7457 */ 7458 readonly logLevel: LogLevel; 7459 7460 /** 7461 * An {@link Event} which fires when the log level of the channel changes. 7462 */ 7463 readonly onDidChangeLogLevel: Event<LogLevel>; 7464 7465 /** 7466 * Outputs the given trace message to the channel. Use this method to log verbose information. 7467 * 7468 * The message is only logged if the channel is configured to display {@link LogLevel.Trace trace} log level. 7469 * 7470 * @param message trace message to log 7471 */ 7472 trace(message: string, ...args: any[]): void; 7473 7474 /** 7475 * Outputs the given debug message to the channel. 7476 * 7477 * The message is only logged if the channel is configured to display {@link LogLevel.Debug debug} log level or lower. 7478 * 7479 * @param message debug message to log 7480 */ 7481 debug(message: string, ...args: any[]): void; 7482 7483 /** 7484 * Outputs the given information message to the channel. 7485 * 7486 * The message is only logged if the channel is configured to display {@link LogLevel.Info info} log level or lower. 7487 * 7488 * @param message info message to log 7489 */ 7490 info(message: string, ...args: any[]): void; 7491 7492 /** 7493 * Outputs the given warning message to the channel. 7494 * 7495 * The message is only logged if the channel is configured to display {@link LogLevel.Warning warning} log level or lower. 7496 * 7497 * @param message warning message to log 7498 */ 7499 warn(message: string, ...args: any[]): void; 7500 7501 /** 7502 * Outputs the given error or error message to the channel. 7503 * 7504 * The message is only logged if the channel is configured to display {@link LogLevel.Error error} log level or lower. 7505 * 7506 * @param error Error or error message to log 7507 */ 7508 error(error: string | Error, ...args: any[]): void; 7509 } 7510 7511 /** 7512 * Accessibility information which controls screen reader behavior. 7513 */ 7514 export interface AccessibilityInformation { 7515 /** 7516 * Label to be read out by a screen reader once the item has focus. 7517 */ 7518 readonly label: string; 7519 7520 /** 7521 * Role of the widget which defines how a screen reader interacts with it. 7522 * The role should be set in special cases when for example a tree-like element behaves like a checkbox. 7523 * If role is not specified the editor will pick the appropriate role automatically. 7524 * More about aria roles can be found here https://w3c.github.io/aria/#widget_roles 7525 */ 7526 readonly role?: string; 7527 } 7528 7529 /** 7530 * Represents the alignment of status bar items. 7531 */ 7532 export enum StatusBarAlignment { 7533 7534 /** 7535 * Aligned to the left side. 7536 */ 7537 Left = 1, 7538 7539 /** 7540 * Aligned to the right side. 7541 */ 7542 Right = 2 7543 } 7544 7545 /** 7546 * A status bar item is a status bar contribution that can 7547 * show text and icons and run a command on click. 7548 */ 7549 export interface StatusBarItem { 7550 7551 /** 7552 * The identifier of this item. 7553 * 7554 * *Note*: if no identifier was provided by the {@linkcode window.createStatusBarItem} 7555 * method, the identifier will match the {@link Extension.id extension identifier}. 7556 */ 7557 readonly id: string; 7558 7559 /** 7560 * The alignment of this item. 7561 */ 7562 readonly alignment: StatusBarAlignment; 7563 7564 /** 7565 * The priority of this item. Higher value means the item should 7566 * be shown more to the left. 7567 */ 7568 readonly priority: number | undefined; 7569 7570 /** 7571 * The name of the entry, like 'Python Language Indicator', 'Git Status' etc. 7572 * Try to keep the length of the name short, yet descriptive enough that 7573 * users can understand what the status bar item is about. 7574 */ 7575 name: string | undefined; 7576 7577 /** 7578 * The text to show for the entry. You can embed icons in the text by leveraging the syntax: 7579 * 7580 * `My text $(icon-name) contains icons like $(icon-name) this one.` 7581 * 7582 * Where the icon-name is taken from the ThemeIcon [icon set](https://code.visualstudio.com/api/references/icons-in-labels#icon-listing), e.g. 7583 * `light-bulb`, `thumbsup`, `zap` etc. 7584 */ 7585 text: string; 7586 7587 /** 7588 * The tooltip text when you hover over this entry. 7589 */ 7590 tooltip: string | MarkdownString | undefined; 7591 7592 /** 7593 * The foreground color for this entry. 7594 */ 7595 color: string | ThemeColor | undefined; 7596 7597 /** 7598 * The background color for this entry. 7599 * 7600 * *Note*: only the following colors are supported: 7601 * * `new ThemeColor('statusBarItem.errorBackground')` 7602 * * `new ThemeColor('statusBarItem.warningBackground')` 7603 * 7604 * More background colors may be supported in the future. 7605 * 7606 * *Note*: when a background color is set, the statusbar may override 7607 * the `color` choice to ensure the entry is readable in all themes. 7608 */ 7609 backgroundColor: ThemeColor | undefined; 7610 7611 /** 7612 * {@linkcode Command} or identifier of a command to run on click. 7613 * 7614 * The command must be {@link commands.getCommands known}. 7615 * 7616 * Note that if this is a {@linkcode Command} object, only the {@linkcode Command.command command} and {@linkcode Command.arguments arguments} 7617 * are used by the editor. 7618 */ 7619 command: string | Command | undefined; 7620 7621 /** 7622 * Accessibility information used when a screen reader interacts with this StatusBar item 7623 */ 7624 accessibilityInformation: AccessibilityInformation | undefined; 7625 7626 /** 7627 * Shows the entry in the status bar. 7628 */ 7629 show(): void; 7630 7631 /** 7632 * Hide the entry in the status bar. 7633 */ 7634 hide(): void; 7635 7636 /** 7637 * Dispose and free associated resources. Call 7638 * {@link StatusBarItem.hide hide}. 7639 */ 7640 dispose(): void; 7641 } 7642 7643 /** 7644 * Defines a generalized way of reporting progress updates. 7645 */ 7646 export interface Progress<T> { 7647 7648 /** 7649 * Report a progress update. 7650 * @param value A progress item, like a message and/or an 7651 * report on how much work finished 7652 */ 7653 report(value: T): void; 7654 } 7655 7656 /** 7657 * An individual terminal instance within the integrated terminal. 7658 */ 7659 export interface Terminal { 7660 7661 /** 7662 * The name of the terminal. 7663 */ 7664 readonly name: string; 7665 7666 /** 7667 * The process ID of the shell process. 7668 */ 7669 readonly processId: Thenable<number | undefined>; 7670 7671 /** 7672 * The object used to initialize the terminal, this is useful for example to detecting the 7673 * shell type of when the terminal was not launched by this extension or for detecting what 7674 * folder the shell was launched in. 7675 */ 7676 readonly creationOptions: Readonly<TerminalOptions | ExtensionTerminalOptions>; 7677 7678 /** 7679 * The exit status of the terminal, this will be undefined while the terminal is active. 7680 * 7681 * **Example:** Show a notification with the exit code when the terminal exits with a 7682 * non-zero exit code. 7683 * ```typescript 7684 * window.onDidCloseTerminal(t => { 7685 * if (t.exitStatus && t.exitStatus.code) { 7686 * vscode.window.showInformationMessage(`Exit code: ${t.exitStatus.code}`); 7687 * } 7688 * }); 7689 * ``` 7690 */ 7691 readonly exitStatus: TerminalExitStatus | undefined; 7692 7693 /** 7694 * The current state of the {@link Terminal}. 7695 */ 7696 readonly state: TerminalState; 7697 7698 /** 7699 * An object that contains [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration)-powered 7700 * features for the terminal. This will always be `undefined` immediately after the terminal 7701 * is created. Listen to {@link window.onDidChangeTerminalShellIntegration} to be notified 7702 * when shell integration is activated for a terminal. 7703 * 7704 * Note that this object may remain undefined if shell integration never activates. For 7705 * example Command Prompt does not support shell integration and a user's shell setup could 7706 * conflict with the automatic shell integration activation. 7707 */ 7708 readonly shellIntegration: TerminalShellIntegration | undefined; 7709 7710 /** 7711 * Send text to the terminal. The text is written to the stdin of the underlying pty process 7712 * (shell) of the terminal. 7713 * 7714 * @param text The text to send. 7715 * @param shouldExecute Indicates that the text being sent should be executed rather than just inserted in the terminal. 7716 * The character(s) added are `\n` or `\r\n`, depending on the platform. This defaults to `true`. 7717 */ 7718 sendText(text: string, shouldExecute?: boolean): void; 7719 7720 /** 7721 * Show the terminal panel and reveal this terminal in the UI. 7722 * 7723 * @param preserveFocus When `true` the terminal will not take focus. 7724 */ 7725 show(preserveFocus?: boolean): void; 7726 7727 /** 7728 * Hide the terminal panel if this terminal is currently showing. 7729 */ 7730 hide(): void; 7731 7732 /** 7733 * Dispose and free associated resources. 7734 */ 7735 dispose(): void; 7736 } 7737 7738 /** 7739 * The location of the terminal. 7740 */ 7741 export enum TerminalLocation { 7742 /** 7743 * In the terminal view 7744 */ 7745 Panel = 1, 7746 /** 7747 * In the editor area 7748 */ 7749 Editor = 2, 7750 } 7751 7752 /** 7753 * Assumes a {@link TerminalLocation} of editor and allows specifying a {@link ViewColumn} and 7754 * {@link TerminalEditorLocationOptions.preserveFocus preserveFocus } property 7755 */ 7756 export interface TerminalEditorLocationOptions { 7757 /** 7758 * A view column in which the {@link Terminal terminal} should be shown in the editor area. 7759 * The default is the {@link ViewColumn.Active active}. Columns that do not exist 7760 * will be created as needed up to the maximum of {@linkcode ViewColumn.Nine}. 7761 * Use {@linkcode ViewColumn.Beside} to open the editor to the side of the currently 7762 * active one. 7763 */ 7764 viewColumn: ViewColumn; 7765 /** 7766 * An optional flag that when `true` will stop the {@link Terminal} from taking focus. 7767 */ 7768 preserveFocus?: boolean; 7769 } 7770 7771 /** 7772 * Uses the parent {@link Terminal}'s location for the terminal 7773 */ 7774 export interface TerminalSplitLocationOptions { 7775 /** 7776 * The parent terminal to split this terminal beside. This works whether the parent terminal 7777 * is in the panel or the editor area. 7778 */ 7779 parentTerminal: Terminal; 7780 } 7781 7782 /** 7783 * Represents the state of a {@link Terminal}. 7784 */ 7785 export interface TerminalState { 7786 /** 7787 * Whether the {@link Terminal} has been interacted with. Interaction means that the 7788 * terminal has sent data to the process which depending on the terminal's _mode_. By 7789 * default input is sent when a key is pressed or when a command or extension sends text, 7790 * but based on the terminal's mode it can also happen on: 7791 * 7792 * - a pointer click event 7793 * - a pointer scroll event 7794 * - a pointer move event 7795 * - terminal focus in/out 7796 * 7797 * For more information on events that can send data see "DEC Private Mode Set (DECSET)" on 7798 * https://invisible-island.net/xterm/ctlseqs/ctlseqs.html 7799 */ 7800 readonly isInteractedWith: boolean; 7801 7802 /** 7803 * The detected shell type of the {@link Terminal}. This will be `undefined` when there is 7804 * not a clear signal as to what the shell is, or the shell is not supported yet. This 7805 * value should change to the shell type of a sub-shell when launched (for example, running 7806 * `bash` inside `zsh`). 7807 * 7808 * Note that the possible values are currently defined as any of the following: 7809 * 'bash', 'cmd', 'csh', 'fish', 'gitbash', 'julia', 'ksh', 'node', 'nu', 'pwsh', 'python', 7810 * 'sh', 'wsl', 'xonsh', 'zsh'. 7811 */ 7812 readonly shell: string | undefined; 7813 } 7814 7815 /** 7816 * [Shell integration](https://code.visualstudio.com/docs/terminal/shell-integration)-powered capabilities owned by a terminal. 7817 */ 7818 export interface TerminalShellIntegration { 7819 /** 7820 * The current working directory of the terminal. This {@link Uri} may represent a file on 7821 * another machine (eg. ssh into another machine). This requires the shell integration to 7822 * support working directory reporting. 7823 */ 7824 readonly cwd: Uri | undefined; 7825 7826 /** 7827 * Execute a command, sending ^C as necessary to interrupt any running command if needed. 7828 * 7829 * @param commandLine The command line to execute, this is the exact text that will be sent 7830 * to the terminal. 7831 * 7832 * @throws When run on a terminal doesn't support this API, such as task terminals. 7833 * 7834 * @example 7835 * // Execute a command in a terminal immediately after being created 7836 * const myTerm = window.createTerminal(); 7837 * window.onDidChangeTerminalShellIntegration(async ({ terminal, shellIntegration }) => { 7838 * if (terminal === myTerm) { 7839 * const execution = shellIntegration.executeCommand('echo "Hello world"'); 7840 * window.onDidEndTerminalShellExecution(event => { 7841 * if (event.execution === execution) { 7842 * console.log(`Command exited with code ${event.exitCode}`); 7843 * } 7844 * }); 7845 * } 7846 * })); 7847 * // Fallback to sendText if there is no shell integration within 3 seconds of launching 7848 * setTimeout(() => { 7849 * if (!myTerm.shellIntegration) { 7850 * myTerm.sendText('echo "Hello world"'); 7851 * // Without shell integration, we can't know when the command has finished or what the 7852 * // exit code was. 7853 * } 7854 * }, 3000); 7855 * 7856 * @example 7857 * // Send command to terminal that has been alive for a while 7858 * const commandLine = 'echo "Hello world"'; 7859 * if (term.shellIntegration) { 7860 * const execution = shellIntegration.executeCommand({ commandLine }); 7861 * window.onDidEndTerminalShellExecution(event => { 7862 * if (event.execution === execution) { 7863 * console.log(`Command exited with code ${event.exitCode}`); 7864 * } 7865 * }); 7866 * } else { 7867 * term.sendText(commandLine); 7868 * // Without shell integration, we can't know when the command has finished or what the 7869 * // exit code was. 7870 * } 7871 */ 7872 executeCommand(commandLine: string): TerminalShellExecution; 7873 7874 /** 7875 * Execute a command, sending ^C as necessary to interrupt any running command if needed. 7876 * 7877 * *Note* This is not guaranteed to work as [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) 7878 * must be activated. Check whether {@link TerminalShellExecution.exitCode} is rejected to 7879 * verify whether it was successful. 7880 * 7881 * @param executable A command to run. 7882 * @param args Arguments to launch the executable with. The arguments will be escaped such 7883 * that they are interpreted as single arguments when the argument both contains whitespace 7884 * and does not include any single quote, double quote or backtick characters. 7885 * 7886 * Note that this escaping is not intended to be a security measure, be careful when passing 7887 * untrusted data to this API as strings like `$(...)` can often be used in shells to 7888 * execute code within a string. 7889 * 7890 * @example 7891 * // Execute a command in a terminal immediately after being created 7892 * const myTerm = window.createTerminal(); 7893 * window.onDidChangeTerminalShellIntegration(async ({ terminal, shellIntegration }) => { 7894 * if (terminal === myTerm) { 7895 * const command = shellIntegration.executeCommand({ 7896 * command: 'echo', 7897 * args: ['Hello world'] 7898 * }); 7899 * const code = await command.exitCode; 7900 * console.log(`Command exited with code ${code}`); 7901 * } 7902 * })); 7903 * // Fallback to sendText if there is no shell integration within 3 seconds of launching 7904 * setTimeout(() => { 7905 * if (!myTerm.shellIntegration) { 7906 * myTerm.sendText('echo "Hello world"'); 7907 * // Without shell integration, we can't know when the command has finished or what the 7908 * // exit code was. 7909 * } 7910 * }, 3000); 7911 * 7912 * @example 7913 * // Send command to terminal that has been alive for a while 7914 * const commandLine = 'echo "Hello world"'; 7915 * if (term.shellIntegration) { 7916 * const command = term.shellIntegration.executeCommand({ 7917 * command: 'echo', 7918 * args: ['Hello world'] 7919 * }); 7920 * const code = await command.exitCode; 7921 * console.log(`Command exited with code ${code}`); 7922 * } else { 7923 * term.sendText(commandLine); 7924 * // Without shell integration, we can't know when the command has finished or what the 7925 * // exit code was. 7926 * } 7927 */ 7928 executeCommand(executable: string, args: string[]): TerminalShellExecution; 7929 } 7930 7931 /** 7932 * A command that was executed in a terminal. 7933 */ 7934 export interface TerminalShellExecution { 7935 /** 7936 * The command line that was executed. The {@link TerminalShellExecutionCommandLineConfidence confidence} 7937 * of this value depends on the specific shell's shell integration implementation. This 7938 * value may become more accurate after {@link window.onDidEndTerminalShellExecution} is 7939 * fired. 7940 * 7941 * @example 7942 * // Log the details of the command line on start and end 7943 * window.onDidStartTerminalShellExecution(event => { 7944 * const commandLine = event.execution.commandLine; 7945 * console.log(`Command started\n${summarizeCommandLine(commandLine)}`); 7946 * }); 7947 * window.onDidEndTerminalShellExecution(event => { 7948 * const commandLine = event.execution.commandLine; 7949 * console.log(`Command ended\n${summarizeCommandLine(commandLine)}`); 7950 * }); 7951 * function summarizeCommandLine(commandLine: TerminalShellExecutionCommandLine) { 7952 * return [ 7953 * ` Command line: ${command.commandLine.value}`, 7954 * ` Confidence: ${command.commandLine.confidence}`, 7955 * ` Trusted: ${command.commandLine.isTrusted} 7956 * ].join('\n'); 7957 * } 7958 */ 7959 readonly commandLine: TerminalShellExecutionCommandLine; 7960 7961 /** 7962 * The working directory that was reported by the shell when this command executed. This 7963 * {@link Uri} may represent a file on another machine (eg. ssh into another machine). This 7964 * requires the shell integration to support working directory reporting. 7965 */ 7966 readonly cwd: Uri | undefined; 7967 7968 /** 7969 * Creates a stream of raw data (including escape sequences) that is written to the 7970 * terminal. This will only include data that was written after `read` was called for 7971 * the first time, ie. you must call `read` immediately after the command is executed via 7972 * {@link TerminalShellIntegration.executeCommand} or 7973 * {@link window.onDidStartTerminalShellExecution} to not miss any data. 7974 * 7975 * @example 7976 * // Log all data written to the terminal for a command 7977 * const command = term.shellIntegration.executeCommand({ commandLine: 'echo "Hello world"' }); 7978 * const stream = command.read(); 7979 * for await (const data of stream) { 7980 * console.log(data); 7981 * } 7982 */ 7983 read(): AsyncIterable<string>; 7984 } 7985 7986 /** 7987 * A command line that was executed in a terminal. 7988 */ 7989 export interface TerminalShellExecutionCommandLine { 7990 /** 7991 * The full command line that was executed, including both the command and its arguments. 7992 */ 7993 readonly value: string; 7994 7995 /** 7996 * Whether the command line value came from a trusted source and is therefore safe to 7997 * execute without user additional confirmation, such as a notification that asks "Do you 7998 * want to execute (command)?". This verification is likely only needed if you are going to 7999 * execute the command again. 8000 * 8001 * This is `true` only when the command line was reported explicitly by the shell 8002 * integration script (ie. {@link TerminalShellExecutionCommandLineConfidence.High high confidence}) 8003 * and it used a nonce for verification. 8004 */ 8005 readonly isTrusted: boolean; 8006 8007 /** 8008 * The confidence of the command line value which is determined by how the value was 8009 * obtained. This depends upon the implementation of the shell integration script. 8010 */ 8011 readonly confidence: TerminalShellExecutionCommandLineConfidence; 8012 } 8013 8014 /** 8015 * The confidence of a {@link TerminalShellExecutionCommandLine} value. 8016 */ 8017 export enum TerminalShellExecutionCommandLineConfidence { 8018 /** 8019 * The command line value confidence is low. This means that the value was read from the 8020 * terminal buffer using markers reported by the shell integration script. Additionally one 8021 * of the following conditions will be met: 8022 * 8023 * - The command started on the very left-most column which is unusual, or 8024 * - The command is multi-line which is more difficult to accurately detect due to line 8025 * continuation characters and right prompts. 8026 * - Command line markers were not reported by the shell integration script. 8027 */ 8028 Low = 0, 8029 8030 /** 8031 * The command line value confidence is medium. This means that the value was read from the 8032 * terminal buffer using markers reported by the shell integration script. The command is 8033 * single-line and does not start on the very left-most column (which is unusual). 8034 */ 8035 Medium = 1, 8036 8037 /** 8038 * The command line value confidence is high. This means that the value was explicitly sent 8039 * from the shell integration script or the command was executed via the 8040 * {@link TerminalShellIntegration.executeCommand} API. 8041 */ 8042 High = 2 8043 } 8044 8045 /** 8046 * An event signalling that a terminal's shell integration has changed. 8047 */ 8048 export interface TerminalShellIntegrationChangeEvent { 8049 /** 8050 * The terminal that shell integration has been activated in. 8051 */ 8052 readonly terminal: Terminal; 8053 8054 /** 8055 * The shell integration object. 8056 */ 8057 readonly shellIntegration: TerminalShellIntegration; 8058 } 8059 8060 /** 8061 * An event signalling that an execution has started in a terminal. 8062 */ 8063 export interface TerminalShellExecutionStartEvent { 8064 /** 8065 * The terminal that shell integration has been activated in. 8066 */ 8067 readonly terminal: Terminal; 8068 8069 /** 8070 * The shell integration object. 8071 */ 8072 readonly shellIntegration: TerminalShellIntegration; 8073 8074 /** 8075 * The terminal shell execution that has ended. 8076 */ 8077 readonly execution: TerminalShellExecution; 8078 } 8079 8080 /** 8081 * An event signalling that an execution has ended in a terminal. 8082 */ 8083 export interface TerminalShellExecutionEndEvent { 8084 /** 8085 * The terminal that shell integration has been activated in. 8086 */ 8087 readonly terminal: Terminal; 8088 8089 /** 8090 * The shell integration object. 8091 */ 8092 readonly shellIntegration: TerminalShellIntegration; 8093 8094 /** 8095 * The terminal shell execution that has ended. 8096 */ 8097 readonly execution: TerminalShellExecution; 8098 8099 /** 8100 * The exit code reported by the shell. 8101 * 8102 * When this is `undefined` it can mean several things: 8103 * 8104 * - The shell either did not report an exit code (ie. the shell integration script is 8105 * misbehaving) 8106 * - The shell reported a command started before the command finished (eg. a sub-shell was 8107 * opened). 8108 * - The user canceled the command via ctrl+c. 8109 * - The user pressed enter when there was no input. 8110 * 8111 * Generally this should not happen. Depending on the use case, it may be best to treat this 8112 * as a failure. 8113 * 8114 * @example 8115 * const execution = shellIntegration.executeCommand({ 8116 * command: 'echo', 8117 * args: ['Hello world'] 8118 * }); 8119 * window.onDidEndTerminalShellExecution(event => { 8120 * if (event.execution === execution) { 8121 * if (event.exitCode === undefined) { 8122 * console.log('Command finished but exit code is unknown'); 8123 * } else if (event.exitCode === 0) { 8124 * console.log('Command succeeded'); 8125 * } else { 8126 * console.log('Command failed'); 8127 * } 8128 * } 8129 * }); 8130 */ 8131 readonly exitCode: number | undefined; 8132 } 8133 8134 /** 8135 * Provides information on a line in a terminal in order to provide links for it. 8136 */ 8137 export interface TerminalLinkContext { 8138 /** 8139 * This is the text from the unwrapped line in the terminal. 8140 */ 8141 line: string; 8142 8143 /** 8144 * The terminal the link belongs to. 8145 */ 8146 terminal: Terminal; 8147 } 8148 8149 /** 8150 * A provider that enables detection and handling of links within terminals. 8151 */ 8152 export interface TerminalLinkProvider<T extends TerminalLink = TerminalLink> { 8153 /** 8154 * Provide terminal links for the given context. Note that this can be called multiple times 8155 * even before previous calls resolve, make sure to not share global objects (eg. `RegExp`) 8156 * that could have problems when asynchronous usage may overlap. 8157 * @param context Information about what links are being provided for. 8158 * @param token A cancellation token. 8159 * @returns A list of terminal links for the given line. 8160 */ 8161 provideTerminalLinks(context: TerminalLinkContext, token: CancellationToken): ProviderResult<T[]>; 8162 8163 /** 8164 * Handle an activated terminal link. 8165 * @param link The link to handle. 8166 */ 8167 handleTerminalLink(link: T): ProviderResult<void>; 8168 } 8169 8170 /** 8171 * A link on a terminal line. 8172 */ 8173 export class TerminalLink { 8174 /** 8175 * The start index of the link on {@link TerminalLinkContext.line}. 8176 */ 8177 startIndex: number; 8178 8179 /** 8180 * The length of the link on {@link TerminalLinkContext.line}. 8181 */ 8182 length: number; 8183 8184 /** 8185 * The tooltip text when you hover over this link. 8186 * 8187 * If a tooltip is provided, is will be displayed in a string that includes instructions on 8188 * how to trigger the link, such as `{0} (ctrl + click)`. The specific instructions vary 8189 * depending on OS, user settings, and localization. 8190 */ 8191 tooltip?: string; 8192 8193 /** 8194 * Creates a new terminal link. 8195 * @param startIndex The start index of the link on {@link TerminalLinkContext.line}. 8196 * @param length The length of the link on {@link TerminalLinkContext.line}. 8197 * @param tooltip The tooltip text when you hover over this link. 8198 * 8199 * If a tooltip is provided, is will be displayed in a string that includes instructions on 8200 * how to trigger the link, such as `{0} (ctrl + click)`. The specific instructions vary 8201 * depending on OS, user settings, and localization. 8202 */ 8203 constructor(startIndex: number, length: number, tooltip?: string); 8204 } 8205 8206 /** 8207 * Provides a terminal profile for the contributed terminal profile when launched via the UI or 8208 * command. 8209 */ 8210 export interface TerminalProfileProvider { 8211 /** 8212 * Provide the terminal profile. 8213 * @param token A cancellation token that indicates the result is no longer needed. 8214 * @returns The terminal profile. 8215 */ 8216 provideTerminalProfile(token: CancellationToken): ProviderResult<TerminalProfile>; 8217 } 8218 8219 /** 8220 * A terminal profile defines how a terminal will be launched. 8221 */ 8222 export class TerminalProfile { 8223 /** 8224 * The options that the terminal will launch with. 8225 */ 8226 options: TerminalOptions | ExtensionTerminalOptions; 8227 8228 /** 8229 * Creates a new terminal profile. 8230 * @param options The options that the terminal will launch with. 8231 */ 8232 constructor(options: TerminalOptions | ExtensionTerminalOptions); 8233 } 8234 8235 /** 8236 * A file decoration represents metadata that can be rendered with a file. 8237 */ 8238 export class FileDecoration { 8239 8240 /** 8241 * A very short string that represents this decoration. 8242 */ 8243 badge?: string; 8244 8245 /** 8246 * A human-readable tooltip for this decoration. 8247 */ 8248 tooltip?: string; 8249 8250 /** 8251 * The color of this decoration. 8252 */ 8253 color?: ThemeColor; 8254 8255 /** 8256 * A flag expressing that this decoration should be 8257 * propagated to its parents. 8258 */ 8259 propagate?: boolean; 8260 8261 /** 8262 * Creates a new decoration. 8263 * 8264 * @param badge A letter that represents the decoration. 8265 * @param tooltip The tooltip of the decoration. 8266 * @param color The color of the decoration. 8267 */ 8268 constructor(badge?: string, tooltip?: string, color?: ThemeColor); 8269 } 8270 8271 /** 8272 * The decoration provider interfaces defines the contract between extensions and 8273 * file decorations. 8274 */ 8275 export interface FileDecorationProvider { 8276 8277 /** 8278 * An optional event to signal that decorations for one or many files have changed. 8279 * 8280 * *Note* that this event should be used to propagate information about children. 8281 * 8282 * @see {@link EventEmitter} 8283 */ 8284 onDidChangeFileDecorations?: Event<undefined | Uri | Uri[]>; 8285 8286 /** 8287 * Provide decorations for a given uri. 8288 * 8289 * *Note* that this function is only called when a file gets rendered in the UI. 8290 * This means a decoration from a descendent that propagates upwards must be signaled 8291 * to the editor via the {@link FileDecorationProvider.onDidChangeFileDecorations onDidChangeFileDecorations}-event. 8292 * 8293 * @param uri The uri of the file to provide a decoration for. 8294 * @param token A cancellation token. 8295 * @returns A decoration or a thenable that resolves to such. 8296 */ 8297 provideFileDecoration(uri: Uri, token: CancellationToken): ProviderResult<FileDecoration>; 8298 } 8299 8300 8301 /** 8302 * In a remote window the extension kind describes if an extension 8303 * runs where the UI (window) runs or if an extension runs remotely. 8304 */ 8305 export enum ExtensionKind { 8306 8307 /** 8308 * Extension runs where the UI runs. 8309 */ 8310 UI = 1, 8311 8312 /** 8313 * Extension runs where the remote extension host runs. 8314 */ 8315 Workspace = 2 8316 } 8317 8318 /** 8319 * Represents an extension. 8320 * 8321 * To get an instance of an `Extension` use {@link extensions.getExtension getExtension}. 8322 */ 8323 export interface Extension<T> { 8324 8325 /** 8326 * The canonical extension identifier in the form of: `publisher.name`. 8327 */ 8328 readonly id: string; 8329 8330 /** 8331 * The uri of the directory containing the extension. 8332 */ 8333 readonly extensionUri: Uri; 8334 8335 /** 8336 * The absolute file path of the directory containing this extension. Shorthand 8337 * notation for {@link Extension.extensionUri Extension.extensionUri.fsPath} (independent of the uri scheme). 8338 */ 8339 readonly extensionPath: string; 8340 8341 /** 8342 * `true` if the extension has been activated. 8343 */ 8344 readonly isActive: boolean; 8345 8346 /** 8347 * The parsed contents of the extension's package.json. 8348 */ 8349 readonly packageJSON: any; 8350 8351 /** 8352 * The extension kind describes if an extension runs where the UI runs 8353 * or if an extension runs where the remote extension host runs. The extension kind 8354 * is defined in the `package.json`-file of extensions but can also be refined 8355 * via the `remote.extensionKind`-setting. When no remote extension host exists, 8356 * the value is {@linkcode ExtensionKind.UI}. 8357 */ 8358 extensionKind: ExtensionKind; 8359 8360 /** 8361 * The public API exported by this extension (return value of `activate`). 8362 * It is an invalid action to access this field before this extension has been activated. 8363 */ 8364 readonly exports: T; 8365 8366 /** 8367 * Activates this extension and returns its public API. 8368 * 8369 * @returns A promise that will resolve when this extension has been activated. 8370 */ 8371 activate(): Thenable<T>; 8372 } 8373 8374 /** 8375 * The ExtensionMode is provided on the `ExtensionContext` and indicates the 8376 * mode the specific extension is running in. 8377 */ 8378 export enum ExtensionMode { 8379 /** 8380 * The extension is installed normally (for example, from the marketplace 8381 * or VSIX) in the editor. 8382 */ 8383 Production = 1, 8384 8385 /** 8386 * The extension is running from an `--extensionDevelopmentPath` provided 8387 * when launching the editor. 8388 */ 8389 Development = 2, 8390 8391 /** 8392 * The extension is running from an `--extensionTestsPath` and 8393 * the extension host is running unit tests. 8394 */ 8395 Test = 3, 8396 } 8397 8398 /** 8399 * An extension context is a collection of utilities private to an 8400 * extension. 8401 * 8402 * An instance of an `ExtensionContext` is provided as the first 8403 * parameter to the `activate`-call of an extension. 8404 */ 8405 export interface ExtensionContext { 8406 8407 /** 8408 * An array to which disposables can be added. When this 8409 * extension is deactivated the disposables will be disposed. 8410 * 8411 * *Note* that asynchronous dispose-functions aren't awaited. 8412 */ 8413 readonly subscriptions: { 8414 /** 8415 * Function to clean up resources. 8416 */ 8417 dispose(): any; 8418 }[]; 8419 8420 /** 8421 * A memento object that stores state in the context 8422 * of the currently opened {@link workspace.workspaceFolders workspace}. 8423 */ 8424 readonly workspaceState: Memento; 8425 8426 /** 8427 * A memento object that stores state independent 8428 * of the current opened {@link workspace.workspaceFolders workspace}. 8429 */ 8430 readonly globalState: Memento & { 8431 /** 8432 * Set the keys whose values should be synchronized across devices when synchronizing user-data 8433 * like configuration, extensions, and mementos. 8434 * 8435 * Note that this function defines the whole set of keys whose values are synchronized: 8436 * - calling it with an empty array stops synchronization for this memento 8437 * - calling it with a non-empty array replaces all keys whose values are synchronized 8438 * 8439 * For any given set of keys this function needs to be called only once but there is no harm in 8440 * repeatedly calling it. 8441 * 8442 * @param keys The set of keys whose values are synced. 8443 */ 8444 setKeysForSync(keys: readonly string[]): void; 8445 }; 8446 8447 /** 8448 * A secret storage object that stores state independent 8449 * of the current opened {@link workspace.workspaceFolders workspace}. 8450 */ 8451 readonly secrets: SecretStorage; 8452 8453 /** 8454 * The uri of the directory containing the extension. 8455 */ 8456 readonly extensionUri: Uri; 8457 8458 /** 8459 * The absolute file path of the directory containing the extension. Shorthand 8460 * notation for {@link TextDocument.uri ExtensionContext.extensionUri.fsPath} (independent of the uri scheme). 8461 */ 8462 readonly extensionPath: string; 8463 8464 /** 8465 * Gets the extension's global environment variable collection for this workspace, enabling changes to be 8466 * applied to terminal environment variables. 8467 */ 8468 readonly environmentVariableCollection: GlobalEnvironmentVariableCollection; 8469 8470 /** 8471 * Get the absolute path of a resource contained in the extension. 8472 * 8473 * *Note* that an absolute uri can be constructed via {@linkcode Uri.joinPath} and 8474 * {@linkcode ExtensionContext.extensionUri extensionUri}, e.g. `vscode.Uri.joinPath(context.extensionUri, relativePath);` 8475 * 8476 * @param relativePath A relative path to a resource contained in the extension. 8477 * @returns The absolute path of the resource. 8478 */ 8479 asAbsolutePath(relativePath: string): string; 8480 8481 /** 8482 * The uri of a workspace specific directory in which the extension 8483 * can store private state. The directory might not exist and creation is 8484 * up to the extension. However, the parent directory is guaranteed to be existent. 8485 * The value is `undefined` when no workspace nor folder has been opened. 8486 * 8487 * Use {@linkcode ExtensionContext.workspaceState workspaceState} or 8488 * {@linkcode ExtensionContext.globalState globalState} to store key value data. 8489 * 8490 * @see {@linkcode FileSystem workspace.fs} for how to read and write files and folders from 8491 * a uri. 8492 */ 8493 readonly storageUri: Uri | undefined; 8494 8495 /** 8496 * An absolute file path of a workspace specific directory in which the extension 8497 * can store private state. The directory might not exist on disk and creation is 8498 * up to the extension. However, the parent directory is guaranteed to be existent. 8499 * 8500 * Use {@linkcode ExtensionContext.workspaceState workspaceState} or 8501 * {@linkcode ExtensionContext.globalState globalState} to store key value data. 8502 * 8503 * @deprecated Use {@link ExtensionContext.storageUri storageUri} instead. 8504 */ 8505 readonly storagePath: string | undefined; 8506 8507 /** 8508 * The uri of a directory in which the extension can store global state. 8509 * The directory might not exist on disk and creation is 8510 * up to the extension. However, the parent directory is guaranteed to be existent. 8511 * 8512 * Use {@linkcode ExtensionContext.globalState globalState} to store key value data. 8513 * 8514 * @see {@linkcode FileSystem workspace.fs} for how to read and write files and folders from 8515 * an uri. 8516 */ 8517 readonly globalStorageUri: Uri; 8518 8519 /** 8520 * An absolute file path in which the extension can store global state. 8521 * The directory might not exist on disk and creation is 8522 * up to the extension. However, the parent directory is guaranteed to be existent. 8523 * 8524 * Use {@linkcode ExtensionContext.globalState globalState} to store key value data. 8525 * 8526 * @deprecated Use {@link ExtensionContext.globalStorageUri globalStorageUri} instead. 8527 */ 8528 readonly globalStoragePath: string; 8529 8530 /** 8531 * The uri of a directory in which the extension can create log files. 8532 * The directory might not exist on disk and creation is up to the extension. However, 8533 * the parent directory is guaranteed to be existent. 8534 * 8535 * @see {@linkcode FileSystem workspace.fs} for how to read and write files and folders from 8536 * an uri. 8537 */ 8538 readonly logUri: Uri; 8539 8540 /** 8541 * An absolute file path of a directory in which the extension can create log files. 8542 * The directory might not exist on disk and creation is up to the extension. However, 8543 * the parent directory is guaranteed to be existent. 8544 * 8545 * @deprecated Use {@link ExtensionContext.logUri logUri} instead. 8546 */ 8547 readonly logPath: string; 8548 8549 /** 8550 * The mode the extension is running in. See {@link ExtensionMode} 8551 * for possible values and scenarios. 8552 */ 8553 readonly extensionMode: ExtensionMode; 8554 8555 /** 8556 * The current `Extension` instance. 8557 */ 8558 readonly extension: Extension<any>; 8559 8560 /** 8561 * An object that keeps information about how this extension can use language models. 8562 * 8563 * @see {@link LanguageModelChat.sendRequest} 8564 */ 8565 readonly languageModelAccessInformation: LanguageModelAccessInformation; 8566 } 8567 8568 /** 8569 * A memento represents a storage utility. It can store and retrieve 8570 * values. 8571 */ 8572 export interface Memento { 8573 8574 /** 8575 * Returns the stored keys. 8576 * 8577 * @returns The stored keys. 8578 */ 8579 keys(): readonly string[]; 8580 8581 /** 8582 * Return a value. 8583 * 8584 * @param key A string. 8585 * @returns The stored value or `undefined`. 8586 */ 8587 get<T>(key: string): T | undefined; 8588 8589 /** 8590 * Return a value. 8591 * 8592 * @param key A string. 8593 * @param defaultValue A value that should be returned when there is no 8594 * value (`undefined`) with the given key. 8595 * @returns The stored value or the defaultValue. 8596 */ 8597 get<T>(key: string, defaultValue: T): T; 8598 8599 /** 8600 * Store a value. The value must be JSON-stringifyable. 8601 * 8602 * *Note* that using `undefined` as value removes the key from the underlying 8603 * storage. 8604 * 8605 * @param key A string. 8606 * @param value A value. MUST not contain cyclic references. 8607 */ 8608 update(key: string, value: any): Thenable<void>; 8609 } 8610 8611 /** 8612 * The event data that is fired when a secret is added or removed. 8613 */ 8614 export interface SecretStorageChangeEvent { 8615 /** 8616 * The key of the secret that has changed. 8617 */ 8618 readonly key: string; 8619 } 8620 8621 /** 8622 * Represents a storage utility for secrets (or any information that is sensitive) 8623 * that will be stored encrypted. The implementation of the secret storage will 8624 * be different on each platform and the secrets will not be synced across 8625 * machines. 8626 */ 8627 export interface SecretStorage { 8628 /** 8629 * Retrieve the keys of all the secrets stored by this extension. 8630 */ 8631 keys(): Thenable<string[]>; 8632 8633 /** 8634 * Retrieve a secret that was stored with key. Returns undefined if there 8635 * is no password matching that key. 8636 * @param key The key the secret was stored under. 8637 * @returns The stored value or `undefined`. 8638 */ 8639 get(key: string): Thenable<string | undefined>; 8640 8641 /** 8642 * Store a secret under a given key. 8643 * @param key The key to store the secret under. 8644 * @param value The secret. 8645 */ 8646 store(key: string, value: string): Thenable<void>; 8647 8648 /** 8649 * Remove a secret from storage. 8650 * @param key The key the secret was stored under. 8651 */ 8652 delete(key: string): Thenable<void>; 8653 8654 /** 8655 * Fires when a secret is stored or deleted. 8656 */ 8657 readonly onDidChange: Event<SecretStorageChangeEvent>; 8658 } 8659 8660 /** 8661 * Represents a color theme kind. 8662 */ 8663 export enum ColorThemeKind { 8664 /** 8665 * A light color theme. 8666 */ 8667 Light = 1, 8668 /** 8669 * A dark color theme. 8670 */ 8671 Dark = 2, 8672 /** 8673 * A dark high contrast color theme. 8674 */ 8675 HighContrast = 3, 8676 /** 8677 * A light high contrast color theme. 8678 */ 8679 HighContrastLight = 4 8680 } 8681 8682 /** 8683 * Represents a color theme. 8684 */ 8685 export interface ColorTheme { 8686 8687 /** 8688 * The kind of this color theme: light, dark, high contrast dark and high contrast light. 8689 */ 8690 readonly kind: ColorThemeKind; 8691 } 8692 8693 /** 8694 * Controls the behaviour of the terminal's visibility. 8695 */ 8696 export enum TaskRevealKind { 8697 /** 8698 * Always brings the terminal to front if the task is executed. 8699 */ 8700 Always = 1, 8701 8702 /** 8703 * Only brings the terminal to front if a problem is detected executing the task 8704 * (e.g. the task couldn't be started because). 8705 */ 8706 Silent = 2, 8707 8708 /** 8709 * The terminal never comes to front when the task is executed. 8710 */ 8711 Never = 3 8712 } 8713 8714 /** 8715 * Controls how the task channel is used between tasks 8716 */ 8717 export enum TaskPanelKind { 8718 8719 /** 8720 * Shares a panel with other tasks. This is the default. 8721 */ 8722 Shared = 1, 8723 8724 /** 8725 * Uses a dedicated panel for this tasks. The panel is not 8726 * shared with other tasks. 8727 */ 8728 Dedicated = 2, 8729 8730 /** 8731 * Creates a new panel whenever this task is executed. 8732 */ 8733 New = 3 8734 } 8735 8736 /** 8737 * Controls how the task is presented in the UI. 8738 */ 8739 export interface TaskPresentationOptions { 8740 /** 8741 * Controls whether the task output is reveal in the user interface. 8742 * Defaults to `RevealKind.Always`. 8743 */ 8744 reveal?: TaskRevealKind; 8745 8746 /** 8747 * Controls whether the command associated with the task is echoed 8748 * in the user interface. 8749 */ 8750 echo?: boolean; 8751 8752 /** 8753 * Controls whether the panel showing the task output is taking focus. 8754 */ 8755 focus?: boolean; 8756 8757 /** 8758 * Controls if the task panel is used for this task only (dedicated), 8759 * shared between tasks (shared) or if a new panel is created on 8760 * every task execution (new). Defaults to `TaskInstanceKind.Shared` 8761 */ 8762 panel?: TaskPanelKind; 8763 8764 /** 8765 * Controls whether to show the "Terminal will be reused by tasks, press any key to close it" message. 8766 */ 8767 showReuseMessage?: boolean; 8768 8769 /** 8770 * Controls whether the terminal is cleared before executing the task. 8771 */ 8772 clear?: boolean; 8773 8774 /** 8775 * Controls whether the terminal is closed after executing the task. 8776 */ 8777 close?: boolean; 8778 } 8779 8780 /** 8781 * A grouping for tasks. The editor by default supports the 8782 * 'Clean', 'Build', 'RebuildAll' and 'Test' group. 8783 */ 8784 export class TaskGroup { 8785 8786 /** 8787 * The clean task group; 8788 */ 8789 static Clean: TaskGroup; 8790 8791 /** 8792 * The build task group; 8793 */ 8794 static Build: TaskGroup; 8795 8796 /** 8797 * The rebuild all task group; 8798 */ 8799 static Rebuild: TaskGroup; 8800 8801 /** 8802 * The test all task group; 8803 */ 8804 static Test: TaskGroup; 8805 8806 /** 8807 * Whether the task that is part of this group is the default for the group. 8808 * This property cannot be set through API, and is controlled by a user's task configurations. 8809 */ 8810 readonly isDefault: boolean | undefined; 8811 8812 /** 8813 * The ID of the task group. Is one of TaskGroup.Clean.id, TaskGroup.Build.id, TaskGroup.Rebuild.id, or TaskGroup.Test.id. 8814 */ 8815 readonly id: string; 8816 8817 /** 8818 * Private constructor 8819 * 8820 * @param id Identifier of a task group. 8821 * @param label The human-readable name of a task group. 8822 */ 8823 private constructor(id: string, label: string); 8824 } 8825 8826 /** 8827 * A structure that defines a task kind in the system. 8828 * The value must be JSON-stringifyable. 8829 */ 8830 export interface TaskDefinition { 8831 /** 8832 * The task definition describing the task provided by an extension. 8833 * Usually a task provider defines more properties to identify 8834 * a task. They need to be defined in the package.json of the 8835 * extension under the 'taskDefinitions' extension point. The npm 8836 * task definition for example looks like this 8837 * ```typescript 8838 * interface NpmTaskDefinition extends TaskDefinition { 8839 * script: string; 8840 * } 8841 * ``` 8842 * 8843 * Note that type identifier starting with a '$' are reserved for internal 8844 * usages and shouldn't be used by extensions. 8845 */ 8846 readonly type: string; 8847 8848 /** 8849 * Additional attributes of a concrete task definition. 8850 */ 8851 [name: string]: any; 8852 } 8853 8854 /** 8855 * Options for a process execution 8856 */ 8857 export interface ProcessExecutionOptions { 8858 /** 8859 * The current working directory of the executed program or shell. 8860 * If omitted the tools current workspace root is used. 8861 */ 8862 cwd?: string; 8863 8864 /** 8865 * The additional environment of the executed program or shell. If omitted 8866 * the parent process' environment is used. If provided it is merged with 8867 * the parent process' environment. 8868 */ 8869 env?: { [key: string]: string }; 8870 } 8871 8872 /** 8873 * The execution of a task happens as an external process 8874 * without shell interaction. 8875 */ 8876 export class ProcessExecution { 8877 8878 /** 8879 * Creates a process execution. 8880 * 8881 * @param process The process to start. 8882 * @param options Optional options for the started process. 8883 */ 8884 constructor(process: string, options?: ProcessExecutionOptions); 8885 8886 /** 8887 * Creates a process execution. 8888 * 8889 * @param process The process to start. 8890 * @param args Arguments to be passed to the process. 8891 * @param options Optional options for the started process. 8892 */ 8893 constructor(process: string, args: string[], options?: ProcessExecutionOptions); 8894 8895 /** 8896 * The process to be executed. 8897 */ 8898 process: string; 8899 8900 /** 8901 * The arguments passed to the process. Defaults to an empty array. 8902 */ 8903 args: string[]; 8904 8905 /** 8906 * The process options used when the process is executed. 8907 * Defaults to undefined. 8908 */ 8909 options?: ProcessExecutionOptions; 8910 } 8911 8912 /** 8913 * The shell quoting options. 8914 */ 8915 export interface ShellQuotingOptions { 8916 8917 /** 8918 * The character used to do character escaping. If a string is provided only spaces 8919 * are escaped. If a `{ escapeChar, charsToEscape }` literal is provide all characters 8920 * in `charsToEscape` are escaped using the `escapeChar`. 8921 */ 8922 escape?: string | { 8923 /** 8924 * The escape character. 8925 */ 8926 escapeChar: string; 8927 /** 8928 * The characters to escape. 8929 */ 8930 charsToEscape: string; 8931 }; 8932 8933 /** 8934 * The character used for strong quoting. The string's length must be 1. 8935 */ 8936 strong?: string; 8937 8938 /** 8939 * The character used for weak quoting. The string's length must be 1. 8940 */ 8941 weak?: string; 8942 } 8943 8944 /** 8945 * Options for a shell execution 8946 */ 8947 export interface ShellExecutionOptions { 8948 /** 8949 * The shell executable. 8950 */ 8951 executable?: string; 8952 8953 /** 8954 * The arguments to be passed to the shell executable used to run the task. Most shells 8955 * require special arguments to execute a command. For example `bash` requires the `-c` 8956 * argument to execute a command, `PowerShell` requires `-Command` and `cmd` requires both 8957 * `/d` and `/c`. 8958 */ 8959 shellArgs?: string[]; 8960 8961 /** 8962 * The shell quotes supported by this shell. 8963 */ 8964 shellQuoting?: ShellQuotingOptions; 8965 8966 /** 8967 * The current working directory of the executed shell. 8968 * If omitted the tools current workspace root is used. 8969 */ 8970 cwd?: string; 8971 8972 /** 8973 * The additional environment of the executed shell. If omitted 8974 * the parent process' environment is used. If provided it is merged with 8975 * the parent process' environment. 8976 */ 8977 env?: { [key: string]: string }; 8978 } 8979 8980 /** 8981 * Defines how an argument should be quoted if it contains 8982 * spaces or unsupported characters. 8983 */ 8984 export enum ShellQuoting { 8985 8986 /** 8987 * Character escaping should be used. This for example 8988 * uses \ on bash and ` on PowerShell. 8989 */ 8990 Escape = 1, 8991 8992 /** 8993 * Strong string quoting should be used. This for example 8994 * uses " for Windows cmd and ' for bash and PowerShell. 8995 * Strong quoting treats arguments as literal strings. 8996 * Under PowerShell echo 'The value is $(2 * 3)' will 8997 * print `The value is $(2 * 3)` 8998 */ 8999 Strong = 2, 9000 9001 /** 9002 * Weak string quoting should be used. This for example 9003 * uses " for Windows cmd, bash and PowerShell. Weak quoting 9004 * still performs some kind of evaluation inside the quoted 9005 * string. Under PowerShell echo "The value is $(2 * 3)" 9006 * will print `The value is 6` 9007 */ 9008 Weak = 3 9009 } 9010 9011 /** 9012 * A string that will be quoted depending on the used shell. 9013 */ 9014 export interface ShellQuotedString { 9015 /** 9016 * The actual string value. 9017 */ 9018 value: string; 9019 9020 /** 9021 * The quoting style to use. 9022 */ 9023 quoting: ShellQuoting; 9024 } 9025 9026 /** 9027 * Represents a task execution that happens inside a shell. 9028 */ 9029 export class ShellExecution { 9030 /** 9031 * Creates a shell execution with a full command line. 9032 * 9033 * @param commandLine The command line to execute. 9034 * @param options Optional options for the started the shell. 9035 */ 9036 constructor(commandLine: string, options?: ShellExecutionOptions); 9037 9038 /** 9039 * Creates a shell execution with a command and arguments. For the real execution the editor will 9040 * construct a command line from the command and the arguments. This is subject to interpretation 9041 * especially when it comes to quoting. If full control over the command line is needed please 9042 * use the constructor that creates a `ShellExecution` with the full command line. 9043 * 9044 * @param command The command to execute. 9045 * @param args The command arguments. 9046 * @param options Optional options for the started the shell. 9047 */ 9048 constructor(command: string | ShellQuotedString, args: Array<string | ShellQuotedString>, options?: ShellExecutionOptions); 9049 9050 /** 9051 * The shell command line. Is `undefined` if created with a command and arguments. 9052 */ 9053 commandLine: string | undefined; 9054 9055 /** 9056 * The shell command. Is `undefined` if created with a full command line. 9057 */ 9058 command: string | ShellQuotedString | undefined; 9059 9060 /** 9061 * The shell args. Is `undefined` if created with a full command line. 9062 */ 9063 args: Array<string | ShellQuotedString> | undefined; 9064 9065 /** 9066 * The shell options used when the command line is executed in a shell. 9067 * Defaults to undefined. 9068 */ 9069 options?: ShellExecutionOptions; 9070 } 9071 9072 /** 9073 * Class used to execute an extension callback as a task. 9074 */ 9075 export class CustomExecution { 9076 /** 9077 * Constructs a CustomExecution task object. The callback will be executed when the task is run, at which point the 9078 * extension should return the Pseudoterminal it will "run in". The task should wait to do further execution until 9079 * {@link Pseudoterminal.open} is called. Task cancellation should be handled using 9080 * {@link Pseudoterminal.close}. When the task is complete fire 9081 * {@link Pseudoterminal.onDidClose}. 9082 * @param callback The callback that will be called when the task is started by a user. Any ${} style variables that 9083 * were in the task definition will be resolved and passed into the callback as `resolvedDefinition`. 9084 */ 9085 constructor(callback: (resolvedDefinition: TaskDefinition) => Thenable<Pseudoterminal>); 9086 } 9087 9088 /** 9089 * The scope of a task. 9090 */ 9091 export enum TaskScope { 9092 /** 9093 * The task is a global task. Global tasks are currently not supported. 9094 */ 9095 Global = 1, 9096 9097 /** 9098 * The task is a workspace task 9099 */ 9100 Workspace = 2 9101 } 9102 9103 /** 9104 * Run options for a task. 9105 */ 9106 export interface RunOptions { 9107 /** 9108 * Controls whether task variables are re-evaluated on rerun. 9109 */ 9110 reevaluateOnRerun?: boolean; 9111 } 9112 9113 /** 9114 * A task to execute 9115 */ 9116 export class Task { 9117 9118 /** 9119 * Creates a new task. 9120 * 9121 * @param taskDefinition The task definition as defined in the taskDefinitions extension point. 9122 * @param scope Specifies the task's scope. It is either a global or a workspace task or a task for a specific workspace folder. Global tasks are currently not supported. 9123 * @param name The task's name. Is presented in the user interface. 9124 * @param source The task's source (e.g. 'gulp', 'npm', ...). Is presented in the user interface. 9125 * @param execution The process or shell execution. 9126 * @param problemMatchers the names of problem matchers to use, like '$tsc' 9127 * or '$eslint'. Problem matchers can be contributed by an extension using 9128 * the `problemMatchers` extension point. 9129 */ 9130 constructor(taskDefinition: TaskDefinition, scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace, name: string, source: string, execution?: ProcessExecution | ShellExecution | CustomExecution, problemMatchers?: string | string[]); 9131 9132 /** 9133 * Creates a new task. 9134 * 9135 * @deprecated Use the new constructors that allow specifying a scope for the task. 9136 * 9137 * @param taskDefinition The task definition as defined in the taskDefinitions extension point. 9138 * @param name The task's name. Is presented in the user interface. 9139 * @param source The task's source (e.g. 'gulp', 'npm', ...). Is presented in the user interface. 9140 * @param execution The process or shell execution. 9141 * @param problemMatchers the names of problem matchers to use, like '$tsc' 9142 * or '$eslint'. Problem matchers can be contributed by an extension using 9143 * the `problemMatchers` extension point. 9144 */ 9145 constructor(taskDefinition: TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]); 9146 9147 /** 9148 * The task's definition. 9149 */ 9150 definition: TaskDefinition; 9151 9152 /** 9153 * The task's scope. 9154 */ 9155 readonly scope: TaskScope.Global | TaskScope.Workspace | WorkspaceFolder | undefined; 9156 9157 /** 9158 * The task's name 9159 */ 9160 name: string; 9161 9162 /** 9163 * A human-readable string which is rendered less prominently on a separate line in places 9164 * where the task's name is displayed. Supports rendering of {@link ThemeIcon theme icons} 9165 * via the `$(<name>)`-syntax. 9166 */ 9167 detail?: string; 9168 9169 /** 9170 * The task's execution engine 9171 */ 9172 execution?: ProcessExecution | ShellExecution | CustomExecution; 9173 9174 /** 9175 * Whether the task is a background task or not. 9176 */ 9177 isBackground: boolean; 9178 9179 /** 9180 * A human-readable string describing the source of this shell task, e.g. 'gulp' 9181 * or 'npm'. Supports rendering of {@link ThemeIcon theme icons} via the `$(<name>)`-syntax. 9182 */ 9183 source: string; 9184 9185 /** 9186 * The task group this tasks belongs to. See TaskGroup 9187 * for a predefined set of available groups. 9188 * Defaults to undefined meaning that the task doesn't 9189 * belong to any special group. 9190 */ 9191 group?: TaskGroup; 9192 9193 /** 9194 * The presentation options. Defaults to an empty literal. 9195 */ 9196 presentationOptions: TaskPresentationOptions; 9197 9198 /** 9199 * The problem matchers attached to the task. Defaults to an empty 9200 * array. 9201 */ 9202 problemMatchers: string[]; 9203 9204 /** 9205 * Run options for the task 9206 */ 9207 runOptions: RunOptions; 9208 } 9209 9210 /** 9211 * A task provider allows to add tasks to the task service. 9212 * A task provider is registered via {@link tasks.registerTaskProvider}. 9213 */ 9214 export interface TaskProvider<T extends Task = Task> { 9215 /** 9216 * Provides tasks. 9217 * @param token A cancellation token. 9218 * @returns an array of tasks 9219 */ 9220 provideTasks(token: CancellationToken): ProviderResult<T[]>; 9221 9222 /** 9223 * Resolves a task that has no {@linkcode Task.execution execution} set. Tasks are 9224 * often created from information found in the `tasks.json`-file. Such tasks miss 9225 * the information on how to execute them and a task provider must fill in 9226 * the missing information in the `resolveTask`-method. This method will not be 9227 * called for tasks returned from the above `provideTasks` method since those 9228 * tasks are always fully resolved. A valid default implementation for the 9229 * `resolveTask` method is to return `undefined`. 9230 * 9231 * Note that when filling in the properties of `task`, you _must_ be sure to 9232 * use the exact same `TaskDefinition` and not create a new one. Other properties 9233 * may be changed. 9234 * 9235 * @param task The task to resolve. 9236 * @param token A cancellation token. 9237 * @returns The resolved task 9238 */ 9239 resolveTask(task: T, token: CancellationToken): ProviderResult<T>; 9240 } 9241 9242 /** 9243 * An object representing an executed Task. It can be used 9244 * to terminate a task. 9245 * 9246 * This interface is not intended to be implemented. 9247 */ 9248 export interface TaskExecution { 9249 /** 9250 * The task that got started. 9251 */ 9252 task: Task; 9253 9254 /** 9255 * Terminates the task execution. 9256 */ 9257 terminate(): void; 9258 } 9259 9260 /** 9261 * An event signaling the start of a task execution. 9262 * 9263 * This interface is not intended to be implemented. 9264 */ 9265 export interface TaskStartEvent { 9266 /** 9267 * The task item representing the task that got started. 9268 */ 9269 readonly execution: TaskExecution; 9270 } 9271 9272 /** 9273 * An event signaling the end of an executed task. 9274 * 9275 * This interface is not intended to be implemented. 9276 */ 9277 export interface TaskEndEvent { 9278 /** 9279 * The task item representing the task that finished. 9280 */ 9281 readonly execution: TaskExecution; 9282 } 9283 9284 /** 9285 * An event signaling the start of a process execution 9286 * triggered through a task 9287 */ 9288 export interface TaskProcessStartEvent { 9289 9290 /** 9291 * The task execution for which the process got started. 9292 */ 9293 readonly execution: TaskExecution; 9294 9295 /** 9296 * The underlying process id. 9297 */ 9298 readonly processId: number; 9299 } 9300 9301 /** 9302 * An event signaling the end of a process execution 9303 * triggered through a task 9304 */ 9305 export interface TaskProcessEndEvent { 9306 9307 /** 9308 * The task execution for which the process got started. 9309 */ 9310 readonly execution: TaskExecution; 9311 9312 /** 9313 * The process's exit code. Will be `undefined` when the task is terminated. 9314 */ 9315 readonly exitCode: number | undefined; 9316 } 9317 9318 /** 9319 * A task filter denotes tasks by their version and types 9320 */ 9321 export interface TaskFilter { 9322 /** 9323 * The task version as used in the tasks.json file. 9324 * The string support the package.json semver notation. 9325 */ 9326 version?: string; 9327 9328 /** 9329 * The task type to return; 9330 */ 9331 type?: string; 9332 } 9333 9334 /** 9335 * Namespace for tasks functionality. 9336 */ 9337 export namespace tasks { 9338 9339 /** 9340 * Register a task provider. 9341 * 9342 * @param type The task kind type this provider is registered for. 9343 * @param provider A task provider. 9344 * @returns A {@link Disposable} that unregisters this provider when being disposed. 9345 */ 9346 export function registerTaskProvider(type: string, provider: TaskProvider): Disposable; 9347 9348 /** 9349 * Fetches all tasks available in the systems. This includes tasks 9350 * from `tasks.json` files as well as tasks from task providers 9351 * contributed through extensions. 9352 * 9353 * @param filter Optional filter to select tasks of a certain type or version. 9354 * @returns A thenable that resolves to an array of tasks. 9355 */ 9356 export function fetchTasks(filter?: TaskFilter): Thenable<Task[]>; 9357 9358 /** 9359 * Executes a task that is managed by the editor. The returned 9360 * task execution can be used to terminate the task. 9361 * 9362 * @throws When running a ShellExecution or a ProcessExecution 9363 * task in an environment where a new process cannot be started. 9364 * In such an environment, only CustomExecution tasks can be run. 9365 * 9366 * @param task the task to execute 9367 * @returns A thenable that resolves to a task execution. 9368 */ 9369 export function executeTask(task: Task): Thenable<TaskExecution>; 9370 9371 /** 9372 * The currently active task executions or an empty array. 9373 */ 9374 export const taskExecutions: readonly TaskExecution[]; 9375 9376 /** 9377 * Fires when a task starts. 9378 */ 9379 export const onDidStartTask: Event<TaskStartEvent>; 9380 9381 /** 9382 * Fires when a task ends. 9383 */ 9384 export const onDidEndTask: Event<TaskEndEvent>; 9385 9386 /** 9387 * Fires when the underlying process has been started. 9388 * This event will not fire for tasks that don't 9389 * execute an underlying process. 9390 */ 9391 export const onDidStartTaskProcess: Event<TaskProcessStartEvent>; 9392 9393 /** 9394 * Fires when the underlying process has ended. 9395 * This event will not fire for tasks that don't 9396 * execute an underlying process. 9397 */ 9398 export const onDidEndTaskProcess: Event<TaskProcessEndEvent>; 9399 } 9400 9401 /** 9402 * Enumeration of file types. The types `File` and `Directory` can also be 9403 * a symbolic links, in that case use `FileType.File | FileType.SymbolicLink` and 9404 * `FileType.Directory | FileType.SymbolicLink`. 9405 */ 9406 export enum FileType { 9407 /** 9408 * The file type is unknown. 9409 */ 9410 Unknown = 0, 9411 /** 9412 * A regular file. 9413 */ 9414 File = 1, 9415 /** 9416 * A directory. 9417 */ 9418 Directory = 2, 9419 /** 9420 * A symbolic link to a file. 9421 */ 9422 SymbolicLink = 64 9423 } 9424 9425 /** 9426 * Permissions of a file. 9427 */ 9428 export enum FilePermission { 9429 /** 9430 * The file is readonly. 9431 * 9432 * *Note:* All `FileStat` from a `FileSystemProvider` that is registered with 9433 * the option `isReadonly: true` will be implicitly handled as if `FilePermission.Readonly` 9434 * is set. As a consequence, it is not possible to have a readonly file system provider 9435 * registered where some `FileStat` are not readonly. 9436 */ 9437 Readonly = 1 9438 } 9439 9440 /** 9441 * The `FileStat`-type represents metadata about a file 9442 */ 9443 export interface FileStat { 9444 /** 9445 * The type of the file, e.g. is a regular file, a directory, or symbolic link 9446 * to a file. 9447 * 9448 * *Note:* This value might be a bitmask, e.g. `FileType.File | FileType.SymbolicLink`. 9449 */ 9450 type: FileType; 9451 /** 9452 * The creation timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC. 9453 */ 9454 ctime: number; 9455 /** 9456 * The modification timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC. 9457 * 9458 * *Note:* If the file changed, it is important to provide an updated `mtime` that advanced 9459 * from the previous value. Otherwise there may be optimizations in place that will not show 9460 * the updated file contents in an editor for example. 9461 */ 9462 mtime: number; 9463 /** 9464 * The size in bytes. 9465 * 9466 * *Note:* If the file changed, it is important to provide an updated `size`. Otherwise there 9467 * may be optimizations in place that will not show the updated file contents in an editor for 9468 * example. 9469 */ 9470 size: number; 9471 /** 9472 * The permissions of the file, e.g. whether the file is readonly. 9473 * 9474 * *Note:* This value might be a bitmask, e.g. `FilePermission.Readonly | FilePermission.Other`. 9475 */ 9476 permissions?: FilePermission; 9477 } 9478 9479 /** 9480 * A type that filesystem providers should use to signal errors. 9481 * 9482 * This class has factory methods for common error-cases, like `FileNotFound` when 9483 * a file or folder doesn't exist, use them like so: `throw vscode.FileSystemError.FileNotFound(someUri);` 9484 */ 9485 export class FileSystemError extends Error { 9486 9487 /** 9488 * Create an error to signal that a file or folder wasn't found. 9489 * @param messageOrUri Message or uri. 9490 */ 9491 static FileNotFound(messageOrUri?: string | Uri): FileSystemError; 9492 9493 /** 9494 * Create an error to signal that a file or folder already exists, e.g. when 9495 * creating but not overwriting a file. 9496 * @param messageOrUri Message or uri. 9497 */ 9498 static FileExists(messageOrUri?: string | Uri): FileSystemError; 9499 9500 /** 9501 * Create an error to signal that a file is not a folder. 9502 * @param messageOrUri Message or uri. 9503 */ 9504 static FileNotADirectory(messageOrUri?: string | Uri): FileSystemError; 9505 9506 /** 9507 * Create an error to signal that a file is a folder. 9508 * @param messageOrUri Message or uri. 9509 */ 9510 static FileIsADirectory(messageOrUri?: string | Uri): FileSystemError; 9511 9512 /** 9513 * Create an error to signal that an operation lacks required permissions. 9514 * @param messageOrUri Message or uri. 9515 */ 9516 static NoPermissions(messageOrUri?: string | Uri): FileSystemError; 9517 9518 /** 9519 * Create an error to signal that the file system is unavailable or too busy to 9520 * complete a request. 9521 * @param messageOrUri Message or uri. 9522 */ 9523 static Unavailable(messageOrUri?: string | Uri): FileSystemError; 9524 9525 /** 9526 * Creates a new filesystem error. 9527 * 9528 * @param messageOrUri Message or uri. 9529 */ 9530 constructor(messageOrUri?: string | Uri); 9531 9532 /** 9533 * A code that identifies this error. 9534 * 9535 * Possible values are names of errors, like {@linkcode FileSystemError.FileNotFound FileNotFound}, 9536 * or `Unknown` for unspecified errors. 9537 */ 9538 readonly code: string; 9539 } 9540 9541 /** 9542 * Enumeration of file change types. 9543 */ 9544 export enum FileChangeType { 9545 9546 /** 9547 * The contents or metadata of a file have changed. 9548 */ 9549 Changed = 1, 9550 9551 /** 9552 * A file has been created. 9553 */ 9554 Created = 2, 9555 9556 /** 9557 * A file has been deleted. 9558 */ 9559 Deleted = 3, 9560 } 9561 9562 /** 9563 * The event filesystem providers must use to signal a file change. 9564 */ 9565 export interface FileChangeEvent { 9566 9567 /** 9568 * The type of change. 9569 */ 9570 readonly type: FileChangeType; 9571 9572 /** 9573 * The uri of the file that has changed. 9574 */ 9575 readonly uri: Uri; 9576 } 9577 9578 /** 9579 * The filesystem provider defines what the editor needs to read, write, discover, 9580 * and to manage files and folders. It allows extensions to serve files from remote places, 9581 * like ftp-servers, and to seamlessly integrate those into the editor. 9582 * 9583 * * *Note 1:* The filesystem provider API works with {@link Uri uris} and assumes hierarchical 9584 * paths, e.g. `foo:/my/path` is a child of `foo:/my/` and a parent of `foo:/my/path/deeper`. 9585 * * *Note 2:* There is an activation event `onFileSystem:<scheme>` that fires when a file 9586 * or folder is being accessed. 9587 * * *Note 3:* The word 'file' is often used to denote all {@link FileType kinds} of files, e.g. 9588 * folders, symbolic links, and regular files. 9589 */ 9590 export interface FileSystemProvider { 9591 9592 /** 9593 * An event to signal that a resource has been created, changed, or deleted. This 9594 * event should fire for resources that are being {@link FileSystemProvider.watch watched} 9595 * by clients of this provider. 9596 * 9597 * *Note:* It is important that the metadata of the file that changed provides an 9598 * updated `mtime` that advanced from the previous value in the {@link FileStat stat} and a 9599 * correct `size` value. Otherwise there may be optimizations in place that will not show 9600 * the change in an editor for example. 9601 */ 9602 readonly onDidChangeFile: Event<FileChangeEvent[]>; 9603 9604 /** 9605 * Subscribes to file change events in the file or folder denoted by `uri`. For folders, 9606 * the option `recursive` indicates whether subfolders, sub-subfolders, etc. should 9607 * be watched for file changes as well. With `recursive: false`, only changes to the 9608 * files that are direct children of the folder should trigger an event. 9609 * 9610 * The `excludes` array is used to indicate paths that should be excluded from file 9611 * watching. It is typically derived from the `files.watcherExclude` setting that 9612 * is configurable by the user. Each entry can be be: 9613 * - the absolute path to exclude 9614 * - a relative path to exclude (for example `build/output`) 9615 * - a simple glob pattern (for example `**/build`, `output/**`) 9616 * 9617 * *Note* that case-sensitivity of the {@link excludes} patterns for built-in file system providers 9618 * will depend on the underlying file system: on Windows and macOS the matching will be case-insensitive and 9619 * on Linux it will be case-sensitive. 9620 * 9621 * It is the file system provider's job to call {@linkcode FileSystemProvider.onDidChangeFile onDidChangeFile} 9622 * for every change given these rules. No event should be emitted for files that match any of the provided 9623 * excludes. 9624 * 9625 * @param uri The uri of the file or folder to be watched. 9626 * @param options Configures the watch. 9627 * @returns A disposable that tells the provider to stop watching the `uri`. 9628 */ 9629 watch(uri: Uri, options: { 9630 /** 9631 * When enabled also watch subfolders. 9632 */ 9633 readonly recursive: boolean; 9634 /** 9635 * A list of paths and pattern to exclude from watching. 9636 */ 9637 readonly excludes: readonly string[]; 9638 }): Disposable; 9639 9640 /** 9641 * Retrieve metadata about a file. 9642 * 9643 * Note that the metadata for symbolic links should be the metadata of the file they refer to. 9644 * Still, the {@link FileType.SymbolicLink SymbolicLink}-type must be used in addition to the actual type, e.g. 9645 * `FileType.SymbolicLink | FileType.Directory`. 9646 * 9647 * @param uri The uri of the file to retrieve metadata about. 9648 * @returns The file metadata about the file. 9649 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. 9650 */ 9651 stat(uri: Uri): FileStat | Thenable<FileStat>; 9652 9653 /** 9654 * Retrieve all entries of a {@link FileType.Directory directory}. 9655 * 9656 * @param uri The uri of the folder. 9657 * @returns An array of name/type-tuples or a thenable that resolves to such. 9658 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. 9659 */ 9660 readDirectory(uri: Uri): [string, FileType][] | Thenable<[string, FileType][]>; 9661 9662 /** 9663 * Create a new directory (Note, that new files are created via `write`-calls). 9664 * 9665 * @param uri The uri of the new folder. 9666 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when the parent of `uri` doesn't exist, e.g. no mkdirp-logic required. 9667 * @throws {@linkcode FileSystemError.FileExists FileExists} when `uri` already exists. 9668 * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. 9669 */ 9670 createDirectory(uri: Uri): void | Thenable<void>; 9671 9672 /** 9673 * Read the entire contents of a file. 9674 * 9675 * @param uri The uri of the file. 9676 * @returns An array of bytes or a thenable that resolves to such. 9677 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. 9678 */ 9679 readFile(uri: Uri): Uint8Array | Thenable<Uint8Array>; 9680 9681 /** 9682 * Write data to a file, replacing its entire contents. 9683 * 9684 * @param uri The uri of the file. 9685 * @param content The new content of the file. 9686 * @param options Defines if missing files should or must be created. 9687 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist and `create` is not set. 9688 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when the parent of `uri` doesn't exist and `create` is set, e.g. no mkdirp-logic required. 9689 * @throws {@linkcode FileSystemError.FileExists FileExists} when `uri` already exists, `create` is set but `overwrite` is not set. 9690 * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. 9691 */ 9692 writeFile(uri: Uri, content: Uint8Array, options: { 9693 /** 9694 * Create the file if it does not exist already. 9695 */ 9696 readonly create: boolean; 9697 /** 9698 * Overwrite the file if it does exist. 9699 */ 9700 readonly overwrite: boolean; 9701 }): void | Thenable<void>; 9702 9703 /** 9704 * Delete a file. 9705 * 9706 * @param uri The resource that is to be deleted. 9707 * @param options Defines if deletion of folders is recursive. 9708 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `uri` doesn't exist. 9709 * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. 9710 */ 9711 delete(uri: Uri, options: { 9712 /** 9713 * Delete the content recursively if a folder is denoted. 9714 */ 9715 readonly recursive: boolean; 9716 }): void | Thenable<void>; 9717 9718 /** 9719 * Rename a file or folder. 9720 * 9721 * @param oldUri The existing file. 9722 * @param newUri The new location. 9723 * @param options Defines if existing files should be overwritten. 9724 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `oldUri` doesn't exist. 9725 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when parent of `newUri` doesn't exist, e.g. no mkdirp-logic required. 9726 * @throws {@linkcode FileSystemError.FileExists FileExists} when `newUri` exists and when the `overwrite` option is not `true`. 9727 * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. 9728 */ 9729 rename(oldUri: Uri, newUri: Uri, options: { 9730 /** 9731 * Overwrite the file if it does exist. 9732 */ 9733 readonly overwrite: boolean; 9734 }): void | Thenable<void>; 9735 9736 /** 9737 * Copy files or folders. Implementing this function is optional but it will speedup 9738 * the copy operation. 9739 * 9740 * @param source The existing file. 9741 * @param destination The destination location. 9742 * @param options Defines if existing files should be overwritten. 9743 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when `source` doesn't exist. 9744 * @throws {@linkcode FileSystemError.FileNotFound FileNotFound} when parent of `destination` doesn't exist, e.g. no mkdirp-logic required. 9745 * @throws {@linkcode FileSystemError.FileExists FileExists} when `destination` exists and when the `overwrite` option is not `true`. 9746 * @throws {@linkcode FileSystemError.NoPermissions NoPermissions} when permissions aren't sufficient. 9747 */ 9748 copy?(source: Uri, destination: Uri, options: { 9749 /** 9750 * Overwrite the file if it does exist. 9751 */ 9752 readonly overwrite: boolean; 9753 }): void | Thenable<void>; 9754 } 9755 9756 /** 9757 * The file system interface exposes the editor's built-in and contributed 9758 * {@link FileSystemProvider file system providers}. It allows extensions to work 9759 * with files from the local disk as well as files from remote places, like the 9760 * remote extension host or ftp-servers. 9761 * 9762 * *Note* that an instance of this interface is available as {@linkcode workspace.fs}. 9763 */ 9764 export interface FileSystem { 9765 9766 /** 9767 * Retrieve metadata about a file. 9768 * 9769 * @param uri The uri of the file to retrieve metadata about. 9770 * @returns The file metadata about the file. 9771 */ 9772 stat(uri: Uri): Thenable<FileStat>; 9773 9774 /** 9775 * Retrieve all entries of a {@link FileType.Directory directory}. 9776 * 9777 * @param uri The uri of the folder. 9778 * @returns An array of name/type-tuples or a thenable that resolves to such. 9779 */ 9780 readDirectory(uri: Uri): Thenable<[string, FileType][]>; 9781 9782 /** 9783 * Create a new directory (Note, that new files are created via `write`-calls). 9784 * 9785 * *Note* that missing directories are created automatically, e.g this call has 9786 * `mkdirp` semantics. 9787 * 9788 * @param uri The uri of the new folder. 9789 */ 9790 createDirectory(uri: Uri): Thenable<void>; 9791 9792 /** 9793 * Read the entire contents of a file. 9794 * 9795 * @param uri The uri of the file. 9796 * @returns An array of bytes or a thenable that resolves to such. 9797 */ 9798 readFile(uri: Uri): Thenable<Uint8Array>; 9799 9800 /** 9801 * Write data to a file, replacing its entire contents. 9802 * 9803 * @param uri The uri of the file. 9804 * @param content The new content of the file. 9805 */ 9806 writeFile(uri: Uri, content: Uint8Array): Thenable<void>; 9807 9808 /** 9809 * Delete a file. 9810 * 9811 * @param uri The resource that is to be deleted. 9812 * @param options Defines if trash can should be used and if deletion of folders is recursive 9813 */ 9814 delete(uri: Uri, options?: { 9815 /** 9816 * Delete the content recursively if a folder is denoted. 9817 */ 9818 recursive?: boolean; 9819 /** 9820 * Use the os's trashcan instead of permanently deleting files whenever possible. 9821 */ 9822 useTrash?: boolean; 9823 }): Thenable<void>; 9824 9825 /** 9826 * Rename a file or folder. 9827 * 9828 * @param source The existing file. 9829 * @param target The new location. 9830 * @param options Defines if existing files should be overwritten. 9831 */ 9832 rename(source: Uri, target: Uri, options?: { 9833 /** 9834 * Overwrite the file if it does exist. 9835 */ 9836 overwrite?: boolean; 9837 }): Thenable<void>; 9838 9839 /** 9840 * Copy files or folders. 9841 * 9842 * @param source The existing file. 9843 * @param target The destination location. 9844 * @param options Defines if existing files should be overwritten. 9845 */ 9846 copy(source: Uri, target: Uri, options?: { 9847 /** 9848 * Overwrite the file if it does exist. 9849 */ 9850 overwrite?: boolean; 9851 }): Thenable<void>; 9852 9853 /** 9854 * Check if a given file system supports writing files. 9855 * 9856 * Keep in mind that just because a file system supports writing, that does 9857 * not mean that writes will always succeed. There may be permissions issues 9858 * or other errors that prevent writing a file. 9859 * 9860 * @param scheme The scheme of the filesystem, for example `file` or `git`. 9861 * 9862 * @returns `true` if the file system supports writing, `false` if it does not 9863 * support writing (i.e. it is readonly), and `undefined` if the editor does not 9864 * know about the filesystem. 9865 */ 9866 isWritableFileSystem(scheme: string): boolean | undefined; 9867 } 9868 9869 /** 9870 * Defines a port mapping used for localhost inside the webview. 9871 */ 9872 export interface WebviewPortMapping { 9873 /** 9874 * Localhost port to remap inside the webview. 9875 */ 9876 readonly webviewPort: number; 9877 9878 /** 9879 * Destination port. The `webviewPort` is resolved to this port. 9880 */ 9881 readonly extensionHostPort: number; 9882 } 9883 9884 /** 9885 * Content settings for a webview. 9886 */ 9887 export interface WebviewOptions { 9888 /** 9889 * Controls whether scripts are enabled in the webview content or not. 9890 * 9891 * Defaults to false (scripts-disabled). 9892 */ 9893 readonly enableScripts?: boolean; 9894 9895 /** 9896 * Controls whether forms are enabled in the webview content or not. 9897 * 9898 * Defaults to true if {@link WebviewOptions.enableScripts scripts are enabled}. Otherwise defaults to false. 9899 * Explicitly setting this property to either true or false overrides the default. 9900 */ 9901 readonly enableForms?: boolean; 9902 9903 /** 9904 * Controls whether command uris are enabled in webview content or not. 9905 * 9906 * Defaults to `false` (command uris are disabled). 9907 * 9908 * If you pass in an array, only the commands in the array are allowed. 9909 */ 9910 readonly enableCommandUris?: boolean | readonly string[]; 9911 9912 /** 9913 * Root paths from which the webview can load local (filesystem) resources using uris from `asWebviewUri` 9914 * 9915 * Default to the root folders of the current workspace plus the extension's install directory. 9916 * 9917 * Pass in an empty array to disallow access to any local resources. 9918 */ 9919 readonly localResourceRoots?: readonly Uri[]; 9920 9921 /** 9922 * Mappings of localhost ports used inside the webview. 9923 * 9924 * Port mapping allow webviews to transparently define how localhost ports are resolved. This can be used 9925 * to allow using a static localhost port inside the webview that is resolved to random port that a service is 9926 * running on. 9927 * 9928 * If a webview accesses localhost content, we recommend that you specify port mappings even if 9929 * the `webviewPort` and `extensionHostPort` ports are the same. 9930 * 9931 * *Note* that port mappings only work for `http` or `https` urls. Websocket urls (e.g. `ws://localhost:3000`) 9932 * cannot be mapped to another port. 9933 */ 9934 readonly portMapping?: readonly WebviewPortMapping[]; 9935 } 9936 9937 /** 9938 * Displays html content, similarly to an iframe. 9939 */ 9940 export interface Webview { 9941 /** 9942 * Content settings for the webview. 9943 */ 9944 options: WebviewOptions; 9945 9946 /** 9947 * HTML contents of the webview. 9948 * 9949 * This should be a complete, valid html document. Changing this property causes the webview to be reloaded. 9950 * 9951 * Webviews are sandboxed from normal extension process, so all communication with the webview must use 9952 * message passing. To send a message from the extension to the webview, use {@linkcode Webview.postMessage postMessage}. 9953 * To send message from the webview back to an extension, use the `acquireVsCodeApi` function inside the webview 9954 * to get a handle to the editor's api and then call `.postMessage()`: 9955 * 9956 * ```html 9957 * <script> 9958 * const vscode = acquireVsCodeApi(); // acquireVsCodeApi can only be invoked once 9959 * vscode.postMessage({ message: 'hello!' }); 9960 * </script> 9961 * ``` 9962 * 9963 * To load a resources from the workspace inside a webview, use the {@linkcode Webview.asWebviewUri asWebviewUri} method 9964 * and ensure the resource's directory is listed in {@linkcode WebviewOptions.localResourceRoots}. 9965 * 9966 * Keep in mind that even though webviews are sandboxed, they still allow running scripts and loading arbitrary content, 9967 * so extensions must follow all standard web security best practices when working with webviews. This includes 9968 * properly sanitizing all untrusted input (including content from the workspace) and 9969 * setting a [content security policy](https://aka.ms/vscode-api-webview-csp). 9970 */ 9971 html: string; 9972 9973 /** 9974 * Fired when the webview content posts a message. 9975 * 9976 * Webview content can post strings or json serializable objects back to an extension. They cannot 9977 * post `Blob`, `File`, `ImageData` and other DOM specific objects since the extension that receives the 9978 * message does not run in a browser environment. 9979 */ 9980 readonly onDidReceiveMessage: Event<any>; 9981 9982 /** 9983 * Post a message to the webview content. 9984 * 9985 * Messages are only delivered if the webview is live (either visible or in the 9986 * background with `retainContextWhenHidden`). 9987 * 9988 * @param message Body of the message. This must be a string or other json serializable object. 9989 * 9990 * For older versions of vscode, if an `ArrayBuffer` is included in `message`, 9991 * it will not be serialized properly and will not be received by the webview. 9992 * Similarly any TypedArrays, such as a `Uint8Array`, will be very inefficiently 9993 * serialized and will also not be recreated as a typed array inside the webview. 9994 * 9995 * However if your extension targets vscode 1.57+ in the `engines` field of its 9996 * `package.json`, any `ArrayBuffer` values that appear in `message` will be more 9997 * efficiently transferred to the webview and will also be correctly recreated inside 9998 * of the webview. 9999 * 10000 * @returns A promise that resolves when the message is posted to a webview or when it is 10001 * dropped because the message was not deliverable. 10002 * 10003 * Returns `true` if the message was posted to the webview. Messages can only be posted to 10004 * live webviews (i.e. either visible webviews or hidden webviews that set `retainContextWhenHidden`). 10005 * 10006 * A response of `true` does not mean that the message was actually received by the webview. 10007 * For example, no message listeners may be have been hooked up inside the webview or the webview may 10008 * have been destroyed after the message was posted but before it was received. 10009 * 10010 * If you want confirm that a message as actually received, you can try having your webview posting a 10011 * confirmation message back to your extension. 10012 */ 10013 postMessage(message: any): Thenable<boolean>; 10014 10015 /** 10016 * Convert a uri for the local file system to one that can be used inside webviews. 10017 * 10018 * Webviews cannot directly load resources from the workspace or local file system using `file:` uris. The 10019 * `asWebviewUri` function takes a local `file:` uri and converts it into a uri that can be used inside of 10020 * a webview to load the same resource: 10021 * 10022 * ```ts 10023 * webview.html = `<img src="${webview.asWebviewUri(vscode.Uri.file('/Users/codey/workspace/cat.gif'))}">` 10024 * ``` 10025 */ 10026 asWebviewUri(localResource: Uri): Uri; 10027 10028 /** 10029 * Content security policy source for webview resources. 10030 * 10031 * This is the origin that should be used in a content security policy rule: 10032 * 10033 * ```ts 10034 * `img-src https: ${webview.cspSource} ...;` 10035 * ``` 10036 */ 10037 readonly cspSource: string; 10038 } 10039 10040 /** 10041 * Content settings for a webview panel. 10042 */ 10043 export interface WebviewPanelOptions { 10044 /** 10045 * Controls if the find widget is enabled in the panel. 10046 * 10047 * Defaults to `false`. 10048 */ 10049 readonly enableFindWidget?: boolean; 10050 10051 /** 10052 * Controls if the webview panel's content (iframe) is kept around even when the panel 10053 * is no longer visible. 10054 * 10055 * Normally the webview panel's html context is created when the panel becomes visible 10056 * and destroyed when it is hidden. Extensions that have complex state 10057 * or UI can set the `retainContextWhenHidden` to make the editor keep the webview 10058 * context around, even when the webview moves to a background tab. When a webview using 10059 * `retainContextWhenHidden` becomes hidden, its scripts and other dynamic content are suspended. 10060 * When the panel becomes visible again, the context is automatically restored 10061 * in the exact same state it was in originally. You cannot send messages to a 10062 * hidden webview, even with `retainContextWhenHidden` enabled. 10063 * 10064 * `retainContextWhenHidden` has a high memory overhead and should only be used if 10065 * your panel's context cannot be quickly saved and restored. 10066 */ 10067 readonly retainContextWhenHidden?: boolean; 10068 } 10069 10070 /** 10071 * A panel that contains a {@linkcode Webview}. 10072 */ 10073 export interface WebviewPanel { 10074 /** 10075 * Identifies the type of the webview panel, such as `'markdown.preview'`. 10076 */ 10077 readonly viewType: string; 10078 10079 /** 10080 * Title of the panel shown in UI. 10081 */ 10082 title: string; 10083 10084 /** 10085 * Icon for the panel shown in UI. 10086 */ 10087 iconPath?: IconPath; 10088 10089 /** 10090 * {@linkcode Webview} belonging to the panel. 10091 */ 10092 readonly webview: Webview; 10093 10094 /** 10095 * Content settings for the webview panel. 10096 */ 10097 readonly options: WebviewPanelOptions; 10098 10099 /** 10100 * Editor position of the panel. This property is only set if the webview is in 10101 * one of the editor view columns. 10102 */ 10103 readonly viewColumn: ViewColumn | undefined; 10104 10105 /** 10106 * Whether the panel is active (focused by the user). 10107 */ 10108 readonly active: boolean; 10109 10110 /** 10111 * Whether the panel is visible. 10112 */ 10113 readonly visible: boolean; 10114 10115 /** 10116 * Fired when the panel's view state changes. 10117 */ 10118 readonly onDidChangeViewState: Event<WebviewPanelOnDidChangeViewStateEvent>; 10119 10120 /** 10121 * Fired when the panel is disposed. 10122 * 10123 * This may be because the user closed the panel or because {@linkcode WebviewPanel.dispose dispose} was 10124 * called on it. 10125 * 10126 * Trying to use the panel after it has been disposed throws an exception. 10127 */ 10128 readonly onDidDispose: Event<void>; 10129 10130 /** 10131 * Show the webview panel in a given column. 10132 * 10133 * A webview panel may only show in a single column at a time. If it is already showing, this 10134 * method moves it to a new column. 10135 * 10136 * @param viewColumn View column to show the panel in. Shows in the current {@linkcode WebviewPanel.viewColumn} if undefined. 10137 * @param preserveFocus When `true`, the webview will not take focus. 10138 */ 10139 reveal(viewColumn?: ViewColumn, preserveFocus?: boolean): void; 10140 10141 /** 10142 * Dispose of the webview panel. 10143 * 10144 * This closes the panel if it showing and disposes of the resources owned by the webview. 10145 * Webview panels are also disposed when the user closes the webview panel. Both cases 10146 * fire the {@linkcode onDidDispose} event. 10147 */ 10148 dispose(): any; 10149 } 10150 10151 /** 10152 * Event fired when a {@linkcode WebviewPanel webview panel's} view state changes. 10153 */ 10154 export interface WebviewPanelOnDidChangeViewStateEvent { 10155 /** 10156 * {@linkcode WebviewPanel} whose view state changed. 10157 */ 10158 readonly webviewPanel: WebviewPanel; 10159 } 10160 10161 /** 10162 * Restore webview panels that have been persisted when vscode shuts down. 10163 * 10164 * There are two types of webview persistence: 10165 * 10166 * - Persistence within a session. 10167 * - Persistence across sessions (across restarts of the editor). 10168 * 10169 * A `WebviewPanelSerializer` is only required for the second case: persisting a webview across sessions. 10170 * 10171 * Persistence within a session allows a webview to save its state when it becomes hidden 10172 * and restore its content from this state when it becomes visible again. It is powered entirely 10173 * by the webview content itself. To save off a persisted state, call `acquireVsCodeApi().setState()` with 10174 * any json serializable object. To restore the state again, call `getState()` 10175 * 10176 * ```js 10177 * // Within the webview 10178 * const vscode = acquireVsCodeApi(); 10179 * 10180 * // Get existing state 10181 * const oldState = vscode.getState() || { value: 0 }; 10182 * 10183 * // Update state 10184 * setState({ value: oldState.value + 1 }) 10185 * ``` 10186 * 10187 * A `WebviewPanelSerializer` extends this persistence across restarts of the editor. When the editor is shutdown, 10188 * it will save off the state from `setState` of all webviews that have a serializer. When the 10189 * webview first becomes visible after the restart, this state is passed to `deserializeWebviewPanel`. 10190 * The extension can then restore the old `WebviewPanel` from this state. 10191 * 10192 * @param T Type of the webview's state. 10193 */ 10194 export interface WebviewPanelSerializer<T = unknown> { 10195 /** 10196 * Restore a webview panel from its serialized `state`. 10197 * 10198 * Called when a serialized webview first becomes visible. 10199 * 10200 * @param webviewPanel Webview panel to restore. The serializer should take ownership of this panel. The 10201 * serializer must restore the webview's `.html` and hook up all webview events. 10202 * @param state Persisted state from the webview content. 10203 * 10204 * @returns Thenable indicating that the webview has been fully restored. 10205 */ 10206 deserializeWebviewPanel(webviewPanel: WebviewPanel, state: T): Thenable<void>; 10207 } 10208 10209 /** 10210 * A webview based view. 10211 */ 10212 export interface WebviewView { 10213 /** 10214 * Identifies the type of the webview view, such as `'hexEditor.dataView'`. 10215 */ 10216 readonly viewType: string; 10217 10218 /** 10219 * The underlying webview for the view. 10220 */ 10221 readonly webview: Webview; 10222 10223 /** 10224 * View title displayed in the UI. 10225 * 10226 * The view title is initially taken from the extension `package.json` contribution. 10227 */ 10228 title?: string; 10229 10230 /** 10231 * Human-readable string which is rendered less prominently in the title. 10232 */ 10233 description?: string; 10234 10235 /** 10236 * The badge to display for this webview view. 10237 * To remove the badge, set to undefined. 10238 */ 10239 badge?: ViewBadge | undefined; 10240 10241 /** 10242 * Event fired when the view is disposed. 10243 * 10244 * Views are disposed when they are explicitly hidden by a user (this happens when a user 10245 * right clicks in a view and unchecks the webview view). 10246 * 10247 * Trying to use the view after it has been disposed throws an exception. 10248 */ 10249 readonly onDidDispose: Event<void>; 10250 10251 /** 10252 * Tracks if the webview is currently visible. 10253 * 10254 * Views are visible when they are on the screen and expanded. 10255 */ 10256 readonly visible: boolean; 10257 10258 /** 10259 * Event fired when the visibility of the view changes. 10260 * 10261 * Actions that trigger a visibility change: 10262 * 10263 * - The view is collapsed or expanded. 10264 * - The user switches to a different view group in the sidebar or panel. 10265 * 10266 * Note that hiding a view using the context menu instead disposes of the view and fires `onDidDispose`. 10267 */ 10268 readonly onDidChangeVisibility: Event<void>; 10269 10270 /** 10271 * Reveal the view in the UI. 10272 * 10273 * If the view is collapsed, this will expand it. 10274 * 10275 * @param preserveFocus When `true` the view will not take focus. 10276 */ 10277 show(preserveFocus?: boolean): void; 10278 } 10279 10280 /** 10281 * Additional information the webview view being resolved. 10282 * 10283 * @param T Type of the webview's state. 10284 */ 10285 export interface WebviewViewResolveContext<T = unknown> { 10286 /** 10287 * Persisted state from the webview content. 10288 * 10289 * To save resources, the editor normally deallocates webview documents (the iframe content) that are not visible. 10290 * For example, when the user collapse a view or switches to another top level activity in the sidebar, the 10291 * {@linkcode WebviewView} itself is kept alive but the webview's underlying document is deallocated. It is recreated when 10292 * the view becomes visible again. 10293 * 10294 * You can prevent this behavior by setting {@linkcode WebviewOptions.retainContextWhenHidden retainContextWhenHidden} in the {@linkcode WebviewOptions}. 10295 * However this increases resource usage and should be avoided wherever possible. Instead, you can use 10296 * persisted state to save off a webview's state so that it can be quickly recreated as needed. 10297 * 10298 * To save off a persisted state, inside the webview call `acquireVsCodeApi().setState()` with 10299 * any json serializable object. To restore the state again, call `getState()`. For example: 10300 * 10301 * ```js 10302 * // Within the webview 10303 * const vscode = acquireVsCodeApi(); 10304 * 10305 * // Get existing state 10306 * const oldState = vscode.getState() || { value: 0 }; 10307 * 10308 * // Update state 10309 * setState({ value: oldState.value + 1 }) 10310 * ``` 10311 * 10312 * The editor ensures that the persisted state is saved correctly when a webview is hidden and across 10313 * editor restarts. 10314 */ 10315 readonly state: T | undefined; 10316 } 10317 10318 /** 10319 * Provider for creating {@linkcode WebviewView} elements. 10320 */ 10321 export interface WebviewViewProvider { 10322 /** 10323 * Resolves a webview view. 10324 * 10325 * `resolveWebviewView` is called when a view first becomes visible. This may happen when the view is 10326 * first loaded or when the user hides and then shows a view again. 10327 * 10328 * @param webviewView Webview view to restore. The provider should take ownership of this view. The 10329 * provider must set the webview's `.html` and hook up all webview events it is interested in. 10330 * @param context Additional metadata about the view being resolved. 10331 * @param token Cancellation token indicating that the view being provided is no longer needed. 10332 * 10333 * @returns Optional thenable indicating that the view has been fully resolved. 10334 */ 10335 resolveWebviewView(webviewView: WebviewView, context: WebviewViewResolveContext, token: CancellationToken): Thenable<void> | void; 10336 } 10337 10338 /** 10339 * Provider for text based custom editors. 10340 * 10341 * Text based custom editors use a {@linkcode TextDocument} as their data model. This considerably simplifies 10342 * implementing a custom editor as it allows the editor to handle many common operations such as 10343 * undo and backup. The provider is responsible for synchronizing text changes between the webview and the {@linkcode TextDocument}. 10344 */ 10345 export interface CustomTextEditorProvider { 10346 10347 /** 10348 * Resolve a custom editor for a given text resource. 10349 * 10350 * This is called when a user first opens a resource for a `CustomTextEditorProvider`, or if they reopen an 10351 * existing editor using this `CustomTextEditorProvider`. 10352 * 10353 * @param document Document for the resource to resolve. 10354 * 10355 * @param webviewPanel The webview panel used to display the editor UI for this resource. 10356 * 10357 * During resolve, the provider must fill in the initial html for the content webview panel and hook up all 10358 * the event listeners on it that it is interested in. The provider can also hold onto the {@linkcode WebviewPanel} to 10359 * use later for example in a command. See {@linkcode WebviewPanel} for additional details. 10360 * 10361 * @param token A cancellation token that indicates the result is no longer needed. 10362 * 10363 * @returns Thenable indicating that the custom editor has been resolved. 10364 */ 10365 resolveCustomTextEditor(document: TextDocument, webviewPanel: WebviewPanel, token: CancellationToken): Thenable<void> | void; 10366 } 10367 10368 /** 10369 * Represents a custom document used by a {@linkcode CustomEditorProvider}. 10370 * 10371 * Custom documents are only used within a given `CustomEditorProvider`. The lifecycle of a `CustomDocument` is 10372 * managed by the editor. When no more references remain to a `CustomDocument`, it is disposed of. 10373 */ 10374 export interface CustomDocument { 10375 /** 10376 * The associated uri for this document. 10377 */ 10378 readonly uri: Uri; 10379 10380 /** 10381 * Dispose of the custom document. 10382 * 10383 * This is invoked by the editor when there are no more references to a given `CustomDocument` (for example when 10384 * all editors associated with the document have been closed.) 10385 */ 10386 dispose(): void; 10387 } 10388 10389 /** 10390 * Event triggered by extensions to signal to the editor that an edit has occurred on an {@linkcode CustomDocument}. 10391 * 10392 * @see {@linkcode CustomEditorProvider.onDidChangeCustomDocument}. 10393 */ 10394 export interface CustomDocumentEditEvent<T extends CustomDocument = CustomDocument> { 10395 10396 /** 10397 * The document that the edit is for. 10398 */ 10399 readonly document: T; 10400 10401 /** 10402 * Undo the edit operation. 10403 * 10404 * This is invoked by the editor when the user undoes this edit. To implement `undo`, your 10405 * extension should restore the document and editor to the state they were in just before this 10406 * edit was added to the editor's internal edit stack by {@linkcode CustomEditorProvider.onDidChangeCustomDocument}. 10407 */ 10408 undo(): Thenable<void> | void; 10409 10410 /** 10411 * Redo the edit operation. 10412 * 10413 * This is invoked by the editor when the user redoes this edit. To implement `redo`, your 10414 * extension should restore the document and editor to the state they were in just after this 10415 * edit was added to the editor's internal edit stack by {@linkcode CustomEditorProvider.onDidChangeCustomDocument}. 10416 */ 10417 redo(): Thenable<void> | void; 10418 10419 /** 10420 * Display name describing the edit. 10421 * 10422 * This will be shown to users in the UI for undo/redo operations. 10423 */ 10424 readonly label?: string; 10425 } 10426 10427 /** 10428 * Event triggered by extensions to signal to the editor that the content of a {@linkcode CustomDocument} 10429 * has changed. 10430 * 10431 * @see {@linkcode CustomEditorProvider.onDidChangeCustomDocument}. 10432 */ 10433 export interface CustomDocumentContentChangeEvent<T extends CustomDocument = CustomDocument> { 10434 /** 10435 * The document that the change is for. 10436 */ 10437 readonly document: T; 10438 } 10439 10440 /** 10441 * A backup for an {@linkcode CustomDocument}. 10442 */ 10443 export interface CustomDocumentBackup { 10444 /** 10445 * Unique identifier for the backup. 10446 * 10447 * This id is passed back to your extension in {@linkcode CustomReadonlyEditorProvider.openCustomDocument openCustomDocument} when opening a custom editor from a backup. 10448 */ 10449 readonly id: string; 10450 10451 /** 10452 * Delete the current backup. 10453 * 10454 * This is called by the editor when it is clear the current backup is no longer needed, such as when a new backup 10455 * is made or when the file is saved. 10456 */ 10457 delete(): void; 10458 } 10459 10460 /** 10461 * Additional information used to implement {@linkcode CustomDocumentBackup}. 10462 */ 10463 export interface CustomDocumentBackupContext { 10464 /** 10465 * Suggested file location to write the new backup. 10466 * 10467 * Note that your extension is free to ignore this and use its own strategy for backup. 10468 * 10469 * If the editor is for a resource from the current workspace, `destination` will point to a file inside 10470 * `ExtensionContext.storagePath`. The parent folder of `destination` may not exist, so make sure to created it 10471 * before writing the backup to this location. 10472 */ 10473 readonly destination: Uri; 10474 } 10475 10476 /** 10477 * Additional information about the opening custom document. 10478 */ 10479 export interface CustomDocumentOpenContext { 10480 /** 10481 * The id of the backup to restore the document from or `undefined` if there is no backup. 10482 * 10483 * If this is provided, your extension should restore the editor from the backup instead of reading the file 10484 * from the user's workspace. 10485 */ 10486 readonly backupId: string | undefined; 10487 10488 /** 10489 * If the URI is an untitled file, this will be populated with the byte data of that file 10490 * 10491 * If this is provided, your extension should utilize this byte data rather than executing fs APIs on the URI passed in 10492 */ 10493 readonly untitledDocumentData: Uint8Array | undefined; 10494 } 10495 10496 /** 10497 * Provider for readonly custom editors that use a custom document model. 10498 * 10499 * Custom editors use {@linkcode CustomDocument} as their document model instead of a {@linkcode TextDocument}. 10500 * 10501 * You should use this type of custom editor when dealing with binary files or more complex scenarios. For simple 10502 * text based documents, use {@linkcode CustomTextEditorProvider} instead. 10503 * 10504 * @param T Type of the custom document returned by this provider. 10505 */ 10506 export interface CustomReadonlyEditorProvider<T extends CustomDocument = CustomDocument> { 10507 10508 /** 10509 * Create a new document for a given resource. 10510 * 10511 * `openCustomDocument` is called when the first time an editor for a given resource is opened. The opened 10512 * document is then passed to {@link resolveCustomEditor} so that the editor can be shown to the user. 10513 * 10514 * Already opened {@linkcode CustomDocument CustomDocuments} are re-used if the user opened additional editors. When all editors for a 10515 * given resource are closed, the {@linkcode CustomDocument CustomDocuments} is disposed of. Opening an editor at this point will 10516 * trigger another call to `openCustomDocument`. 10517 * 10518 * @param uri Uri of the document to open. 10519 * @param openContext Additional information about the opening custom document. 10520 * @param token A cancellation token that indicates the result is no longer needed. 10521 * 10522 * @returns The custom document. 10523 */ 10524 openCustomDocument(uri: Uri, openContext: CustomDocumentOpenContext, token: CancellationToken): Thenable<T> | T; 10525 10526 /** 10527 * Resolve a custom editor for a given resource. 10528 * 10529 * This is called whenever the user opens a new editor for this `CustomEditorProvider`. 10530 * 10531 * @param document Document for the resource being resolved. 10532 * 10533 * @param webviewPanel The webview panel used to display the editor UI for this resource. 10534 * 10535 * During resolve, the provider must fill in the initial html for the content webview panel and hook up all 10536 * the event listeners on it that it is interested in. The provider can also hold onto the `WebviewPanel` to 10537 * use later for example in a command. See {@linkcode WebviewPanel} for additional details. 10538 * 10539 * @param token A cancellation token that indicates the result is no longer needed. 10540 * 10541 * @returns Optional thenable indicating that the custom editor has been resolved. 10542 */ 10543 resolveCustomEditor(document: T, webviewPanel: WebviewPanel, token: CancellationToken): Thenable<void> | void; 10544 } 10545 10546 /** 10547 * Provider for editable custom editors that use a custom document model. 10548 * 10549 * Custom editors use {@linkcode CustomDocument} as their document model instead of a {@linkcode TextDocument}. 10550 * This gives extensions full control over actions such as edit, save, and backup. 10551 * 10552 * You should use this type of custom editor when dealing with binary files or more complex scenarios. For simple 10553 * text based documents, use {@linkcode CustomTextEditorProvider} instead. 10554 * 10555 * @param T Type of the custom document returned by this provider. 10556 */ 10557 export interface CustomEditorProvider<T extends CustomDocument = CustomDocument> extends CustomReadonlyEditorProvider<T> { 10558 /** 10559 * Signal that an edit has occurred inside a custom editor. 10560 * 10561 * This event must be fired by your extension whenever an edit happens in a custom editor. An edit can be 10562 * anything from changing some text, to cropping an image, to reordering a list. Your extension is free to 10563 * define what an edit is and what data is stored on each edit. 10564 * 10565 * Firing {@linkcode CustomEditorProvider.onDidChangeCustomDocument onDidChangeCustomDocument} causes the 10566 * editors to be marked as being dirty. This is cleared when the user either saves or reverts the file. 10567 * 10568 * Editors that support undo/redo must fire a {@linkcode CustomDocumentEditEvent} whenever an edit happens. This allows 10569 * users to undo and redo the edit using the editor's standard keyboard shortcuts. The editor will also mark 10570 * the editor as no longer being dirty if the user undoes all edits to the last saved state. 10571 * 10572 * Editors that support editing but cannot use the editor's standard undo/redo mechanism must fire a {@linkcode CustomDocumentContentChangeEvent}. 10573 * The only way for a user to clear the dirty state of an editor that does not support undo/redo is to either 10574 * `save` or `revert` the file. 10575 * 10576 * An editor should only ever fire {@linkcode CustomDocumentEditEvent} events, or only ever fire {@linkcode CustomDocumentContentChangeEvent} events. 10577 */ 10578 readonly onDidChangeCustomDocument: Event<CustomDocumentEditEvent<T>> | Event<CustomDocumentContentChangeEvent<T>>; 10579 10580 /** 10581 * Save a custom document. 10582 * 10583 * This method is invoked by the editor when the user saves a custom editor. This can happen when the user 10584 * triggers save while the custom editor is active, by commands such as `save all`, or by auto save if enabled. 10585 * 10586 * The implementer must persist the custom editor. This usually means writing the 10587 * file data for the custom document to disk. After {@linkcode saveCustomDocument} completes, any associated 10588 * editor instances will no longer be marked as dirty. 10589 * 10590 * @param document Document to save. 10591 * @param cancellation Token that signals the save is no longer required (for example, if another save was triggered). 10592 * 10593 * @returns A {@linkcode Thenable} that saving has completed. 10594 */ 10595 saveCustomDocument(document: T, cancellation: CancellationToken): Thenable<void>; 10596 10597 /** 10598 * Save a custom document to a different location. 10599 * 10600 * This method is invoked by the editor when the user triggers 'save as' on a custom editor. The implementer must 10601 * persist the custom editor to {@linkcode destination}. 10602 * 10603 * When the user accepts save as, the current editor is be replaced by an non-dirty editor for the newly saved file. 10604 * 10605 * @param document Document to save. 10606 * @param destination Location to save to. 10607 * @param cancellation Token that signals the save is no longer required. 10608 * 10609 * @returns A {@linkcode Thenable} signaling that saving has completed. 10610 */ 10611 saveCustomDocumentAs(document: T, destination: Uri, cancellation: CancellationToken): Thenable<void>; 10612 10613 /** 10614 * Revert a custom document to its last saved state. 10615 * 10616 * This method is invoked by the editor when the user triggers `File: Revert File` in a custom editor. (Note that 10617 * this is only used using the editor's `File: Revert File` command and not on a `git revert` of the file). 10618 * 10619 * The implementer must make sure all editor instances (webviews) for {@linkcode document} 10620 * are displaying the document in the same state is saved in. This usually means reloading the file from the 10621 * workspace. 10622 * 10623 * @param document Document to revert. 10624 * @param cancellation Token that signals the revert is no longer required. 10625 * 10626 * @returns A {@linkcode Thenable} signaling that the revert has completed. 10627 */ 10628 revertCustomDocument(document: T, cancellation: CancellationToken): Thenable<void>; 10629 10630 /** 10631 * Back up a dirty custom document. 10632 * 10633 * Backups are used for hot exit and to prevent data loss. Your {@linkcode backupCustomDocument} method should persist the resource in 10634 * its current state, i.e. with the edits applied. Most commonly this means saving the resource to disk in 10635 * the `ExtensionContext.storagePath`. When the editor reloads and your custom editor is opened for a resource, 10636 * your extension should first check to see if any backups exist for the resource. If there is a backup, your 10637 * extension should load the file contents from there instead of from the resource in the workspace. 10638 * 10639 * {@linkcode backupCustomDocument} is triggered approximately one second after the user stops editing the document. If the user 10640 * rapidly edits the document, {@linkcode backupCustomDocument} will not be invoked until the editing stops. 10641 * 10642 * {@linkcode backupCustomDocument} is not invoked when `auto save` is enabled (since auto save already persists the resource). 10643 * 10644 * @param document Document to backup. 10645 * @param context Information that can be used to backup the document. 10646 * @param cancellation Token that signals the current backup since a new backup is coming in. It is up to your 10647 * extension to decided how to respond to cancellation. If for example your extension is backing up a large file 10648 * in an operation that takes time to complete, your extension may decide to finish the ongoing backup rather 10649 * than cancelling it to ensure that the editor has some valid backup. 10650 * 10651 * @returns A {@linkcode Thenable} signaling that the backup has completed. 10652 */ 10653 backupCustomDocument(document: T, context: CustomDocumentBackupContext, cancellation: CancellationToken): Thenable<CustomDocumentBackup>; 10654 } 10655 10656 /** 10657 * The clipboard provides read and write access to the system's clipboard. 10658 */ 10659 export interface Clipboard { 10660 10661 /** 10662 * Read the current clipboard contents as text. 10663 * @returns A thenable that resolves to a string. 10664 */ 10665 readText(): Thenable<string>; 10666 10667 /** 10668 * Writes text into the clipboard. 10669 * @returns A thenable that resolves when writing happened. 10670 */ 10671 writeText(value: string): Thenable<void>; 10672 } 10673 10674 /** 10675 * Possible kinds of UI that can use extensions. 10676 */ 10677 export enum UIKind { 10678 10679 /** 10680 * Extensions are accessed from a desktop application. 10681 */ 10682 Desktop = 1, 10683 10684 /** 10685 * Extensions are accessed from a web browser. 10686 */ 10687 Web = 2 10688 } 10689 10690 /** 10691 * Log levels 10692 */ 10693 export enum LogLevel { 10694 10695 /** 10696 * No messages are logged with this level. 10697 */ 10698 Off = 0, 10699 10700 /** 10701 * All messages are logged with this level. 10702 */ 10703 Trace = 1, 10704 10705 /** 10706 * Messages with debug and higher log level are logged with this level. 10707 */ 10708 Debug = 2, 10709 10710 /** 10711 * Messages with info and higher log level are logged with this level. 10712 */ 10713 Info = 3, 10714 10715 /** 10716 * Messages with warning and higher log level are logged with this level. 10717 */ 10718 Warning = 4, 10719 10720 /** 10721 * Only error messages are logged with this level. 10722 */ 10723 Error = 5 10724 } 10725 10726 /** 10727 * Namespace describing the environment the editor runs in. 10728 */ 10729 export namespace env { 10730 10731 /** 10732 * The application name of the editor, like 'VS Code'. 10733 */ 10734 export const appName: string; 10735 10736 /** 10737 * The application root folder from which the editor is running. 10738 * 10739 * *Note* that the value is the empty string when running in an 10740 * environment that has no representation of an application root folder. 10741 */ 10742 export const appRoot: string; 10743 10744 /** 10745 * The hosted location of the application 10746 * On desktop this is 'desktop' 10747 * In the web this is the specified embedder i.e. 'github.dev', 'codespaces', or 'web' if the embedder 10748 * does not provide that information 10749 */ 10750 export const appHost: string; 10751 10752 /** 10753 * The custom uri scheme the editor registers to in the operating system. 10754 */ 10755 export const uriScheme: string; 10756 10757 /** 10758 * Represents the preferred user-language, like `de-CH`, `fr`, or `en-US`. 10759 */ 10760 export const language: string; 10761 10762 /** 10763 * The system clipboard. 10764 */ 10765 export const clipboard: Clipboard; 10766 10767 /** 10768 * A unique identifier for the computer. 10769 */ 10770 export const machineId: string; 10771 10772 /** 10773 * A unique identifier for the current session. 10774 * Changes each time the editor is started. 10775 */ 10776 export const sessionId: string; 10777 10778 /** 10779 * Indicates that this is a fresh install of the application. 10780 * `true` if within the first day of installation otherwise `false`. 10781 */ 10782 export const isNewAppInstall: boolean; 10783 10784 /** 10785 * Indicates whether the users has telemetry enabled. 10786 * Can be observed to determine if the extension should send telemetry. 10787 */ 10788 export const isTelemetryEnabled: boolean; 10789 10790 /** 10791 * An {@link Event} which fires when the user enabled or disables telemetry. 10792 * `true` if the user has enabled telemetry or `false` if the user has disabled telemetry. 10793 */ 10794 export const onDidChangeTelemetryEnabled: Event<boolean>; 10795 10796 /** 10797 * An {@link Event} which fires when the default shell changes. This fires with the new 10798 * shell path. 10799 */ 10800 export const onDidChangeShell: Event<string>; 10801 10802 /** 10803 * Creates a new {@link TelemetryLogger telemetry logger}. 10804 * 10805 * @param sender The telemetry sender that is used by the telemetry logger. 10806 * @param options Options for the telemetry logger. 10807 * @returns A new telemetry logger 10808 */ 10809 export function createTelemetryLogger(sender: TelemetrySender, options?: TelemetryLoggerOptions): TelemetryLogger; 10810 10811 /** 10812 * The name of a remote. Defined by extensions, popular samples are `wsl` for the Windows 10813 * Subsystem for Linux or `ssh-remote` for remotes using a secure shell. 10814 * 10815 * *Note* that the value is `undefined` when there is no remote extension host but that the 10816 * value is defined in all extension hosts (local and remote) in case a remote extension host 10817 * exists. Use {@link Extension.extensionKind} to know if 10818 * a specific extension runs remote or not. 10819 */ 10820 export const remoteName: string | undefined; 10821 10822 /** 10823 * The detected default shell for the extension host, this is overridden by the 10824 * `terminal.integrated.defaultProfile` setting for the extension host's platform. Note that in 10825 * environments that do not support a shell the value is the empty string. 10826 */ 10827 export const shell: string; 10828 10829 /** 10830 * The UI kind property indicates from which UI extensions 10831 * are accessed from. For example, extensions could be accessed 10832 * from a desktop application or a web browser. 10833 */ 10834 export const uiKind: UIKind; 10835 10836 /** 10837 * Opens a link externally using the default application. Depending on the 10838 * used scheme this can be: 10839 * * a browser (`http:`, `https:`) 10840 * * a mail client (`mailto:`) 10841 * * VSCode itself (`vscode:` from `vscode.env.uriScheme`) 10842 * 10843 * *Note* that {@linkcode window.showTextDocument showTextDocument} is the right 10844 * way to open a text document inside the editor, not this function. 10845 * 10846 * @param target The uri that should be opened. 10847 * @returns A promise indicating if open was successful. 10848 */ 10849 export function openExternal(target: Uri): Thenable<boolean>; 10850 10851 /** 10852 * Resolves a uri to a form that is accessible externally. 10853 * 10854 * #### `http:` or `https:` scheme 10855 * 10856 * Resolves an *external* uri, such as a `http:` or `https:` link, from where the extension is running to a 10857 * uri to the same resource on the client machine. 10858 * 10859 * This is a no-op if the extension is running on the client machine. 10860 * 10861 * If the extension is running remotely, this function automatically establishes a port forwarding tunnel 10862 * from the local machine to `target` on the remote and returns a local uri to the tunnel. The lifetime of 10863 * the port forwarding tunnel is managed by the editor and the tunnel can be closed by the user. 10864 * 10865 * *Note* that uris passed through `openExternal` are automatically resolved and you should not call `asExternalUri` on them. 10866 * 10867 * #### `vscode.env.uriScheme` 10868 * 10869 * Creates a uri that - if opened in a browser (e.g. via `openExternal`) - will result in a registered {@link UriHandler} 10870 * to trigger. 10871 * 10872 * Extensions should not make any assumptions about the resulting uri and should not alter it in any way. 10873 * Rather, extensions can e.g. use this uri in an authentication flow, by adding the uri as callback query 10874 * argument to the server to authenticate to. 10875 * 10876 * *Note* that if the server decides to add additional query parameters to the uri (e.g. a token or secret), it 10877 * will appear in the uri that is passed to the {@link UriHandler}. 10878 * 10879 * **Example** of an authentication flow: 10880 * ```typescript 10881 * vscode.window.registerUriHandler({ 10882 * handleUri(uri: vscode.Uri): vscode.ProviderResult<void> { 10883 * if (uri.path === '/did-authenticate') { 10884 * console.log(uri.toString()); 10885 * } 10886 * } 10887 * }); 10888 * 10889 * const callableUri = await vscode.env.asExternalUri(vscode.Uri.parse(vscode.env.uriScheme + '://my.extension/did-authenticate')); 10890 * await vscode.env.openExternal(callableUri); 10891 * ``` 10892 * 10893 * *Note* that extensions should not cache the result of `asExternalUri` as the resolved uri may become invalid due to 10894 * a system or user action — for example, in remote cases, a user may close a port forwarding tunnel that was opened by 10895 * `asExternalUri`. 10896 * 10897 * #### Any other scheme 10898 * 10899 * Any other scheme will be handled as if the provided URI is a workspace URI. In that case, the method will return 10900 * a URI which, when handled, will make the editor open the workspace. 10901 * 10902 * @returns A uri that can be used on the client machine. 10903 */ 10904 export function asExternalUri(target: Uri): Thenable<Uri>; 10905 10906 /** 10907 * The current log level of the editor. 10908 */ 10909 export const logLevel: LogLevel; 10910 10911 /** 10912 * An {@link Event} which fires when the log level of the editor changes. 10913 */ 10914 export const onDidChangeLogLevel: Event<LogLevel>; 10915 } 10916 10917 /** 10918 * Namespace for dealing with commands. In short, a command is a function with a 10919 * unique identifier. The function is sometimes also called _command handler_. 10920 * 10921 * Commands can be added to the editor using the {@link commands.registerCommand registerCommand} 10922 * and {@link commands.registerTextEditorCommand registerTextEditorCommand} functions. Commands 10923 * can be executed {@link commands.executeCommand manually} or from a UI gesture. Those are: 10924 * 10925 * * palette - Use the `commands`-section in `package.json` to make a command show in 10926 * the [command palette](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette). 10927 * * keybinding - Use the `keybindings`-section in `package.json` to enable 10928 * [keybindings](https://code.visualstudio.com/docs/getstarted/keybindings#_advanced-customization) 10929 * for your extension. 10930 * 10931 * Commands from other extensions and from the editor itself are accessible to an extension. However, 10932 * when invoking an editor command not all argument types are supported. 10933 * 10934 * This is a sample that registers a command handler and adds an entry for that command to the palette. First 10935 * register a command handler with the identifier `extension.sayHello`. 10936 * ```javascript 10937 * commands.registerCommand('extension.sayHello', () => { 10938 * window.showInformationMessage('Hello World!'); 10939 * }); 10940 * ``` 10941 * Second, bind the command identifier to a title under which it will show in the palette (`package.json`). 10942 * ```json 10943 * { 10944 * "contributes": { 10945 * "commands": [{ 10946 * "command": "extension.sayHello", 10947 * "title": "Hello World" 10948 * }] 10949 * } 10950 * } 10951 * ``` 10952 */ 10953 export namespace commands { 10954 10955 /** 10956 * Registers a command that can be invoked via a keyboard shortcut, 10957 * a menu item, an action, or directly. 10958 * 10959 * Registering a command with an existing command identifier twice 10960 * will cause an error. 10961 * 10962 * @param command A unique identifier for the command. 10963 * @param callback A command handler function. 10964 * @param thisArg The `this` context used when invoking the handler function. 10965 * @returns Disposable which unregisters this command on disposal. 10966 */ 10967 export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable; 10968 10969 /** 10970 * Registers a text editor command that can be invoked via a keyboard shortcut, 10971 * a menu item, an action, or directly. 10972 * 10973 * Text editor commands are different from ordinary {@link commands.registerCommand commands} as 10974 * they only execute when there is an active editor when the command is called. Also, the 10975 * command handler of an editor command has access to the active editor and to an 10976 * {@link TextEditorEdit edit}-builder. Note that the edit-builder is only valid while the 10977 * callback executes. 10978 * 10979 * @param command A unique identifier for the command. 10980 * @param callback A command handler function with access to an {@link TextEditor editor} and an {@link TextEditorEdit edit}. 10981 * @param thisArg The `this` context used when invoking the handler function. 10982 * @returns Disposable which unregisters this command on disposal. 10983 */ 10984 export function registerTextEditorCommand(command: string, callback: (textEditor: TextEditor, edit: TextEditorEdit, ...args: any[]) => void, thisArg?: any): Disposable; 10985 10986 /** 10987 * Executes the command denoted by the given command identifier. 10988 * 10989 * * *Note 1:* When executing an editor command not all types are allowed to 10990 * be passed as arguments. Allowed are the primitive types `string`, `boolean`, 10991 * `number`, `undefined`, and `null`, as well as {@linkcode Position}, {@linkcode Range}, {@linkcode Uri} and {@linkcode Location}. 10992 * * *Note 2:* There are no restrictions when executing commands that have been contributed 10993 * by extensions. 10994 * 10995 * @param command Identifier of the command to execute. 10996 * @param rest Parameters passed to the command function. 10997 * @returns A thenable that resolves to the returned value of the given command. Returns `undefined` when 10998 * the command handler function doesn't return anything. 10999 */ 11000 export function executeCommand<T = unknown>(command: string, ...rest: any[]): Thenable<T>; 11001 11002 /** 11003 * Retrieve the list of all available commands. Commands starting with an underscore are 11004 * treated as internal commands. 11005 * 11006 * @param filterInternal Set `true` to not see internal commands (starting with an underscore) 11007 * @returns Thenable that resolves to a list of command ids. 11008 */ 11009 export function getCommands(filterInternal?: boolean): Thenable<string[]>; 11010 } 11011 11012 /** 11013 * Represents the state of a window. 11014 */ 11015 export interface WindowState { 11016 11017 /** 11018 * Whether the current window is focused. 11019 */ 11020 readonly focused: boolean; 11021 11022 /** 11023 * Whether the window has been interacted with recently. This will change 11024 * immediately on activity, or after a short time of user inactivity. 11025 */ 11026 readonly active: boolean; 11027 } 11028 11029 /** 11030 * A uri handler is responsible for handling system-wide {@link Uri uris}. 11031 * 11032 * @see {@link window.registerUriHandler}. 11033 */ 11034 export interface UriHandler { 11035 11036 /** 11037 * Handle the provided system-wide {@link Uri}. 11038 * 11039 * @see {@link window.registerUriHandler}. 11040 */ 11041 handleUri(uri: Uri): ProviderResult<void>; 11042 } 11043 11044 /** 11045 * Namespace for dealing with the current window of the editor. That is visible 11046 * and active editors, as well as, UI elements to show messages, selections, and 11047 * asking for user input. 11048 */ 11049 export namespace window { 11050 11051 /** 11052 * Represents the grid widget within the main editor area 11053 */ 11054 export const tabGroups: TabGroups; 11055 11056 /** 11057 * The currently active editor or `undefined`. The active editor is the one 11058 * that currently has focus or, when none has focus, the one that has changed 11059 * input most recently. 11060 */ 11061 export let activeTextEditor: TextEditor | undefined; 11062 11063 /** 11064 * The currently visible editors or an empty array. 11065 */ 11066 export let visibleTextEditors: readonly TextEditor[]; 11067 11068 /** 11069 * An {@link Event} which fires when the {@link window.activeTextEditor active editor} 11070 * has changed. *Note* that the event also fires when the active editor changes 11071 * to `undefined`. 11072 */ 11073 export const onDidChangeActiveTextEditor: Event<TextEditor | undefined>; 11074 11075 /** 11076 * An {@link Event} which fires when the array of {@link window.visibleTextEditors visible editors} 11077 * has changed. 11078 */ 11079 export const onDidChangeVisibleTextEditors: Event<readonly TextEditor[]>; 11080 11081 /** 11082 * An {@link Event} which fires when the selection in an editor has changed. 11083 */ 11084 export const onDidChangeTextEditorSelection: Event<TextEditorSelectionChangeEvent>; 11085 11086 /** 11087 * An {@link Event} which fires when the visible ranges of an editor has changed. 11088 */ 11089 export const onDidChangeTextEditorVisibleRanges: Event<TextEditorVisibleRangesChangeEvent>; 11090 11091 /** 11092 * An {@link Event} which fires when the options of an editor have changed. 11093 */ 11094 export const onDidChangeTextEditorOptions: Event<TextEditorOptionsChangeEvent>; 11095 11096 /** 11097 * An {@link Event} which fires when the view column of an editor has changed. 11098 */ 11099 export const onDidChangeTextEditorViewColumn: Event<TextEditorViewColumnChangeEvent>; 11100 11101 /** 11102 * The currently visible {@link NotebookEditor notebook editors} or an empty array. 11103 */ 11104 export const visibleNotebookEditors: readonly NotebookEditor[]; 11105 11106 /** 11107 * An {@link Event} which fires when the {@link window.visibleNotebookEditors visible notebook editors} 11108 * has changed. 11109 */ 11110 export const onDidChangeVisibleNotebookEditors: Event<readonly NotebookEditor[]>; 11111 11112 /** 11113 * The currently active {@link NotebookEditor notebook editor} or `undefined`. The active editor is the one 11114 * that currently has focus or, when none has focus, the one that has changed 11115 * input most recently. 11116 */ 11117 export const activeNotebookEditor: NotebookEditor | undefined; 11118 11119 /** 11120 * An {@link Event} which fires when the {@link window.activeNotebookEditor active notebook editor} 11121 * has changed. *Note* that the event also fires when the active editor changes 11122 * to `undefined`. 11123 */ 11124 export const onDidChangeActiveNotebookEditor: Event<NotebookEditor | undefined>; 11125 11126 /** 11127 * An {@link Event} which fires when the {@link NotebookEditor.selections notebook editor selections} 11128 * have changed. 11129 */ 11130 export const onDidChangeNotebookEditorSelection: Event<NotebookEditorSelectionChangeEvent>; 11131 11132 /** 11133 * An {@link Event} which fires when the {@link NotebookEditor.visibleRanges notebook editor visible ranges} 11134 * have changed. 11135 */ 11136 export const onDidChangeNotebookEditorVisibleRanges: Event<NotebookEditorVisibleRangesChangeEvent>; 11137 11138 /** 11139 * The currently opened terminals or an empty array. 11140 */ 11141 export const terminals: readonly Terminal[]; 11142 11143 /** 11144 * The currently active terminal or `undefined`. The active terminal is the one that 11145 * currently has focus or most recently had focus. 11146 */ 11147 export const activeTerminal: Terminal | undefined; 11148 11149 /** 11150 * An {@link Event} which fires when the {@link window.activeTerminal active terminal} 11151 * has changed. *Note* that the event also fires when the active terminal changes 11152 * to `undefined`. 11153 */ 11154 export const onDidChangeActiveTerminal: Event<Terminal | undefined>; 11155 11156 /** 11157 * An {@link Event} which fires when a terminal has been created, either through the 11158 * {@link window.createTerminal createTerminal} API or commands. 11159 */ 11160 export const onDidOpenTerminal: Event<Terminal>; 11161 11162 /** 11163 * An {@link Event} which fires when a terminal is disposed. 11164 */ 11165 export const onDidCloseTerminal: Event<Terminal>; 11166 11167 /** 11168 * An {@link Event} which fires when a {@link Terminal.state terminal's state} has changed. 11169 */ 11170 export const onDidChangeTerminalState: Event<Terminal>; 11171 11172 /** 11173 * Fires when shell integration activates or one of its properties changes in a terminal. 11174 */ 11175 export const onDidChangeTerminalShellIntegration: Event<TerminalShellIntegrationChangeEvent>; 11176 11177 /** 11178 * This will be fired when a terminal command is started. This event will fire only when 11179 * [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) is 11180 * activated for the terminal. 11181 */ 11182 export const onDidStartTerminalShellExecution: Event<TerminalShellExecutionStartEvent>; 11183 11184 /** 11185 * This will be fired when a terminal command is ended. This event will fire only when 11186 * [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) is 11187 * activated for the terminal. 11188 */ 11189 export const onDidEndTerminalShellExecution: Event<TerminalShellExecutionEndEvent>; 11190 11191 /** 11192 * Represents the current window's state. 11193 */ 11194 export const state: WindowState; 11195 11196 /** 11197 * An {@link Event} which fires when the focus or activity state of the current window 11198 * changes. The value of the event represents whether the window is focused. 11199 */ 11200 export const onDidChangeWindowState: Event<WindowState>; 11201 11202 /** 11203 * Show the given document in a text editor. A {@link ViewColumn column} can be provided 11204 * to control where the editor is being shown. Might change the {@link window.activeTextEditor active editor}. 11205 * 11206 * @param document A text document to be shown. 11207 * @param column A view column in which the {@link TextEditor editor} should be shown. The default is the {@link ViewColumn.Active active}. 11208 * Columns that do not exist will be created as needed up to the maximum of {@linkcode ViewColumn.Nine}. Use {@linkcode ViewColumn.Beside} 11209 * to open the editor to the side of the currently active one. 11210 * @param preserveFocus When `true` the editor will not take focus. 11211 * @returns A promise that resolves to an {@link TextEditor editor}. 11212 */ 11213 export function showTextDocument(document: TextDocument, column?: ViewColumn, preserveFocus?: boolean): Thenable<TextEditor>; 11214 11215 /** 11216 * Show the given document in a text editor. {@link TextDocumentShowOptions Options} can be provided 11217 * to control options of the editor is being shown. Might change the {@link window.activeTextEditor active editor}. 11218 * 11219 * @param document A text document to be shown. 11220 * @param options {@link TextDocumentShowOptions Editor options} to configure the behavior of showing the {@link TextEditor editor}. 11221 * @returns A promise that resolves to an {@link TextEditor editor}. 11222 */ 11223 export function showTextDocument(document: TextDocument, options?: TextDocumentShowOptions): Thenable<TextEditor>; 11224 11225 /** 11226 * A short-hand for `openTextDocument(uri).then(document => showTextDocument(document, options))`. 11227 * 11228 * @see {@link workspace.openTextDocument} 11229 * 11230 * @param uri A resource identifier. 11231 * @param options {@link TextDocumentShowOptions Editor options} to configure the behavior of showing the {@link TextEditor editor}. 11232 * @returns A promise that resolves to an {@link TextEditor editor}. 11233 */ 11234 export function showTextDocument(uri: Uri, options?: TextDocumentShowOptions): Thenable<TextEditor>; 11235 11236 /** 11237 * Show the given {@link NotebookDocument} in a {@link NotebookEditor notebook editor}. 11238 * 11239 * @param document A text document to be shown. 11240 * @param options {@link NotebookDocumentShowOptions Editor options} to configure the behavior of showing the {@link NotebookEditor notebook editor}. 11241 * 11242 * @returns A promise that resolves to an {@link NotebookEditor notebook editor}. 11243 */ 11244 export function showNotebookDocument(document: NotebookDocument, options?: NotebookDocumentShowOptions): Thenable<NotebookEditor>; 11245 11246 /** 11247 * Create a TextEditorDecorationType that can be used to add decorations to text editors. 11248 * 11249 * @param options Rendering options for the decoration type. 11250 * @returns A new decoration type instance. 11251 */ 11252 export function createTextEditorDecorationType(options: DecorationRenderOptions): TextEditorDecorationType; 11253 11254 /** 11255 * Show an information message to users. Optionally provide an array of items which will be presented as 11256 * clickable buttons. 11257 * 11258 * @param message The message to show. 11259 * @param items A set of items that will be rendered as actions in the message. 11260 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11261 */ 11262 export function showInformationMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>; 11263 11264 /** 11265 * Show an information message to users. Optionally provide an array of items which will be presented as 11266 * clickable buttons. 11267 * 11268 * @param message The message to show. 11269 * @param options Configures the behaviour of the message. 11270 * @param items A set of items that will be rendered as actions in the message. 11271 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11272 */ 11273 export function showInformationMessage<T extends string>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>; 11274 11275 /** 11276 * Show an information message. 11277 * 11278 * @see {@link window.showInformationMessage showInformationMessage} 11279 * 11280 * @param message The message to show. 11281 * @param items A set of items that will be rendered as actions in the message. 11282 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11283 */ 11284 export function showInformationMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>; 11285 11286 /** 11287 * Show an information message. 11288 * 11289 * @see {@link window.showInformationMessage showInformationMessage} 11290 * 11291 * @param message The message to show. 11292 * @param options Configures the behaviour of the message. 11293 * @param items A set of items that will be rendered as actions in the message. 11294 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11295 */ 11296 export function showInformationMessage<T extends MessageItem>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>; 11297 11298 /** 11299 * Show a warning message. 11300 * 11301 * @see {@link window.showInformationMessage showInformationMessage} 11302 * 11303 * @param message The message to show. 11304 * @param items A set of items that will be rendered as actions in the message. 11305 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11306 */ 11307 export function showWarningMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>; 11308 11309 /** 11310 * Show a warning message. 11311 * 11312 * @see {@link window.showInformationMessage showInformationMessage} 11313 * 11314 * @param message The message to show. 11315 * @param options Configures the behaviour of the message. 11316 * @param items A set of items that will be rendered as actions in the message. 11317 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11318 */ 11319 export function showWarningMessage<T extends string>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>; 11320 11321 /** 11322 * Show a warning message. 11323 * 11324 * @see {@link window.showInformationMessage showInformationMessage} 11325 * 11326 * @param message The message to show. 11327 * @param items A set of items that will be rendered as actions in the message. 11328 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11329 */ 11330 export function showWarningMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>; 11331 11332 /** 11333 * Show a warning message. 11334 * 11335 * @see {@link window.showInformationMessage showInformationMessage} 11336 * 11337 * @param message The message to show. 11338 * @param options Configures the behaviour of the message. 11339 * @param items A set of items that will be rendered as actions in the message. 11340 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11341 */ 11342 export function showWarningMessage<T extends MessageItem>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>; 11343 11344 /** 11345 * Show an error message. 11346 * 11347 * @see {@link window.showInformationMessage showInformationMessage} 11348 * 11349 * @param message The message to show. 11350 * @param items A set of items that will be rendered as actions in the message. 11351 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11352 */ 11353 export function showErrorMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>; 11354 11355 /** 11356 * Show an error message. 11357 * 11358 * @see {@link window.showInformationMessage showInformationMessage} 11359 * 11360 * @param message The message to show. 11361 * @param options Configures the behaviour of the message. 11362 * @param items A set of items that will be rendered as actions in the message. 11363 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11364 */ 11365 export function showErrorMessage<T extends string>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>; 11366 11367 /** 11368 * Show an error message. 11369 * 11370 * @see {@link window.showInformationMessage showInformationMessage} 11371 * 11372 * @param message The message to show. 11373 * @param items A set of items that will be rendered as actions in the message. 11374 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11375 */ 11376 export function showErrorMessage<T extends MessageItem>(message: string, ...items: T[]): Thenable<T | undefined>; 11377 11378 /** 11379 * Show an error message. 11380 * 11381 * @see {@link window.showInformationMessage showInformationMessage} 11382 * 11383 * @param message The message to show. 11384 * @param options Configures the behaviour of the message. 11385 * @param items A set of items that will be rendered as actions in the message. 11386 * @returns A thenable that resolves to the selected item or `undefined` when being dismissed. 11387 */ 11388 export function showErrorMessage<T extends MessageItem>(message: string, options: MessageOptions, ...items: T[]): Thenable<T | undefined>; 11389 11390 /** 11391 * Shows a selection list allowing multiple selections. 11392 * 11393 * @param items An array of strings, or a promise that resolves to an array of strings. 11394 * @param options Configures the behavior of the selection list. 11395 * @param token A token that can be used to signal cancellation. 11396 * @returns A thenable that resolves to the selected items or `undefined`. 11397 */ 11398 export function showQuickPick(items: readonly string[] | Thenable<readonly string[]>, options: QuickPickOptions & { /** literal-type defines return type */canPickMany: true }, token?: CancellationToken): Thenable<string[] | undefined>; 11399 11400 /** 11401 * Shows a selection list. 11402 * 11403 * @param items An array of strings, or a promise that resolves to an array of strings. 11404 * @param options Configures the behavior of the selection list. 11405 * @param token A token that can be used to signal cancellation. 11406 * @returns A thenable that resolves to the selected string or `undefined`. 11407 */ 11408 export function showQuickPick(items: readonly string[] | Thenable<readonly string[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<string | undefined>; 11409 11410 /** 11411 * Shows a selection list allowing multiple selections. 11412 * 11413 * @param items An array of items, or a promise that resolves to an array of items. 11414 * @param options Configures the behavior of the selection list. 11415 * @param token A token that can be used to signal cancellation. 11416 * @returns A thenable that resolves to the selected items or `undefined`. 11417 */ 11418 export function showQuickPick<T extends QuickPickItem>(items: readonly T[] | Thenable<readonly T[]>, options: QuickPickOptions & { /** literal-type defines return type */ canPickMany: true }, token?: CancellationToken): Thenable<T[] | undefined>; 11419 11420 /** 11421 * Shows a selection list. 11422 * 11423 * @param items An array of items, or a promise that resolves to an array of items. 11424 * @param options Configures the behavior of the selection list. 11425 * @param token A token that can be used to signal cancellation. 11426 * @returns A thenable that resolves to the selected item or `undefined`. 11427 */ 11428 export function showQuickPick<T extends QuickPickItem>(items: readonly T[] | Thenable<readonly T[]>, options?: QuickPickOptions, token?: CancellationToken): Thenable<T | undefined>; 11429 11430 /** 11431 * Shows a selection list of {@link workspace.workspaceFolders workspace folders} to pick from. 11432 * Returns `undefined` if no folder is open. 11433 * 11434 * @param options Configures the behavior of the workspace folder list. 11435 * @returns A promise that resolves to the workspace folder or `undefined`. 11436 */ 11437 export function showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions): Thenable<WorkspaceFolder | undefined>; 11438 11439 /** 11440 * Shows a file open dialog to the user which allows to select a file 11441 * for opening-purposes. 11442 * 11443 * @param options Options that control the dialog. 11444 * @returns A promise that resolves to the selected resources or `undefined`. 11445 */ 11446 export function showOpenDialog(options?: OpenDialogOptions): Thenable<Uri[] | undefined>; 11447 11448 /** 11449 * Shows a file save dialog to the user which allows to select a file 11450 * for saving-purposes. 11451 * 11452 * @param options Options that control the dialog. 11453 * @returns A promise that resolves to the selected resource or `undefined`. 11454 */ 11455 export function showSaveDialog(options?: SaveDialogOptions): Thenable<Uri | undefined>; 11456 11457 /** 11458 * Opens an input box to ask the user for input. 11459 * 11460 * The returned value will be `undefined` if the input box was canceled (e.g., pressing ESC). Otherwise the 11461 * returned value will be the string typed by the user or an empty string if the user did not type 11462 * anything but dismissed the input box with OK. 11463 * 11464 * @param options Configures the behavior of the input box. 11465 * @param token A token that can be used to signal cancellation. 11466 * @returns A thenable that resolves to a string the user provided or to `undefined` in case of dismissal. 11467 */ 11468 export function showInputBox(options?: InputBoxOptions, token?: CancellationToken): Thenable<string | undefined>; 11469 11470 /** 11471 * Creates a {@link QuickPick} to let the user pick an item from a list of items of type `T`. 11472 * 11473 * Note that in many cases the more convenient {@link window.showQuickPick} is easier to use. 11474 * {@link window.createQuickPick} should be used when {@link window.showQuickPick} does not offer 11475 * the required flexibility. 11476 * 11477 * @returns A new {@link QuickPick}. 11478 */ 11479 export function createQuickPick<T extends QuickPickItem>(): QuickPick<T>; 11480 11481 /** 11482 * Creates a {@link InputBox} to let the user enter some text input. 11483 * 11484 * Note that in many cases the more convenient {@link window.showInputBox} is easier to use. 11485 * {@link window.createInputBox} should be used when {@link window.showInputBox} does not offer 11486 * the required flexibility. 11487 * 11488 * @returns A new {@link InputBox}. 11489 */ 11490 export function createInputBox(): InputBox; 11491 11492 /** 11493 * Creates a new {@link OutputChannel output channel} with the given name and language id 11494 * If language id is not provided, then **Log** is used as default language id. 11495 * 11496 * You can access the visible or active output channel as a {@link TextDocument text document} from {@link window.visibleTextEditors visible editors} or {@link window.activeTextEditor active editor} 11497 * and use the language id to contribute language features like syntax coloring, code lens etc., 11498 * 11499 * @param name Human-readable string which will be used to represent the channel in the UI. 11500 * @param languageId The identifier of the language associated with the channel. 11501 * @returns A new output channel. 11502 */ 11503 export function createOutputChannel(name: string, languageId?: string): OutputChannel; 11504 11505 /** 11506 * Creates a new {@link LogOutputChannel log output channel} with the given name. 11507 * 11508 * @param name Human-readable string which will be used to represent the channel in the UI. 11509 * @param options Options for the log output channel. 11510 * @returns A new log output channel. 11511 */ 11512 export function createOutputChannel(name: string, options: { /** literal-type defines return type */log: true }): LogOutputChannel; 11513 11514 /** 11515 * Create and show a new webview panel. 11516 * 11517 * @param viewType Identifies the type of the webview panel. 11518 * @param title Title of the panel. 11519 * @param showOptions Where to show the webview in the editor. If preserveFocus is set, the new webview will not take focus. 11520 * @param options Settings for the new panel. 11521 * 11522 * @returns New webview panel. 11523 */ 11524 export function createWebviewPanel(viewType: string, title: string, showOptions: ViewColumn | { 11525 /** 11526 * The view column in which the {@link WebviewPanel} should be shown. 11527 */ 11528 readonly viewColumn: ViewColumn; 11529 /** 11530 * An optional flag that when `true` will stop the panel from taking focus. 11531 */ 11532 readonly preserveFocus?: boolean; 11533 }, options?: WebviewPanelOptions & WebviewOptions): WebviewPanel; 11534 11535 /** 11536 * Set a message to the status bar. This is a short hand for the more powerful 11537 * status bar {@link window.createStatusBarItem items}. 11538 * 11539 * @param text The message to show, supports icon substitution as in status bar {@link StatusBarItem.text items}. 11540 * @param hideAfterTimeout Timeout in milliseconds after which the message will be disposed. 11541 * @returns A disposable which hides the status bar message. 11542 */ 11543 export function setStatusBarMessage(text: string, hideAfterTimeout: number): Disposable; 11544 11545 /** 11546 * Set a message to the status bar. This is a short hand for the more powerful 11547 * status bar {@link window.createStatusBarItem items}. 11548 * 11549 * @param text The message to show, supports icon substitution as in status bar {@link StatusBarItem.text items}. 11550 * @param hideWhenDone Thenable on which completion (resolve or reject) the message will be disposed. 11551 * @returns A disposable which hides the status bar message. 11552 */ 11553 export function setStatusBarMessage(text: string, hideWhenDone: Thenable<any>): Disposable; 11554 11555 /** 11556 * Set a message to the status bar. This is a short hand for the more powerful 11557 * status bar {@link window.createStatusBarItem items}. 11558 * 11559 * *Note* that status bar messages stack and that they must be disposed when no 11560 * longer used. 11561 * 11562 * @param text The message to show, supports icon substitution as in status bar {@link StatusBarItem.text items}. 11563 * @returns A disposable which hides the status bar message. 11564 */ 11565 export function setStatusBarMessage(text: string): Disposable; 11566 11567 /** 11568 * Show progress in the Source Control viewlet while running the given callback and while 11569 * its returned promise isn't resolve or rejected. 11570 * 11571 * @deprecated Use `withProgress` instead. 11572 * 11573 * @param task A callback returning a promise. Progress increments can be reported with 11574 * the provided {@link Progress}-object. 11575 * @returns The thenable the task did return. 11576 */ 11577 export function withScmProgress<R>(task: (progress: Progress<number>) => Thenable<R>): Thenable<R>; 11578 11579 /** 11580 * Show progress in the editor. Progress is shown while running the given callback 11581 * and while the promise it returned isn't resolved nor rejected. The location at which 11582 * progress should show (and other details) is defined via the passed {@linkcode ProgressOptions}. 11583 * 11584 * @param options A {@linkcode ProgressOptions}-object describing the options to use for showing progress, like its location 11585 * @param task A callback returning a promise. Progress state can be reported with 11586 * the provided {@link Progress}-object. 11587 * 11588 * To report discrete progress, use `increment` to indicate how much work has been completed. Each call with 11589 * a `increment` value will be summed up and reflected as overall progress until 100% is reached (a value of 11590 * e.g. `10` accounts for `10%` of work done). 11591 * Note that currently only `ProgressLocation.Notification` is capable of showing discrete progress. 11592 * 11593 * To monitor if the operation has been cancelled by the user, use the provided {@linkcode CancellationToken}. 11594 * Note that currently only `ProgressLocation.Notification` is supporting to show a cancel button to cancel the 11595 * long running operation. 11596 * 11597 * @returns The thenable the task-callback returned. 11598 */ 11599 export function withProgress<R>(options: ProgressOptions, task: (progress: Progress<{ 11600 /** 11601 * A progress message that represents a chunk of work 11602 */ 11603 message?: string; 11604 /** 11605 * An increment for discrete progress. Increments will be summed up until 100% is reached 11606 */ 11607 increment?: number; 11608 }>, token: CancellationToken) => Thenable<R>): Thenable<R>; 11609 11610 /** 11611 * Creates a status bar {@link StatusBarItem item}. 11612 * 11613 * @param id The identifier of the item. Must be unique within the extension. 11614 * @param alignment The alignment of the item. 11615 * @param priority The priority of the item. Higher values mean the item should be shown more to the left. 11616 * @returns A new status bar item. 11617 */ 11618 export function createStatusBarItem(id: string, alignment?: StatusBarAlignment, priority?: number): StatusBarItem; 11619 11620 /** 11621 * Creates a status bar {@link StatusBarItem item}. 11622 * 11623 * @see {@link createStatusBarItem} for creating a status bar item with an identifier. 11624 * @param alignment The alignment of the item. 11625 * @param priority The priority of the item. Higher values mean the item should be shown more to the left. 11626 * @returns A new status bar item. 11627 */ 11628 export function createStatusBarItem(alignment?: StatusBarAlignment, priority?: number): StatusBarItem; 11629 11630 /** 11631 * Creates a {@link Terminal} with a backing shell process. The cwd of the terminal will be the workspace 11632 * directory if it exists. 11633 * 11634 * @param name Optional human-readable string which will be used to represent the terminal in the UI. 11635 * @param shellPath Optional path to a custom shell executable to be used in the terminal. 11636 * @param shellArgs Optional args for the custom shell executable. A string can be used on Windows only which 11637 * allows specifying shell args in 11638 * [command-line format](https://msdn.microsoft.com/en-au/08dfcab2-eb6e-49a4-80eb-87d4076c98c6). 11639 * @returns A new Terminal. 11640 * @throws When running in an environment where a new process cannot be started. 11641 */ 11642 export function createTerminal(name?: string, shellPath?: string, shellArgs?: readonly string[] | string): Terminal; 11643 11644 /** 11645 * Creates a {@link Terminal} with a backing shell process. 11646 * 11647 * @param options A TerminalOptions object describing the characteristics of the new terminal. 11648 * @returns A new Terminal. 11649 * @throws When running in an environment where a new process cannot be started. 11650 */ 11651 export function createTerminal(options: TerminalOptions): Terminal; 11652 11653 /** 11654 * Creates a {@link Terminal} where an extension controls its input and output. 11655 * 11656 * @param options An {@link ExtensionTerminalOptions} object describing 11657 * the characteristics of the new terminal. 11658 * @returns A new Terminal. 11659 */ 11660 export function createTerminal(options: ExtensionTerminalOptions): Terminal; 11661 11662 /** 11663 * Register a {@link TreeDataProvider} for the view contributed using the extension point `views`. 11664 * This will allow you to contribute data to the {@link TreeView} and update if the data changes. 11665 * 11666 * **Note:** To get access to the {@link TreeView} and perform operations on it, use {@link window.createTreeView createTreeView}. 11667 * 11668 * @param viewId Id of the view contributed using the extension point `views`. 11669 * @param treeDataProvider A {@link TreeDataProvider} that provides tree data for the view 11670 * @returns A {@link Disposable disposable} that unregisters the {@link TreeDataProvider}. 11671 */ 11672 export function registerTreeDataProvider<T>(viewId: string, treeDataProvider: TreeDataProvider<T>): Disposable; 11673 11674 /** 11675 * Create a {@link TreeView} for the view contributed using the extension point `views`. 11676 * @param viewId Id of the view contributed using the extension point `views`. 11677 * @param options Options for creating the {@link TreeView} 11678 * @returns a {@link TreeView}. 11679 */ 11680 export function createTreeView<T>(viewId: string, options: TreeViewOptions<T>): TreeView<T>; 11681 11682 /** 11683 * Registers a {@link UriHandler uri handler} capable of handling system-wide {@link Uri uris}. 11684 * In case there are multiple windows open, the topmost window will handle the uri. 11685 * A uri handler is scoped to the extension it is contributed from; it will only 11686 * be able to handle uris which are directed to the extension itself. A uri must respect 11687 * the following rules: 11688 * 11689 * - The uri-scheme must be `vscode.env.uriScheme`; 11690 * - The uri-authority must be the extension id (e.g. `my.extension`); 11691 * - The uri-path, -query and -fragment parts are arbitrary. 11692 * 11693 * For example, if the `my.extension` extension registers a uri handler, it will only 11694 * be allowed to handle uris with the prefix `product-name://my.extension`. 11695 * 11696 * An extension can only register a single uri handler in its entire activation lifetime. 11697 * 11698 * * *Note:* There is an activation event `onUri` that fires when a uri directed for 11699 * the current extension is about to be handled. 11700 * 11701 * @param handler The uri handler to register for this extension. 11702 * @returns A {@link Disposable disposable} that unregisters the handler. 11703 */ 11704 export function registerUriHandler(handler: UriHandler): Disposable; 11705 11706 /** 11707 * Registers a webview panel serializer. 11708 * 11709 * Extensions that support reviving should have an `"onWebviewPanel:viewType"` activation event and 11710 * make sure that `registerWebviewPanelSerializer` is called during activation. 11711 * 11712 * Only a single serializer may be registered at a time for a given `viewType`. 11713 * 11714 * @param viewType Type of the webview panel that can be serialized. 11715 * @param serializer Webview serializer. 11716 * @returns A {@link Disposable disposable} that unregisters the serializer. 11717 */ 11718 export function registerWebviewPanelSerializer(viewType: string, serializer: WebviewPanelSerializer): Disposable; 11719 11720 /** 11721 * Register a new provider for webview views. 11722 * 11723 * @param viewId Unique id of the view. This should match the `id` from the 11724 * `views` contribution in the package.json. 11725 * @param provider Provider for the webview views. 11726 * 11727 * @returns Disposable that unregisters the provider. 11728 */ 11729 export function registerWebviewViewProvider(viewId: string, provider: WebviewViewProvider, options?: { 11730 /** 11731 * Content settings for the webview created for this view. 11732 */ 11733 readonly webviewOptions?: { 11734 /** 11735 * Controls if the webview element itself (iframe) is kept around even when the view 11736 * is no longer visible. 11737 * 11738 * Normally the webview's html context is created when the view becomes visible 11739 * and destroyed when it is hidden. Extensions that have complex state 11740 * or UI can set the `retainContextWhenHidden` to make the editor keep the webview 11741 * context around, even when the webview moves to a background tab. When a webview using 11742 * `retainContextWhenHidden` becomes hidden, its scripts and other dynamic content are suspended. 11743 * When the view becomes visible again, the context is automatically restored 11744 * in the exact same state it was in originally. You cannot send messages to a 11745 * hidden webview, even with `retainContextWhenHidden` enabled. 11746 * 11747 * `retainContextWhenHidden` has a high memory overhead and should only be used if 11748 * your view's context cannot be quickly saved and restored. 11749 */ 11750 readonly retainContextWhenHidden?: boolean; 11751 }; 11752 }): Disposable; 11753 11754 /** 11755 * Register a provider for custom editors for the `viewType` contributed by the `customEditors` extension point. 11756 * 11757 * When a custom editor is opened, an `onCustomEditor:viewType` activation event is fired. Your extension 11758 * must register a {@linkcode CustomTextEditorProvider}, {@linkcode CustomReadonlyEditorProvider}, 11759 * {@linkcode CustomEditorProvider}for `viewType` as part of activation. 11760 * 11761 * @param viewType Unique identifier for the custom editor provider. This should match the `viewType` from the 11762 * `customEditors` contribution point. 11763 * @param provider Provider that resolves custom editors. 11764 * @param options Options for the provider. 11765 * 11766 * @returns Disposable that unregisters the provider. 11767 */ 11768 export function registerCustomEditorProvider(viewType: string, provider: CustomTextEditorProvider | CustomReadonlyEditorProvider | CustomEditorProvider, options?: { 11769 /** 11770 * Content settings for the webview panels created for this custom editor. 11771 */ 11772 readonly webviewOptions?: WebviewPanelOptions; 11773 11774 /** 11775 * Only applies to `CustomReadonlyEditorProvider | CustomEditorProvider`. 11776 * 11777 * Indicates that the provider allows multiple editor instances to be open at the same time for 11778 * the same resource. 11779 * 11780 * By default, the editor only allows one editor instance to be open at a time for each resource. If the 11781 * user tries to open a second editor instance for the resource, the first one is instead moved to where 11782 * the second one was to be opened. 11783 * 11784 * When `supportsMultipleEditorsPerDocument` is enabled, users can split and create copies of the custom 11785 * editor. In this case, the custom editor must make sure it can properly synchronize the states of all 11786 * editor instances for a resource so that they are consistent. 11787 */ 11788 readonly supportsMultipleEditorsPerDocument?: boolean; 11789 }): Disposable; 11790 11791 /** 11792 * Register provider that enables the detection and handling of links within the terminal. 11793 * @param provider The provider that provides the terminal links. 11794 * @returns Disposable that unregisters the provider. 11795 */ 11796 export function registerTerminalLinkProvider(provider: TerminalLinkProvider): Disposable; 11797 11798 /** 11799 * Registers a provider for a contributed terminal profile. 11800 * 11801 * @param id The ID of the contributed terminal profile. 11802 * @param provider The terminal profile provider. 11803 * @returns A {@link Disposable disposable} that unregisters the provider. 11804 */ 11805 export function registerTerminalProfileProvider(id: string, provider: TerminalProfileProvider): Disposable; 11806 /** 11807 * Register a file decoration provider. 11808 * 11809 * @param provider A {@link FileDecorationProvider}. 11810 * @returns A {@link Disposable} that unregisters the provider. 11811 */ 11812 export function registerFileDecorationProvider(provider: FileDecorationProvider): Disposable; 11813 11814 /** 11815 * The currently active color theme as configured in the settings. The active 11816 * theme can be changed via the `workbench.colorTheme` setting. 11817 */ 11818 export let activeColorTheme: ColorTheme; 11819 11820 /** 11821 * An {@link Event} which fires when the active color theme is changed or has changes. 11822 */ 11823 export const onDidChangeActiveColorTheme: Event<ColorTheme>; 11824 } 11825 11826 /** 11827 * Options for creating a {@link TreeView} 11828 */ 11829 export interface TreeViewOptions<T> { 11830 11831 /** 11832 * A data provider that provides tree data. 11833 */ 11834 treeDataProvider: TreeDataProvider<T>; 11835 11836 /** 11837 * Whether to show collapse all action or not. 11838 */ 11839 showCollapseAll?: boolean; 11840 11841 /** 11842 * Whether the tree supports multi-select. When the tree supports multi-select and a command is executed from the tree, 11843 * the first argument to the command is the tree item that the command was executed on and the second argument is an 11844 * array containing all selected tree items. 11845 */ 11846 canSelectMany?: boolean; 11847 11848 /** 11849 * An optional interface to implement drag and drop in the tree view. 11850 */ 11851 dragAndDropController?: TreeDragAndDropController<T>; 11852 11853 /** 11854 * By default, when the children of a tree item have already been fetched, child checkboxes are automatically managed based on the checked state of the parent tree item. 11855 * If the tree item is collapsed by default (meaning that the children haven't yet been fetched) then child checkboxes will not be updated. 11856 * To override this behavior and manage child and parent checkbox state in the extension, set this to `true`. 11857 * 11858 * Examples where {@link TreeViewOptions.manageCheckboxStateManually} is false, the default behavior: 11859 * 11860 * 1. A tree item is checked, then its children are fetched. The children will be checked. 11861 * 11862 * 2. A tree item's parent is checked. The tree item and all of it's siblings will be checked. 11863 * - [ ] Parent 11864 * - [ ] Child 1 11865 * - [ ] Child 2 11866 * When the user checks Parent, the tree will look like this: 11867 * - [x] Parent 11868 * - [x] Child 1 11869 * - [x] Child 2 11870 * 11871 * 3. A tree item and all of it's siblings are checked. The parent will be checked. 11872 * - [ ] Parent 11873 * - [ ] Child 1 11874 * - [ ] Child 2 11875 * When the user checks Child 1 and Child 2, the tree will look like this: 11876 * - [x] Parent 11877 * - [x] Child 1 11878 * - [x] Child 2 11879 * 11880 * 4. A tree item is unchecked. The parent will be unchecked. 11881 * - [x] Parent 11882 * - [x] Child 1 11883 * - [x] Child 2 11884 * When the user unchecks Child 1, the tree will look like this: 11885 * - [ ] Parent 11886 * - [ ] Child 1 11887 * - [x] Child 2 11888 */ 11889 manageCheckboxStateManually?: boolean; 11890 } 11891 11892 /** 11893 * The event that is fired when an element in the {@link TreeView} is expanded or collapsed 11894 */ 11895 export interface TreeViewExpansionEvent<T> { 11896 11897 /** 11898 * Element that is expanded or collapsed. 11899 */ 11900 readonly element: T; 11901 11902 } 11903 11904 /** 11905 * The event that is fired when there is a change in {@link TreeView.selection tree view's selection} 11906 */ 11907 export interface TreeViewSelectionChangeEvent<T> { 11908 11909 /** 11910 * Selected elements. 11911 */ 11912 readonly selection: readonly T[]; 11913 11914 } 11915 11916 /** 11917 * The event that is fired when there is a change in {@link TreeView.visible tree view's visibility} 11918 */ 11919 export interface TreeViewVisibilityChangeEvent { 11920 11921 /** 11922 * `true` if the {@link TreeView tree view} is visible otherwise `false`. 11923 */ 11924 readonly visible: boolean; 11925 } 11926 11927 /** 11928 * A file associated with a {@linkcode DataTransferItem}. 11929 * 11930 * Instances of this type can only be created by the editor and not by extensions. 11931 */ 11932 export interface DataTransferFile { 11933 /** 11934 * The name of the file. 11935 */ 11936 readonly name: string; 11937 11938 /** 11939 * The full file path of the file. 11940 * 11941 * May be `undefined` on web. 11942 */ 11943 readonly uri?: Uri; 11944 11945 /** 11946 * The full file contents of the file. 11947 */ 11948 data(): Thenable<Uint8Array>; 11949 } 11950 11951 /** 11952 * Encapsulates data transferred during drag and drop operations. 11953 */ 11954 export class DataTransferItem { 11955 /** 11956 * Get a string representation of this item. 11957 * 11958 * If {@linkcode DataTransferItem.value} is an object, this returns the result of json stringifying {@linkcode DataTransferItem.value} value. 11959 */ 11960 asString(): Thenable<string>; 11961 11962 /** 11963 * Try getting the {@link DataTransferFile file} associated with this data transfer item. 11964 * 11965 * Note that the file object is only valid for the scope of the drag and drop operation. 11966 * 11967 * @returns The file for the data transfer or `undefined` if the item is either not a file or the 11968 * file data cannot be accessed. 11969 */ 11970 asFile(): DataTransferFile | undefined; 11971 11972 /** 11973 * Custom data stored on this item. 11974 * 11975 * You can use `value` to share data across operations. The original object can be retrieved so long as the extension that 11976 * created the `DataTransferItem` runs in the same extension host. 11977 */ 11978 readonly value: any; 11979 11980 /** 11981 * @param value Custom data stored on this item. Can be retrieved using {@linkcode DataTransferItem.value}. 11982 */ 11983 constructor(value: any); 11984 } 11985 11986 /** 11987 * A map containing a mapping of the mime type of the corresponding transferred data. 11988 * 11989 * Drag and drop controllers that implement {@link TreeDragAndDropController.handleDrag `handleDrag`} can add additional mime types to the 11990 * data transfer. These additional mime types will only be included in the `handleDrop` when the drag was initiated from 11991 * an element in the same drag and drop controller. 11992 */ 11993 export class DataTransfer implements Iterable<[mimeType: string, item: DataTransferItem]> { 11994 /** 11995 * Retrieves the data transfer item for a given mime type. 11996 * 11997 * @param mimeType The mime type to get the data transfer item for, such as `text/plain` or `image/png`. 11998 * Mimes type look ups are case-insensitive. 11999 * 12000 * Special mime types: 12001 * - `text/uri-list` — A string with `toString()`ed Uris separated by `\r\n`. To specify a cursor position in the file, 12002 * set the Uri's fragment to `L3,5`, where 3 is the line number and 5 is the column number. 12003 */ 12004 get(mimeType: string): DataTransferItem | undefined; 12005 12006 /** 12007 * Sets a mime type to data transfer item mapping. 12008 * 12009 * @param mimeType The mime type to set the data for. Mimes types stored in lower case, with case-insensitive looks up. 12010 * @param value The data transfer item for the given mime type. 12011 */ 12012 set(mimeType: string, value: DataTransferItem): void; 12013 12014 /** 12015 * Allows iteration through the data transfer items. 12016 * 12017 * @param callbackfn Callback for iteration through the data transfer items. 12018 * @param thisArg The `this` context used when invoking the handler function. 12019 */ 12020 forEach(callbackfn: (item: DataTransferItem, mimeType: string, dataTransfer: DataTransfer) => void, thisArg?: any): void; 12021 12022 /** 12023 * Get a new iterator with the `[mime, item]` pairs for each element in this data transfer. 12024 */ 12025 [Symbol.iterator](): IterableIterator<[mimeType: string, item: DataTransferItem]>; 12026 } 12027 12028 /** 12029 * Provides support for drag and drop in `TreeView`. 12030 */ 12031 export interface TreeDragAndDropController<T> { 12032 12033 /** 12034 * The mime types that the {@link TreeDragAndDropController.handleDrop `handleDrop`} method of this `DragAndDropController` supports. 12035 * This could be well-defined, existing, mime types, and also mime types defined by the extension. 12036 * 12037 * To support drops from trees, you will need to add the mime type of that tree. 12038 * This includes drops from within the same tree. 12039 * The mime type of a tree is recommended to be of the format `application/vnd.code.tree.<treeidlowercase>`. 12040 * 12041 * Use the special `files` mime type to support all types of dropped files {@link DataTransferFile files}, regardless of the file's actual mime type. 12042 * 12043 * To learn the mime type of a dragged item: 12044 * 1. Set up your `DragAndDropController` 12045 * 2. Use the Developer: Set Log Level... command to set the level to "Debug" 12046 * 3. Open the developer tools and drag the item with unknown mime type over your tree. The mime types will be logged to the developer console 12047 * 12048 * Note that mime types that cannot be sent to the extension will be omitted. 12049 */ 12050 readonly dropMimeTypes: readonly string[]; 12051 12052 /** 12053 * The mime types that the {@link TreeDragAndDropController.handleDrag `handleDrag`} method of this `TreeDragAndDropController` may add to the tree data transfer. 12054 * This could be well-defined, existing, mime types, and also mime types defined by the extension. 12055 * 12056 * The recommended mime type of the tree (`application/vnd.code.tree.<treeidlowercase>`) will be automatically added. 12057 */ 12058 readonly dragMimeTypes: readonly string[]; 12059 12060 /** 12061 * When the user starts dragging items from this `DragAndDropController`, `handleDrag` will be called. 12062 * Extensions can use `handleDrag` to add their {@link DataTransferItem `DataTransferItem`} items to the drag and drop. 12063 * 12064 * Mime types added in `handleDrag` won't be available outside the application. 12065 * 12066 * When the items are dropped on **another tree item** in **the same tree**, your `DataTransferItem` objects 12067 * will be preserved. Use the recommended mime type for the tree (`application/vnd.code.tree.<treeidlowercase>`) to add 12068 * tree objects in a data transfer. See the documentation for `DataTransferItem` for how best to take advantage of this. 12069 * 12070 * To add a data transfer item that can be dragged into the editor, use the application specific mime type "text/uri-list". 12071 * The data for "text/uri-list" should be a string with `toString()`ed Uris separated by `\r\n`. To specify a cursor position in the file, 12072 * set the Uri's fragment to `L3,5`, where 3 is the line number and 5 is the column number. 12073 * 12074 * @param source The source items for the drag and drop operation. 12075 * @param dataTransfer The data transfer associated with this drag. 12076 * @param token A cancellation token indicating that drag has been cancelled. 12077 */ 12078 handleDrag?(source: readonly T[], dataTransfer: DataTransfer, token: CancellationToken): Thenable<void> | void; 12079 12080 /** 12081 * Called when a drag and drop action results in a drop on the tree that this `DragAndDropController` belongs to. 12082 * 12083 * Extensions should fire {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} for any elements that need to be refreshed. 12084 * 12085 * @param target The target tree element that the drop is occurring on. When undefined, the target is the root. 12086 * @param dataTransfer The data transfer items of the source of the drag. 12087 * @param token A cancellation token indicating that the drop has been cancelled. 12088 */ 12089 handleDrop?(target: T | undefined, dataTransfer: DataTransfer, token: CancellationToken): Thenable<void> | void; 12090 } 12091 12092 /** 12093 * A badge presenting a value for a view 12094 */ 12095 export interface ViewBadge { 12096 12097 /** 12098 * A label to present in tooltip for the badge. 12099 */ 12100 readonly tooltip: string; 12101 12102 /** 12103 * The value to present in the badge. 12104 */ 12105 readonly value: number; 12106 } 12107 12108 /** 12109 * An event describing the change in a tree item's checkbox state. 12110 */ 12111 export interface TreeCheckboxChangeEvent<T> { 12112 /** 12113 * The items that were checked or unchecked. 12114 */ 12115 readonly items: ReadonlyArray<[T, TreeItemCheckboxState]>; 12116 } 12117 12118 /** 12119 * Represents a Tree view 12120 */ 12121 export interface TreeView<T> extends Disposable { 12122 12123 /** 12124 * Event that is fired when an element is expanded 12125 */ 12126 readonly onDidExpandElement: Event<TreeViewExpansionEvent<T>>; 12127 12128 /** 12129 * Event that is fired when an element is collapsed 12130 */ 12131 readonly onDidCollapseElement: Event<TreeViewExpansionEvent<T>>; 12132 12133 /** 12134 * Currently selected elements. 12135 */ 12136 readonly selection: readonly T[]; 12137 12138 /** 12139 * Event that is fired when the {@link TreeView.selection selection} has changed 12140 */ 12141 readonly onDidChangeSelection: Event<TreeViewSelectionChangeEvent<T>>; 12142 12143 /** 12144 * `true` if the {@link TreeView tree view} is visible otherwise `false`. 12145 */ 12146 readonly visible: boolean; 12147 12148 /** 12149 * Event that is fired when {@link TreeView.visible visibility} has changed 12150 */ 12151 readonly onDidChangeVisibility: Event<TreeViewVisibilityChangeEvent>; 12152 12153 /** 12154 * An event to signal that an element or root has either been checked or unchecked. 12155 */ 12156 readonly onDidChangeCheckboxState: Event<TreeCheckboxChangeEvent<T>>; 12157 12158 /** 12159 * An optional human-readable message that will be rendered in the view. 12160 * Setting the message to null, undefined, or empty string will remove the message from the view. 12161 */ 12162 message?: string; 12163 12164 /** 12165 * The tree view title is initially taken from the extension package.json 12166 * Changes to the title property will be properly reflected in the UI in the title of the view. 12167 */ 12168 title?: string; 12169 12170 /** 12171 * An optional human-readable description which is rendered less prominently in the title of the view. 12172 * Setting the title description to null, undefined, or empty string will remove the description from the view. 12173 */ 12174 description?: string; 12175 12176 /** 12177 * The badge to display for this TreeView. 12178 * To remove the badge, set to undefined. 12179 */ 12180 badge?: ViewBadge | undefined; 12181 12182 /** 12183 * Reveals the given element in the tree view. 12184 * If the tree view is not visible then the tree view is shown and element is revealed. 12185 * 12186 * By default revealed element is selected. 12187 * In order to not to select, set the option `select` to `false`. 12188 * In order to focus, set the option `focus` to `true`. 12189 * In order to expand the revealed element, set the option `expand` to `true`. To expand recursively set `expand` to the number of levels to expand. 12190 * 12191 * * *NOTE:* You can expand only to 3 levels maximum. 12192 * * *NOTE:* The {@link TreeDataProvider} that the `TreeView` {@link window.createTreeView is registered with} with must implement {@link TreeDataProvider.getParent getParent} method to access this API. 12193 */ 12194 reveal(element: T, options?: { 12195 /** 12196 * If true, then the element will be selected. 12197 */ 12198 readonly select?: boolean; 12199 /** 12200 * If true, then the element will be focused. 12201 */ 12202 readonly focus?: boolean; 12203 /** 12204 * If true, then the element will be expanded. If a number is passed, then up to that number of levels of children will be expanded 12205 */ 12206 readonly expand?: boolean | number; 12207 }): Thenable<void>; 12208 } 12209 12210 /** 12211 * A data provider that provides tree data 12212 */ 12213 export interface TreeDataProvider<T> { 12214 /** 12215 * An optional event to signal that an element or root has changed. 12216 * This will trigger the view to update the changed element/root and its children recursively (if shown). 12217 * To signal that root has changed, do not pass any argument or pass `undefined` or `null`. 12218 */ 12219 onDidChangeTreeData?: Event<T | T[] | undefined | null | void>; 12220 12221 /** 12222 * Get {@link TreeItem} representation of the `element` 12223 * 12224 * @param element The element for which {@link TreeItem} representation is asked for. 12225 * @returns TreeItem representation of the element. 12226 */ 12227 getTreeItem(element: T): TreeItem | Thenable<TreeItem>; 12228 12229 /** 12230 * Get the children of `element` or root if no element is passed. 12231 * 12232 * @param element The element from which the provider gets children. Can be `undefined`. 12233 * @returns Children of `element` or root if no element is passed. 12234 */ 12235 getChildren(element?: T): ProviderResult<T[]>; 12236 12237 /** 12238 * Optional method to return the parent of `element`. 12239 * Return `null` or `undefined` if `element` is a child of root. 12240 * 12241 * **NOTE:** This method should be implemented in order to access {@link TreeView.reveal reveal} API. 12242 * 12243 * @param element The element for which the parent has to be returned. 12244 * @returns Parent of `element`. 12245 */ 12246 getParent?(element: T): ProviderResult<T>; 12247 12248 /** 12249 * Called on hover to resolve the {@link TreeItem.tooltip TreeItem} property if it is undefined. 12250 * Called on tree item click/open to resolve the {@link TreeItem.command TreeItem} property if it is undefined. 12251 * Only properties that were undefined can be resolved in `resolveTreeItem`. 12252 * Functionality may be expanded later to include being called to resolve other missing 12253 * properties on selection and/or on open. 12254 * 12255 * Will only ever be called once per TreeItem. 12256 * 12257 * onDidChangeTreeData should not be triggered from within resolveTreeItem. 12258 * 12259 * *Note* that this function is called when tree items are already showing in the UI. 12260 * Because of that, no property that changes the presentation (label, description, etc.) 12261 * can be changed. 12262 * 12263 * @param item Undefined properties of `item` should be set then `item` should be returned. 12264 * @param element The object associated with the TreeItem. 12265 * @param token A cancellation token. 12266 * @returns The resolved tree item or a thenable that resolves to such. It is OK to return the given 12267 * `item`. When no result is returned, the given `item` will be used. 12268 */ 12269 resolveTreeItem?(item: TreeItem, element: T, token: CancellationToken): ProviderResult<TreeItem>; 12270 } 12271 12272 /** 12273 * A tree item is an UI element of the tree. Tree items are created by the {@link TreeDataProvider data provider}. 12274 */ 12275 export class TreeItem { 12276 /** 12277 * A human-readable string describing this item. When `falsy`, it is derived from {@link TreeItem.resourceUri resourceUri}. 12278 */ 12279 label?: string | TreeItemLabel; 12280 12281 /** 12282 * Optional id for the tree item that has to be unique across tree. The id is used to preserve the selection and expansion state of the tree item. 12283 * 12284 * If not provided, an id is generated using the tree item's label. **Note** that when labels change, ids will change and that selection and expansion state cannot be kept stable anymore. 12285 */ 12286 id?: string; 12287 12288 /** 12289 * The icon path or {@link ThemeIcon} for the tree item. 12290 * When `falsy`, {@link ThemeIcon.Folder Folder Theme Icon} is assigned, if item is collapsible otherwise {@link ThemeIcon.File File Theme Icon}. 12291 * When a file or folder {@link ThemeIcon} is specified, icon is derived from the current file icon theme for the specified theme icon using {@link TreeItem.resourceUri resourceUri} (if provided). 12292 */ 12293 iconPath?: string | IconPath; 12294 12295 /** 12296 * A human-readable string which is rendered less prominent. 12297 * When `true`, it is derived from {@link TreeItem.resourceUri resourceUri} and when `falsy`, it is not shown. 12298 */ 12299 description?: string | boolean; 12300 12301 /** 12302 * A {@link Uri} representing the resource associated with this item. 12303 * 12304 * When set, this property is used to automatically derive several item properties if they are not explicitly provided: 12305 * - **Label**: Derived from the resource's file name when {@link TreeItem.label label} is not provided. 12306 * - **Description**: Derived from the resource's path when {@link TreeItem.description description} is set to `true`. 12307 * - **Icon**: Derived from the current file icon theme when {@link TreeItem.iconPath iconPath} is set to 12308 * {@link ThemeIcon.File} or {@link ThemeIcon.Folder}. 12309 */ 12310 resourceUri?: Uri; 12311 12312 /** 12313 * The tooltip text when you hover over this item. 12314 */ 12315 tooltip?: string | MarkdownString | undefined; 12316 12317 /** 12318 * The {@link Command} that should be executed when the tree item is selected. 12319 * 12320 * Please use `vscode.open` or `vscode.diff` as command IDs when the tree item is opening 12321 * something in the editor. Using these commands ensures that the resulting editor will 12322 * appear consistent with how other built-in trees open editors. 12323 */ 12324 command?: Command; 12325 12326 /** 12327 * {@link TreeItemCollapsibleState} of the tree item. 12328 */ 12329 collapsibleState?: TreeItemCollapsibleState; 12330 12331 /** 12332 * Context value of the tree item. This can be used to contribute item specific actions in the tree. 12333 * For example, a tree item is given a context value as `folder`. When contributing actions to `view/item/context` 12334 * using `menus` extension point, you can specify context value for key `viewItem` in `when` expression like `viewItem == folder`. 12335 * ```json 12336 * "contributes": { 12337 * "menus": { 12338 * "view/item/context": [ 12339 * { 12340 * "command": "extension.deleteFolder", 12341 * "when": "viewItem == folder" 12342 * } 12343 * ] 12344 * } 12345 * } 12346 * ``` 12347 * This will show action `extension.deleteFolder` only for items with `contextValue` is `folder`. 12348 */ 12349 contextValue?: string; 12350 12351 /** 12352 * Accessibility information used when screen reader interacts with this tree item. 12353 * Generally, a TreeItem has no need to set the `role` of the accessibilityInformation; 12354 * however, there are cases where a TreeItem is not displayed in a tree-like way where setting the `role` may make sense. 12355 */ 12356 accessibilityInformation?: AccessibilityInformation; 12357 12358 /** 12359 * {@link TreeItemCheckboxState TreeItemCheckboxState} of the tree item. 12360 * {@link TreeDataProvider.onDidChangeTreeData onDidChangeTreeData} should be fired when {@link TreeItem.checkboxState checkboxState} changes. 12361 */ 12362 checkboxState?: TreeItemCheckboxState | { 12363 /** 12364 * The {@link TreeItemCheckboxState} of the tree item 12365 */ 12366 readonly state: TreeItemCheckboxState; 12367 /** 12368 * A tooltip for the checkbox 12369 */ 12370 readonly tooltip?: string; 12371 /** 12372 * Accessibility information used when screen readers interact with this checkbox 12373 */ 12374 readonly accessibilityInformation?: AccessibilityInformation; 12375 }; 12376 12377 /** 12378 * @param label A human-readable string describing this item 12379 * @param collapsibleState {@link TreeItemCollapsibleState} of the tree item. Default is {@link TreeItemCollapsibleState.None} 12380 */ 12381 constructor(label: string | TreeItemLabel, collapsibleState?: TreeItemCollapsibleState); 12382 12383 /** 12384 * @param resourceUri The {@link Uri} of the resource representing this item. 12385 * @param collapsibleState {@link TreeItemCollapsibleState} of the tree item. Default is {@link TreeItemCollapsibleState.None} 12386 */ 12387 constructor(resourceUri: Uri, collapsibleState?: TreeItemCollapsibleState); 12388 } 12389 12390 /** 12391 * Collapsible state of the tree item 12392 */ 12393 export enum TreeItemCollapsibleState { 12394 /** 12395 * Determines an item can be neither collapsed nor expanded. Implies it has no children. 12396 */ 12397 None = 0, 12398 /** 12399 * Determines an item is collapsed 12400 */ 12401 Collapsed = 1, 12402 /** 12403 * Determines an item is expanded 12404 */ 12405 Expanded = 2 12406 } 12407 12408 /** 12409 * Label describing the {@link TreeItem Tree item} 12410 */ 12411 export interface TreeItemLabel { 12412 12413 /** 12414 * A human-readable string describing the {@link TreeItem Tree item}. 12415 */ 12416 label: string; 12417 12418 /** 12419 * Ranges in the label to highlight. A range is defined as a tuple of two number where the 12420 * first is the inclusive start index and the second the exclusive end index 12421 */ 12422 highlights?: [number, number][]; 12423 } 12424 12425 /** 12426 * Checkbox state of the tree item 12427 */ 12428 export enum TreeItemCheckboxState { 12429 /** 12430 * Determines an item is unchecked 12431 */ 12432 Unchecked = 0, 12433 /** 12434 * Determines an item is checked 12435 */ 12436 Checked = 1 12437 } 12438 12439 /** 12440 * Value-object describing what options a terminal should use. 12441 */ 12442 export interface TerminalOptions { 12443 /** 12444 * A human-readable string which will be used to represent the terminal in the UI. 12445 */ 12446 name?: string; 12447 12448 /** 12449 * A path to a custom shell executable to be used in the terminal. 12450 */ 12451 shellPath?: string; 12452 12453 /** 12454 * Args for the custom shell executable. A string can be used on Windows only which allows 12455 * specifying shell args in [command-line format](https://msdn.microsoft.com/en-au/08dfcab2-eb6e-49a4-80eb-87d4076c98c6). 12456 */ 12457 shellArgs?: string[] | string; 12458 12459 /** 12460 * A path or Uri for the current working directory to be used for the terminal. 12461 */ 12462 cwd?: string | Uri; 12463 12464 /** 12465 * Object with environment variables that will be added to the editor process. 12466 */ 12467 env?: { [key: string]: string | null | undefined }; 12468 12469 /** 12470 * Whether the terminal process environment should be exactly as provided in 12471 * `TerminalOptions.env`. When this is false (default), the environment will be based on the 12472 * window's environment and also apply configured platform settings like 12473 * `terminal.integrated.env.windows` on top. When this is true, the complete environment 12474 * must be provided as nothing will be inherited from the process or any configuration. 12475 */ 12476 strictEnv?: boolean; 12477 12478 /** 12479 * When enabled the terminal will run the process as normal but not be surfaced to the user 12480 * until `Terminal.show` is called. The typical usage for this is when you need to run 12481 * something that may need interactivity but only want to tell the user about it when 12482 * interaction is needed. Note that the terminals will still be exposed to all extensions 12483 * as normal. The hidden terminals will not be restored when the workspace is next opened. 12484 */ 12485 hideFromUser?: boolean; 12486 12487 /** 12488 * A message to write to the terminal on first launch, note that this is not sent to the 12489 * process but, rather written directly to the terminal. This supports escape sequences such 12490 * a setting text style. 12491 */ 12492 message?: string; 12493 12494 /** 12495 * The icon path or {@link ThemeIcon} for the terminal. 12496 */ 12497 iconPath?: IconPath; 12498 12499 /** 12500 * The icon {@link ThemeColor} for the terminal. 12501 * The `terminal.ansi*` theme keys are 12502 * recommended for the best contrast and consistency across themes. 12503 */ 12504 color?: ThemeColor; 12505 12506 /** 12507 * The {@link TerminalLocation} or {@link TerminalEditorLocationOptions} or {@link TerminalSplitLocationOptions} for the terminal. 12508 */ 12509 location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions; 12510 12511 /** 12512 * Opt-out of the default terminal persistence on restart and reload. 12513 * This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled. 12514 */ 12515 isTransient?: boolean; 12516 12517 /** 12518 * The nonce to use to verify shell integration sequences are coming from a trusted source. 12519 * An example impact of UX of this is if the command line is reported with a nonce, it will 12520 * not need to verify with the user that the command line is correct before rerunning it 12521 * via the [shell integration command decoration](https://code.visualstudio.com/docs/terminal/shell-integration#_command-decorations-and-the-overview-ruler). 12522 * 12523 * This should be used if the terminal includes [custom shell integration support](https://code.visualstudio.com/docs/terminal/shell-integration#_supported-escape-sequences). 12524 * It should be set to a random GUID which will then set the `VSCODE_NONCE` environment 12525 * variable. Inside the shell, this should then be removed from the environment so as to 12526 * protect it from general access. Once that is done it can be passed through in the 12527 * relevant sequences to make them trusted. 12528 */ 12529 shellIntegrationNonce?: string; 12530 } 12531 12532 /** 12533 * Value-object describing what options a virtual process terminal should use. 12534 */ 12535 export interface ExtensionTerminalOptions { 12536 /** 12537 * A human-readable string which will be used to represent the terminal in the UI. 12538 */ 12539 name: string; 12540 12541 /** 12542 * An implementation of {@link Pseudoterminal} that allows an extension to 12543 * control a terminal. 12544 */ 12545 pty: Pseudoterminal; 12546 12547 /** 12548 * The icon path or {@link ThemeIcon} for the terminal. 12549 */ 12550 iconPath?: IconPath; 12551 12552 /** 12553 * The icon {@link ThemeColor} for the terminal. 12554 * The standard `terminal.ansi*` theme keys are 12555 * recommended for the best contrast and consistency across themes. 12556 */ 12557 color?: ThemeColor; 12558 12559 /** 12560 * The {@link TerminalLocation} or {@link TerminalEditorLocationOptions} or {@link TerminalSplitLocationOptions} for the terminal. 12561 */ 12562 location?: TerminalLocation | TerminalEditorLocationOptions | TerminalSplitLocationOptions; 12563 12564 /** 12565 * Opt-out of the default terminal persistence on restart and reload. 12566 * This will only take effect when `terminal.integrated.enablePersistentSessions` is enabled. 12567 */ 12568 isTransient?: boolean; 12569 12570 /** 12571 * The nonce to use to verify shell integration sequences are coming from a trusted source. 12572 * An example impact of UX of this is if the command line is reported with a nonce, it will 12573 * not need to verify with the user that the command line is correct before rerunning it 12574 * via the [shell integration command decoration](https://code.visualstudio.com/docs/terminal/shell-integration#_command-decorations-and-the-overview-ruler). 12575 * 12576 * This should be used if the terminal includes [custom shell integration support](https://code.visualstudio.com/docs/terminal/shell-integration#_supported-escape-sequences). 12577 * It should be set to a random GUID. Inside the {@link Pseudoterminal} implementation, this value 12578 * can be passed through in the relevant sequences to make them trusted. 12579 */ 12580 shellIntegrationNonce?: string; 12581 } 12582 12583 /** 12584 * Defines the interface of a terminal pty, enabling extensions to control a terminal. 12585 */ 12586 export interface Pseudoterminal { 12587 /** 12588 * An event that when fired will write data to the terminal. Unlike 12589 * {@link Terminal.sendText} which sends text to the underlying child 12590 * pseudo-device (the child), this will write the text to parent pseudo-device (the 12591 * _terminal_ itself). 12592 * 12593 * Note writing `\n` will just move the cursor down 1 row, you need to write `\r` as well 12594 * to move the cursor to the left-most cell. 12595 * 12596 * Events fired before {@link Pseudoterminal.open} is called will be be ignored. 12597 * 12598 * **Example:** Write red text to the terminal 12599 * ```typescript 12600 * const writeEmitter = new vscode.EventEmitter<string>(); 12601 * const pty: vscode.Pseudoterminal = { 12602 * onDidWrite: writeEmitter.event, 12603 * open: () => writeEmitter.fire('\x1b[31mHello world\x1b[0m'), 12604 * close: () => {} 12605 * }; 12606 * vscode.window.createTerminal({ name: 'My terminal', pty }); 12607 * ``` 12608 * 12609 * **Example:** Move the cursor to the 10th row and 20th column and write an asterisk 12610 * ```typescript 12611 * writeEmitter.fire('\x1b[10;20H*'); 12612 * ``` 12613 */ 12614 onDidWrite: Event<string>; 12615 12616 /** 12617 * An event that when fired allows overriding the {@link Pseudoterminal.setDimensions dimensions} of the 12618 * terminal. Note that when set, the overridden dimensions will only take effect when they 12619 * are lower than the actual dimensions of the terminal (ie. there will never be a scroll 12620 * bar). Set to `undefined` for the terminal to go back to the regular dimensions (fit to 12621 * the size of the panel). 12622 * 12623 * Events fired before {@link Pseudoterminal.open} is called will be be ignored. 12624 * 12625 * **Example:** Override the dimensions of a terminal to 20 columns and 10 rows 12626 * ```typescript 12627 * const dimensionsEmitter = new vscode.EventEmitter<vscode.TerminalDimensions>(); 12628 * const pty: vscode.Pseudoterminal = { 12629 * onDidWrite: writeEmitter.event, 12630 * onDidOverrideDimensions: dimensionsEmitter.event, 12631 * open: () => { 12632 * dimensionsEmitter.fire({ 12633 * columns: 20, 12634 * rows: 10 12635 * }); 12636 * }, 12637 * close: () => {} 12638 * }; 12639 * vscode.window.createTerminal({ name: 'My terminal', pty }); 12640 * ``` 12641 */ 12642 onDidOverrideDimensions?: Event<TerminalDimensions | undefined>; 12643 12644 /** 12645 * An event that when fired will signal that the pty is closed and dispose of the terminal. 12646 * 12647 * Events fired before {@link Pseudoterminal.open} is called will be be ignored. 12648 * 12649 * A number can be used to provide an exit code for the terminal. Exit codes must be 12650 * positive and a non-zero exit codes signals failure which shows a notification for a 12651 * regular terminal and allows dependent tasks to proceed when used with the 12652 * `CustomExecution` API. 12653 * 12654 * **Example:** Exit the terminal when "y" is pressed, otherwise show a notification. 12655 * ```typescript 12656 * const writeEmitter = new vscode.EventEmitter<string>(); 12657 * const closeEmitter = new vscode.EventEmitter<void>(); 12658 * const pty: vscode.Pseudoterminal = { 12659 * onDidWrite: writeEmitter.event, 12660 * onDidClose: closeEmitter.event, 12661 * open: () => writeEmitter.fire('Press y to exit successfully'), 12662 * close: () => {}, 12663 * handleInput: data => { 12664 * if (data !== 'y') { 12665 * vscode.window.showInformationMessage('Something went wrong'); 12666 * } 12667 * closeEmitter.fire(); 12668 * } 12669 * }; 12670 * const terminal = vscode.window.createTerminal({ name: 'Exit example', pty }); 12671 * terminal.show(true); 12672 * ``` 12673 */ 12674 onDidClose?: Event<void | number>; 12675 12676 /** 12677 * An event that when fired allows changing the name of the terminal. 12678 * 12679 * Events fired before {@link Pseudoterminal.open} is called will be be ignored. 12680 * 12681 * **Example:** Change the terminal name to "My new terminal". 12682 * ```typescript 12683 * const writeEmitter = new vscode.EventEmitter<string>(); 12684 * const changeNameEmitter = new vscode.EventEmitter<string>(); 12685 * const pty: vscode.Pseudoterminal = { 12686 * onDidWrite: writeEmitter.event, 12687 * onDidChangeName: changeNameEmitter.event, 12688 * open: () => changeNameEmitter.fire('My new terminal'), 12689 * close: () => {} 12690 * }; 12691 * vscode.window.createTerminal({ name: 'My terminal', pty }); 12692 * ``` 12693 */ 12694 onDidChangeName?: Event<string>; 12695 12696 /** 12697 * Implement to handle when the pty is open and ready to start firing events. 12698 * 12699 * @param initialDimensions The dimensions of the terminal, this will be undefined if the 12700 * terminal panel has not been opened before this is called. 12701 */ 12702 open(initialDimensions: TerminalDimensions | undefined): void; 12703 12704 /** 12705 * Implement to handle when the terminal is closed by an act of the user. 12706 */ 12707 close(): void; 12708 12709 /** 12710 * Implement to handle incoming keystrokes in the terminal or when an extension calls 12711 * {@link Terminal.sendText}. `data` contains the keystrokes/text serialized into 12712 * their corresponding VT sequence representation. 12713 * 12714 * @param data The incoming data. 12715 * 12716 * **Example:** Echo input in the terminal. The sequence for enter (`\r`) is translated to 12717 * CRLF to go to a new line and move the cursor to the start of the line. 12718 * ```typescript 12719 * const writeEmitter = new vscode.EventEmitter<string>(); 12720 * const pty: vscode.Pseudoterminal = { 12721 * onDidWrite: writeEmitter.event, 12722 * open: () => {}, 12723 * close: () => {}, 12724 * handleInput: data => writeEmitter.fire(data === '\r' ? '\r\n' : data) 12725 * }; 12726 * vscode.window.createTerminal({ name: 'Local echo', pty }); 12727 * ``` 12728 */ 12729 handleInput?(data: string): void; 12730 12731 /** 12732 * Implement to handle when the number of rows and columns that fit into the terminal panel 12733 * changes, for example when font size changes or when the panel is resized. The initial 12734 * state of a terminal's dimensions should be treated as `undefined` until this is triggered 12735 * as the size of a terminal isn't known until it shows up in the user interface. 12736 * 12737 * When dimensions are overridden by 12738 * {@link Pseudoterminal.onDidOverrideDimensions onDidOverrideDimensions}, `setDimensions` will 12739 * continue to be called with the regular panel dimensions, allowing the extension continue 12740 * to react dimension changes. 12741 * 12742 * @param dimensions The new dimensions. 12743 */ 12744 setDimensions?(dimensions: TerminalDimensions): void; 12745 } 12746 12747 /** 12748 * Represents the dimensions of a terminal. 12749 */ 12750 export interface TerminalDimensions { 12751 /** 12752 * The number of columns in the terminal. 12753 */ 12754 readonly columns: number; 12755 12756 /** 12757 * The number of rows in the terminal. 12758 */ 12759 readonly rows: number; 12760 } 12761 12762 /** 12763 * Represents how a terminal exited. 12764 */ 12765 export interface TerminalExitStatus { 12766 /** 12767 * The exit code that a terminal exited with, it can have the following values: 12768 * - Zero: the terminal process or custom execution succeeded. 12769 * - Non-zero: the terminal process or custom execution failed. 12770 * - `undefined`: the user forcibly closed the terminal or a custom execution exited 12771 * without providing an exit code. 12772 */ 12773 readonly code: number | undefined; 12774 12775 /** 12776 * The reason that triggered the exit of a terminal. 12777 */ 12778 readonly reason: TerminalExitReason; 12779 } 12780 12781 /** 12782 * Terminal exit reason kind. 12783 */ 12784 export enum TerminalExitReason { 12785 /** 12786 * Unknown reason. 12787 */ 12788 Unknown = 0, 12789 12790 /** 12791 * The window closed/reloaded. 12792 */ 12793 Shutdown = 1, 12794 12795 /** 12796 * The shell process exited. 12797 */ 12798 Process = 2, 12799 12800 /** 12801 * The user closed the terminal. 12802 */ 12803 User = 3, 12804 12805 /** 12806 * An extension disposed the terminal. 12807 */ 12808 Extension = 4, 12809 } 12810 12811 /** 12812 * A type of mutation that can be applied to an environment variable. 12813 */ 12814 export enum EnvironmentVariableMutatorType { 12815 /** 12816 * Replace the variable's existing value. 12817 */ 12818 Replace = 1, 12819 /** 12820 * Append to the end of the variable's existing value. 12821 */ 12822 Append = 2, 12823 /** 12824 * Prepend to the start of the variable's existing value. 12825 */ 12826 Prepend = 3 12827 } 12828 12829 /** 12830 * Options applied to the mutator. 12831 */ 12832 export interface EnvironmentVariableMutatorOptions { 12833 /** 12834 * Apply to the environment just before the process is created. Defaults to false. 12835 */ 12836 applyAtProcessCreation?: boolean; 12837 12838 /** 12839 * Apply to the environment in the shell integration script. Note that this _will not_ apply 12840 * the mutator if shell integration is disabled or not working for some reason. Defaults to 12841 * false. 12842 */ 12843 applyAtShellIntegration?: boolean; 12844 } 12845 12846 /** 12847 * A type of mutation and its value to be applied to an environment variable. 12848 */ 12849 export interface EnvironmentVariableMutator { 12850 /** 12851 * The type of mutation that will occur to the variable. 12852 */ 12853 readonly type: EnvironmentVariableMutatorType; 12854 12855 /** 12856 * The value to use for the variable. 12857 */ 12858 readonly value: string; 12859 12860 /** 12861 * Options applied to the mutator. 12862 */ 12863 readonly options: EnvironmentVariableMutatorOptions; 12864 } 12865 12866 /** 12867 * A collection of mutations that an extension can apply to a process environment. 12868 */ 12869 export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> { 12870 /** 12871 * Whether the collection should be cached for the workspace and applied to the terminal 12872 * across window reloads. When true the collection will be active immediately such when the 12873 * window reloads. Additionally, this API will return the cached version if it exists. The 12874 * collection will be invalidated when the extension is uninstalled or when the collection 12875 * is cleared. Defaults to true. 12876 */ 12877 persistent: boolean; 12878 12879 /** 12880 * A description for the environment variable collection, this will be used to describe the 12881 * changes in the UI. 12882 */ 12883 description: string | MarkdownString | undefined; 12884 12885 /** 12886 * Replace an environment variable with a value. 12887 * 12888 * Note that an extension can only make a single change to any one variable, so this will 12889 * overwrite any previous calls to replace, append or prepend. 12890 * 12891 * @param variable The variable to replace. 12892 * @param value The value to replace the variable with. 12893 * @param options Options applied to the mutator, when no options are provided this will 12894 * default to `{ applyAtProcessCreation: true }`. 12895 */ 12896 replace(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void; 12897 12898 /** 12899 * Append a value to an environment variable. 12900 * 12901 * Note that an extension can only make a single change to any one variable, so this will 12902 * overwrite any previous calls to replace, append or prepend. 12903 * 12904 * @param variable The variable to append to. 12905 * @param value The value to append to the variable. 12906 * @param options Options applied to the mutator, when no options are provided this will 12907 * default to `{ applyAtProcessCreation: true }`. 12908 */ 12909 append(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void; 12910 12911 /** 12912 * Prepend a value to an environment variable. 12913 * 12914 * Note that an extension can only make a single change to any one variable, so this will 12915 * overwrite any previous calls to replace, append or prepend. 12916 * 12917 * @param variable The variable to prepend. 12918 * @param value The value to prepend to the variable. 12919 * @param options Options applied to the mutator, when no options are provided this will 12920 * default to `{ applyAtProcessCreation: true }`. 12921 */ 12922 prepend(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void; 12923 12924 /** 12925 * Gets the mutator that this collection applies to a variable, if any. 12926 * 12927 * @param variable The variable to get the mutator for. 12928 */ 12929 get(variable: string): EnvironmentVariableMutator | undefined; 12930 12931 /** 12932 * Iterate over each mutator in this collection. 12933 * 12934 * @param callback Function to execute for each entry. 12935 * @param thisArg The `this` context used when invoking the handler function. 12936 */ 12937 forEach(callback: (variable: string, mutator: EnvironmentVariableMutator, collection: EnvironmentVariableCollection) => any, thisArg?: any): void; 12938 12939 /** 12940 * Deletes this collection's mutator for a variable. 12941 * 12942 * @param variable The variable to delete the mutator for. 12943 */ 12944 delete(variable: string): void; 12945 12946 /** 12947 * Clears all mutators from this collection. 12948 */ 12949 clear(): void; 12950 } 12951 12952 /** 12953 * A collection of mutations that an extension can apply to a process environment. Applies to all scopes. 12954 */ 12955 export interface GlobalEnvironmentVariableCollection extends EnvironmentVariableCollection { 12956 /** 12957 * Gets scope-specific environment variable collection for the extension. This enables alterations to 12958 * terminal environment variables solely within the designated scope, and is applied in addition to (and 12959 * after) the global collection. 12960 * 12961 * Each object obtained through this method is isolated and does not impact objects for other scopes, 12962 * including the global collection. 12963 * 12964 * @param scope The scope to which the environment variable collection applies to. 12965 * 12966 * If a scope parameter is omitted, collection applicable to all relevant scopes for that parameter is 12967 * returned. For instance, if the 'workspaceFolder' parameter is not specified, the collection that applies 12968 * across all workspace folders will be returned. 12969 * 12970 * @returns Environment variable collection for the passed in scope. 12971 */ 12972 getScoped(scope: EnvironmentVariableScope): EnvironmentVariableCollection; 12973 } 12974 12975 /** 12976 * The scope object to which the environment variable collection applies. 12977 */ 12978 export interface EnvironmentVariableScope { 12979 /** 12980 * Any specific workspace folder to get collection for. 12981 */ 12982 workspaceFolder?: WorkspaceFolder; 12983 } 12984 12985 /** 12986 * A location in the editor at which progress information can be shown. It depends on the 12987 * location how progress is visually represented. 12988 */ 12989 export enum ProgressLocation { 12990 12991 /** 12992 * Show progress for the source control viewlet, as overlay for the icon and as progress bar 12993 * inside the viewlet (when visible). Neither supports cancellation nor discrete progress nor 12994 * a label to describe the operation. 12995 */ 12996 SourceControl = 1, 12997 12998 /** 12999 * Show progress in the status bar of the editor. Neither supports cancellation nor discrete progress. 13000 * Supports rendering of {@link ThemeIcon theme icons} via the `$(<name>)`-syntax in the progress label. 13001 */ 13002 Window = 10, 13003 13004 /** 13005 * Show progress as notification with an optional cancel button. Supports to show infinite and discrete 13006 * progress but does not support rendering of icons. 13007 */ 13008 Notification = 15 13009 } 13010 13011 /** 13012 * Value-object describing where and how progress should show. 13013 */ 13014 export interface ProgressOptions { 13015 13016 /** 13017 * The location at which progress should show. 13018 */ 13019 location: ProgressLocation | { 13020 /** 13021 * The identifier of a view for which progress should be shown. 13022 */ 13023 viewId: string; 13024 }; 13025 13026 /** 13027 * A human-readable string which will be used to describe the 13028 * operation. 13029 */ 13030 title?: string; 13031 13032 /** 13033 * Controls if a cancel button should show to allow the user to 13034 * cancel the long running operation. Note that currently only 13035 * `ProgressLocation.Notification` is supporting to show a cancel 13036 * button. 13037 */ 13038 cancellable?: boolean; 13039 } 13040 13041 /** 13042 * The base interface for all quick input types. 13043 * 13044 * Quick input provides a unified way for extensions to interact with users through simple UI elements. 13045 * A quick input UI is initially not visible. After configuring it through its properties the extension 13046 * can make it visible by calling {@link QuickInput.show show}. 13047 * 13048 * There are several reasons why this UI might have to be hidden and the extension will be notified 13049 * through {@link QuickInput.onDidHide onDidHide}. Examples include: an explicit call to 13050 * {@link QuickInput.hide hide}, the user pressing Esc, some other input UI opening, etc. 13051 * 13052 * A user pressing Enter or some other gesture implying acceptance of the current state does not 13053 * automatically hide this UI component. It is up to the extension to decide whether to accept the 13054 * user's input and if the UI should indeed be hidden through a call to {@link QuickInput.hide hide}. 13055 * 13056 * When the extension no longer needs this input UI, it should {@link QuickInput.dispose dispose} it 13057 * to allow for freeing up any resources associated with it. 13058 * 13059 * See {@link QuickPick} and {@link InputBox} for concrete UIs. 13060 */ 13061 export interface QuickInput { 13062 13063 /** 13064 * An optional title for the input UI. 13065 */ 13066 title: string | undefined; 13067 13068 /** 13069 * An optional current step count for multi-step input flows. 13070 */ 13071 step: number | undefined; 13072 13073 /** 13074 * An optional total step count for multi-step input flows. 13075 */ 13076 totalSteps: number | undefined; 13077 13078 /** 13079 * Determines if the UI should allow for user input. Defaults to `true`. 13080 * 13081 * Change this to `false`, for example, while validating user input or loading data for the next 13082 * step in user input. 13083 */ 13084 enabled: boolean; 13085 13086 /** 13087 * Determines if the UI should show a progress indicator. Defaults to `false`. 13088 * 13089 * Change this to `true`, for example, while loading more data or validating user input. 13090 */ 13091 busy: boolean; 13092 13093 /** 13094 * Determines if the UI should stay open even when losing UI focus. Defaults to `false`. 13095 * This setting is ignored on iPad and is always `false`. 13096 */ 13097 ignoreFocusOut: boolean; 13098 13099 /** 13100 * Makes the input UI visible in its current configuration. 13101 * 13102 * Any other input UI will first fire an {@link QuickInput.onDidHide onDidHide} event. 13103 */ 13104 show(): void; 13105 13106 /** 13107 * Hides this input UI. 13108 * 13109 * This will also fire an {@link QuickInput.onDidHide onDidHide} event. 13110 */ 13111 hide(): void; 13112 13113 /** 13114 * An event signaling when this input UI is hidden. 13115 * 13116 * There are several reasons why this UI might have to be hidden and the extension will be notified 13117 * through {@link QuickInput.onDidHide onDidHide}. Examples include: an explicit call to 13118 * {@link QuickInput.hide hide}, the user pressing Esc, some other input UI opening, etc. 13119 */ 13120 readonly onDidHide: Event<void>; 13121 13122 /** 13123 * Dispose of this input UI and any associated resources. 13124 * 13125 * If it is still visible, it is first hidden. After this call the input UI is no longer functional 13126 * and no additional methods or properties on it should be accessed. Instead a new input UI should 13127 * be created. 13128 */ 13129 dispose(): void; 13130 } 13131 13132 /** 13133 * A concrete {@link QuickInput} to let the user pick an item from a list of items of type `T`. 13134 * 13135 * The items can be filtered through a filter text field and there is an option 13136 * {@link QuickPick.canSelectMany canSelectMany} to allow for selecting multiple items. 13137 * 13138 * Note that in many cases the more convenient {@link window.showQuickPick} is easier to use. 13139 * {@link window.createQuickPick} should be used when {@link window.showQuickPick} does not offer 13140 * the required flexibility. 13141 */ 13142 export interface QuickPick<T extends QuickPickItem> extends QuickInput { 13143 13144 /** 13145 * The current value of the filter text. 13146 */ 13147 value: string; 13148 13149 /** 13150 * Optional placeholder text displayed in the filter text box when no value has been entered. 13151 */ 13152 placeholder: string | undefined; 13153 13154 /** 13155 * Optional text that provides instructions or context to the user. 13156 * 13157 * The prompt is displayed below the input box and above the list of items. 13158 */ 13159 prompt: string | undefined; 13160 13161 /** 13162 * An event signaling when the value of the filter text has changed. 13163 */ 13164 readonly onDidChangeValue: Event<string>; 13165 13166 /** 13167 * An event signaling when the user indicated acceptance of the selected item(s). 13168 */ 13169 readonly onDidAccept: Event<void>; 13170 13171 /** 13172 * Buttons for actions in the UI. 13173 */ 13174 buttons: readonly QuickInputButton[]; 13175 13176 /** 13177 * An event signaling when a button was triggered. 13178 * 13179 * This event fires for buttons stored in the {@link QuickPick.buttons buttons} array. This event does 13180 * not fire for buttons on a {@link QuickPickItem}. 13181 */ 13182 readonly onDidTriggerButton: Event<QuickInputButton>; 13183 13184 /** 13185 * An event signaling when a button in a particular {@link QuickPickItem} was triggered. 13186 * 13187 * This event does not fire for buttons in the title bar which are part of {@link QuickPick.buttons buttons}. 13188 */ 13189 readonly onDidTriggerItemButton: Event<QuickPickItemButtonEvent<T>>; 13190 13191 /** 13192 * Items to pick from. This can be read and updated by the extension. 13193 */ 13194 items: readonly T[]; 13195 13196 /** 13197 * Determines if multiple items can be selected at the same time. Defaults to `false`. 13198 */ 13199 canSelectMany: boolean; 13200 13201 /** 13202 * Determines if the filter text should also be matched against the {@link QuickPickItem.description description} of the items. Defaults to `false`. 13203 */ 13204 matchOnDescription: boolean; 13205 13206 /** 13207 * Determines if the filter text should also be matched against the {@link QuickPickItem.detail detail} of the items. Defaults to `false`. 13208 */ 13209 matchOnDetail: boolean; 13210 13211 /** 13212 * Determines if the scroll position is maintained when the quick pick items are updated. Defaults to `false`. 13213 */ 13214 keepScrollPosition?: boolean; 13215 13216 /** 13217 * Active items. This can be read and updated by the extension. 13218 */ 13219 activeItems: readonly T[]; 13220 13221 /** 13222 * An event signaling when the active items have changed. 13223 */ 13224 readonly onDidChangeActive: Event<readonly T[]>; 13225 13226 /** 13227 * Selected items. This can be read and updated by the extension. 13228 */ 13229 selectedItems: readonly T[]; 13230 13231 /** 13232 * An event signaling when the selected items have changed. 13233 */ 13234 readonly onDidChangeSelection: Event<readonly T[]>; 13235 } 13236 13237 /** 13238 * A concrete {@link QuickInput} to let the user input a text value. 13239 * 13240 * Note that in many cases the more convenient {@link window.showInputBox} is easier to use. 13241 * {@link window.createInputBox} should be used when {@link window.showInputBox} does not offer 13242 * the required flexibility. 13243 */ 13244 export interface InputBox extends QuickInput { 13245 13246 /** 13247 * The current input value. 13248 */ 13249 value: string; 13250 13251 /** 13252 * Selection range in the input value. 13253 * 13254 * Defined as tuple of two numbers where the first is the inclusive start index and the second the 13255 * exclusive end index. When `undefined` the whole pre-filled value will be selected, when empty 13256 * (start equals end) only the cursor will be set, otherwise the defined range will be selected. 13257 * 13258 * This property does not get updated when the user types or makes a selection, but it can be updated 13259 * by the extension. 13260 */ 13261 valueSelection: readonly [number, number] | undefined; 13262 13263 /** 13264 * Optional placeholder text shown when no value has been input. 13265 */ 13266 placeholder: string | undefined; 13267 13268 /** 13269 * Determines if the input value should be hidden. Defaults to `false`. 13270 */ 13271 password: boolean; 13272 13273 /** 13274 * An event signaling when the value has changed. 13275 */ 13276 readonly onDidChangeValue: Event<string>; 13277 13278 /** 13279 * An event signaling when the user indicated acceptance of the input value. 13280 */ 13281 readonly onDidAccept: Event<void>; 13282 13283 /** 13284 * Buttons for actions in the UI. 13285 */ 13286 buttons: readonly QuickInputButton[]; 13287 13288 /** 13289 * An event signaling when a button was triggered. 13290 */ 13291 readonly onDidTriggerButton: Event<QuickInputButton>; 13292 13293 /** 13294 * An optional prompt text providing some ask or explanation to the user. 13295 */ 13296 prompt: string | undefined; 13297 13298 /** 13299 * An optional validation message indicating a problem with the current input value. 13300 * 13301 * By setting a string, the InputBox will use a default {@link InputBoxValidationSeverity} of Error. 13302 * Returning `undefined` clears the validation message. 13303 */ 13304 validationMessage: string | InputBoxValidationMessage | undefined; 13305 } 13306 13307 /** 13308 * Specifies the location where a {@link QuickInputButton} should be rendered. 13309 */ 13310 export enum QuickInputButtonLocation { 13311 /** 13312 * The button is rendered in the title bar. 13313 */ 13314 Title = 1, 13315 13316 /** 13317 * The button is rendered inline to the right of the input box. 13318 */ 13319 Inline = 2, 13320 13321 /** 13322 * The button is rendered at the far end inside the input box. 13323 */ 13324 Input = 3 13325 } 13326 13327 /** 13328 * A button for an action in a {@link QuickPick} or {@link InputBox}. 13329 */ 13330 export interface QuickInputButton { 13331 /** 13332 * The icon for the button. 13333 */ 13334 readonly iconPath: IconPath; 13335 13336 /** 13337 * An optional tooltip displayed when hovering over the button. 13338 */ 13339 readonly tooltip?: string | undefined; 13340 13341 /** 13342 * The location where the button should be rendered. 13343 * 13344 * Defaults to {@link QuickInputButtonLocation.Title}. 13345 * 13346 * **Note:** This property is ignored if the button was added to a {@link QuickPickItem}. 13347 */ 13348 location?: QuickInputButtonLocation; 13349 13350 /** 13351 * When present, indicates that the button is a toggle button that can be checked or unchecked. 13352 */ 13353 readonly toggle?: { 13354 /** 13355 * Indicates whether the toggle button is currently checked. 13356 * This property will be updated when the button is toggled. 13357 */ 13358 checked: boolean; 13359 }; 13360 } 13361 13362 /** 13363 * Predefined buttons for {@link QuickPick} and {@link InputBox}. 13364 */ 13365 export class QuickInputButtons { 13366 /** 13367 * A predefined back button for {@link QuickPick} and {@link InputBox}. 13368 * 13369 * This button should be used for consistency when a navigation back button is needed. It comes 13370 * with a predefined icon, tooltip, and location. 13371 */ 13372 static readonly Back: QuickInputButton; 13373 13374 /** 13375 * @hidden 13376 */ 13377 private constructor(); 13378 } 13379 13380 /** 13381 * An event describing a button that was pressed on a {@link QuickPickItem}. 13382 */ 13383 export interface QuickPickItemButtonEvent<T extends QuickPickItem> { 13384 /** 13385 * The button that was pressed. 13386 */ 13387 readonly button: QuickInputButton; 13388 /** 13389 * The item that the button belongs to. 13390 */ 13391 readonly item: T; 13392 } 13393 13394 /** 13395 * An event describing an individual change in the text of a {@link TextDocument document}. 13396 */ 13397 export interface TextDocumentContentChangeEvent { 13398 /** 13399 * The range that got replaced. 13400 */ 13401 readonly range: Range; 13402 /** 13403 * The offset of the range that got replaced. 13404 */ 13405 readonly rangeOffset: number; 13406 /** 13407 * The length of the range that got replaced. 13408 */ 13409 readonly rangeLength: number; 13410 /** 13411 * The new text for the range. 13412 */ 13413 readonly text: string; 13414 } 13415 13416 /** 13417 * Reasons for why a text document has changed. 13418 */ 13419 export enum TextDocumentChangeReason { 13420 /** The text change is caused by an undo operation. */ 13421 Undo = 1, 13422 13423 /** The text change is caused by an redo operation. */ 13424 Redo = 2, 13425 } 13426 13427 /** 13428 * An event describing a transactional {@link TextDocument document} change. 13429 */ 13430 export interface TextDocumentChangeEvent { 13431 13432 /** 13433 * The affected document. 13434 */ 13435 readonly document: TextDocument; 13436 13437 /** 13438 * An array of content changes. 13439 */ 13440 readonly contentChanges: readonly TextDocumentContentChangeEvent[]; 13441 13442 /** 13443 * The reason why the document was changed. 13444 * Is `undefined` if the reason is not known. 13445 */ 13446 readonly reason: TextDocumentChangeReason | undefined; 13447 } 13448 13449 /** 13450 * Represents reasons why a text document is saved. 13451 */ 13452 export enum TextDocumentSaveReason { 13453 13454 /** 13455 * Manually triggered, e.g. by the user pressing save, by starting debugging, 13456 * or by an API call. 13457 */ 13458 Manual = 1, 13459 13460 /** 13461 * Automatic after a delay. 13462 */ 13463 AfterDelay = 2, 13464 13465 /** 13466 * When the editor lost focus. 13467 */ 13468 FocusOut = 3 13469 } 13470 13471 /** 13472 * An event that is fired when a {@link TextDocument document} will be saved. 13473 * 13474 * To make modifications to the document before it is being saved, call the 13475 * {@linkcode TextDocumentWillSaveEvent.waitUntil waitUntil}-function with a thenable 13476 * that resolves to an array of {@link TextEdit text edits}. 13477 */ 13478 export interface TextDocumentWillSaveEvent { 13479 13480 /** 13481 * The document that will be saved. 13482 */ 13483 readonly document: TextDocument; 13484 13485 /** 13486 * The reason why save was triggered. 13487 */ 13488 readonly reason: TextDocumentSaveReason; 13489 13490 /** 13491 * Allows to pause the event loop and to apply {@link TextEdit pre-save-edits}. 13492 * Edits of subsequent calls to this function will be applied in order. The 13493 * edits will be *ignored* if concurrent modifications of the document happened. 13494 * 13495 * *Note:* This function can only be called during event dispatch and not 13496 * in an asynchronous manner: 13497 * 13498 * ```ts 13499 * workspace.onWillSaveTextDocument(event => { 13500 * // async, will *throw* an error 13501 * setTimeout(() => event.waitUntil(promise)); 13502 * 13503 * // sync, OK 13504 * event.waitUntil(promise); 13505 * }) 13506 * ``` 13507 * 13508 * @param thenable A thenable that resolves to {@link TextEdit pre-save-edits}. 13509 */ 13510 waitUntil(thenable: Thenable<readonly TextEdit[]>): void; 13511 13512 /** 13513 * Allows to pause the event loop until the provided thenable resolved. 13514 * 13515 * *Note:* This function can only be called during event dispatch. 13516 * 13517 * @param thenable A thenable that delays saving. 13518 */ 13519 waitUntil(thenable: Thenable<any>): void; 13520 } 13521 13522 /** 13523 * An event that is fired when files are going to be created. 13524 * 13525 * To make modifications to the workspace before the files are created, 13526 * call the {@linkcode FileWillCreateEvent.waitUntil waitUntil}-function with a 13527 * thenable that resolves to a {@link WorkspaceEdit workspace edit}. 13528 */ 13529 export interface FileWillCreateEvent { 13530 13531 /** 13532 * A cancellation token. 13533 */ 13534 readonly token: CancellationToken; 13535 13536 /** 13537 * The files that are going to be created. 13538 */ 13539 readonly files: readonly Uri[]; 13540 13541 /** 13542 * Allows to pause the event and to apply a {@link WorkspaceEdit workspace edit}. 13543 * 13544 * *Note:* This function can only be called during event dispatch and not 13545 * in an asynchronous manner: 13546 * 13547 * ```ts 13548 * workspace.onWillCreateFiles(event => { 13549 * // async, will *throw* an error 13550 * setTimeout(() => event.waitUntil(promise)); 13551 * 13552 * // sync, OK 13553 * event.waitUntil(promise); 13554 * }) 13555 * ``` 13556 * 13557 * @param thenable A thenable that delays saving. 13558 */ 13559 waitUntil(thenable: Thenable<WorkspaceEdit>): void; 13560 13561 /** 13562 * Allows to pause the event until the provided thenable resolves. 13563 * 13564 * *Note:* This function can only be called during event dispatch. 13565 * 13566 * @param thenable A thenable that delays saving. 13567 */ 13568 waitUntil(thenable: Thenable<any>): void; 13569 } 13570 13571 /** 13572 * An event that is fired after files are created. 13573 */ 13574 export interface FileCreateEvent { 13575 13576 /** 13577 * The files that got created. 13578 */ 13579 readonly files: readonly Uri[]; 13580 } 13581 13582 /** 13583 * An event that is fired when files are going to be deleted. 13584 * 13585 * To make modifications to the workspace before the files are deleted, 13586 * call the {@link FileWillCreateEvent.waitUntil `waitUntil`}-function with a 13587 * thenable that resolves to a {@link WorkspaceEdit workspace edit}. 13588 */ 13589 export interface FileWillDeleteEvent { 13590 13591 /** 13592 * A cancellation token. 13593 */ 13594 readonly token: CancellationToken; 13595 13596 /** 13597 * The files that are going to be deleted. 13598 */ 13599 readonly files: readonly Uri[]; 13600 13601 /** 13602 * Allows to pause the event and to apply a {@link WorkspaceEdit workspace edit}. 13603 * 13604 * *Note:* This function can only be called during event dispatch and not 13605 * in an asynchronous manner: 13606 * 13607 * ```ts 13608 * workspace.onWillCreateFiles(event => { 13609 * // async, will *throw* an error 13610 * setTimeout(() => event.waitUntil(promise)); 13611 * 13612 * // sync, OK 13613 * event.waitUntil(promise); 13614 * }) 13615 * ``` 13616 * 13617 * @param thenable A thenable that delays saving. 13618 */ 13619 waitUntil(thenable: Thenable<WorkspaceEdit>): void; 13620 13621 /** 13622 * Allows to pause the event until the provided thenable resolves. 13623 * 13624 * *Note:* This function can only be called during event dispatch. 13625 * 13626 * @param thenable A thenable that delays saving. 13627 */ 13628 waitUntil(thenable: Thenable<any>): void; 13629 } 13630 13631 /** 13632 * An event that is fired after files are deleted. 13633 */ 13634 export interface FileDeleteEvent { 13635 13636 /** 13637 * The files that got deleted. 13638 */ 13639 readonly files: readonly Uri[]; 13640 } 13641 13642 /** 13643 * An event that is fired when files are going to be renamed. 13644 * 13645 * To make modifications to the workspace before the files are renamed, 13646 * call the {@link FileWillCreateEvent.waitUntil `waitUntil`}-function with a 13647 * thenable that resolves to a {@link WorkspaceEdit workspace edit}. 13648 */ 13649 export interface FileWillRenameEvent { 13650 13651 /** 13652 * A cancellation token. 13653 */ 13654 readonly token: CancellationToken; 13655 13656 /** 13657 * The files that are going to be renamed. 13658 */ 13659 readonly files: ReadonlyArray<{ 13660 /** 13661 * The old uri of a file. 13662 */ 13663 readonly oldUri: Uri; 13664 /** 13665 * The new uri of a file. 13666 */ 13667 readonly newUri: Uri; 13668 }>; 13669 13670 /** 13671 * Allows to pause the event and to apply a {@link WorkspaceEdit workspace edit}. 13672 * 13673 * *Note:* This function can only be called during event dispatch and not 13674 * in an asynchronous manner: 13675 * 13676 * ```ts 13677 * workspace.onWillCreateFiles(event => { 13678 * // async, will *throw* an error 13679 * setTimeout(() => event.waitUntil(promise)); 13680 * 13681 * // sync, OK 13682 * event.waitUntil(promise); 13683 * }) 13684 * ``` 13685 * 13686 * @param thenable A thenable that delays saving. 13687 */ 13688 waitUntil(thenable: Thenable<WorkspaceEdit>): void; 13689 13690 /** 13691 * Allows to pause the event until the provided thenable resolves. 13692 * 13693 * *Note:* This function can only be called during event dispatch. 13694 * 13695 * @param thenable A thenable that delays saving. 13696 */ 13697 waitUntil(thenable: Thenable<any>): void; 13698 } 13699 13700 /** 13701 * An event that is fired after files are renamed. 13702 */ 13703 export interface FileRenameEvent { 13704 13705 /** 13706 * The files that got renamed. 13707 */ 13708 readonly files: ReadonlyArray<{ 13709 /** 13710 * The old uri of a file. 13711 */ 13712 readonly oldUri: Uri; 13713 /** 13714 * The new uri of a file. 13715 */ 13716 readonly newUri: Uri; 13717 }>; 13718 } 13719 13720 /** 13721 * An event describing a change to the set of {@link workspace.workspaceFolders workspace folders}. 13722 */ 13723 export interface WorkspaceFoldersChangeEvent { 13724 /** 13725 * Added workspace folders. 13726 */ 13727 readonly added: readonly WorkspaceFolder[]; 13728 13729 /** 13730 * Removed workspace folders. 13731 */ 13732 readonly removed: readonly WorkspaceFolder[]; 13733 } 13734 13735 /** 13736 * A workspace folder is one of potentially many roots opened by the editor. All workspace folders 13737 * are equal which means there is no notion of an active or primary workspace folder. 13738 */ 13739 export interface WorkspaceFolder { 13740 13741 /** 13742 * The associated uri for this workspace folder. 13743 * 13744 * *Note:* The {@link Uri}-type was intentionally chosen such that future releases of the editor can support 13745 * workspace folders that are not stored on the local disk, e.g. `ftp://server/workspaces/foo`. 13746 */ 13747 readonly uri: Uri; 13748 13749 /** 13750 * The name of this workspace folder. Defaults to 13751 * the basename of its {@link Uri.path uri-path} 13752 */ 13753 readonly name: string; 13754 13755 /** 13756 * The ordinal number of this workspace folder. 13757 */ 13758 readonly index: number; 13759 } 13760 13761 /** 13762 * Namespace for dealing with the current workspace. A workspace is the collection of one 13763 * or more folders that are opened in an editor window (instance). 13764 * 13765 * It is also possible to open an editor without a workspace. For example, when you open a 13766 * new editor window by selecting a file from your platform's File menu, you will not be 13767 * inside a workspace. In this mode, some of the editor's capabilities are reduced but you can 13768 * still open text files and edit them. 13769 * 13770 * Refer to https://code.visualstudio.com/docs/editor/workspaces for more information on 13771 * the concept of workspaces. 13772 * 13773 * The workspace offers support for {@link workspace.createFileSystemWatcher listening} to fs 13774 * events and for {@link workspace.findFiles finding} files. Both perform well and run _outside_ 13775 * the editor-process so that they should be always used instead of nodejs-equivalents. 13776 */ 13777 export namespace workspace { 13778 13779 /** 13780 * A {@link FileSystem file system} instance that allows to interact with local and remote 13781 * files, e.g. `vscode.workspace.fs.readDirectory(someUri)` allows to retrieve all entries 13782 * of a directory or `vscode.workspace.fs.stat(anotherUri)` returns the meta data for a 13783 * file. 13784 */ 13785 export const fs: FileSystem; 13786 13787 /** 13788 * The uri of the first entry of {@linkcode workspace.workspaceFolders workspaceFolders} 13789 * as `string`. `undefined` if there is no first entry. 13790 * 13791 * Refer to https://code.visualstudio.com/docs/editor/workspaces for more information 13792 * on workspaces. 13793 * 13794 * @deprecated Use {@linkcode workspace.workspaceFolders workspaceFolders} instead. 13795 */ 13796 export const rootPath: string | undefined; 13797 13798 /** 13799 * List of workspace folders (0-N) that are open in the editor. `undefined` when no workspace 13800 * has been opened. 13801 * 13802 * Refer to https://code.visualstudio.com/docs/editor/workspaces for more information 13803 * on workspaces. 13804 */ 13805 export const workspaceFolders: readonly WorkspaceFolder[] | undefined; 13806 13807 /** 13808 * The name of the workspace. `undefined` when no workspace 13809 * has been opened. 13810 * 13811 * Refer to https://code.visualstudio.com/docs/editor/workspaces for more information on 13812 * the concept of workspaces. 13813 */ 13814 export const name: string | undefined; 13815 13816 /** 13817 * The location of the workspace file, for example: 13818 * 13819 * `file:///Users/name/Development/myProject.code-workspace` 13820 * 13821 * or 13822 * 13823 * `untitled:1555503116870` 13824 * 13825 * for a workspace that is untitled and not yet saved. 13826 * 13827 * Depending on the workspace that is opened, the value will be: 13828 * * `undefined` when no workspace is opened 13829 * * the path of the workspace file as `Uri` otherwise. if the workspace 13830 * is untitled, the returned URI will use the `untitled:` scheme 13831 * 13832 * The location can e.g. be used with the `vscode.openFolder` command to 13833 * open the workspace again after it has been closed. 13834 * 13835 * **Example:** 13836 * ```typescript 13837 * vscode.commands.executeCommand('vscode.openFolder', uriOfWorkspace); 13838 * ``` 13839 * 13840 * Refer to https://code.visualstudio.com/docs/editor/workspaces for more information on 13841 * the concept of workspaces. 13842 * 13843 * **Note:** it is not advised to use `workspace.workspaceFile` to write 13844 * configuration data into the file. You can use `workspace.getConfiguration().update()` 13845 * for that purpose which will work both when a single folder is opened as 13846 * well as an untitled or saved workspace. 13847 */ 13848 export const workspaceFile: Uri | undefined; 13849 13850 /** 13851 * An event that is emitted when a workspace folder is added or removed. 13852 * 13853 * **Note:** this event will not fire if the first workspace folder is added, removed or changed, 13854 * because in that case the currently executing extensions (including the one that listens to this 13855 * event) will be terminated and restarted so that the (deprecated) `rootPath` property is updated 13856 * to point to the first workspace folder. 13857 */ 13858 export const onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>; 13859 13860 /** 13861 * Returns the {@link WorkspaceFolder workspace folder} that contains a given uri. 13862 * * returns `undefined` when the given uri doesn't match any workspace folder 13863 * * returns the *input* when the given uri is a workspace folder itself 13864 * 13865 * @param uri An uri. 13866 * @returns A workspace folder or `undefined` 13867 */ 13868 export function getWorkspaceFolder(uri: Uri): WorkspaceFolder | undefined; 13869 13870 /** 13871 * Returns a path that is relative to the workspace folder or folders. 13872 * 13873 * When there are no {@link workspace.workspaceFolders workspace folders} or when the path 13874 * is not contained in them, the input is returned. 13875 * 13876 * @param pathOrUri A path or uri. When a uri is given its {@link Uri.fsPath fsPath} is used. 13877 * @param includeWorkspaceFolder When `true` and when the given path is contained inside a 13878 * workspace folder the name of the workspace is prepended. Defaults to `true` when there are 13879 * multiple workspace folders and `false` otherwise. 13880 * @returns A path relative to the root or the input. 13881 */ 13882 export function asRelativePath(pathOrUri: string | Uri, includeWorkspaceFolder?: boolean): string; 13883 13884 /** 13885 * This method replaces `deleteCount` {@link workspace.workspaceFolders workspace folders} starting at index `start` 13886 * by an optional set of `workspaceFoldersToAdd` on the `vscode.workspace.workspaceFolders` array. This "splice" 13887 * behavior can be used to add, remove and change workspace folders in a single operation. 13888 * 13889 * **Note:** in some cases calling this method may result in the currently executing extensions (including the 13890 * one that called this method) to be terminated and restarted. For example when the first workspace folder is 13891 * added, removed or changed the (deprecated) `rootPath` property is updated to point to the first workspace 13892 * folder. Another case is when transitioning from an empty or single-folder workspace into a multi-folder 13893 * workspace (see also: https://code.visualstudio.com/docs/editor/workspaces). 13894 * 13895 * Use the {@linkcode onDidChangeWorkspaceFolders onDidChangeWorkspaceFolders()} event to get notified when the 13896 * workspace folders have been updated. 13897 * 13898 * **Example:** adding a new workspace folder at the end of workspace folders 13899 * ```typescript 13900 * workspace.updateWorkspaceFolders(workspace.workspaceFolders ? workspace.workspaceFolders.length : 0, null, { uri: ...}); 13901 * ``` 13902 * 13903 * **Example:** removing the first workspace folder 13904 * ```typescript 13905 * workspace.updateWorkspaceFolders(0, 1); 13906 * ``` 13907 * 13908 * **Example:** replacing an existing workspace folder with a new one 13909 * ```typescript 13910 * workspace.updateWorkspaceFolders(0, 1, { uri: ...}); 13911 * ``` 13912 * 13913 * It is valid to remove an existing workspace folder and add it again with a different name 13914 * to rename that folder. 13915 * 13916 * **Note:** it is not valid to call {@link updateWorkspaceFolders updateWorkspaceFolders()} multiple times 13917 * without waiting for the {@linkcode onDidChangeWorkspaceFolders onDidChangeWorkspaceFolders()} to fire. 13918 * 13919 * @param start the zero-based location in the list of currently opened {@link WorkspaceFolder workspace folders} 13920 * from which to start deleting workspace folders. 13921 * @param deleteCount the optional number of workspace folders to remove. 13922 * @param workspaceFoldersToAdd the optional variable set of workspace folders to add in place of the deleted ones. 13923 * Each workspace is identified with a mandatory URI and an optional name. 13924 * @returns true if the operation was successfully started and false otherwise if arguments were used that would result 13925 * in invalid workspace folder state (e.g. 2 folders with the same URI). 13926 */ 13927 export function updateWorkspaceFolders(start: number, deleteCount: number | undefined | null, ...workspaceFoldersToAdd: { 13928 /** 13929 * The uri of a workspace folder that's to be added. 13930 */ 13931 readonly uri: Uri; 13932 /** 13933 * The name of a workspace folder that's to be added. 13934 */ 13935 readonly name?: string; 13936 }[]): boolean; 13937 13938 /** 13939 * Creates a file system watcher that is notified on file events (create, change, delete) 13940 * depending on the parameters provided. 13941 * 13942 * By default, all opened {@link workspace.workspaceFolders workspace folders} will be watched 13943 * for file changes recursively. 13944 * 13945 * Additional paths can be added for file watching by providing a {@link RelativePattern} with 13946 * a `base` path to watch. If the path is a folder and the `pattern` is complex (e.g. contains 13947 * `**` or path segments), it will be watched recursively and otherwise will be watched 13948 * non-recursively (i.e. only changes to the first level of the path will be reported). 13949 * 13950 * *Note* that paths that do not exist in the file system will be monitored with a delay until 13951 * created and then watched depending on the parameters provided. If a watched path is deleted, 13952 * the watcher will suspend and not report any events until the path is created again. 13953 * 13954 * If possible, keep the use of recursive watchers to a minimum because recursive file watching 13955 * is quite resource intense. 13956 * 13957 * Providing a `string` as `globPattern` acts as convenience method for watching file events in 13958 * all opened workspace folders. It cannot be used to add more folders for file watching, nor will 13959 * it report any file events from folders that are not part of the opened workspace folders. 13960 * 13961 * *Note* that case-sensitivity of the {@link globPattern} parameter will depend on the file system 13962 * where the watcher is running: on Windows and macOS the matching will be case-insensitive and 13963 * on Linux it will be case-sensitive. 13964 * 13965 * Optionally, flags to ignore certain kinds of events can be provided. 13966 * 13967 * To stop listening to events the watcher must be disposed. 13968 * 13969 * *Note* that file events from deleting a folder may not include events for the contained files. 13970 * For example, when a folder is moved to the trash, only one event is reported because technically 13971 * this is a rename/move operation and not a delete operation for each files within. 13972 * On top of that, performance optimizations are in place to fold multiple events that all belong 13973 * to the same parent operation (e.g. delete folder) into one event for that parent. As such, if 13974 * you need to know about all deleted files, you have to watch with `**` and deal with all file 13975 * events yourself. 13976 * 13977 * *Note* that file events from recursive file watchers may be excluded based on user configuration. 13978 * The setting `files.watcherExclude` helps to reduce the overhead of file events from folders 13979 * that are known to produce many file changes at once (such as `.git` folders). As such, 13980 * it is highly recommended to watch with simple patterns that do not require recursive watchers 13981 * where the exclude settings are ignored and you have full control over the events. 13982 * 13983 * *Note* that symbolic links are not automatically followed for file watching unless the path to 13984 * watch itself is a symbolic link. 13985 * 13986 * *Note* that the file paths that are reported for having changed may have a different path casing 13987 * compared to the actual casing on disk on case-insensitive platforms (typically macOS and Windows 13988 * but not Linux). We allow a user to open a workspace folder with any desired path casing and try 13989 * to preserve that. This means: 13990 * * if the path is within any of the workspace folders, the path will match the casing of the 13991 * workspace folder up to that portion of the path and match the casing on disk for children 13992 * * if the path is outside of any of the workspace folders, the casing will match the case of the 13993 * path that was provided for watching 13994 * In the same way, symbolic links are preserved, i.e. the file event will report the path of the 13995 * symbolic link as it was provided for watching and not the target. 13996 * 13997 * ### Examples 13998 * 13999 * The basic anatomy of a file watcher is as follows: 14000 * 14001 * ```ts 14002 * const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(<folder>, <pattern>)); 14003 * 14004 * watcher.onDidChange(uri => { ... }); // listen to files being changed 14005 * watcher.onDidCreate(uri => { ... }); // listen to files/folders being created 14006 * watcher.onDidDelete(uri => { ... }); // listen to files/folders getting deleted 14007 * 14008 * watcher.dispose(); // dispose after usage 14009 * ``` 14010 * 14011 * #### Workspace file watching 14012 * 14013 * If you only care about file events in a specific workspace folder: 14014 * 14015 * ```ts 14016 * vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.workspace.workspaceFolders[0], '**/*.js')); 14017 * ``` 14018 * 14019 * If you want to monitor file events across all opened workspace folders: 14020 * 14021 * ```ts 14022 * vscode.workspace.createFileSystemWatcher('**/*.js'); 14023 * ``` 14024 * 14025 * *Note:* the array of workspace folders can be empty if no workspace is opened (empty window). 14026 * 14027 * #### Out of workspace file watching 14028 * 14029 * To watch a folder for changes to *.js files outside the workspace (non recursively), pass in a `Uri` to such 14030 * a folder: 14031 * 14032 * ```ts 14033 * vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.Uri.file(<path to folder outside workspace>), '*.js')); 14034 * ``` 14035 * 14036 * And use a complex glob pattern to watch recursively: 14037 * 14038 * ```ts 14039 * vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.Uri.file(<path to folder outside workspace>), '**/*.js')); 14040 * ``` 14041 * 14042 * Here is an example for watching the active editor for file changes: 14043 * 14044 * ```ts 14045 * vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(vscode.window.activeTextEditor.document.uri, '*')); 14046 * ``` 14047 * 14048 * @param globPattern A {@link GlobPattern glob pattern} that controls which file events the watcher should report. 14049 * @param ignoreCreateEvents Ignore when files have been created. 14050 * @param ignoreChangeEvents Ignore when files have been changed. 14051 * @param ignoreDeleteEvents Ignore when files have been deleted. 14052 * @returns A new file system watcher instance. Must be disposed when no longer needed. 14053 */ 14054 export function createFileSystemWatcher(globPattern: GlobPattern, ignoreCreateEvents?: boolean, ignoreChangeEvents?: boolean, ignoreDeleteEvents?: boolean): FileSystemWatcher; 14055 14056 /** 14057 * Find files across all {@link workspace.workspaceFolders workspace folders} in the workspace. 14058 * 14059 * @example 14060 * findFiles('**/*.js', '**/node_modules/**', 10) 14061 * 14062 * @param include A {@link GlobPattern glob pattern} that defines the files to search for. The glob pattern 14063 * will be matched against the file paths of resulting matches relative to their workspace. Use a {@link RelativePattern relative pattern} 14064 * to restrict the search results to a {@link WorkspaceFolder workspace folder}. 14065 * @param exclude A {@link GlobPattern glob pattern} that defines files and folders to exclude. The glob pattern 14066 * will be matched against the file paths of resulting matches relative to their workspace. When `undefined`, default file-excludes (e.g. the `files.exclude`-setting 14067 * but not `search.exclude`) will apply. When `null`, no excludes will apply. 14068 * @param maxResults An upper-bound for the result. 14069 * @param token A token that can be used to signal cancellation to the underlying search engine. 14070 * @returns A thenable that resolves to an array of resource identifiers. Will return no results if no 14071 * {@link workspace.workspaceFolders workspace folders} are opened. 14072 */ 14073 export function findFiles(include: GlobPattern, exclude?: GlobPattern | null, maxResults?: number, token?: CancellationToken): Thenable<Uri[]>; 14074 14075 /** 14076 * Saves the editor identified by the given resource and returns the resulting resource or `undefined` 14077 * if save was not successful or no editor with the given resource was found. 14078 * 14079 * **Note** that an editor with the provided resource must be opened in order to be saved. 14080 * 14081 * @param uri the associated uri for the opened editor to save. 14082 * @returns A thenable that resolves when the save operation has finished. 14083 */ 14084 export function save(uri: Uri): Thenable<Uri | undefined>; 14085 14086 /** 14087 * Saves the editor identified by the given resource to a new file name as provided by the user and 14088 * returns the resulting resource or `undefined` if save was not successful or cancelled or no editor 14089 * with the given resource was found. 14090 * 14091 * **Note** that an editor with the provided resource must be opened in order to be saved as. 14092 * 14093 * @param uri the associated uri for the opened editor to save as. 14094 * @returns A thenable that resolves when the save-as operation has finished. 14095 */ 14096 export function saveAs(uri: Uri): Thenable<Uri | undefined>; 14097 14098 /** 14099 * Save all dirty files. 14100 * 14101 * @param includeUntitled Also save files that have been created during this session. 14102 * @returns A thenable that resolves when the files have been saved. Will return `false` 14103 * for any file that failed to save. 14104 */ 14105 export function saveAll(includeUntitled?: boolean): Thenable<boolean>; 14106 14107 /** 14108 * Make changes to one or many resources or create, delete, and rename resources as defined by the given 14109 * {@link WorkspaceEdit workspace edit}. 14110 * 14111 * All changes of a workspace edit are applied in the same order in which they have been added. If 14112 * multiple textual inserts are made at the same position, these strings appear in the resulting text 14113 * in the order the 'inserts' were made, unless that are interleaved with resource edits. Invalid sequences 14114 * like 'delete file a' -> 'insert text in file a' cause failure of the operation. 14115 * 14116 * When applying a workspace edit that consists only of text edits an 'all-or-nothing'-strategy is used. 14117 * A workspace edit with resource creations or deletions aborts the operation, e.g. consecutive edits will 14118 * not be attempted, when a single edit fails. 14119 * 14120 * @param edit A workspace edit. 14121 * @param metadata Optional {@link WorkspaceEditMetadata metadata} for the edit. 14122 * @returns A thenable that resolves when the edit could be applied. 14123 */ 14124 export function applyEdit(edit: WorkspaceEdit, metadata?: WorkspaceEditMetadata): Thenable<boolean>; 14125 14126 /** 14127 * All text documents currently known to the editor. 14128 */ 14129 export const textDocuments: readonly TextDocument[]; 14130 14131 /** 14132 * Opens a document. Will return early if this document is already open. Otherwise 14133 * the document is loaded and the {@link workspace.onDidOpenTextDocument didOpen}-event fires. 14134 * 14135 * The document is denoted by an {@link Uri}. Depending on the {@link Uri.scheme scheme} the 14136 * following rules apply: 14137 * * `file`-scheme: Open a file on disk (`openTextDocument(Uri.file(path))`). Will be rejected if the file 14138 * does not exist or cannot be loaded. 14139 * * `untitled`-scheme: Open a blank untitled file with associated path (`openTextDocument(Uri.file(path).with({ scheme: 'untitled' }))`). 14140 * The language will be derived from the file name. 14141 * * For all other schemes contributed {@link TextDocumentContentProvider text document content providers} and 14142 * {@link FileSystemProvider file system providers} are consulted. 14143 * 14144 * *Note* that the lifecycle of the returned document is owned by the editor and not by the extension. That means an 14145 * {@linkcode workspace.onDidCloseTextDocument onDidClose}-event can occur at any time after opening it. 14146 * 14147 * @param uri Identifies the resource to open. 14148 * @returns A promise that resolves to a {@link TextDocument document}. 14149 */ 14150 export function openTextDocument(uri: Uri, options?: { 14151 /** 14152 * The {@link TextDocument.encoding encoding} of the document to use 14153 * for decoding the underlying buffer to text. If omitted, the encoding 14154 * will be guessed based on the file content and/or the editor settings 14155 * unless the document is already opened. 14156 * 14157 * Opening a text document that was already opened with a different encoding 14158 * has the potential of changing the text contents of the text document. 14159 * Specifically, when the encoding results in a different set of characters 14160 * than the previous encoding. As such, an error is thrown for dirty documents 14161 * when the specified encoding is different from the encoding of the document. 14162 * 14163 * See {@link TextDocument.encoding} for more information about valid 14164 * values for encoding. Using an unsupported encoding will fallback to the 14165 * default encoding for the document. 14166 * 14167 * *Note* that if you open a document with an encoding that does not 14168 * support decoding the underlying bytes, content may be replaced with 14169 * substitution characters as appropriate. 14170 */ 14171 readonly encoding?: string; 14172 }): Thenable<TextDocument>; 14173 14174 /** 14175 * A short-hand for `openTextDocument(Uri.file(path))`. 14176 * 14177 * @see {@link workspace.openTextDocument} 14178 * @param path A path of a file on disk. 14179 * @returns A promise that resolves to a {@link TextDocument document}. 14180 */ 14181 export function openTextDocument(path: string, options?: { 14182 /** 14183 * The {@link TextDocument.encoding encoding} of the document to use 14184 * for decoding the underlying buffer to text. If omitted, the encoding 14185 * will be guessed based on the file content and/or the editor settings 14186 * unless the document is already opened. 14187 * 14188 * Opening a text document that was already opened with a different encoding 14189 * has the potential of changing the text contents of the text document. 14190 * Specifically, when the encoding results in a different set of characters 14191 * than the previous encoding. As such, an error is thrown for dirty documents 14192 * when the specified encoding is different from the encoding of the document. 14193 * 14194 * See {@link TextDocument.encoding} for more information about valid 14195 * values for encoding. Using an unsupported encoding will fallback to the 14196 * default encoding for the document. 14197 * 14198 * *Note* that if you open a document with an encoding that does not 14199 * support decoding the underlying bytes, content may be replaced with 14200 * substitution characters as appropriate. 14201 */ 14202 readonly encoding?: string; 14203 }): Thenable<TextDocument>; 14204 14205 /** 14206 * Opens an untitled text document. The editor will prompt the user for a file 14207 * path when the document is to be saved. The `options` parameter allows to 14208 * specify the *language* and/or the *content* of the document. 14209 * 14210 * @param options Options to control how the document will be created. 14211 * @returns A promise that resolves to a {@link TextDocument document}. 14212 */ 14213 export function openTextDocument(options?: { 14214 /** 14215 * The {@link TextDocument.languageId language} of the document. 14216 */ 14217 language?: string; 14218 /** 14219 * The initial contents of the document. 14220 */ 14221 content?: string; 14222 /** 14223 * The {@link TextDocument.encoding encoding} of the document. 14224 * 14225 * See {@link TextDocument.encoding} for more information about valid 14226 * values for encoding. Using an unsupported encoding will fallback to the 14227 * default encoding for the document. 14228 */ 14229 readonly encoding?: string; 14230 }): Thenable<TextDocument>; 14231 14232 /** 14233 * Register a text document content provider. 14234 * 14235 * Only one provider can be registered per scheme. 14236 * 14237 * @param scheme The uri-scheme to register for. 14238 * @param provider A content provider. 14239 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14240 */ 14241 export function registerTextDocumentContentProvider(scheme: string, provider: TextDocumentContentProvider): Disposable; 14242 14243 /** 14244 * An event that is emitted when a {@link TextDocument text document} is opened or when the language id 14245 * of a text document {@link languages.setTextDocumentLanguage has been changed}. 14246 * 14247 * To add an event listener when a visible text document is opened, use the {@link TextEditor} events in the 14248 * {@link window} namespace. Note that: 14249 * 14250 * - The event is emitted before the {@link TextDocument document} is updated in the 14251 * {@link window.activeTextEditor active text editor} 14252 * - When a {@link TextDocument text document} is already open (e.g.: open in another {@link window.visibleTextEditors visible text editor}) this event is not emitted 14253 * 14254 */ 14255 export const onDidOpenTextDocument: Event<TextDocument>; 14256 14257 /** 14258 * An event that is emitted when a {@link TextDocument text document} is disposed or when the language id 14259 * of a text document {@link languages.setTextDocumentLanguage has been changed}. 14260 * 14261 * *Note 1:* There is no guarantee that this event fires when an editor tab is closed, use the 14262 * {@linkcode window.onDidChangeVisibleTextEditors onDidChangeVisibleTextEditors}-event to know when editors change. 14263 * 14264 * *Note 2:* A document can be open but not shown in an editor which means this event can fire 14265 * for a document that has not been shown in an editor. 14266 */ 14267 export const onDidCloseTextDocument: Event<TextDocument>; 14268 14269 /** 14270 * An event that is emitted when a {@link TextDocument text document} is changed. This usually happens 14271 * when the {@link TextDocument.getText contents} changes but also when other things like the 14272 * {@link TextDocument.isDirty dirty}-state changes. 14273 */ 14274 export const onDidChangeTextDocument: Event<TextDocumentChangeEvent>; 14275 14276 /** 14277 * An event that is emitted when a {@link TextDocument text document} will be saved to disk. 14278 * 14279 * *Note 1:* Subscribers can delay saving by registering asynchronous work. For the sake of data integrity the editor 14280 * might save without firing this event. For instance when shutting down with dirty files. 14281 * 14282 * *Note 2:* Subscribers are called sequentially and they can {@link TextDocumentWillSaveEvent.waitUntil delay} saving 14283 * by registering asynchronous work. Protection against misbehaving listeners is implemented as such: 14284 * * there is an overall time budget that all listeners share and if that is exhausted no further listener is called 14285 * * listeners that take a long time or produce errors frequently will not be called anymore 14286 * 14287 * The current thresholds are 1.5 seconds as overall time budget and a listener can misbehave 3 times before being ignored. 14288 */ 14289 export const onWillSaveTextDocument: Event<TextDocumentWillSaveEvent>; 14290 14291 /** 14292 * An event that is emitted when a {@link TextDocument text document} is saved to disk. 14293 */ 14294 export const onDidSaveTextDocument: Event<TextDocument>; 14295 14296 /** 14297 * All notebook documents currently known to the editor. 14298 */ 14299 export const notebookDocuments: readonly NotebookDocument[]; 14300 14301 /** 14302 * Open a notebook. Will return early if this notebook is already {@link notebookDocuments loaded}. Otherwise 14303 * the notebook is loaded and the {@linkcode onDidOpenNotebookDocument}-event fires. 14304 * 14305 * *Note* that the lifecycle of the returned notebook is owned by the editor and not by the extension. That means an 14306 * {@linkcode onDidCloseNotebookDocument}-event can occur at any time after. 14307 * 14308 * *Note* that opening a notebook does not show a notebook editor. This function only returns a notebook document which 14309 * can be shown in a notebook editor but it can also be used for other things. 14310 * 14311 * @param uri The resource to open. 14312 * @returns A promise that resolves to a {@link NotebookDocument notebook} 14313 */ 14314 export function openNotebookDocument(uri: Uri): Thenable<NotebookDocument>; 14315 14316 /** 14317 * Open an untitled notebook. The editor will prompt the user for a file 14318 * path when the document is to be saved. 14319 * 14320 * @see {@link workspace.openNotebookDocument} 14321 * @param notebookType The notebook type that should be used. 14322 * @param content The initial contents of the notebook. 14323 * @returns A promise that resolves to a {@link NotebookDocument notebook}. 14324 */ 14325 export function openNotebookDocument(notebookType: string, content?: NotebookData): Thenable<NotebookDocument>; 14326 14327 /** 14328 * An event that is emitted when a {@link NotebookDocument notebook} has changed. 14329 */ 14330 export const onDidChangeNotebookDocument: Event<NotebookDocumentChangeEvent>; 14331 14332 /** 14333 * An event that is emitted when a {@link NotebookDocument notebook document} will be saved to disk. 14334 * 14335 * *Note 1:* Subscribers can delay saving by registering asynchronous work. For the sake of data integrity the editor 14336 * might save without firing this event. For instance when shutting down with dirty files. 14337 * 14338 * *Note 2:* Subscribers are called sequentially and they can {@link NotebookDocumentWillSaveEvent.waitUntil delay} saving 14339 * by registering asynchronous work. Protection against misbehaving listeners is implemented as such: 14340 * * there is an overall time budget that all listeners share and if that is exhausted no further listener is called 14341 * * listeners that take a long time or produce errors frequently will not be called anymore 14342 * 14343 * The current thresholds are 1.5 seconds as overall time budget and a listener can misbehave 3 times before being ignored. 14344 */ 14345 export const onWillSaveNotebookDocument: Event<NotebookDocumentWillSaveEvent>; 14346 14347 /** 14348 * An event that is emitted when a {@link NotebookDocument notebook} is saved. 14349 */ 14350 export const onDidSaveNotebookDocument: Event<NotebookDocument>; 14351 14352 /** 14353 * Register a {@link NotebookSerializer notebook serializer}. 14354 * 14355 * A notebook serializer must be contributed through the `notebooks` extension point. When opening a notebook file, the editor will send 14356 * the `onNotebook:<notebookType>` activation event, and extensions must register their serializer in return. 14357 * 14358 * @param notebookType A notebook. 14359 * @param serializer A notebook serializer. 14360 * @param options Optional context options that define what parts of a notebook should be persisted 14361 * @returns A {@link Disposable} that unregisters this serializer when being disposed. 14362 */ 14363 export function registerNotebookSerializer(notebookType: string, serializer: NotebookSerializer, options?: NotebookDocumentContentOptions): Disposable; 14364 14365 /** 14366 * An event that is emitted when a {@link NotebookDocument notebook} is opened. 14367 */ 14368 export const onDidOpenNotebookDocument: Event<NotebookDocument>; 14369 14370 /** 14371 * An event that is emitted when a {@link NotebookDocument notebook} is disposed. 14372 * 14373 * *Note 1:* There is no guarantee that this event fires when an editor tab is closed. 14374 * 14375 * *Note 2:* A notebook can be open but not shown in an editor which means this event can fire 14376 * for a notebook that has not been shown in an editor. 14377 */ 14378 export const onDidCloseNotebookDocument: Event<NotebookDocument>; 14379 14380 /** 14381 * An event that is emitted when files are being created. 14382 * 14383 * *Note 1:* This event is triggered by user gestures, like creating a file from the 14384 * explorer, or from the {@linkcode workspace.applyEdit}-api. This event is *not* fired when 14385 * files change on disk, e.g triggered by another application, or when using the 14386 * {@linkcode FileSystem workspace.fs}-api. 14387 * 14388 * *Note 2:* When this event is fired, edits to files that are are being created cannot be applied. 14389 */ 14390 export const onWillCreateFiles: Event<FileWillCreateEvent>; 14391 14392 /** 14393 * An event that is emitted when files have been created. 14394 * 14395 * *Note:* This event is triggered by user gestures, like creating a file from the 14396 * explorer, or from the {@linkcode workspace.applyEdit}-api, but this event is *not* fired when 14397 * files change on disk, e.g triggered by another application, or when using the 14398 * {@linkcode FileSystem workspace.fs}-api. 14399 */ 14400 export const onDidCreateFiles: Event<FileCreateEvent>; 14401 14402 /** 14403 * An event that is emitted when files are being deleted. 14404 * 14405 * *Note 1:* This event is triggered by user gestures, like deleting a file from the 14406 * explorer, or from the {@linkcode workspace.applyEdit}-api, but this event is *not* fired when 14407 * files change on disk, e.g triggered by another application, or when using the 14408 * {@linkcode FileSystem workspace.fs}-api. 14409 * 14410 * *Note 2:* When deleting a folder with children only one event is fired. 14411 */ 14412 export const onWillDeleteFiles: Event<FileWillDeleteEvent>; 14413 14414 /** 14415 * An event that is emitted when files have been deleted. 14416 * 14417 * *Note 1:* This event is triggered by user gestures, like deleting a file from the 14418 * explorer, or from the {@linkcode workspace.applyEdit}-api, but this event is *not* fired when 14419 * files change on disk, e.g triggered by another application, or when using the 14420 * {@linkcode FileSystem workspace.fs}-api. 14421 * 14422 * *Note 2:* When deleting a folder with children only one event is fired. 14423 */ 14424 export const onDidDeleteFiles: Event<FileDeleteEvent>; 14425 14426 /** 14427 * An event that is emitted when files are being renamed. 14428 * 14429 * *Note 1:* This event is triggered by user gestures, like renaming a file from the 14430 * explorer, and from the {@linkcode workspace.applyEdit}-api, but this event is *not* fired when 14431 * files change on disk, e.g triggered by another application, or when using the 14432 * {@linkcode FileSystem workspace.fs}-api. 14433 * 14434 * *Note 2:* When renaming a folder with children only one event is fired. 14435 */ 14436 export const onWillRenameFiles: Event<FileWillRenameEvent>; 14437 14438 /** 14439 * An event that is emitted when files have been renamed. 14440 * 14441 * *Note 1:* This event is triggered by user gestures, like renaming a file from the 14442 * explorer, and from the {@linkcode workspace.applyEdit}-api, but this event is *not* fired when 14443 * files change on disk, e.g triggered by another application, or when using the 14444 * {@linkcode FileSystem workspace.fs}-api. 14445 * 14446 * *Note 2:* When renaming a folder with children only one event is fired. 14447 */ 14448 export const onDidRenameFiles: Event<FileRenameEvent>; 14449 14450 /** 14451 * Get a workspace configuration object. 14452 * 14453 * When a section-identifier is provided only that part of the configuration 14454 * is returned. Dots in the section-identifier are interpreted as child-access, 14455 * like `{ myExt: { setting: { doIt: true }}}` and `getConfiguration('myExt.setting').get('doIt') === true`. 14456 * 14457 * When a scope is provided configuration confined to that scope is returned. Scope can be a resource or a language identifier or both. 14458 * 14459 * @param section A dot-separated identifier. 14460 * @param scope A scope for which the configuration is asked for. 14461 * @returns The full configuration or a subset. 14462 */ 14463 export function getConfiguration(section?: string, scope?: ConfigurationScope | null): WorkspaceConfiguration; 14464 14465 /** 14466 * An event that is emitted when the {@link WorkspaceConfiguration configuration} changed. 14467 */ 14468 export const onDidChangeConfiguration: Event<ConfigurationChangeEvent>; 14469 14470 /** 14471 * Register a task provider. 14472 * 14473 * @deprecated Use the corresponding function on the `tasks` namespace instead 14474 * 14475 * @param type The task kind type this provider is registered for. 14476 * @param provider A task provider. 14477 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14478 */ 14479 export function registerTaskProvider(type: string, provider: TaskProvider): Disposable; 14480 14481 /** 14482 * Register a filesystem provider for a given scheme, e.g. `ftp`. 14483 * 14484 * There can only be one provider per scheme and an error is being thrown when a scheme 14485 * has been claimed by another provider or when it is reserved. 14486 * 14487 * @param scheme The uri-{@link Uri.scheme scheme} the provider registers for. 14488 * @param provider The filesystem provider. 14489 * @param options Immutable metadata about the provider. 14490 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14491 */ 14492 export function registerFileSystemProvider(scheme: string, provider: FileSystemProvider, options?: { 14493 /** 14494 * Whether the file system provider use case sensitive compare for {@link Uri.path paths} 14495 */ 14496 readonly isCaseSensitive?: boolean; 14497 /** 14498 * Whether the file system provider is readonly, no modifications like write, delete, create are possible. 14499 * If a {@link MarkdownString} is given, it will be shown as the reason why the file system is readonly. 14500 */ 14501 readonly isReadonly?: boolean | MarkdownString; 14502 }): Disposable; 14503 14504 /** 14505 * When true, the user has explicitly trusted the contents of the workspace. 14506 */ 14507 export const isTrusted: boolean; 14508 14509 /** 14510 * Event that fires when the current workspace has been trusted. 14511 */ 14512 export const onDidGrantWorkspaceTrust: Event<void>; 14513 14514 /** 14515 * Decodes the content from a `Uint8Array` to a `string`. You MUST 14516 * provide the entire content at once to ensure that the encoding 14517 * can properly apply. Do not use this method to decode content 14518 * in chunks, as that may lead to incorrect results. 14519 * 14520 * Will pick an encoding based on settings and the content of the 14521 * buffer (for example byte order marks). 14522 * 14523 * *Note* that if you decode content that is unsupported by the 14524 * encoding, the result may contain substitution characters as 14525 * appropriate. 14526 * 14527 * @throws This method will throw an error when the content is binary. 14528 * 14529 * @param content The text content to decode as a `Uint8Array`. 14530 * @returns A thenable that resolves to the decoded `string`. 14531 */ 14532 export function decode(content: Uint8Array): Thenable<string>; 14533 14534 /** 14535 * Decodes the content from a `Uint8Array` to a `string` using the 14536 * provided encoding. You MUST provide the entire content at once 14537 * to ensure that the encoding can properly apply. Do not use this 14538 * method to decode content in chunks, as that may lead to incorrect 14539 * results. 14540 * 14541 * *Note* that if you decode content that is unsupported by the 14542 * encoding, the result may contain substitution characters as 14543 * appropriate. 14544 * 14545 * @throws This method will throw an error when the content is binary. 14546 * 14547 * @param content The text content to decode as a `Uint8Array`. 14548 * @param options Additional context for picking the encoding. 14549 * @returns A thenable that resolves to the decoded `string`. 14550 */ 14551 export function decode(content: Uint8Array, options: { 14552 /** 14553 * Allows to explicitly pick the encoding to use. 14554 * See {@link TextDocument.encoding} for more information 14555 * about valid values for encoding. 14556 * Using an unsupported encoding will fallback to the 14557 * default configured encoding. 14558 */ 14559 readonly encoding: string; 14560 }): Thenable<string>; 14561 14562 /** 14563 * Decodes the content from a `Uint8Array` to a `string`. You MUST 14564 * provide the entire content at once to ensure that the encoding 14565 * can properly apply. Do not use this method to decode content 14566 * in chunks, as that may lead to incorrect results. 14567 * 14568 * The encoding is picked based on settings and the content 14569 * of the buffer (for example byte order marks). 14570 * 14571 * *Note* that if you decode content that is unsupported by the 14572 * encoding, the result may contain substitution characters as 14573 * appropriate. 14574 * 14575 * @throws This method will throw an error when the content is binary. 14576 * 14577 * @param content The content to decode as a `Uint8Array`. 14578 * @param options Additional context for picking the encoding. 14579 * @returns A thenable that resolves to the decoded `string`. 14580 */ 14581 export function decode(content: Uint8Array, options: { 14582 /** 14583 * The URI that represents the file if known. This information 14584 * is used to figure out the encoding related configuration 14585 * for the file if any. 14586 */ 14587 readonly uri: Uri; 14588 }): Thenable<string>; 14589 14590 /** 14591 * Encodes the content of a `string` to a `Uint8Array`. 14592 * 14593 * Will pick an encoding based on settings. 14594 * 14595 * @param content The content to decode as a `string`. 14596 * @returns A thenable that resolves to the encoded `Uint8Array`. 14597 */ 14598 export function encode(content: string): Thenable<Uint8Array>; 14599 14600 /** 14601 * Encodes the content of a `string` to a `Uint8Array` using the 14602 * provided encoding. 14603 * 14604 * @param content The content to decode as a `string`. 14605 * @param options Additional context for picking the encoding. 14606 * @returns A thenable that resolves to the encoded `Uint8Array`. 14607 */ 14608 export function encode(content: string, options: { 14609 /** 14610 * Allows to explicitly pick the encoding to use. 14611 * See {@link TextDocument.encoding} for more information 14612 * about valid values for encoding. 14613 * Using an unsupported encoding will fallback to the 14614 * default configured encoding. 14615 */ 14616 readonly encoding: string; 14617 }): Thenable<Uint8Array>; 14618 14619 /** 14620 * Encodes the content of a `string` to a `Uint8Array`. 14621 * 14622 * The encoding is picked based on settings. 14623 * 14624 * @param content The content to decode as a `string`. 14625 * @param options Additional context for picking the encoding. 14626 * @returns A thenable that resolves to the encoded `Uint8Array`. 14627 */ 14628 export function encode(content: string, options: { 14629 /** 14630 * The URI that represents the file if known. This information 14631 * is used to figure out the encoding related configuration 14632 * for the file if any. 14633 */ 14634 readonly uri: Uri; 14635 }): Thenable<Uint8Array>; 14636 } 14637 14638 /** 14639 * The configuration scope which can be: 14640 * - a {@link Uri} representing a resource 14641 * - a {@link TextDocument} representing an open text document 14642 * - a {@link WorkspaceFolder} representing a workspace folder 14643 * - an object containing: 14644 * - `uri`: an optional {@link Uri} of a text document 14645 * - `languageId`: the language identifier of a text document 14646 */ 14647 export type ConfigurationScope = Uri | TextDocument | WorkspaceFolder | { 14648 /** 14649 * The uri of a {@link TextDocument text document} 14650 */ 14651 uri?: Uri; 14652 /** 14653 * The language of a text document 14654 */ 14655 languageId: string; 14656 }; 14657 14658 /** 14659 * An event describing the change in Configuration 14660 */ 14661 export interface ConfigurationChangeEvent { 14662 14663 /** 14664 * Checks if the given section has changed. 14665 * If scope is provided, checks if the section has changed for resources under the given scope. 14666 * 14667 * @param section Configuration name, supports _dotted_ names. 14668 * @param scope A scope in which to check. 14669 * @returns `true` if the given section has changed. 14670 */ 14671 affectsConfiguration(section: string, scope?: ConfigurationScope): boolean; 14672 } 14673 14674 /** 14675 * Namespace for participating in language-specific editor [features](https://code.visualstudio.com/docs/editor/editingevolved), 14676 * like IntelliSense, code actions, diagnostics etc. 14677 * 14678 * Many programming languages exist and there is huge variety in syntaxes, semantics, and paradigms. Despite that, features 14679 * like automatic word-completion, code navigation, or code checking have become popular across different tools for different 14680 * programming languages. 14681 * 14682 * The editor provides an API that makes it simple to provide such common features by having all UI and actions already in place and 14683 * by allowing you to participate by providing data only. For instance, to contribute a hover all you have to do is provide a function 14684 * that can be called with a {@link TextDocument} and a {@link Position} returning hover info. The rest, like tracking the 14685 * mouse, positioning the hover, keeping the hover stable etc. is taken care of by the editor. 14686 * 14687 * ```javascript 14688 * languages.registerHoverProvider('javascript', { 14689 * provideHover(document, position, token) { 14690 * return new Hover('I am a hover!'); 14691 * } 14692 * }); 14693 * ``` 14694 * 14695 * Registration is done using a {@link DocumentSelector document selector} which is either a language id, like `javascript` or 14696 * a more complex {@link DocumentFilter filter} like `{ language: 'typescript', scheme: 'file' }`. Matching a document against such 14697 * a selector will result in a {@link languages.match score} that is used to determine if and how a provider shall be used. When 14698 * scores are equal the provider that came last wins. For features that allow full arity, like {@link languages.registerHoverProvider hover}, 14699 * the score is only checked to be `>0`, for other features, like {@link languages.registerCompletionItemProvider IntelliSense} the 14700 * score is used for determining the order in which providers are asked to participate. 14701 */ 14702 export namespace languages { 14703 14704 /** 14705 * Return the identifiers of all known languages. 14706 * @returns Promise resolving to an array of identifier strings. 14707 */ 14708 export function getLanguages(): Thenable<string[]>; 14709 14710 /** 14711 * Set (and change) the {@link TextDocument.languageId language} that is associated 14712 * with the given document. 14713 * 14714 * *Note* that calling this function will trigger the {@linkcode workspace.onDidCloseTextDocument onDidCloseTextDocument} event 14715 * followed by the {@linkcode workspace.onDidOpenTextDocument onDidOpenTextDocument} event. 14716 * 14717 * @param document The document which language is to be changed 14718 * @param languageId The new language identifier. 14719 * @returns A thenable that resolves with the updated document. 14720 */ 14721 export function setTextDocumentLanguage(document: TextDocument, languageId: string): Thenable<TextDocument>; 14722 14723 /** 14724 * Compute the match between a document {@link DocumentSelector selector} and a document. Values 14725 * greater than zero mean the selector matches the document. 14726 * 14727 * A match is computed according to these rules: 14728 * 1. When {@linkcode DocumentSelector} is an array, compute the match for each contained `DocumentFilter` or language identifier and take the maximum value. 14729 * 2. A string will be desugared to become the `language`-part of a {@linkcode DocumentFilter}, so `"fooLang"` is like `{ language: "fooLang" }`. 14730 * 3. A {@linkcode DocumentFilter} will be matched against the document by comparing its parts with the document. The following rules apply: 14731 * 1. When the `DocumentFilter` is empty (`{}`) the result is `0` 14732 * 2. When `scheme`, `language`, `pattern`, or `notebook` are defined but one doesn't match, the result is `0` 14733 * 3. Matching against `*` gives a score of `5`, matching via equality or via a glob-pattern gives a score of `10` 14734 * 4. The result is the maximum value of each match 14735 * 14736 * Samples: 14737 * ```js 14738 * // default document from disk (file-scheme) 14739 * doc.uri; //'file:///my/file.js' 14740 * doc.languageId; // 'javascript' 14741 * match('javascript', doc); // 10; 14742 * match({ language: 'javascript' }, doc); // 10; 14743 * match({ language: 'javascript', scheme: 'file' }, doc); // 10; 14744 * match('*', doc); // 5 14745 * match('fooLang', doc); // 0 14746 * match(['fooLang', '*'], doc); // 5 14747 * 14748 * // virtual document, e.g. from git-index 14749 * doc.uri; // 'git:/my/file.js' 14750 * doc.languageId; // 'javascript' 14751 * match('javascript', doc); // 10; 14752 * match({ language: 'javascript', scheme: 'git' }, doc); // 10; 14753 * match('*', doc); // 5 14754 * 14755 * // notebook cell document 14756 * doc.uri; // `vscode-notebook-cell:///my/notebook.ipynb#gl65s2pmha`; 14757 * doc.languageId; // 'python' 14758 * match({ notebookType: 'jupyter-notebook' }, doc) // 10 14759 * match({ notebookType: 'fooNotebook', language: 'python' }, doc) // 0 14760 * match({ language: 'python' }, doc) // 10 14761 * match({ notebookType: '*' }, doc) // 5 14762 * ``` 14763 * 14764 * @param selector A document selector. 14765 * @param document A text document. 14766 * @returns A number `>0` when the selector matches and `0` when the selector does not match. 14767 */ 14768 export function match(selector: DocumentSelector, document: TextDocument): number; 14769 14770 /** 14771 * An {@link Event} which fires when the global set of diagnostics changes. This is 14772 * newly added and removed diagnostics. 14773 */ 14774 export const onDidChangeDiagnostics: Event<DiagnosticChangeEvent>; 14775 14776 /** 14777 * Get all diagnostics for a given resource. 14778 * 14779 * @param resource A resource 14780 * @returns An array of {@link Diagnostic diagnostics} objects or an empty array. 14781 */ 14782 export function getDiagnostics(resource: Uri): Diagnostic[]; 14783 14784 /** 14785 * Get all diagnostics. 14786 * 14787 * @returns An array of uri-diagnostics tuples or an empty array. 14788 */ 14789 export function getDiagnostics(): [Uri, Diagnostic[]][]; 14790 14791 /** 14792 * Create a diagnostics collection. 14793 * 14794 * @param name The {@link DiagnosticCollection.name name} of the collection. 14795 * @returns A new diagnostic collection. 14796 */ 14797 export function createDiagnosticCollection(name?: string): DiagnosticCollection; 14798 14799 /** 14800 * Creates a new {@link LanguageStatusItem language status item}. 14801 * 14802 * @param id The identifier of the item. 14803 * @param selector The document selector that defines for what editors the item shows. 14804 * @returns A new language status item. 14805 */ 14806 export function createLanguageStatusItem(id: string, selector: DocumentSelector): LanguageStatusItem; 14807 14808 /** 14809 * Register a completion provider. 14810 * 14811 * Multiple providers can be registered for a language. In that case providers are sorted 14812 * by their {@link languages.match score} and groups of equal score are sequentially asked for 14813 * completion items. The process stops when one or many providers of a group return a 14814 * result. A failing provider (rejected promise or exception) will not fail the whole 14815 * operation. 14816 * 14817 * A completion item provider can be associated with a set of `triggerCharacters`. When trigger 14818 * characters are being typed, completions are requested but only from providers that registered 14819 * the typed character. Because of that trigger characters should be different than {@link LanguageConfiguration.wordPattern word characters}, 14820 * a common trigger character is `.` to trigger member completions. 14821 * 14822 * @param selector A selector that defines the documents this provider is applicable to. 14823 * @param provider A completion provider. 14824 * @param triggerCharacters Trigger completion when the user types one of the characters. 14825 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14826 */ 14827 export function registerCompletionItemProvider(selector: DocumentSelector, provider: CompletionItemProvider, ...triggerCharacters: string[]): Disposable; 14828 14829 /** 14830 * Registers an inline completion provider. 14831 * 14832 * Multiple providers can be registered for a language. In that case providers are asked in 14833 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14834 * not cause a failure of the whole operation. 14835 * 14836 * @param selector A selector that defines the documents this provider is applicable to. 14837 * @param provider An inline completion provider. 14838 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14839 */ 14840 export function registerInlineCompletionItemProvider(selector: DocumentSelector, provider: InlineCompletionItemProvider): Disposable; 14841 14842 /** 14843 * Register a code action provider. 14844 * 14845 * Multiple providers can be registered for a language. In that case providers are asked in 14846 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14847 * not cause a failure of the whole operation. 14848 * 14849 * @param selector A selector that defines the documents this provider is applicable to. 14850 * @param provider A code action provider. 14851 * @param metadata Metadata about the kind of code actions the provider provides. 14852 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14853 */ 14854 export function registerCodeActionsProvider(selector: DocumentSelector, provider: CodeActionProvider, metadata?: CodeActionProviderMetadata): Disposable; 14855 14856 /** 14857 * Register a code lens provider. 14858 * 14859 * Multiple providers can be registered for a language. In that case providers are asked in 14860 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14861 * not cause a failure of the whole operation. 14862 * 14863 * @param selector A selector that defines the documents this provider is applicable to. 14864 * @param provider A code lens provider. 14865 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14866 */ 14867 export function registerCodeLensProvider(selector: DocumentSelector, provider: CodeLensProvider): Disposable; 14868 14869 /** 14870 * Register a definition provider. 14871 * 14872 * Multiple providers can be registered for a language. In that case providers are asked in 14873 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14874 * not cause a failure of the whole operation. 14875 * 14876 * @param selector A selector that defines the documents this provider is applicable to. 14877 * @param provider A definition provider. 14878 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14879 */ 14880 export function registerDefinitionProvider(selector: DocumentSelector, provider: DefinitionProvider): Disposable; 14881 14882 /** 14883 * Register an implementation provider. 14884 * 14885 * Multiple providers can be registered for a language. In that case providers are asked in 14886 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14887 * not cause a failure of the whole operation. 14888 * 14889 * @param selector A selector that defines the documents this provider is applicable to. 14890 * @param provider An implementation provider. 14891 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14892 */ 14893 export function registerImplementationProvider(selector: DocumentSelector, provider: ImplementationProvider): Disposable; 14894 14895 /** 14896 * Register a type definition provider. 14897 * 14898 * Multiple providers can be registered for a language. In that case providers are asked in 14899 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14900 * not cause a failure of the whole operation. 14901 * 14902 * @param selector A selector that defines the documents this provider is applicable to. 14903 * @param provider A type definition provider. 14904 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14905 */ 14906 export function registerTypeDefinitionProvider(selector: DocumentSelector, provider: TypeDefinitionProvider): Disposable; 14907 14908 /** 14909 * Register a declaration provider. 14910 * 14911 * Multiple providers can be registered for a language. In that case providers are asked in 14912 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14913 * not cause a failure of the whole operation. 14914 * 14915 * @param selector A selector that defines the documents this provider is applicable to. 14916 * @param provider A declaration provider. 14917 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14918 */ 14919 export function registerDeclarationProvider(selector: DocumentSelector, provider: DeclarationProvider): Disposable; 14920 14921 /** 14922 * Register a hover provider. 14923 * 14924 * Multiple providers can be registered for a language. In that case providers are asked in 14925 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14926 * not cause a failure of the whole operation. 14927 * 14928 * @param selector A selector that defines the documents this provider is applicable to. 14929 * @param provider A hover provider. 14930 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14931 */ 14932 export function registerHoverProvider(selector: DocumentSelector, provider: HoverProvider): Disposable; 14933 14934 /** 14935 * Register a provider that locates evaluatable expressions in text documents. 14936 * The editor will evaluate the expression in the active debug session and will show the result in the debug hover. 14937 * 14938 * If multiple providers are registered for a language an arbitrary provider will be used. 14939 * 14940 * @param selector A selector that defines the documents this provider is applicable to. 14941 * @param provider An evaluatable expression provider. 14942 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14943 */ 14944 export function registerEvaluatableExpressionProvider(selector: DocumentSelector, provider: EvaluatableExpressionProvider): Disposable; 14945 14946 /** 14947 * Register a provider that returns data for the debugger's 'inline value' feature. 14948 * Whenever the generic debugger has stopped in a source file, providers registered for the language of the file 14949 * are called to return textual data that will be shown in the editor at the end of lines. 14950 * 14951 * Multiple providers can be registered for a language. In that case providers are asked in 14952 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14953 * not cause a failure of the whole operation. 14954 * 14955 * @param selector A selector that defines the documents this provider is applicable to. 14956 * @param provider An inline values provider. 14957 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14958 */ 14959 export function registerInlineValuesProvider(selector: DocumentSelector, provider: InlineValuesProvider): Disposable; 14960 14961 /** 14962 * Register a document highlight provider. 14963 * 14964 * Multiple providers can be registered for a language. In that case providers are sorted 14965 * by their {@link languages.match score} and groups sequentially asked for document highlights. 14966 * The process stops when a provider returns a `non-falsy` or `non-failure` result. 14967 * 14968 * @param selector A selector that defines the documents this provider is applicable to. 14969 * @param provider A document highlight provider. 14970 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14971 */ 14972 export function registerDocumentHighlightProvider(selector: DocumentSelector, provider: DocumentHighlightProvider): Disposable; 14973 14974 /** 14975 * Register a document symbol provider. 14976 * 14977 * Multiple providers can be registered for a language. In that case providers are asked in 14978 * parallel and the results are merged. A failing provider (rejected promise or exception) will 14979 * not cause a failure of the whole operation. 14980 * 14981 * @param selector A selector that defines the documents this provider is applicable to. 14982 * @param provider A document symbol provider. 14983 * @param metaData metadata about the provider 14984 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14985 */ 14986 export function registerDocumentSymbolProvider(selector: DocumentSelector, provider: DocumentSymbolProvider, metaData?: DocumentSymbolProviderMetadata): Disposable; 14987 14988 /** 14989 * Register a workspace symbol provider. 14990 * 14991 * Multiple providers can be registered. In that case providers are asked in parallel and 14992 * the results are merged. A failing provider (rejected promise or exception) will not cause 14993 * a failure of the whole operation. 14994 * 14995 * @param provider A workspace symbol provider. 14996 * @returns A {@link Disposable} that unregisters this provider when being disposed. 14997 */ 14998 export function registerWorkspaceSymbolProvider(provider: WorkspaceSymbolProvider): Disposable; 14999 15000 /** 15001 * Register a reference provider. 15002 * 15003 * Multiple providers can be registered for a language. In that case providers are asked in 15004 * parallel and the results are merged. A failing provider (rejected promise or exception) will 15005 * not cause a failure of the whole operation. 15006 * 15007 * @param selector A selector that defines the documents this provider is applicable to. 15008 * @param provider A reference provider. 15009 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15010 */ 15011 export function registerReferenceProvider(selector: DocumentSelector, provider: ReferenceProvider): Disposable; 15012 15013 /** 15014 * Register a rename provider. 15015 * 15016 * Multiple providers can be registered for a language. In that case providers are sorted 15017 * by their {@link languages.match score} and asked in sequence. The first provider producing a result 15018 * defines the result of the whole operation. 15019 * 15020 * @param selector A selector that defines the documents this provider is applicable to. 15021 * @param provider A rename provider. 15022 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15023 */ 15024 export function registerRenameProvider(selector: DocumentSelector, provider: RenameProvider): Disposable; 15025 15026 /** 15027 * Register a semantic tokens provider for a whole document. 15028 * 15029 * Multiple providers can be registered for a language. In that case providers are sorted 15030 * by their {@link languages.match score} and the best-matching provider is used. Failure 15031 * of the selected provider will cause a failure of the whole operation. 15032 * 15033 * @param selector A selector that defines the documents this provider is applicable to. 15034 * @param provider A document semantic tokens provider. 15035 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15036 */ 15037 export function registerDocumentSemanticTokensProvider(selector: DocumentSelector, provider: DocumentSemanticTokensProvider, legend: SemanticTokensLegend): Disposable; 15038 15039 /** 15040 * Register a semantic tokens provider for a document range. 15041 * 15042 * *Note:* If a document has both a `DocumentSemanticTokensProvider` and a `DocumentRangeSemanticTokensProvider`, 15043 * the range provider will be invoked only initially, for the time in which the full document provider takes 15044 * to resolve the first request. Once the full document provider resolves the first request, the semantic tokens 15045 * provided via the range provider will be discarded and from that point forward, only the document provider 15046 * will be used. 15047 * 15048 * Multiple providers can be registered for a language. In that case providers are sorted 15049 * by their {@link languages.match score} and the best-matching provider is used. Failure 15050 * of the selected provider will cause a failure of the whole operation. 15051 * 15052 * @param selector A selector that defines the documents this provider is applicable to. 15053 * @param provider A document range semantic tokens provider. 15054 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15055 */ 15056 export function registerDocumentRangeSemanticTokensProvider(selector: DocumentSelector, provider: DocumentRangeSemanticTokensProvider, legend: SemanticTokensLegend): Disposable; 15057 15058 /** 15059 * Register a formatting provider for a document. 15060 * 15061 * Multiple providers can be registered for a language. In that case providers are sorted 15062 * by their {@link languages.match score} and the best-matching provider is used. Failure 15063 * of the selected provider will cause a failure of the whole operation. 15064 * 15065 * @param selector A selector that defines the documents this provider is applicable to. 15066 * @param provider A document formatting edit provider. 15067 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15068 */ 15069 export function registerDocumentFormattingEditProvider(selector: DocumentSelector, provider: DocumentFormattingEditProvider): Disposable; 15070 15071 /** 15072 * Register a formatting provider for a document range. 15073 * 15074 * *Note:* A document range provider is also a {@link DocumentFormattingEditProvider document formatter} 15075 * which means there is no need to {@link languages.registerDocumentFormattingEditProvider register} a document 15076 * formatter when also registering a range provider. 15077 * 15078 * Multiple providers can be registered for a language. In that case providers are sorted 15079 * by their {@link languages.match score} and the best-matching provider is used. Failure 15080 * of the selected provider will cause a failure of the whole operation. 15081 * 15082 * @param selector A selector that defines the documents this provider is applicable to. 15083 * @param provider A document range formatting edit provider. 15084 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15085 */ 15086 export function registerDocumentRangeFormattingEditProvider(selector: DocumentSelector, provider: DocumentRangeFormattingEditProvider): Disposable; 15087 15088 /** 15089 * Register a formatting provider that works on type. The provider is active when the user enables the setting `editor.formatOnType`. 15090 * 15091 * Multiple providers can be registered for a language. In that case providers are sorted 15092 * by their {@link languages.match score} and the best-matching provider is used. Failure 15093 * of the selected provider will cause a failure of the whole operation. 15094 * 15095 * @param selector A selector that defines the documents this provider is applicable to. 15096 * @param provider An on type formatting edit provider. 15097 * @param firstTriggerCharacter A character on which formatting should be triggered, like `}`. 15098 * @param moreTriggerCharacter More trigger characters. 15099 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15100 */ 15101 export function registerOnTypeFormattingEditProvider(selector: DocumentSelector, provider: OnTypeFormattingEditProvider, firstTriggerCharacter: string, ...moreTriggerCharacter: string[]): Disposable; 15102 15103 /** 15104 * Register a signature help provider. 15105 * 15106 * Multiple providers can be registered for a language. In that case providers are sorted 15107 * by their {@link languages.match score} and called sequentially until a provider returns a 15108 * valid result. 15109 * 15110 * @param selector A selector that defines the documents this provider is applicable to. 15111 * @param provider A signature help provider. 15112 * @param triggerCharacters Trigger signature help when the user types one of the characters, like `,` or `(`. 15113 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15114 */ 15115 export function registerSignatureHelpProvider(selector: DocumentSelector, provider: SignatureHelpProvider, ...triggerCharacters: string[]): Disposable; 15116 15117 /** 15118 * @see {@link languages.registerSignatureHelpProvider} 15119 * 15120 * @param selector A selector that defines the documents this provider is applicable to. 15121 * @param provider A signature help provider. 15122 * @param metadata Information about the provider. 15123 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15124 */ 15125 export function registerSignatureHelpProvider(selector: DocumentSelector, provider: SignatureHelpProvider, metadata: SignatureHelpProviderMetadata): Disposable; 15126 15127 /** 15128 * Register a document link provider. 15129 * 15130 * Multiple providers can be registered for a language. In that case providers are asked in 15131 * parallel and the results are merged. A failing provider (rejected promise or exception) will 15132 * not cause a failure of the whole operation. 15133 * 15134 * @param selector A selector that defines the documents this provider is applicable to. 15135 * @param provider A document link provider. 15136 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15137 */ 15138 export function registerDocumentLinkProvider(selector: DocumentSelector, provider: DocumentLinkProvider): Disposable; 15139 15140 /** 15141 * Register a color provider. 15142 * 15143 * Multiple providers can be registered for a language. In that case providers are asked in 15144 * parallel and the results are merged. A failing provider (rejected promise or exception) will 15145 * not cause a failure of the whole operation. 15146 * 15147 * @param selector A selector that defines the documents this provider is applicable to. 15148 * @param provider A color provider. 15149 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15150 */ 15151 export function registerColorProvider(selector: DocumentSelector, provider: DocumentColorProvider): Disposable; 15152 15153 /** 15154 * Register a inlay hints provider. 15155 * 15156 * Multiple providers can be registered for a language. In that case providers are asked in 15157 * parallel and the results are merged. A failing provider (rejected promise or exception) will 15158 * not cause a failure of the whole operation. 15159 * 15160 * @param selector A selector that defines the documents this provider is applicable to. 15161 * @param provider An inlay hints provider. 15162 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15163 */ 15164 export function registerInlayHintsProvider(selector: DocumentSelector, provider: InlayHintsProvider): Disposable; 15165 15166 /** 15167 * Register a folding range provider. 15168 * 15169 * Multiple providers can be registered for a language. In that case providers are asked in 15170 * parallel and the results are merged. 15171 * If multiple folding ranges start at the same position, only the range of the first registered provider is used. 15172 * If a folding range overlaps with an other range that has a smaller position, it is also ignored. 15173 * 15174 * A failing provider (rejected promise or exception) will 15175 * not cause a failure of the whole operation. 15176 * 15177 * @param selector A selector that defines the documents this provider is applicable to. 15178 * @param provider A folding range provider. 15179 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15180 */ 15181 export function registerFoldingRangeProvider(selector: DocumentSelector, provider: FoldingRangeProvider): Disposable; 15182 15183 /** 15184 * Register a selection range provider. 15185 * 15186 * Multiple providers can be registered for a language. In that case providers are asked in 15187 * parallel and the results are merged. A failing provider (rejected promise or exception) will 15188 * not cause a failure of the whole operation. 15189 * 15190 * @param selector A selector that defines the documents this provider is applicable to. 15191 * @param provider A selection range provider. 15192 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15193 */ 15194 export function registerSelectionRangeProvider(selector: DocumentSelector, provider: SelectionRangeProvider): Disposable; 15195 15196 /** 15197 * Register a call hierarchy provider. 15198 * 15199 * @param selector A selector that defines the documents this provider is applicable to. 15200 * @param provider A call hierarchy provider. 15201 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15202 */ 15203 export function registerCallHierarchyProvider(selector: DocumentSelector, provider: CallHierarchyProvider): Disposable; 15204 15205 /** 15206 * Register a type hierarchy provider. 15207 * 15208 * @param selector A selector that defines the documents this provider is applicable to. 15209 * @param provider A type hierarchy provider. 15210 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15211 */ 15212 export function registerTypeHierarchyProvider(selector: DocumentSelector, provider: TypeHierarchyProvider): Disposable; 15213 15214 /** 15215 * Register a linked editing range provider. 15216 * 15217 * Multiple providers can be registered for a language. In that case providers are sorted 15218 * by their {@link languages.match score} and the best-matching provider that has a result is used. Failure 15219 * of the selected provider will cause a failure of the whole operation. 15220 * 15221 * @param selector A selector that defines the documents this provider is applicable to. 15222 * @param provider A linked editing range provider. 15223 * @returns A {@link Disposable} that unregisters this provider when being disposed. 15224 */ 15225 export function registerLinkedEditingRangeProvider(selector: DocumentSelector, provider: LinkedEditingRangeProvider): Disposable; 15226 15227 /** 15228 * Registers a new {@link DocumentDropEditProvider}. 15229 * 15230 * Multiple drop providers can be registered for a language. When dropping content into an editor, all 15231 * registered providers for the editor's language will be invoked based on the mimetypes they handle 15232 * as specified by their {@linkcode DocumentDropEditProviderMetadata}. 15233 * 15234 * Each provider can return one or more {@linkcode DocumentDropEdit DocumentDropEdits}. The edits are sorted 15235 * using the {@linkcode DocumentDropEdit.yieldTo} property. By default the first edit will be applied. If there 15236 * are any additional edits, these will be shown to the user as selectable drop options in the drop widget. 15237 * 15238 * @param selector A selector that defines the documents this provider applies to. 15239 * @param provider A drop provider. 15240 * @param metadata Additional metadata about the provider. 15241 * 15242 * @returns A {@linkcode Disposable} that unregisters this provider when disposed of. 15243 */ 15244 export function registerDocumentDropEditProvider(selector: DocumentSelector, provider: DocumentDropEditProvider, metadata?: DocumentDropEditProviderMetadata): Disposable; 15245 15246 /** 15247 * Registers a new {@linkcode DocumentPasteEditProvider}. 15248 * 15249 * Multiple providers can be registered for a language. All registered providers for a language will be invoked 15250 * for copy and paste operations based on their handled mimetypes as specified by the {@linkcode DocumentPasteProviderMetadata}. 15251 * 15252 * For {@link DocumentPasteEditProvider.prepareDocumentPaste copy operations}, changes to the {@linkcode DataTransfer} 15253 * made by each provider will be merged into a single {@linkcode DataTransfer} that is used to populate the clipboard. 15254 * 15255 * For {@link DocumentPasteEditProvider.providerDocumentPasteEdits paste operations}, each provider will be invoked 15256 * and can return one or more {@linkcode DocumentPasteEdit DocumentPasteEdits}. The edits are sorted using 15257 * the {@linkcode DocumentPasteEdit.yieldTo} property. By default the first edit will be applied 15258 * and the rest of the edits will be shown to the user as selectable paste options in the paste widget. 15259 * 15260 * @param selector A selector that defines the documents this provider applies to. 15261 * @param provider A paste editor provider. 15262 * @param metadata Additional metadata about the provider. 15263 * 15264 * @returns A {@linkcode Disposable} that unregisters this provider when disposed of. 15265 */ 15266 export function registerDocumentPasteEditProvider(selector: DocumentSelector, provider: DocumentPasteEditProvider, metadata: DocumentPasteProviderMetadata): Disposable; 15267 15268 15269 /** 15270 * Set a {@link LanguageConfiguration language configuration} for a language. 15271 * 15272 * @param language A language identifier like `typescript`. 15273 * @param configuration Language configuration. 15274 * @returns A {@link Disposable} that unsets this configuration. 15275 */ 15276 export function setLanguageConfiguration(language: string, configuration: LanguageConfiguration): Disposable; 15277 } 15278 15279 /** 15280 * Represents a notebook editor that is attached to a {@link NotebookDocument notebook}. 15281 */ 15282 export enum NotebookEditorRevealType { 15283 /** 15284 * The range will be revealed with as little scrolling as possible. 15285 */ 15286 Default = 0, 15287 15288 /** 15289 * The range will always be revealed in the center of the viewport. 15290 */ 15291 InCenter = 1, 15292 15293 /** 15294 * If the range is outside the viewport, it will be revealed in the center of the viewport. 15295 * Otherwise, it will be revealed with as little scrolling as possible. 15296 */ 15297 InCenterIfOutsideViewport = 2, 15298 15299 /** 15300 * The range will always be revealed at the top of the viewport. 15301 */ 15302 AtTop = 3 15303 } 15304 15305 /** 15306 * Represents a notebook editor that is attached to a {@link NotebookDocument notebook}. 15307 * Additional properties of the NotebookEditor are available in the proposed 15308 * API, which will be finalized later. 15309 */ 15310 export interface NotebookEditor { 15311 15312 /** 15313 * The {@link NotebookDocument notebook document} associated with this notebook editor. 15314 */ 15315 readonly notebook: NotebookDocument; 15316 15317 /** 15318 * The primary selection in this notebook editor. 15319 */ 15320 selection: NotebookRange; 15321 15322 /** 15323 * All selections in this notebook editor. 15324 * 15325 * The primary selection (or focused range) is `selections[0]`. When the document has no cells, the primary selection is empty `{ start: 0, end: 0 }`; 15326 */ 15327 selections: readonly NotebookRange[]; 15328 15329 /** 15330 * The current visible ranges in the editor (vertically). 15331 */ 15332 readonly visibleRanges: readonly NotebookRange[]; 15333 15334 /** 15335 * The column in which this editor shows. 15336 */ 15337 readonly viewColumn?: ViewColumn; 15338 15339 /** 15340 * Scroll as indicated by `revealType` in order to reveal the given range. 15341 * 15342 * @param range A range. 15343 * @param revealType The scrolling strategy for revealing `range`. 15344 */ 15345 revealRange(range: NotebookRange, revealType?: NotebookEditorRevealType): void; 15346 } 15347 15348 /** 15349 * Renderer messaging is used to communicate with a single renderer. It's returned from {@link notebooks.createRendererMessaging}. 15350 */ 15351 export interface NotebookRendererMessaging { 15352 /** 15353 * An event that fires when a message is received from a renderer. 15354 */ 15355 readonly onDidReceiveMessage: Event<{ 15356 /** 15357 * The {@link NotebookEditor editor} that sent the message. 15358 */ 15359 readonly editor: NotebookEditor; 15360 /** 15361 * The actual message. 15362 */ 15363 readonly message: any; 15364 }>; 15365 15366 /** 15367 * Send a message to one or all renderer. 15368 * 15369 * @param message Message to send 15370 * @param editor Editor to target with the message. If not provided, the 15371 * message is sent to all renderers. 15372 * @returns a boolean indicating whether the message was successfully 15373 * delivered to any renderer. 15374 */ 15375 postMessage(message: any, editor?: NotebookEditor): Thenable<boolean>; 15376 } 15377 15378 /** 15379 * A notebook cell kind. 15380 */ 15381 export enum NotebookCellKind { 15382 15383 /** 15384 * A markup-cell is formatted source that is used for display. 15385 */ 15386 Markup = 1, 15387 15388 /** 15389 * A code-cell is source that can be {@link NotebookController executed} and that 15390 * produces {@link NotebookCellOutput output}. 15391 */ 15392 Code = 2 15393 } 15394 15395 /** 15396 * Represents a cell of a {@link NotebookDocument notebook}, either a {@link NotebookCellKind.Code code}-cell 15397 * or {@link NotebookCellKind.Markup markup}-cell. 15398 * 15399 * NotebookCell instances are immutable and are kept in sync for as long as they are part of their notebook. 15400 */ 15401 export interface NotebookCell { 15402 15403 /** 15404 * The index of this cell in its {@link NotebookDocument.cellAt containing notebook}. The 15405 * index is updated when a cell is moved within its notebook. The index is `-1` 15406 * when the cell has been removed from its notebook. 15407 */ 15408 readonly index: number; 15409 15410 /** 15411 * The {@link NotebookDocument notebook} that contains this cell. 15412 */ 15413 readonly notebook: NotebookDocument; 15414 15415 /** 15416 * The kind of this cell. 15417 */ 15418 readonly kind: NotebookCellKind; 15419 15420 /** 15421 * The {@link TextDocument text} of this cell, represented as text document. 15422 */ 15423 readonly document: TextDocument; 15424 15425 /** 15426 * The metadata of this cell. Can be anything but must be JSON-stringifyable. 15427 */ 15428 readonly metadata: { readonly [key: string]: any }; 15429 15430 /** 15431 * The outputs of this cell. 15432 */ 15433 readonly outputs: readonly NotebookCellOutput[]; 15434 15435 /** 15436 * The most recent {@link NotebookCellExecutionSummary execution summary} for this cell. 15437 */ 15438 readonly executionSummary: NotebookCellExecutionSummary | undefined; 15439 } 15440 15441 /** 15442 * Represents a notebook which itself is a sequence of {@link NotebookCell code or markup cells}. Notebook documents are 15443 * created from {@link NotebookData notebook data}. 15444 */ 15445 export interface NotebookDocument { 15446 15447 /** 15448 * The associated uri for this notebook. 15449 * 15450 * *Note* that most notebooks use the `file`-scheme, which means they are files on disk. However, **not** all notebooks are 15451 * saved on disk and therefore the `scheme` must be checked before trying to access the underlying file or siblings on disk. 15452 * 15453 * @see {@link FileSystemProvider} 15454 */ 15455 readonly uri: Uri; 15456 15457 /** 15458 * The type of notebook. 15459 */ 15460 readonly notebookType: string; 15461 15462 /** 15463 * The version number of this notebook (it will strictly increase after each 15464 * change, including undo/redo). 15465 */ 15466 readonly version: number; 15467 15468 /** 15469 * `true` if there are unpersisted changes. 15470 */ 15471 readonly isDirty: boolean; 15472 15473 /** 15474 * Is this notebook representing an untitled file which has not been saved yet. 15475 */ 15476 readonly isUntitled: boolean; 15477 15478 /** 15479 * `true` if the notebook has been closed. A closed notebook isn't synchronized anymore 15480 * and won't be re-used when the same resource is opened again. 15481 */ 15482 readonly isClosed: boolean; 15483 15484 /** 15485 * Arbitrary metadata for this notebook. Can be anything but must be JSON-stringifyable. 15486 */ 15487 readonly metadata: { [key: string]: any }; 15488 15489 /** 15490 * The number of cells in the notebook. 15491 */ 15492 readonly cellCount: number; 15493 15494 /** 15495 * Return the cell at the specified index. The index will be adjusted to the notebook. 15496 * 15497 * @param index - The index of the cell to retrieve. 15498 * @returns A {@link NotebookCell cell}. 15499 */ 15500 cellAt(index: number): NotebookCell; 15501 15502 /** 15503 * Get the cells of this notebook. A subset can be retrieved by providing 15504 * a range. The range will be adjusted to the notebook. 15505 * 15506 * @param range A notebook range. 15507 * @returns The cells contained by the range or all cells. 15508 */ 15509 getCells(range?: NotebookRange): NotebookCell[]; 15510 15511 /** 15512 * Save the document. The saving will be handled by the corresponding {@link NotebookSerializer serializer}. 15513 * 15514 * @returns A promise that will resolve to true when the document 15515 * has been saved. Will return false if the file was not dirty or when save failed. 15516 */ 15517 save(): Thenable<boolean>; 15518 } 15519 15520 /** 15521 * Describes a change to a notebook cell. 15522 * 15523 * @see {@link NotebookDocumentChangeEvent} 15524 */ 15525 export interface NotebookDocumentCellChange { 15526 15527 /** 15528 * The affected cell. 15529 */ 15530 readonly cell: NotebookCell; 15531 15532 /** 15533 * The document of the cell or `undefined` when it did not change. 15534 * 15535 * *Note* that you should use the {@link workspace.onDidChangeTextDocument onDidChangeTextDocument}-event 15536 * for detailed change information, like what edits have been performed. 15537 */ 15538 readonly document: TextDocument | undefined; 15539 15540 /** 15541 * The new metadata of the cell or `undefined` when it did not change. 15542 */ 15543 readonly metadata: { [key: string]: any } | undefined; 15544 15545 /** 15546 * The new outputs of the cell or `undefined` when they did not change. 15547 */ 15548 readonly outputs: readonly NotebookCellOutput[] | undefined; 15549 15550 /** 15551 * The new execution summary of the cell or `undefined` when it did not change. 15552 */ 15553 readonly executionSummary: NotebookCellExecutionSummary | undefined; 15554 } 15555 15556 /** 15557 * Describes a structural change to a notebook document, e.g newly added and removed cells. 15558 * 15559 * @see {@link NotebookDocumentChangeEvent} 15560 */ 15561 export interface NotebookDocumentContentChange { 15562 15563 /** 15564 * The range at which cells have been either added or removed. 15565 * 15566 * Note that no cells have been {@link NotebookDocumentContentChange.removedCells removed} 15567 * when this range is {@link NotebookRange.isEmpty empty}. 15568 */ 15569 readonly range: NotebookRange; 15570 15571 /** 15572 * Cells that have been added to the document. 15573 */ 15574 readonly addedCells: readonly NotebookCell[]; 15575 15576 /** 15577 * Cells that have been removed from the document. 15578 */ 15579 readonly removedCells: readonly NotebookCell[]; 15580 } 15581 15582 /** 15583 * An event describing a transactional {@link NotebookDocument notebook} change. 15584 */ 15585 export interface NotebookDocumentChangeEvent { 15586 15587 /** 15588 * The affected notebook. 15589 */ 15590 readonly notebook: NotebookDocument; 15591 15592 /** 15593 * The new metadata of the notebook or `undefined` when it did not change. 15594 */ 15595 readonly metadata: { [key: string]: any } | undefined; 15596 15597 /** 15598 * An array of content changes describing added or removed {@link NotebookCell cells}. 15599 */ 15600 readonly contentChanges: readonly NotebookDocumentContentChange[]; 15601 15602 /** 15603 * An array of {@link NotebookDocumentCellChange cell changes}. 15604 */ 15605 readonly cellChanges: readonly NotebookDocumentCellChange[]; 15606 } 15607 15608 /** 15609 * An event that is fired when a {@link NotebookDocument notebook document} will be saved. 15610 * 15611 * To make modifications to the document before it is being saved, call the 15612 * {@linkcode NotebookDocumentWillSaveEvent.waitUntil waitUntil}-function with a thenable 15613 * that resolves to a {@link WorkspaceEdit workspace edit}. 15614 */ 15615 export interface NotebookDocumentWillSaveEvent { 15616 /** 15617 * A cancellation token. 15618 */ 15619 readonly token: CancellationToken; 15620 15621 /** 15622 * The {@link NotebookDocument notebook document} that will be saved. 15623 */ 15624 readonly notebook: NotebookDocument; 15625 15626 /** 15627 * The reason why save was triggered. 15628 */ 15629 readonly reason: TextDocumentSaveReason; 15630 15631 /** 15632 * Allows to pause the event loop and to apply {@link WorkspaceEdit workspace edit}. 15633 * Edits of subsequent calls to this function will be applied in order. The 15634 * edits will be *ignored* if concurrent modifications of the notebook document happened. 15635 * 15636 * *Note:* This function can only be called during event dispatch and not 15637 * in an asynchronous manner: 15638 * 15639 * ```ts 15640 * workspace.onWillSaveNotebookDocument(event => { 15641 * // async, will *throw* an error 15642 * setTimeout(() => event.waitUntil(promise)); 15643 * 15644 * // sync, OK 15645 * event.waitUntil(promise); 15646 * }) 15647 * ``` 15648 * 15649 * @param thenable A thenable that resolves to {@link WorkspaceEdit workspace edit}. 15650 */ 15651 waitUntil(thenable: Thenable<WorkspaceEdit>): void; 15652 15653 /** 15654 * Allows to pause the event loop until the provided thenable resolved. 15655 * 15656 * *Note:* This function can only be called during event dispatch. 15657 * 15658 * @param thenable A thenable that delays saving. 15659 */ 15660 waitUntil(thenable: Thenable<any>): void; 15661 } 15662 15663 /** 15664 * The summary of a notebook cell execution. 15665 */ 15666 export interface NotebookCellExecutionSummary { 15667 15668 /** 15669 * The order in which the execution happened. 15670 */ 15671 readonly executionOrder?: number; 15672 15673 /** 15674 * If the execution finished successfully. 15675 */ 15676 readonly success?: boolean; 15677 15678 /** 15679 * The times at which execution started and ended, as unix timestamps 15680 */ 15681 readonly timing?: { 15682 /** 15683 * Execution start time. 15684 */ 15685 readonly startTime: number; 15686 /** 15687 * Execution end time. 15688 */ 15689 readonly endTime: number; 15690 }; 15691 } 15692 15693 /** 15694 * A notebook range represents an ordered pair of two cell indices. 15695 * It is guaranteed that start is less than or equal to end. 15696 */ 15697 export class NotebookRange { 15698 15699 /** 15700 * The zero-based start index of this range. 15701 */ 15702 readonly start: number; 15703 15704 /** 15705 * The exclusive end index of this range (zero-based). 15706 */ 15707 readonly end: number; 15708 15709 /** 15710 * `true` if `start` and `end` are equal. 15711 */ 15712 readonly isEmpty: boolean; 15713 15714 /** 15715 * Create a new notebook range. If `start` is not 15716 * before or equal to `end`, the values will be swapped. 15717 * 15718 * @param start start index 15719 * @param end end index. 15720 */ 15721 constructor(start: number, end: number); 15722 15723 /** 15724 * Derive a new range for this range. 15725 * 15726 * @param change An object that describes a change to this range. 15727 * @returns A range that reflects the given change. Will return `this` range if the change 15728 * is not changing anything. 15729 */ 15730 with(change: { 15731 /** 15732 * New start index, defaults to `this.start`. 15733 */ 15734 start?: number; 15735 /** 15736 * New end index, defaults to `this.end`. 15737 */ 15738 end?: number; 15739 }): NotebookRange; 15740 } 15741 15742 /** 15743 * One representation of a {@link NotebookCellOutput notebook output}, defined by MIME type and data. 15744 */ 15745 export class NotebookCellOutputItem { 15746 15747 /** 15748 * Factory function to create a `NotebookCellOutputItem` from a string. 15749 * 15750 * *Note* that an UTF-8 encoder is used to create bytes for the string. 15751 * 15752 * @param value A string. 15753 * @param mime Optional MIME type, defaults to `text/plain`. 15754 * @returns A new output item object. 15755 */ 15756 static text(value: string, mime?: string): NotebookCellOutputItem; 15757 15758 /** 15759 * Factory function to create a `NotebookCellOutputItem` from 15760 * a JSON object. 15761 * 15762 * *Note* that this function is not expecting "stringified JSON" but 15763 * an object that can be stringified. This function will throw an error 15764 * when the passed value cannot be JSON-stringified. 15765 * 15766 * @param value A JSON-stringifyable value. 15767 * @param mime Optional MIME type, defaults to `application/json` 15768 * @returns A new output item object. 15769 */ 15770 static json(value: any, mime?: string): NotebookCellOutputItem; 15771 15772 /** 15773 * Factory function to create a `NotebookCellOutputItem` that uses 15774 * uses the `application/vnd.code.notebook.stdout` mime type. 15775 * 15776 * @param value A string. 15777 * @returns A new output item object. 15778 */ 15779 static stdout(value: string): NotebookCellOutputItem; 15780 15781 /** 15782 * Factory function to create a `NotebookCellOutputItem` that uses 15783 * uses the `application/vnd.code.notebook.stderr` mime type. 15784 * 15785 * @param value A string. 15786 * @returns A new output item object. 15787 */ 15788 static stderr(value: string): NotebookCellOutputItem; 15789 15790 /** 15791 * Factory function to create a `NotebookCellOutputItem` that uses 15792 * uses the `application/vnd.code.notebook.error` mime type. 15793 * 15794 * @param value An error object. 15795 * @returns A new output item object. 15796 */ 15797 static error(value: Error): NotebookCellOutputItem; 15798 15799 /** 15800 * The mime type which determines how the {@linkcode NotebookCellOutputItem.data data}-property 15801 * is interpreted. 15802 * 15803 * Notebooks have built-in support for certain mime-types, extensions can add support for new 15804 * types and override existing types. 15805 */ 15806 mime: string; 15807 15808 /** 15809 * The data of this output item. Must always be an array of unsigned 8-bit integers. 15810 */ 15811 data: Uint8Array; 15812 15813 /** 15814 * Create a new notebook cell output item. 15815 * 15816 * @param data The value of the output item. 15817 * @param mime The mime type of the output item. 15818 */ 15819 constructor(data: Uint8Array, mime: string); 15820 } 15821 15822 /** 15823 * Notebook cell output represents a result of executing a cell. It is a container type for multiple 15824 * {@link NotebookCellOutputItem output items} where contained items represent the same result but 15825 * use different MIME types. 15826 */ 15827 export class NotebookCellOutput { 15828 15829 /** 15830 * The output items of this output. Each item must represent the same result. _Note_ that repeated 15831 * MIME types per output is invalid and that the editor will just pick one of them. 15832 * 15833 * ```ts 15834 * new vscode.NotebookCellOutput([ 15835 * vscode.NotebookCellOutputItem.text('Hello', 'text/plain'), 15836 * vscode.NotebookCellOutputItem.text('<i>Hello</i>', 'text/html'), 15837 * vscode.NotebookCellOutputItem.text('_Hello_', 'text/markdown'), 15838 * vscode.NotebookCellOutputItem.text('Hey', 'text/plain'), // INVALID: repeated type, editor will pick just one 15839 * ]) 15840 * ``` 15841 */ 15842 items: NotebookCellOutputItem[]; 15843 15844 /** 15845 * Arbitrary metadata for this cell output. Can be anything but must be JSON-stringifyable. 15846 */ 15847 metadata?: { [key: string]: any }; 15848 15849 /** 15850 * Create new notebook output. 15851 * 15852 * @param items Notebook output items. 15853 * @param metadata Optional metadata. 15854 */ 15855 constructor(items: NotebookCellOutputItem[], metadata?: { [key: string]: any }); 15856 } 15857 15858 /** 15859 * NotebookCellData is the raw representation of notebook cells. Its is part of {@linkcode NotebookData}. 15860 */ 15861 export class NotebookCellData { 15862 15863 /** 15864 * The {@link NotebookCellKind kind} of this cell data. 15865 */ 15866 kind: NotebookCellKind; 15867 15868 /** 15869 * The source value of this cell data - either source code or formatted text. 15870 */ 15871 value: string; 15872 15873 /** 15874 * The language identifier of the source value of this cell data. Any value from 15875 * {@linkcode languages.getLanguages getLanguages} is possible. 15876 */ 15877 languageId: string; 15878 15879 /** 15880 * The outputs of this cell data. 15881 */ 15882 outputs?: NotebookCellOutput[]; 15883 15884 /** 15885 * Arbitrary metadata of this cell data. Can be anything but must be JSON-stringifyable. 15886 */ 15887 metadata?: { [key: string]: any }; 15888 15889 /** 15890 * The execution summary of this cell data. 15891 */ 15892 executionSummary?: NotebookCellExecutionSummary; 15893 15894 /** 15895 * Create new cell data. Minimal cell data specifies its kind, its source value, and the 15896 * language identifier of its source. 15897 * 15898 * @param kind The kind. 15899 * @param value The source value. 15900 * @param languageId The language identifier of the source value. 15901 */ 15902 constructor(kind: NotebookCellKind, value: string, languageId: string); 15903 } 15904 15905 /** 15906 * Raw representation of a notebook. 15907 * 15908 * Extensions are responsible for creating {@linkcode NotebookData} so that the editor 15909 * can create a {@linkcode NotebookDocument}. 15910 * 15911 * @see {@link NotebookSerializer} 15912 */ 15913 export class NotebookData { 15914 /** 15915 * The cell data of this notebook data. 15916 */ 15917 cells: NotebookCellData[]; 15918 15919 /** 15920 * Arbitrary metadata of notebook data. 15921 */ 15922 metadata?: { [key: string]: any }; 15923 15924 /** 15925 * Create new notebook data. 15926 * 15927 * @param cells An array of cell data. 15928 */ 15929 constructor(cells: NotebookCellData[]); 15930 } 15931 15932 /** 15933 * The notebook serializer enables the editor to open notebook files. 15934 * 15935 * At its core the editor only knows a {@link NotebookData notebook data structure} but not 15936 * how that data structure is written to a file, nor how it is read from a file. The 15937 * notebook serializer bridges this gap by deserializing bytes into notebook data and 15938 * vice versa. 15939 */ 15940 export interface NotebookSerializer { 15941 15942 /** 15943 * Deserialize contents of a notebook file into the notebook data structure. 15944 * 15945 * @param content Contents of a notebook file. 15946 * @param token A cancellation token. 15947 * @returns Notebook data or a thenable that resolves to such. 15948 */ 15949 deserializeNotebook(content: Uint8Array, token: CancellationToken): NotebookData | Thenable<NotebookData>; 15950 15951 /** 15952 * Serialize notebook data into file contents. 15953 * 15954 * @param data A notebook data structure. 15955 * @param token A cancellation token. 15956 * @returns An array of bytes or a thenable that resolves to such. 15957 */ 15958 serializeNotebook(data: NotebookData, token: CancellationToken): Uint8Array | Thenable<Uint8Array>; 15959 } 15960 15961 /** 15962 * Notebook content options define what parts of a notebook are persisted. Note 15963 * 15964 * For instance, a notebook serializer can opt-out of saving outputs and in that case the editor doesn't mark a 15965 * notebooks as {@link NotebookDocument.isDirty dirty} when its output has changed. 15966 */ 15967 export interface NotebookDocumentContentOptions { 15968 /** 15969 * Controls if output change events will trigger notebook document content change events and 15970 * if it will be used in the diff editor, defaults to false. If the content provider doesn't 15971 * persist the outputs in the file document, this should be set to true. 15972 */ 15973 transientOutputs?: boolean; 15974 15975 /** 15976 * Controls if a cell metadata property change event will trigger notebook document content 15977 * change events and if it will be used in the diff editor, defaults to false. If the 15978 * content provider doesn't persist a metadata property in the file document, it should be 15979 * set to true. 15980 */ 15981 transientCellMetadata?: { [key: string]: boolean | undefined }; 15982 15983 /** 15984 * Controls if a document metadata property change event will trigger notebook document 15985 * content change event and if it will be used in the diff editor, defaults to false. If the 15986 * content provider doesn't persist a metadata property in the file document, it should be 15987 * set to true. 15988 */ 15989 transientDocumentMetadata?: { [key: string]: boolean | undefined }; 15990 } 15991 15992 /** 15993 * Notebook controller affinity for notebook documents. 15994 * 15995 * @see {@link NotebookController.updateNotebookAffinity} 15996 */ 15997 export enum NotebookControllerAffinity { 15998 /** 15999 * Default affinity. 16000 */ 16001 Default = 1, 16002 /** 16003 * A controller is preferred for a notebook. 16004 */ 16005 Preferred = 2 16006 } 16007 16008 /** 16009 * A notebook controller represents an entity that can execute notebook cells. This is often referred to as a kernel. 16010 * 16011 * There can be multiple controllers and the editor will let users choose which controller to use for a certain notebook. The 16012 * {@linkcode NotebookController.notebookType notebookType}-property defines for what kind of notebooks a controller is for and 16013 * the {@linkcode NotebookController.updateNotebookAffinity updateNotebookAffinity}-function allows controllers to set a preference 16014 * for specific notebook documents. When a controller has been selected its 16015 * {@link NotebookController.onDidChangeSelectedNotebooks onDidChangeSelectedNotebooks}-event fires. 16016 * 16017 * When a cell is being run the editor will invoke the {@linkcode NotebookController.executeHandler executeHandler} and a controller 16018 * is expected to create and finalize a {@link NotebookCellExecution notebook cell execution}. However, controllers are also free 16019 * to create executions by themselves. 16020 */ 16021 export interface NotebookController { 16022 16023 /** 16024 * The identifier of this notebook controller. 16025 * 16026 * _Note_ that controllers are remembered by their identifier and that extensions should use 16027 * stable identifiers across sessions. 16028 */ 16029 readonly id: string; 16030 16031 /** 16032 * The notebook type this controller is for. 16033 */ 16034 readonly notebookType: string; 16035 16036 /** 16037 * An array of language identifiers that are supported by this 16038 * controller. Any language identifier from {@linkcode languages.getLanguages getLanguages} 16039 * is possible. When falsy all languages are supported. 16040 * 16041 * Samples: 16042 * ```js 16043 * // support JavaScript and TypeScript 16044 * myController.supportedLanguages = ['javascript', 'typescript'] 16045 * 16046 * // support all languages 16047 * myController.supportedLanguages = undefined; // falsy 16048 * myController.supportedLanguages = []; // falsy 16049 * ``` 16050 */ 16051 supportedLanguages?: string[]; 16052 16053 /** 16054 * The human-readable label of this notebook controller. 16055 */ 16056 label: string; 16057 16058 /** 16059 * The human-readable description which is rendered less prominent. 16060 */ 16061 description?: string; 16062 16063 /** 16064 * The human-readable detail which is rendered less prominent. 16065 */ 16066 detail?: string; 16067 16068 /** 16069 * Whether this controller supports execution order so that the 16070 * editor can render placeholders for them. 16071 */ 16072 supportsExecutionOrder?: boolean; 16073 16074 /** 16075 * Create a cell execution task. 16076 * 16077 * _Note_ that there can only be one execution per cell at a time and that an error is thrown if 16078 * a cell execution is created while another is still active. 16079 * 16080 * This should be used in response to the {@link NotebookController.executeHandler execution handler} 16081 * being called or when cell execution has been started else, e.g when a cell was already 16082 * executing or when cell execution was triggered from another source. 16083 * 16084 * @param cell The notebook cell for which to create the execution. 16085 * @returns A notebook cell execution. 16086 */ 16087 createNotebookCellExecution(cell: NotebookCell): NotebookCellExecution; 16088 16089 /** 16090 * The execute handler is invoked when the run gestures in the UI are selected, e.g Run Cell, Run All, 16091 * Run Selection etc. The execute handler is responsible for creating and managing {@link NotebookCellExecution execution}-objects. 16092 */ 16093 executeHandler: (cells: NotebookCell[], notebook: NotebookDocument, controller: NotebookController) => void | Thenable<void>; 16094 16095 /** 16096 * Optional interrupt handler. 16097 * 16098 * By default cell execution is canceled via {@link NotebookCellExecution.token tokens}. Cancellation 16099 * tokens require that a controller can keep track of its execution so that it can cancel a specific execution at a later 16100 * point. Not all scenarios allow for that, eg. REPL-style controllers often work by interrupting whatever is currently 16101 * running. For those cases the interrupt handler exists - it can be thought of as the equivalent of `SIGINT` 16102 * or `Control+C` in terminals. 16103 * 16104 * _Note_ that supporting {@link NotebookCellExecution.token cancellation tokens} is preferred and that interrupt handlers should 16105 * only be used when tokens cannot be supported. 16106 */ 16107 interruptHandler?: (notebook: NotebookDocument) => void | Thenable<void>; 16108 16109 /** 16110 * An event that fires whenever a controller has been selected or un-selected for a notebook document. 16111 * 16112 * There can be multiple controllers for a notebook and in that case a controllers needs to be _selected_. This is a user gesture 16113 * and happens either explicitly or implicitly when interacting with a notebook for which a controller was _suggested_. When possible, 16114 * the editor _suggests_ a controller that is most likely to be _selected_. 16115 * 16116 * _Note_ that controller selection is persisted (by the controllers {@link NotebookController.id id}) and restored as soon as a 16117 * controller is re-created or as a notebook is {@link workspace.onDidOpenNotebookDocument opened}. 16118 */ 16119 readonly onDidChangeSelectedNotebooks: Event<{ 16120 /** 16121 * The notebook for which the controller has been selected or un-selected. 16122 */ 16123 readonly notebook: NotebookDocument; 16124 /** 16125 * Whether the controller has been selected or un-selected. 16126 */ 16127 readonly selected: boolean; 16128 }>; 16129 16130 /** 16131 * A controller can set affinities for specific notebook documents. This allows a controller 16132 * to be presented more prominent for some notebooks. 16133 * 16134 * @param notebook The notebook for which a priority is set. 16135 * @param affinity A controller affinity 16136 */ 16137 updateNotebookAffinity(notebook: NotebookDocument, affinity: NotebookControllerAffinity): void; 16138 16139 /** 16140 * Dispose and free associated resources. 16141 */ 16142 dispose(): void; 16143 } 16144 16145 /** 16146 * A NotebookCellExecution is how {@link NotebookController notebook controller} modify a notebook cell as 16147 * it is executing. 16148 * 16149 * When a cell execution object is created, the cell enters the {@linkcode NotebookCellExecutionState.Pending Pending} state. 16150 * When {@linkcode NotebookCellExecution.start start(...)} is called on the execution task, it enters the {@linkcode NotebookCellExecutionState.Executing Executing} state. When 16151 * {@linkcode NotebookCellExecution.end end(...)} is called, it enters the {@linkcode NotebookCellExecutionState.Idle Idle} state. 16152 */ 16153 export interface NotebookCellExecution { 16154 16155 /** 16156 * The {@link NotebookCell cell} for which this execution has been created. 16157 */ 16158 readonly cell: NotebookCell; 16159 16160 /** 16161 * A cancellation token which will be triggered when the cell execution is canceled 16162 * from the UI. 16163 * 16164 * _Note_ that the cancellation token will not be triggered when the {@link NotebookController controller} 16165 * that created this execution uses an {@link NotebookController.interruptHandler interrupt-handler}. 16166 */ 16167 readonly token: CancellationToken; 16168 16169 /** 16170 * Set and unset the order of this cell execution. 16171 */ 16172 executionOrder: number | undefined; 16173 16174 /** 16175 * Signal that the execution has begun. 16176 * 16177 * @param startTime The time that execution began, in milliseconds in the Unix epoch. Used to drive the clock 16178 * that shows for how long a cell has been running. If not given, the clock won't be shown. 16179 */ 16180 start(startTime?: number): void; 16181 16182 /** 16183 * Signal that execution has ended. 16184 * 16185 * @param success If true, a green check is shown on the cell status bar. 16186 * If false, a red X is shown. 16187 * If undefined, no check or X icon is shown. 16188 * @param endTime The time that execution finished, in milliseconds in the Unix epoch. 16189 */ 16190 end(success: boolean | undefined, endTime?: number): void; 16191 16192 /** 16193 * Clears the output of the cell that is executing or of another cell that is affected by this execution. 16194 * 16195 * @param cell Cell for which output is cleared. Defaults to the {@link NotebookCellExecution.cell cell} of 16196 * this execution. 16197 * @returns A thenable that resolves when the operation finished. 16198 */ 16199 clearOutput(cell?: NotebookCell): Thenable<void>; 16200 16201 /** 16202 * Replace the output of the cell that is executing or of another cell that is affected by this execution. 16203 * 16204 * @param out Output that replaces the current output. 16205 * @param cell Cell for which output is cleared. Defaults to the {@link NotebookCellExecution.cell cell} of 16206 * this execution. 16207 * @returns A thenable that resolves when the operation finished. 16208 */ 16209 replaceOutput(out: NotebookCellOutput | readonly NotebookCellOutput[], cell?: NotebookCell): Thenable<void>; 16210 16211 /** 16212 * Append to the output of the cell that is executing or to another cell that is affected by this execution. 16213 * 16214 * @param out Output that is appended to the current output. 16215 * @param cell Cell for which output is cleared. Defaults to the {@link NotebookCellExecution.cell cell} of 16216 * this execution. 16217 * @returns A thenable that resolves when the operation finished. 16218 */ 16219 appendOutput(out: NotebookCellOutput | readonly NotebookCellOutput[], cell?: NotebookCell): Thenable<void>; 16220 16221 /** 16222 * Replace all output items of existing cell output. 16223 * 16224 * @param items Output items that replace the items of existing output. 16225 * @param output Output object that already exists. 16226 * @returns A thenable that resolves when the operation finished. 16227 */ 16228 replaceOutputItems(items: NotebookCellOutputItem | readonly NotebookCellOutputItem[], output: NotebookCellOutput): Thenable<void>; 16229 16230 /** 16231 * Append output items to existing cell output. 16232 * 16233 * @param items Output items that are append to existing output. 16234 * @param output Output object that already exists. 16235 * @returns A thenable that resolves when the operation finished. 16236 */ 16237 appendOutputItems(items: NotebookCellOutputItem | readonly NotebookCellOutputItem[], output: NotebookCellOutput): Thenable<void>; 16238 } 16239 16240 /** 16241 * Represents the alignment of status bar items. 16242 */ 16243 export enum NotebookCellStatusBarAlignment { 16244 16245 /** 16246 * Aligned to the left side. 16247 */ 16248 Left = 1, 16249 16250 /** 16251 * Aligned to the right side. 16252 */ 16253 Right = 2 16254 } 16255 16256 /** 16257 * A contribution to a cell's status bar 16258 */ 16259 export class NotebookCellStatusBarItem { 16260 /** 16261 * The text to show for the item. 16262 */ 16263 text: string; 16264 16265 /** 16266 * Whether the item is aligned to the left or right. 16267 */ 16268 alignment: NotebookCellStatusBarAlignment; 16269 16270 /** 16271 * An optional {@linkcode Command} or identifier of a command to run on click. 16272 * 16273 * The command must be {@link commands.getCommands known}. 16274 * 16275 * Note that if this is a {@linkcode Command} object, only the {@linkcode Command.command command} and {@linkcode Command.arguments arguments} 16276 * are used by the editor. 16277 */ 16278 command?: string | Command; 16279 16280 /** 16281 * A tooltip to show when the item is hovered. 16282 */ 16283 tooltip?: string; 16284 16285 /** 16286 * The priority of the item. A higher value item will be shown more to the left. 16287 */ 16288 priority?: number; 16289 16290 /** 16291 * Accessibility information used when a screen reader interacts with this item. 16292 */ 16293 accessibilityInformation?: AccessibilityInformation; 16294 16295 /** 16296 * Creates a new NotebookCellStatusBarItem. 16297 * @param text The text to show for the item. 16298 * @param alignment Whether the item is aligned to the left or right. 16299 */ 16300 constructor(text: string, alignment: NotebookCellStatusBarAlignment); 16301 } 16302 16303 /** 16304 * A provider that can contribute items to the status bar that appears below a cell's editor. 16305 */ 16306 export interface NotebookCellStatusBarItemProvider { 16307 /** 16308 * An optional event to signal that statusbar items have changed. The provide method will be called again. 16309 */ 16310 onDidChangeCellStatusBarItems?: Event<void>; 16311 16312 /** 16313 * The provider will be called when the cell scrolls into view, when its content, outputs, language, or metadata change, and when it changes execution state. 16314 * @param cell The cell for which to return items. 16315 * @param token A token triggered if this request should be cancelled. 16316 * @returns One or more {@link NotebookCellStatusBarItem cell statusbar items} 16317 */ 16318 provideCellStatusBarItems(cell: NotebookCell, token: CancellationToken): ProviderResult<NotebookCellStatusBarItem | NotebookCellStatusBarItem[]>; 16319 } 16320 16321 /** 16322 * Namespace for notebooks. 16323 * 16324 * The notebooks functionality is composed of three loosely coupled components: 16325 * 16326 * 1. {@link NotebookSerializer} enable the editor to open, show, and save notebooks 16327 * 2. {@link NotebookController} own the execution of notebooks, e.g they create output from code cells. 16328 * 3. NotebookRenderer present notebook output in the editor. They run in a separate context. 16329 */ 16330 export namespace notebooks { 16331 16332 /** 16333 * Creates a new notebook controller. 16334 * 16335 * @param id Identifier of the controller. Must be unique per extension. 16336 * @param notebookType A notebook type for which this controller is for. 16337 * @param label The label of the controller. 16338 * @param handler The execute-handler of the controller. 16339 * @returns A new notebook controller. 16340 */ 16341 export function createNotebookController(id: string, notebookType: string, label: string, handler?: (cells: NotebookCell[], notebook: NotebookDocument, controller: NotebookController) => void | Thenable<void>): NotebookController; 16342 16343 /** 16344 * Register a {@link NotebookCellStatusBarItemProvider cell statusbar item provider} for the given notebook type. 16345 * 16346 * @param notebookType The notebook type to register for. 16347 * @param provider A cell status bar provider. 16348 * @returns A {@link Disposable} that unregisters this provider when being disposed. 16349 */ 16350 export function registerNotebookCellStatusBarItemProvider(notebookType: string, provider: NotebookCellStatusBarItemProvider): Disposable; 16351 16352 /** 16353 * Creates a new messaging instance used to communicate with a specific renderer. 16354 * 16355 * * *Note 1:* Extensions can only create renderer that they have defined in their `package.json`-file 16356 * * *Note 2:* A renderer only has access to messaging if `requiresMessaging` is set to `always` or `optional` in 16357 * its `notebookRenderer` contribution. 16358 * 16359 * @param rendererId The renderer ID to communicate with 16360 * @returns A new notebook renderer messaging object. 16361 */ 16362 export function createRendererMessaging(rendererId: string): NotebookRendererMessaging; 16363 } 16364 16365 /** 16366 * Represents the input box in the Source Control viewlet. 16367 */ 16368 export interface SourceControlInputBox { 16369 16370 /** 16371 * Setter and getter for the contents of the input box. 16372 */ 16373 value: string; 16374 16375 /** 16376 * A string to show as placeholder in the input box to guide the user. 16377 */ 16378 placeholder: string; 16379 16380 /** 16381 * Controls whether the input box is enabled (default is `true`). 16382 */ 16383 enabled: boolean; 16384 16385 /** 16386 * Controls whether the input box is visible (default is `true`). 16387 */ 16388 visible: boolean; 16389 } 16390 16391 /** 16392 * A quick diff provider provides a {@link Uri uri} to the original state of a 16393 * modified resource. The editor will use this information to render ad'hoc diffs 16394 * within the text. 16395 */ 16396 export interface QuickDiffProvider { 16397 16398 /** 16399 * Provide a {@link Uri} to the original resource of any given resource uri. 16400 * 16401 * @param uri The uri of the resource open in a text editor. 16402 * @param token A cancellation token. 16403 * @returns A thenable that resolves to uri of the matching original resource. 16404 */ 16405 provideOriginalResource?(uri: Uri, token: CancellationToken): ProviderResult<Uri>; 16406 } 16407 16408 /** 16409 * The theme-aware decorations for a 16410 * {@link SourceControlResourceState source control resource state}. 16411 */ 16412 export interface SourceControlResourceThemableDecorations { 16413 16414 /** 16415 * The icon path for a specific 16416 * {@link SourceControlResourceState source control resource state}. 16417 */ 16418 readonly iconPath?: string | Uri | ThemeIcon; 16419 } 16420 16421 /** 16422 * The decorations for a {@link SourceControlResourceState source control resource state}. 16423 * Can be independently specified for light and dark themes. 16424 */ 16425 export interface SourceControlResourceDecorations extends SourceControlResourceThemableDecorations { 16426 16427 /** 16428 * Whether the {@link SourceControlResourceState source control resource state} should 16429 * be striked-through in the UI. 16430 */ 16431 readonly strikeThrough?: boolean; 16432 16433 /** 16434 * Whether the {@link SourceControlResourceState source control resource state} should 16435 * be faded in the UI. 16436 */ 16437 readonly faded?: boolean; 16438 16439 /** 16440 * The title for a specific 16441 * {@link SourceControlResourceState source control resource state}. 16442 */ 16443 readonly tooltip?: string; 16444 16445 /** 16446 * The light theme decorations. 16447 */ 16448 readonly light?: SourceControlResourceThemableDecorations; 16449 16450 /** 16451 * The dark theme decorations. 16452 */ 16453 readonly dark?: SourceControlResourceThemableDecorations; 16454 } 16455 16456 /** 16457 * An source control resource state represents the state of an underlying workspace 16458 * resource within a certain {@link SourceControlResourceGroup source control group}. 16459 */ 16460 export interface SourceControlResourceState { 16461 16462 /** 16463 * The {@link Uri} of the underlying resource inside the workspace. 16464 */ 16465 readonly resourceUri: Uri; 16466 16467 /** 16468 * The {@link Command} which should be run when the resource 16469 * state is open in the Source Control viewlet. 16470 */ 16471 readonly command?: Command; 16472 16473 /** 16474 * The {@link SourceControlResourceDecorations decorations} for this source control 16475 * resource state. 16476 */ 16477 readonly decorations?: SourceControlResourceDecorations; 16478 16479 /** 16480 * Context value of the resource state. This can be used to contribute resource specific actions. 16481 * For example, if a resource is given a context value as `diffable`. When contributing actions to `scm/resourceState/context` 16482 * using `menus` extension point, you can specify context value for key `scmResourceState` in `when` expressions, like `scmResourceState == diffable`. 16483 * ```json 16484 * "contributes": { 16485 * "menus": { 16486 * "scm/resourceState/context": [ 16487 * { 16488 * "command": "extension.diff", 16489 * "when": "scmResourceState == diffable" 16490 * } 16491 * ] 16492 * } 16493 * } 16494 * ``` 16495 * This will show action `extension.diff` only for resources with `contextValue` is `diffable`. 16496 */ 16497 readonly contextValue?: string; 16498 } 16499 16500 /** 16501 * A source control resource group is a collection of 16502 * {@link SourceControlResourceState source control resource states}. 16503 */ 16504 export interface SourceControlResourceGroup { 16505 16506 /** 16507 * The id of this source control resource group. 16508 */ 16509 readonly id: string; 16510 16511 /** 16512 * The label of this source control resource group. 16513 */ 16514 label: string; 16515 16516 /** 16517 * Whether this source control resource group is hidden when it contains 16518 * no {@link SourceControlResourceState source control resource states}. 16519 */ 16520 hideWhenEmpty?: boolean; 16521 16522 /** 16523 * Context value of the resource group. This can be used to contribute resource group specific actions. 16524 * For example, if a resource group is given a context value of `exportable`, when contributing actions to `scm/resourceGroup/context` 16525 * using `menus` extension point, you can specify context value for key `scmResourceGroupState` in `when` expressions, like `scmResourceGroupState == exportable`. 16526 * ```json 16527 * "contributes": { 16528 * "menus": { 16529 * "scm/resourceGroup/context": [ 16530 * { 16531 * "command": "extension.export", 16532 * "when": "scmResourceGroupState == exportable" 16533 * } 16534 * ] 16535 * } 16536 * } 16537 * ``` 16538 * This will show action `extension.export` only for resource groups with `contextValue` equal to `exportable`. 16539 */ 16540 contextValue?: string; 16541 16542 /** 16543 * This group's collection of 16544 * {@link SourceControlResourceState source control resource states}. 16545 */ 16546 resourceStates: SourceControlResourceState[]; 16547 16548 /** 16549 * Dispose this source control resource group. 16550 */ 16551 dispose(): void; 16552 } 16553 16554 /** 16555 * An source control is able to provide {@link SourceControlResourceState resource states} 16556 * to the editor and interact with the editor in several source control related ways. 16557 */ 16558 export interface SourceControl { 16559 16560 /** 16561 * The id of this source control. 16562 */ 16563 readonly id: string; 16564 16565 /** 16566 * The human-readable label of this source control. 16567 */ 16568 readonly label: string; 16569 16570 /** 16571 * The (optional) Uri of the root of this source control. 16572 */ 16573 readonly rootUri: Uri | undefined; 16574 16575 /** 16576 * The {@link SourceControlInputBox input box} for this source control. 16577 */ 16578 readonly inputBox: SourceControlInputBox; 16579 16580 /** 16581 * The UI-visible count of {@link SourceControlResourceState resource states} of 16582 * this source control. 16583 * 16584 * If undefined, this source control will 16585 * - display its UI-visible count as zero, and 16586 * - contribute the count of its {@link SourceControlResourceState resource states} to the UI-visible aggregated count for all source controls 16587 */ 16588 count?: number; 16589 16590 /** 16591 * An optional {@link QuickDiffProvider quick diff provider}. 16592 */ 16593 quickDiffProvider?: QuickDiffProvider; 16594 16595 /** 16596 * Optional commit template string. 16597 * 16598 * The Source Control viewlet will populate the Source Control 16599 * input with this value when appropriate. 16600 */ 16601 commitTemplate?: string; 16602 16603 /** 16604 * Optional accept input command. 16605 * 16606 * This command will be invoked when the user accepts the value 16607 * in the Source Control input. 16608 */ 16609 acceptInputCommand?: Command; 16610 16611 /** 16612 * Optional status bar commands. 16613 * 16614 * These commands will be displayed in the editor's status bar. 16615 */ 16616 statusBarCommands?: Command[]; 16617 16618 /** 16619 * Create a new {@link SourceControlResourceGroup resource group}. 16620 */ 16621 createResourceGroup(id: string, label: string): SourceControlResourceGroup; 16622 16623 /** 16624 * Dispose this source control. 16625 */ 16626 dispose(): void; 16627 } 16628 16629 /** 16630 * Namespace for source control management. 16631 */ 16632 export namespace scm { 16633 16634 /** 16635 * The {@link SourceControlInputBox input box} for the last source control 16636 * created by the extension. 16637 * 16638 * @deprecated Use SourceControl.inputBox instead 16639 */ 16640 export const inputBox: SourceControlInputBox; 16641 16642 /** 16643 * Creates a new {@link SourceControl source control} instance. 16644 * 16645 * @param id An `id` for the source control. Something short, e.g.: `git`. 16646 * @param label A human-readable string for the source control. E.g.: `Git`. 16647 * @param rootUri An optional Uri of the root of the source control. E.g.: `Uri.parse(workspaceRoot)`. 16648 * @returns An instance of {@link SourceControl source control}. 16649 */ 16650 export function createSourceControl(id: string, label: string, rootUri?: Uri): SourceControl; 16651 } 16652 16653 /** 16654 * A DebugProtocolMessage is an opaque stand-in type for the [ProtocolMessage](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage) type defined in the Debug Adapter Protocol. 16655 */ 16656 export interface DebugProtocolMessage { 16657 // Properties: see [ProtocolMessage details](https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ProtocolMessage). 16658 } 16659 16660 /** 16661 * A DebugProtocolSource is an opaque stand-in type for the [Source](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Source) type defined in the Debug Adapter Protocol. 16662 */ 16663 export interface DebugProtocolSource { 16664 // Properties: see [Source details](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Source). 16665 } 16666 16667 /** 16668 * A DebugProtocolBreakpoint is an opaque stand-in type for the [Breakpoint](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Breakpoint) type defined in the Debug Adapter Protocol. 16669 */ 16670 export interface DebugProtocolBreakpoint { 16671 // Properties: see [Breakpoint details](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Breakpoint). 16672 } 16673 16674 /** 16675 * Configuration for a debug session. 16676 */ 16677 export interface DebugConfiguration { 16678 /** 16679 * The type of the debug session. 16680 */ 16681 type: string; 16682 16683 /** 16684 * The name of the debug session. 16685 */ 16686 name: string; 16687 16688 /** 16689 * The request type of the debug session. 16690 */ 16691 request: string; 16692 16693 /** 16694 * Additional debug type specific properties. 16695 */ 16696 [key: string]: any; 16697 } 16698 16699 /** 16700 * A debug session. 16701 */ 16702 export interface DebugSession { 16703 16704 /** 16705 * The unique ID of this debug session. 16706 */ 16707 readonly id: string; 16708 16709 /** 16710 * The debug session's type from the {@link DebugConfiguration debug configuration}. 16711 */ 16712 readonly type: string; 16713 16714 /** 16715 * The parent session of this debug session, if it was created as a child. 16716 * @see DebugSessionOptions.parentSession 16717 */ 16718 readonly parentSession?: DebugSession; 16719 16720 /** 16721 * The debug session's name is initially taken from the {@link DebugConfiguration debug configuration}. 16722 * Any changes will be properly reflected in the UI. 16723 */ 16724 name: string; 16725 16726 /** 16727 * The workspace folder of this session or `undefined` for a folderless setup. 16728 */ 16729 readonly workspaceFolder: WorkspaceFolder | undefined; 16730 16731 /** 16732 * The "resolved" {@link DebugConfiguration debug configuration} of this session. 16733 * "Resolved" means that 16734 * - all variables have been substituted and 16735 * - platform specific attribute sections have been "flattened" for the matching platform and removed for non-matching platforms. 16736 */ 16737 readonly configuration: DebugConfiguration; 16738 16739 /** 16740 * Send a custom request to the debug adapter. 16741 */ 16742 customRequest(command: string, args?: any): Thenable<any>; 16743 16744 /** 16745 * Maps a breakpoint in the editor to the corresponding Debug Adapter Protocol (DAP) breakpoint that is managed by the debug adapter of the debug session. 16746 * If no DAP breakpoint exists (either because the editor breakpoint was not yet registered or because the debug adapter is not interested in the breakpoint), the value `undefined` is returned. 16747 * 16748 * @param breakpoint A {@link Breakpoint} in the editor. 16749 * @returns A promise that resolves to the Debug Adapter Protocol breakpoint or `undefined`. 16750 */ 16751 getDebugProtocolBreakpoint(breakpoint: Breakpoint): Thenable<DebugProtocolBreakpoint | undefined>; 16752 } 16753 16754 /** 16755 * A custom Debug Adapter Protocol event received from a {@link DebugSession debug session}. 16756 */ 16757 export interface DebugSessionCustomEvent { 16758 /** 16759 * The {@link DebugSession debug session} for which the custom event was received. 16760 */ 16761 readonly session: DebugSession; 16762 16763 /** 16764 * Type of event. 16765 */ 16766 readonly event: string; 16767 16768 /** 16769 * Event specific information. 16770 */ 16771 readonly body: any; 16772 } 16773 16774 /** 16775 * A debug configuration provider allows to add debug configurations to the debug service 16776 * and to resolve launch configurations before they are used to start a debug session. 16777 * A debug configuration provider is registered via {@link debug.registerDebugConfigurationProvider}. 16778 */ 16779 export interface DebugConfigurationProvider { 16780 /** 16781 * Provides {@link DebugConfiguration debug configuration} to the debug service. If more than one debug configuration provider is 16782 * registered for the same type, debug configurations are concatenated in arbitrary order. 16783 * 16784 * @param folder The workspace folder for which the configurations are used or `undefined` for a folderless setup. 16785 * @param token A cancellation token. 16786 * @returns An array of {@link DebugConfiguration debug configurations}. 16787 */ 16788 provideDebugConfigurations?(folder: WorkspaceFolder | undefined, token?: CancellationToken): ProviderResult<DebugConfiguration[]>; 16789 16790 /** 16791 * Resolves a {@link DebugConfiguration debug configuration} by filling in missing values or by adding/changing/removing attributes. 16792 * If more than one debug configuration provider is registered for the same type, the resolveDebugConfiguration calls are chained 16793 * in arbitrary order and the initial debug configuration is piped through the chain. 16794 * Returning the value 'undefined' prevents the debug session from starting. 16795 * Returning the value 'null' prevents the debug session from starting and opens the underlying debug configuration instead. 16796 * 16797 * @param folder The workspace folder from which the configuration originates from or `undefined` for a folderless setup. 16798 * @param debugConfiguration The {@link DebugConfiguration debug configuration} to resolve. 16799 * @param token A cancellation token. 16800 * @returns The resolved debug configuration or undefined or null. 16801 */ 16802 resolveDebugConfiguration?(folder: WorkspaceFolder | undefined, debugConfiguration: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration>; 16803 16804 /** 16805 * This hook is directly called after 'resolveDebugConfiguration' but with all variables substituted. 16806 * It can be used to resolve or verify a {@link DebugConfiguration debug configuration} by filling in missing values or by adding/changing/removing attributes. 16807 * If more than one debug configuration provider is registered for the same type, the 'resolveDebugConfigurationWithSubstitutedVariables' calls are chained 16808 * in arbitrary order and the initial debug configuration is piped through the chain. 16809 * Returning the value 'undefined' prevents the debug session from starting. 16810 * Returning the value 'null' prevents the debug session from starting and opens the underlying debug configuration instead. 16811 * 16812 * @param folder The workspace folder from which the configuration originates from or `undefined` for a folderless setup. 16813 * @param debugConfiguration The {@link DebugConfiguration debug configuration} to resolve. 16814 * @param token A cancellation token. 16815 * @returns The resolved debug configuration or undefined or null. 16816 */ 16817 resolveDebugConfigurationWithSubstitutedVariables?(folder: WorkspaceFolder | undefined, debugConfiguration: DebugConfiguration, token?: CancellationToken): ProviderResult<DebugConfiguration>; 16818 } 16819 16820 /** 16821 * Represents a debug adapter executable and optional arguments and runtime options passed to it. 16822 */ 16823 export class DebugAdapterExecutable { 16824 16825 /** 16826 * Creates a description for a debug adapter based on an executable program. 16827 * 16828 * @param command The command or executable path that implements the debug adapter. 16829 * @param args Optional arguments to be passed to the command or executable. 16830 * @param options Optional options to be used when starting the command or executable. 16831 */ 16832 constructor(command: string, args?: string[], options?: DebugAdapterExecutableOptions); 16833 16834 /** 16835 * The command or path of the debug adapter executable. 16836 * A command must be either an absolute path of an executable or the name of an command to be looked up via the PATH environment variable. 16837 * The special value 'node' will be mapped to the editor's built-in Node.js runtime. 16838 */ 16839 readonly command: string; 16840 16841 /** 16842 * The arguments passed to the debug adapter executable. Defaults to an empty array. 16843 */ 16844 readonly args: string[]; 16845 16846 /** 16847 * Optional options to be used when the debug adapter is started. 16848 * Defaults to undefined. 16849 */ 16850 readonly options?: DebugAdapterExecutableOptions; 16851 } 16852 16853 /** 16854 * Options for a debug adapter executable. 16855 */ 16856 export interface DebugAdapterExecutableOptions { 16857 16858 /** 16859 * The additional environment of the executed program or shell. If omitted 16860 * the parent process' environment is used. If provided it is merged with 16861 * the parent process' environment. 16862 */ 16863 env?: { [key: string]: string }; 16864 16865 /** 16866 * The current working directory for the executed debug adapter. 16867 */ 16868 cwd?: string; 16869 } 16870 16871 /** 16872 * Represents a debug adapter running as a socket based server. 16873 */ 16874 export class DebugAdapterServer { 16875 16876 /** 16877 * The port. 16878 */ 16879 readonly port: number; 16880 16881 /** 16882 * The host. 16883 */ 16884 readonly host?: string | undefined; 16885 16886 /** 16887 * Create a description for a debug adapter running as a socket based server. 16888 */ 16889 constructor(port: number, host?: string); 16890 } 16891 16892 /** 16893 * Represents a debug adapter running as a Named Pipe (on Windows)/UNIX Domain Socket (on non-Windows) based server. 16894 */ 16895 export class DebugAdapterNamedPipeServer { 16896 /** 16897 * The path to the NamedPipe/UNIX Domain Socket. 16898 */ 16899 readonly path: string; 16900 16901 /** 16902 * Create a description for a debug adapter running as a Named Pipe (on Windows)/UNIX Domain Socket (on non-Windows) based server. 16903 */ 16904 constructor(path: string); 16905 } 16906 16907 /** 16908 * A debug adapter that implements the Debug Adapter Protocol can be registered with the editor if it implements the DebugAdapter interface. 16909 */ 16910 export interface DebugAdapter extends Disposable { 16911 16912 /** 16913 * An event which fires after the debug adapter has sent a Debug Adapter Protocol message to the editor. 16914 * Messages can be requests, responses, or events. 16915 */ 16916 readonly onDidSendMessage: Event<DebugProtocolMessage>; 16917 16918 /** 16919 * Handle a Debug Adapter Protocol message. 16920 * Messages can be requests, responses, or events. 16921 * Results or errors are returned via onSendMessage events. 16922 * @param message A Debug Adapter Protocol message 16923 */ 16924 handleMessage(message: DebugProtocolMessage): void; 16925 } 16926 16927 /** 16928 * A debug adapter descriptor for an inline implementation. 16929 */ 16930 export class DebugAdapterInlineImplementation { 16931 16932 /** 16933 * Create a descriptor for an inline implementation of a debug adapter. 16934 */ 16935 constructor(implementation: DebugAdapter); 16936 } 16937 16938 /** 16939 * Represents the different types of debug adapters 16940 */ 16941 export type DebugAdapterDescriptor = DebugAdapterExecutable | DebugAdapterServer | DebugAdapterNamedPipeServer | DebugAdapterInlineImplementation; 16942 16943 /** 16944 * A debug adapter factory that creates {@link DebugAdapterDescriptor debug adapter descriptors}. 16945 */ 16946 export interface DebugAdapterDescriptorFactory { 16947 /** 16948 * 'createDebugAdapterDescriptor' is called at the start of a debug session to provide details about the debug adapter to use. 16949 * These details must be returned as objects of type {@link DebugAdapterDescriptor}. 16950 * Currently two types of debug adapters are supported: 16951 * - a debug adapter executable is specified as a command path and arguments (see {@link DebugAdapterExecutable}), 16952 * - a debug adapter server reachable via a communication port (see {@link DebugAdapterServer}). 16953 * If the method is not implemented the default behavior is this: 16954 * createDebugAdapter(session: DebugSession, executable: DebugAdapterExecutable) { 16955 * if (typeof session.configuration.debugServer === 'number') { 16956 * return new DebugAdapterServer(session.configuration.debugServer); 16957 * } 16958 * return executable; 16959 * } 16960 * @param session The {@link DebugSession debug session} for which the debug adapter will be used. 16961 * @param executable The debug adapter's executable information as specified in the package.json (or undefined if no such information exists). 16962 * @returns a {@link DebugAdapterDescriptor debug adapter descriptor} or undefined. 16963 */ 16964 createDebugAdapterDescriptor(session: DebugSession, executable: DebugAdapterExecutable | undefined): ProviderResult<DebugAdapterDescriptor>; 16965 } 16966 16967 /** 16968 * A Debug Adapter Tracker is a means to track the communication between the editor and a Debug Adapter. 16969 */ 16970 export interface DebugAdapterTracker { 16971 /** 16972 * A session with the debug adapter is about to be started. 16973 */ 16974 onWillStartSession?(): void; 16975 /** 16976 * The debug adapter is about to receive a Debug Adapter Protocol message from the editor. 16977 */ 16978 onWillReceiveMessage?(message: any): void; 16979 /** 16980 * The debug adapter has sent a Debug Adapter Protocol message to the editor. 16981 */ 16982 onDidSendMessage?(message: any): void; 16983 /** 16984 * The debug adapter session is about to be stopped. 16985 */ 16986 onWillStopSession?(): void; 16987 /** 16988 * An error with the debug adapter has occurred. 16989 */ 16990 onError?(error: Error): void; 16991 /** 16992 * The debug adapter has exited with the given exit code or signal. 16993 */ 16994 onExit?(code: number | undefined, signal: string | undefined): void; 16995 } 16996 16997 /** 16998 * A debug adapter factory that creates {@link DebugAdapterTracker debug adapter trackers}. 16999 */ 17000 export interface DebugAdapterTrackerFactory { 17001 /** 17002 * The method 'createDebugAdapterTracker' is called at the start of a debug session in order 17003 * to return a "tracker" object that provides read-access to the communication between the editor and a debug adapter. 17004 * 17005 * @param session The {@link DebugSession debug session} for which the debug adapter tracker will be used. 17006 * @returns A {@link DebugAdapterTracker debug adapter tracker} or undefined. 17007 */ 17008 createDebugAdapterTracker(session: DebugSession): ProviderResult<DebugAdapterTracker>; 17009 } 17010 17011 /** 17012 * Represents the debug console. 17013 */ 17014 export interface DebugConsole { 17015 /** 17016 * Append the given value to the debug console. 17017 * 17018 * @param value A string, falsy values will not be printed. 17019 */ 17020 append(value: string): void; 17021 17022 /** 17023 * Append the given value and a line feed character 17024 * to the debug console. 17025 * 17026 * @param value A string, falsy values will be printed. 17027 */ 17028 appendLine(value: string): void; 17029 } 17030 17031 /** 17032 * An event describing the changes to the set of {@link Breakpoint breakpoints}. 17033 */ 17034 export interface BreakpointsChangeEvent { 17035 /** 17036 * Added breakpoints. 17037 */ 17038 readonly added: readonly Breakpoint[]; 17039 17040 /** 17041 * Removed breakpoints. 17042 */ 17043 readonly removed: readonly Breakpoint[]; 17044 17045 /** 17046 * Changed breakpoints. 17047 */ 17048 readonly changed: readonly Breakpoint[]; 17049 } 17050 17051 /** 17052 * The base class of all breakpoint types. 17053 */ 17054 export class Breakpoint { 17055 /** 17056 * The unique ID of the breakpoint. 17057 */ 17058 readonly id: string; 17059 /** 17060 * Is breakpoint enabled. 17061 */ 17062 readonly enabled: boolean; 17063 /** 17064 * An optional expression for conditional breakpoints. 17065 */ 17066 readonly condition?: string | undefined; 17067 /** 17068 * An optional expression that controls how many hits of the breakpoint are ignored. 17069 */ 17070 readonly hitCondition?: string | undefined; 17071 /** 17072 * An optional message that gets logged when this breakpoint is hit. Embedded expressions within {} are interpolated by the debug adapter. 17073 */ 17074 readonly logMessage?: string | undefined; 17075 17076 /** 17077 * Creates a new breakpoint 17078 * 17079 * @param enabled Is breakpoint enabled. 17080 * @param condition Expression for conditional breakpoints 17081 * @param hitCondition Expression that controls how many hits of the breakpoint are ignored 17082 * @param logMessage Log message to display when breakpoint is hit 17083 */ 17084 protected constructor(enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string); 17085 } 17086 17087 /** 17088 * A breakpoint specified by a source location. 17089 */ 17090 export class SourceBreakpoint extends Breakpoint { 17091 /** 17092 * The source and line position of this breakpoint. 17093 */ 17094 readonly location: Location; 17095 17096 /** 17097 * Create a new breakpoint for a source location. 17098 */ 17099 constructor(location: Location, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string); 17100 } 17101 17102 /** 17103 * A breakpoint specified by a function name. 17104 */ 17105 export class FunctionBreakpoint extends Breakpoint { 17106 /** 17107 * The name of the function to which this breakpoint is attached. 17108 */ 17109 readonly functionName: string; 17110 17111 /** 17112 * Create a new function breakpoint. 17113 */ 17114 constructor(functionName: string, enabled?: boolean, condition?: string, hitCondition?: string, logMessage?: string); 17115 } 17116 17117 /** 17118 * Debug console mode used by debug session, see {@link DebugSessionOptions options}. 17119 */ 17120 export enum DebugConsoleMode { 17121 /** 17122 * Debug session should have a separate debug console. 17123 */ 17124 Separate = 0, 17125 17126 /** 17127 * Debug session should share debug console with its parent session. 17128 * This value has no effect for sessions which do not have a parent session. 17129 */ 17130 MergeWithParent = 1 17131 } 17132 17133 /** 17134 * Options for {@link debug.startDebugging starting a debug session}. 17135 */ 17136 export interface DebugSessionOptions { 17137 17138 /** 17139 * When specified the newly created debug session is registered as a "child" session of this 17140 * "parent" debug session. 17141 */ 17142 parentSession?: DebugSession; 17143 17144 /** 17145 * Controls whether lifecycle requests like 'restart' are sent to the newly created session or its parent session. 17146 * By default (if the property is false or missing), lifecycle requests are sent to the new session. 17147 * This property is ignored if the session has no parent session. 17148 */ 17149 lifecycleManagedByParent?: boolean; 17150 17151 /** 17152 * Controls whether this session should have a separate debug console or share it 17153 * with the parent session. Has no effect for sessions which do not have a parent session. 17154 * Defaults to Separate. 17155 */ 17156 consoleMode?: DebugConsoleMode; 17157 17158 /** 17159 * Controls whether this session should run without debugging, thus ignoring breakpoints. 17160 * When this property is not specified, the value from the parent session (if there is one) is used. 17161 */ 17162 noDebug?: boolean; 17163 17164 /** 17165 * Controls if the debug session's parent session is shown in the CALL STACK view even if it has only a single child. 17166 * By default, the debug session will never hide its parent. 17167 * If compact is true, debug sessions with a single child are hidden in the CALL STACK view to make the tree more compact. 17168 */ 17169 compact?: boolean; 17170 17171 /** 17172 * When true, a save will not be triggered for open editors when starting a debug session, regardless of the value of the `debug.saveBeforeStart` setting. 17173 */ 17174 suppressSaveBeforeStart?: boolean; 17175 17176 /** 17177 * When true, the debug toolbar will not be shown for this session. 17178 */ 17179 suppressDebugToolbar?: boolean; 17180 17181 /** 17182 * When true, the window statusbar color will not be changed for this session. 17183 */ 17184 suppressDebugStatusbar?: boolean; 17185 17186 /** 17187 * When true, the debug viewlet will not be automatically revealed for this session. 17188 */ 17189 suppressDebugView?: boolean; 17190 17191 /** 17192 * Signals to the editor that the debug session was started from a test run 17193 * request. This is used to link the lifecycle of the debug session and 17194 * test run in UI actions. 17195 */ 17196 testRun?: TestRun; 17197 } 17198 17199 /** 17200 * A DebugConfigurationProviderTriggerKind specifies when the `provideDebugConfigurations` method of a `DebugConfigurationProvider` is triggered. 17201 * Currently there are two situations: to provide the initial debug configurations for a newly created launch.json or 17202 * to provide dynamically generated debug configurations when the user asks for them through the UI (e.g. via the "Select and Start Debugging" command). 17203 * A trigger kind is used when registering a `DebugConfigurationProvider` with {@link debug.registerDebugConfigurationProvider}. 17204 */ 17205 export enum DebugConfigurationProviderTriggerKind { 17206 /** 17207 * `DebugConfigurationProvider.provideDebugConfigurations` is called to provide the initial debug configurations for a newly created launch.json. 17208 */ 17209 Initial = 1, 17210 /** 17211 * `DebugConfigurationProvider.provideDebugConfigurations` is called to provide dynamically generated debug configurations when the user asks for them through the UI (e.g. via the "Select and Start Debugging" command). 17212 */ 17213 Dynamic = 2 17214 } 17215 17216 /** 17217 * Represents a thread in a debug session. 17218 */ 17219 export class DebugThread { 17220 /** 17221 * Debug session for thread. 17222 */ 17223 readonly session: DebugSession; 17224 17225 /** 17226 * ID of the associated thread in the debug protocol. 17227 */ 17228 readonly threadId: number; 17229 17230 /** 17231 * @hidden 17232 */ 17233 private constructor(session: DebugSession, threadId: number); 17234 } 17235 17236 /** 17237 * Represents a stack frame in a debug session. 17238 */ 17239 export class DebugStackFrame { 17240 /** 17241 * Debug session for thread. 17242 */ 17243 readonly session: DebugSession; 17244 17245 /** 17246 * ID of the associated thread in the debug protocol. 17247 */ 17248 readonly threadId: number; 17249 /** 17250 * ID of the stack frame in the debug protocol. 17251 */ 17252 readonly frameId: number; 17253 17254 /** 17255 * @hidden 17256 */ 17257 private constructor(session: DebugSession, threadId: number, frameId: number); 17258 } 17259 17260 /** 17261 * Namespace for debug functionality. 17262 */ 17263 export namespace debug { 17264 17265 /** 17266 * The currently active {@link DebugSession debug session} or `undefined`. The active debug session is the one 17267 * represented by the debug action floating window or the one currently shown in the drop down menu of the debug action floating window. 17268 * If no debug session is active, the value is `undefined`. 17269 */ 17270 export let activeDebugSession: DebugSession | undefined; 17271 17272 /** 17273 * The currently active {@link DebugConsole debug console}. 17274 * If no debug session is active, output sent to the debug console is not shown. 17275 */ 17276 export let activeDebugConsole: DebugConsole; 17277 17278 /** 17279 * List of breakpoints. 17280 */ 17281 export let breakpoints: readonly Breakpoint[]; 17282 17283 /** 17284 * An {@link Event} which fires when the {@link debug.activeDebugSession active debug session} 17285 * has changed. *Note* that the event also fires when the active debug session changes 17286 * to `undefined`. 17287 */ 17288 export const onDidChangeActiveDebugSession: Event<DebugSession | undefined>; 17289 17290 /** 17291 * An {@link Event} which fires when a new {@link DebugSession debug session} has been started. 17292 */ 17293 export const onDidStartDebugSession: Event<DebugSession>; 17294 17295 /** 17296 * An {@link Event} which fires when a custom DAP event is received from the {@link DebugSession debug session}. 17297 */ 17298 export const onDidReceiveDebugSessionCustomEvent: Event<DebugSessionCustomEvent>; 17299 17300 /** 17301 * An {@link Event} which fires when a {@link DebugSession debug session} has terminated. 17302 */ 17303 export const onDidTerminateDebugSession: Event<DebugSession>; 17304 17305 /** 17306 * An {@link Event} that is emitted when the set of breakpoints is added, removed, or changed. 17307 */ 17308 export const onDidChangeBreakpoints: Event<BreakpointsChangeEvent>; 17309 17310 /** 17311 * The currently focused thread or stack frame, or `undefined` if no 17312 * thread or stack is focused. A thread can be focused any time there is 17313 * an active debug session, while a stack frame can only be focused when 17314 * a session is paused and the call stack has been retrieved. 17315 */ 17316 export const activeStackItem: DebugThread | DebugStackFrame | undefined; 17317 17318 /** 17319 * An event which fires when the {@link debug.activeStackItem} has changed. 17320 */ 17321 export const onDidChangeActiveStackItem: Event<DebugThread | DebugStackFrame | undefined>; 17322 17323 /** 17324 * Register a {@link DebugConfigurationProvider debug configuration provider} for a specific debug type. 17325 * The optional {@link DebugConfigurationProviderTriggerKind triggerKind} can be used to specify when the `provideDebugConfigurations` method of the provider is triggered. 17326 * Currently two trigger kinds are possible: with the value `Initial` (or if no trigger kind argument is given) the `provideDebugConfigurations` method is used to provide the initial debug configurations to be copied into a newly created launch.json. 17327 * With the trigger kind `Dynamic` the `provideDebugConfigurations` method is used to dynamically determine debug configurations to be presented to the user (in addition to the static configurations from the launch.json). 17328 * Please note that the `triggerKind` argument only applies to the `provideDebugConfigurations` method: so the `resolveDebugConfiguration` methods are not affected at all. 17329 * Registering a single provider with resolve methods for different trigger kinds, results in the same resolve methods called multiple times. 17330 * More than one provider can be registered for the same type. 17331 * 17332 * @param debugType The debug type for which the provider is registered. 17333 * @param provider The {@link DebugConfigurationProvider debug configuration provider} to register. 17334 * @param triggerKind The {@link DebugConfigurationProviderTriggerKind trigger} for which the 'provideDebugConfiguration' method of the provider is registered. If `triggerKind` is missing, the value `DebugConfigurationProviderTriggerKind.Initial` is assumed. 17335 * @returns A {@link Disposable} that unregisters this provider when being disposed. 17336 */ 17337 export function registerDebugConfigurationProvider(debugType: string, provider: DebugConfigurationProvider, triggerKind?: DebugConfigurationProviderTriggerKind): Disposable; 17338 17339 /** 17340 * Register a {@link DebugAdapterDescriptorFactory debug adapter descriptor factory} for a specific debug type. 17341 * An extension is only allowed to register a DebugAdapterDescriptorFactory for the debug type(s) defined by the extension. Otherwise an error is thrown. 17342 * Registering more than one DebugAdapterDescriptorFactory for a debug type results in an error. 17343 * 17344 * @param debugType The debug type for which the factory is registered. 17345 * @param factory The {@link DebugAdapterDescriptorFactory debug adapter descriptor factory} to register. 17346 * @returns A {@link Disposable} that unregisters this factory when being disposed. 17347 */ 17348 export function registerDebugAdapterDescriptorFactory(debugType: string, factory: DebugAdapterDescriptorFactory): Disposable; 17349 17350 /** 17351 * Register a debug adapter tracker factory for the given debug type. 17352 * 17353 * @param debugType The debug type for which the factory is registered or '*' for matching all debug types. 17354 * @param factory The {@link DebugAdapterTrackerFactory debug adapter tracker factory} to register. 17355 * @returns A {@link Disposable} that unregisters this factory when being disposed. 17356 */ 17357 export function registerDebugAdapterTrackerFactory(debugType: string, factory: DebugAdapterTrackerFactory): Disposable; 17358 17359 /** 17360 * Start debugging by using either a named launch or named compound configuration, 17361 * or by directly passing a {@link DebugConfiguration}. 17362 * The named configurations are looked up in '.vscode/launch.json' found in the given folder. 17363 * Before debugging starts, all unsaved files are saved and the launch configurations are brought up-to-date. 17364 * Folder specific variables used in the configuration (e.g. '${workspaceFolder}') are resolved against the given folder. 17365 * @param folder The {@link WorkspaceFolder workspace folder} for looking up named configurations and resolving variables or `undefined` for a non-folder setup. 17366 * @param nameOrConfiguration Either the name of a debug or compound configuration or a {@link DebugConfiguration} object. 17367 * @param parentSessionOrOptions Debug session options. When passed a parent {@link DebugSession debug session}, assumes options with just this parent session. 17368 * @returns A thenable that resolves when debugging could be successfully started. 17369 */ 17370 export function startDebugging(folder: WorkspaceFolder | undefined, nameOrConfiguration: string | DebugConfiguration, parentSessionOrOptions?: DebugSession | DebugSessionOptions): Thenable<boolean>; 17371 17372 /** 17373 * Stop the given debug session or stop all debug sessions if session is omitted. 17374 * 17375 * @param session The {@link DebugSession debug session} to stop; if omitted all sessions are stopped. 17376 * @returns A thenable that resolves when the session(s) have been stopped. 17377 */ 17378 export function stopDebugging(session?: DebugSession): Thenable<void>; 17379 17380 /** 17381 * Add breakpoints. 17382 * @param breakpoints The breakpoints to add. 17383 */ 17384 export function addBreakpoints(breakpoints: readonly Breakpoint[]): void; 17385 17386 /** 17387 * Remove breakpoints. 17388 * @param breakpoints The breakpoints to remove. 17389 */ 17390 export function removeBreakpoints(breakpoints: readonly Breakpoint[]): void; 17391 17392 /** 17393 * Converts a "Source" descriptor object received via the Debug Adapter Protocol into a Uri that can be used to load its contents. 17394 * If the source descriptor is based on a path, a file Uri is returned. 17395 * If the source descriptor uses a reference number, a specific debug Uri (scheme 'debug') is constructed that requires a corresponding ContentProvider and a running debug session 17396 * 17397 * If the "Source" descriptor has insufficient information for creating the Uri, an error is thrown. 17398 * 17399 * @param source An object conforming to the [Source](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Source) type defined in the Debug Adapter Protocol. 17400 * @param session An optional debug session that will be used when the source descriptor uses a reference number to load the contents from an active debug session. 17401 * @returns A uri that can be used to load the contents of the source. 17402 */ 17403 export function asDebugSourceUri(source: DebugProtocolSource, session?: DebugSession): Uri; 17404 } 17405 17406 /** 17407 * Namespace for dealing with installed extensions. Extensions are represented 17408 * by an {@link Extension}-interface which enables reflection on them. 17409 * 17410 * Extension writers can provide APIs to other extensions by returning their API public 17411 * surface from the `activate`-call. 17412 * 17413 * ```javascript 17414 * export function activate(context: vscode.ExtensionContext) { 17415 * let api = { 17416 * sum(a, b) { 17417 * return a + b; 17418 * }, 17419 * mul(a, b) { 17420 * return a * b; 17421 * } 17422 * }; 17423 * // 'export' public api-surface 17424 * return api; 17425 * } 17426 * ``` 17427 * When depending on the API of another extension add an `extensionDependencies`-entry 17428 * to `package.json`, and use the {@link extensions.getExtension getExtension}-function 17429 * and the {@link Extension.exports exports}-property, like below: 17430 * 17431 * ```javascript 17432 * let mathExt = extensions.getExtension('genius.math'); 17433 * let importedApi = mathExt.exports; 17434 * 17435 * console.log(importedApi.mul(42, 1)); 17436 * ``` 17437 */ 17438 export namespace extensions { 17439 17440 /** 17441 * Get an extension by its full identifier in the form of: `publisher.name`. 17442 * 17443 * @param extensionId An extension identifier. 17444 * @returns An extension or `undefined`. 17445 */ 17446 export function getExtension<T = any>(extensionId: string): Extension<T> | undefined; 17447 17448 /** 17449 * All extensions currently known to the system. 17450 */ 17451 export const all: readonly Extension<any>[]; 17452 17453 /** 17454 * An event which fires when `extensions.all` changes. This can happen when extensions are 17455 * installed, uninstalled, enabled or disabled. 17456 */ 17457 export const onDidChange: Event<void>; 17458 } 17459 17460 /** 17461 * Collapsible state of a {@link CommentThread comment thread} 17462 */ 17463 export enum CommentThreadCollapsibleState { 17464 /** 17465 * Determines an item is collapsed 17466 */ 17467 Collapsed = 0, 17468 17469 /** 17470 * Determines an item is expanded 17471 */ 17472 Expanded = 1 17473 } 17474 17475 /** 17476 * Comment mode of a {@link Comment} 17477 */ 17478 export enum CommentMode { 17479 /** 17480 * Displays the comment editor 17481 */ 17482 Editing = 0, 17483 17484 /** 17485 * Displays the preview of the comment 17486 */ 17487 Preview = 1 17488 } 17489 17490 /** 17491 * The state of a comment thread. 17492 */ 17493 export enum CommentThreadState { 17494 /** 17495 * Unresolved thread state 17496 */ 17497 Unresolved = 0, 17498 /** 17499 * Resolved thread state 17500 */ 17501 Resolved = 1 17502 } 17503 17504 /** 17505 * A collection of {@link Comment comments} representing a conversation at a particular range in a document. 17506 */ 17507 export interface CommentThread { 17508 /** 17509 * The uri of the document the thread has been created on. 17510 */ 17511 readonly uri: Uri; 17512 17513 /** 17514 * The range the comment thread is located within the document. The thread icon will be shown 17515 * at the last line of the range. When set to undefined, the comment will be associated with the 17516 * file, and not a specific range. 17517 */ 17518 range: Range | undefined; 17519 17520 /** 17521 * The ordered comments of the thread. 17522 */ 17523 comments: readonly Comment[]; 17524 17525 /** 17526 * Whether the thread should be collapsed or expanded when opening the document. 17527 * Defaults to Collapsed. 17528 */ 17529 collapsibleState: CommentThreadCollapsibleState; 17530 17531 /** 17532 * Whether the thread supports reply. 17533 * Defaults to true. 17534 */ 17535 canReply: boolean | CommentAuthorInformation; 17536 17537 /** 17538 * Context value of the comment thread. This can be used to contribute thread specific actions. 17539 * For example, a comment thread is given a context value as `editable`. When contributing actions to `comments/commentThread/title` 17540 * using `menus` extension point, you can specify context value for key `commentThread` in `when` expression like `commentThread == editable`. 17541 * ```json 17542 * "contributes": { 17543 * "menus": { 17544 * "comments/commentThread/title": [ 17545 * { 17546 * "command": "extension.deleteCommentThread", 17547 * "when": "commentThread == editable" 17548 * } 17549 * ] 17550 * } 17551 * } 17552 * ``` 17553 * This will show action `extension.deleteCommentThread` only for comment threads with `contextValue` is `editable`. 17554 */ 17555 contextValue?: string; 17556 17557 /** 17558 * The optional human-readable label describing the {@link CommentThread Comment Thread} 17559 */ 17560 label?: string; 17561 17562 /** 17563 * The optional state of a comment thread, which may affect how the comment is displayed. 17564 */ 17565 state?: CommentThreadState; 17566 17567 /** 17568 * Dispose this comment thread. 17569 * 17570 * Once disposed, this comment thread will be removed from visible editors and Comment Panel when appropriate. 17571 */ 17572 dispose(): void; 17573 } 17574 17575 /** 17576 * Author information of a {@link Comment} 17577 */ 17578 export interface CommentAuthorInformation { 17579 /** 17580 * The display name of the author of the comment 17581 */ 17582 name: string; 17583 17584 /** 17585 * The optional icon path for the author 17586 */ 17587 iconPath?: Uri; 17588 } 17589 17590 /** 17591 * Reactions of a {@link Comment} 17592 */ 17593 export interface CommentReaction { 17594 /** 17595 * The human-readable label for the reaction 17596 */ 17597 readonly label: string; 17598 17599 /** 17600 * Icon for the reaction shown in UI. 17601 */ 17602 readonly iconPath: string | Uri; 17603 17604 /** 17605 * The number of users who have reacted to this reaction 17606 */ 17607 readonly count: number; 17608 17609 /** 17610 * Whether the {@link CommentAuthorInformation author} of the comment has reacted to this reaction 17611 */ 17612 readonly authorHasReacted: boolean; 17613 } 17614 17615 /** 17616 * A comment is displayed within the editor or the Comments Panel, depending on how it is provided. 17617 */ 17618 export interface Comment { 17619 /** 17620 * The human-readable comment body 17621 */ 17622 body: string | MarkdownString; 17623 17624 /** 17625 * {@link CommentMode Comment mode} of the comment 17626 */ 17627 mode: CommentMode; 17628 17629 /** 17630 * The {@link CommentAuthorInformation author information} of the comment 17631 */ 17632 author: CommentAuthorInformation; 17633 17634 /** 17635 * Context value of the comment. This can be used to contribute comment specific actions. 17636 * For example, a comment is given a context value as `editable`. When contributing actions to `comments/comment/title` 17637 * using `menus` extension point, you can specify context value for key `comment` in `when` expression like `comment == editable`. 17638 * ```json 17639 * "contributes": { 17640 * "menus": { 17641 * "comments/comment/title": [ 17642 * { 17643 * "command": "extension.deleteComment", 17644 * "when": "comment == editable" 17645 * } 17646 * ] 17647 * } 17648 * } 17649 * ``` 17650 * This will show action `extension.deleteComment` only for comments with `contextValue` is `editable`. 17651 */ 17652 contextValue?: string; 17653 17654 /** 17655 * Optional reactions of the {@link Comment} 17656 */ 17657 reactions?: CommentReaction[]; 17658 17659 /** 17660 * Optional label describing the {@link Comment} 17661 * Label will be rendered next to authorName if exists. 17662 */ 17663 label?: string; 17664 17665 /** 17666 * Optional timestamp that will be displayed in comments. 17667 * The date will be formatted according to the user's locale and settings. 17668 */ 17669 timestamp?: Date; 17670 } 17671 17672 /** 17673 * Command argument for actions registered in `comments/commentThread/context`. 17674 */ 17675 export interface CommentReply { 17676 /** 17677 * The active {@link CommentThread comment thread} 17678 */ 17679 thread: CommentThread; 17680 17681 /** 17682 * The value in the comment editor 17683 */ 17684 text: string; 17685 } 17686 17687 /** 17688 * The ranges a CommentingRangeProvider enables commenting on. 17689 */ 17690 export interface CommentingRanges { 17691 /** 17692 * Enables comments to be added to a file without a specific range. 17693 */ 17694 enableFileComments: boolean; 17695 17696 /** 17697 * The ranges which allow new comment threads creation. 17698 */ 17699 ranges?: Range[]; 17700 } 17701 17702 /** 17703 * Commenting range provider for a {@link CommentController comment controller}. 17704 */ 17705 export interface CommentingRangeProvider { 17706 /** 17707 * Provide a list of ranges which allow new comment threads creation or null for a given document 17708 */ 17709 provideCommentingRanges(document: TextDocument, token: CancellationToken): ProviderResult<Range[] | CommentingRanges>; 17710 } 17711 17712 /** 17713 * Represents a {@link CommentController comment controller}'s {@link CommentController.options options}. 17714 */ 17715 export interface CommentOptions { 17716 /** 17717 * An optional string to show on the comment input box when it's collapsed. 17718 */ 17719 prompt?: string; 17720 17721 /** 17722 * An optional string to show as placeholder in the comment input box when it's focused. 17723 */ 17724 placeHolder?: string; 17725 } 17726 17727 /** 17728 * A comment controller is able to provide {@link CommentThread comments} support to the editor and 17729 * provide users various ways to interact with comments. 17730 */ 17731 export interface CommentController { 17732 /** 17733 * The id of this comment controller. 17734 */ 17735 readonly id: string; 17736 17737 /** 17738 * The human-readable label of this comment controller. 17739 */ 17740 readonly label: string; 17741 17742 /** 17743 * Comment controller options 17744 */ 17745 options?: CommentOptions; 17746 17747 /** 17748 * Optional commenting range provider. Provide a list {@link Range ranges} which support commenting to any given resource uri. 17749 * 17750 * If not provided, users cannot leave any comments. 17751 */ 17752 commentingRangeProvider?: CommentingRangeProvider; 17753 17754 /** 17755 * Create a {@link CommentThread comment thread}. The comment thread will be displayed in visible text editors (if the resource matches) 17756 * and Comments Panel once created. 17757 * 17758 * @param uri The uri of the document the thread has been created on. 17759 * @param range The range the comment thread is located within the document. 17760 * @param comments The ordered comments of the thread. 17761 */ 17762 createCommentThread(uri: Uri, range: Range, comments: readonly Comment[]): CommentThread; 17763 17764 /** 17765 * Optional reaction handler for creating and deleting reactions on a {@link Comment}. 17766 */ 17767 reactionHandler?: (comment: Comment, reaction: CommentReaction) => Thenable<void>; 17768 17769 /** 17770 * Dispose this comment controller. 17771 * 17772 * Once disposed, all {@link CommentThread comment threads} created by this comment controller will also be removed from the editor 17773 * and Comments Panel. 17774 */ 17775 dispose(): void; 17776 } 17777 17778 namespace comments { 17779 /** 17780 * Creates a new {@link CommentController comment controller} instance. 17781 * 17782 * @param id An `id` for the comment controller. 17783 * @param label A human-readable string for the comment controller. 17784 * @returns An instance of {@link CommentController comment controller}. 17785 */ 17786 export function createCommentController(id: string, label: string): CommentController; 17787 } 17788 17789 /** 17790 * Represents a session of a currently logged in user. 17791 */ 17792 export interface AuthenticationSession { 17793 /** 17794 * The identifier of the authentication session. 17795 */ 17796 readonly id: string; 17797 17798 /** 17799 * The access token. This token should be used to authenticate requests to a service. Popularized by OAuth. 17800 * @reference https://oauth.net/2/access-tokens/ 17801 */ 17802 readonly accessToken: string; 17803 17804 /** 17805 * The ID token. This token contains identity information about the user. Popularized by OpenID Connect. 17806 * @reference https://openid.net/specs/openid-connect-core-1_0.html#IDToken 17807 */ 17808 readonly idToken?: string; 17809 17810 /** 17811 * The account associated with the session. 17812 */ 17813 readonly account: AuthenticationSessionAccountInformation; 17814 17815 /** 17816 * The permissions granted by the session's access token. Available scopes 17817 * are defined by the {@link AuthenticationProvider}. 17818 */ 17819 readonly scopes: readonly string[]; 17820 } 17821 17822 /** 17823 * The information of an account associated with an {@link AuthenticationSession}. 17824 */ 17825 export interface AuthenticationSessionAccountInformation { 17826 /** 17827 * The unique identifier of the account. 17828 */ 17829 readonly id: string; 17830 17831 /** 17832 * The human-readable name of the account. 17833 */ 17834 readonly label: string; 17835 } 17836 17837 /** 17838 * Optional options to be used when calling {@link authentication.getSession} with interactive options `forceNewSession` & `createIfNone`. 17839 */ 17840 export interface AuthenticationGetSessionPresentationOptions { 17841 /** 17842 * An optional message that will be displayed to the user when we ask to re-authenticate. Providing additional context 17843 * as to why you are asking a user to re-authenticate can help increase the odds that they will accept. 17844 */ 17845 detail?: string; 17846 } 17847 17848 /** 17849 * Optional options to be used when calling {@link authentication.getSession} with the flag `forceNewSession`. 17850 * @deprecated Use {@link AuthenticationGetSessionPresentationOptions} instead. 17851 */ 17852 export type AuthenticationForceNewSessionOptions = AuthenticationGetSessionPresentationOptions; 17853 17854 /** 17855 * Options to be used when getting an {@link AuthenticationSession} from an {@link AuthenticationProvider}. 17856 */ 17857 export interface AuthenticationGetSessionOptions { 17858 /** 17859 * Whether the existing session preference should be cleared. 17860 * 17861 * For authentication providers that support being signed into multiple accounts at once, the user will be 17862 * prompted to select an account to use when {@link authentication.getSession getSession} is called. This preference 17863 * is remembered until {@link authentication.getSession getSession} is called with this flag. 17864 * 17865 * Note: 17866 * The preference is extension specific. So if one extension calls {@link authentication.getSession getSession}, it will not 17867 * affect the session preference for another extension calling {@link authentication.getSession getSession}. Additionally, 17868 * the preference is set for the current workspace and also globally. This means that new workspaces will use the "global" 17869 * value at first and then when this flag is provided, a new value can be set for that workspace. This also means 17870 * that pre-existing workspaces will not lose their preference if a new workspace sets this flag. 17871 * 17872 * Defaults to false. 17873 */ 17874 clearSessionPreference?: boolean; 17875 17876 /** 17877 * Whether login should be performed if there is no matching session. 17878 * 17879 * If true, a modal dialog will be shown asking the user to sign in. If false, a numbered badge will be shown 17880 * on the accounts activity bar icon. An entry for the extension will be added under the menu to sign in. This 17881 * allows quietly prompting the user to sign in. 17882 * 17883 * If you provide options, you will also see the dialog but with the additional context provided. 17884 * 17885 * If there is a matching session but the extension has not been granted access to it, setting this to true 17886 * will also result in an immediate modal dialog, and false will add a numbered badge to the accounts icon. 17887 * 17888 * Defaults to false. 17889 * 17890 * Note: you cannot use this option with {@link AuthenticationGetSessionOptions.silent silent}. 17891 */ 17892 createIfNone?: boolean | AuthenticationGetSessionPresentationOptions; 17893 17894 /** 17895 * Whether we should attempt to reauthenticate even if there is already a session available. 17896 * 17897 * If true, a modal dialog will be shown asking the user to sign in again. This is mostly used for scenarios 17898 * where the token needs to be re minted because it has lost some authorization. 17899 * 17900 * If you provide options, you will also see the dialog but with the additional context provided. 17901 * 17902 * If there are no existing sessions and forceNewSession is true, it will behave identically to 17903 * {@link AuthenticationGetSessionOptions.createIfNone createIfNone}. 17904 * 17905 * This defaults to false. 17906 */ 17907 forceNewSession?: boolean | AuthenticationGetSessionPresentationOptions | AuthenticationForceNewSessionOptions; 17908 17909 /** 17910 * Whether we should show the indication to sign in in the Accounts menu. 17911 * 17912 * If false, the user will be shown a badge on the Accounts menu with an option to sign in for the extension. 17913 * If true, no indication will be shown. 17914 * 17915 * Defaults to false. 17916 * 17917 * Note: you cannot use this option with any other options that prompt the user like {@link AuthenticationGetSessionOptions.createIfNone createIfNone}. 17918 */ 17919 silent?: boolean; 17920 17921 /** 17922 * The account that you would like to get a session for. This is passed down to the Authentication Provider to be used for creating the correct session. 17923 */ 17924 account?: AuthenticationSessionAccountInformation; 17925 } 17926 17927 /** 17928 * Represents parameters for creating a session based on a WWW-Authenticate header value. 17929 * This is used when an API returns a 401 with a WWW-Authenticate header indicating 17930 * that additional authentication is required. The details of which will be passed down 17931 * to the authentication provider to create a session. 17932 * 17933 * @note The authorization provider must support handling challenges and specifically 17934 * the challenges in this WWW-Authenticate value. 17935 * @note For more information on WWW-Authenticate please see https://developer.mozilla.org/docs/Web/HTTP/Reference/Headers/WWW-Authenticate 17936 */ 17937 export interface AuthenticationWwwAuthenticateRequest { 17938 /** 17939 * The raw WWW-Authenticate header value that triggered this challenge. 17940 * This will be parsed by the authentication provider to extract the necessary 17941 * challenge information. 17942 */ 17943 readonly wwwAuthenticate: string; 17944 17945 /** 17946 * The fallback scopes to use if no scopes are found in the WWW-Authenticate header. 17947 */ 17948 readonly fallbackScopes?: readonly string[]; 17949 } 17950 17951 /** 17952 * Basic information about an {@link AuthenticationProvider} 17953 */ 17954 export interface AuthenticationProviderInformation { 17955 /** 17956 * The unique identifier of the authentication provider. 17957 */ 17958 readonly id: string; 17959 17960 /** 17961 * The human-readable name of the authentication provider. 17962 */ 17963 readonly label: string; 17964 } 17965 17966 /** 17967 * An {@link Event} which fires when an {@link AuthenticationSession} is added, removed, or changed. 17968 */ 17969 export interface AuthenticationSessionsChangeEvent { 17970 /** 17971 * The {@link AuthenticationProvider} that has had its sessions change. 17972 */ 17973 readonly provider: AuthenticationProviderInformation; 17974 } 17975 17976 /** 17977 * Options for creating an {@link AuthenticationProvider}. 17978 */ 17979 export interface AuthenticationProviderOptions { 17980 /** 17981 * Whether it is possible to be signed into multiple accounts at once with this provider. 17982 * If not specified, will default to false. 17983 */ 17984 readonly supportsMultipleAccounts?: boolean; 17985 } 17986 17987 /** 17988 * An {@link Event} which fires when an {@link AuthenticationSession} is added, removed, or changed. 17989 */ 17990 export interface AuthenticationProviderAuthenticationSessionsChangeEvent { 17991 /** 17992 * The {@link AuthenticationSession AuthenticationSessions} of the {@link AuthenticationProvider} that have been added. 17993 */ 17994 readonly added: readonly AuthenticationSession[] | undefined; 17995 17996 /** 17997 * The {@link AuthenticationSession AuthenticationSessions} of the {@link AuthenticationProvider} that have been removed. 17998 */ 17999 readonly removed: readonly AuthenticationSession[] | undefined; 18000 18001 /** 18002 * The {@link AuthenticationSession AuthenticationSessions} of the {@link AuthenticationProvider} that have been changed. 18003 * A session changes when its data excluding the id are updated. An example of this is a session refresh that results in a new 18004 * access token being set for the session. 18005 */ 18006 readonly changed: readonly AuthenticationSession[] | undefined; 18007 } 18008 18009 /** 18010 * The options passed in to the {@link AuthenticationProvider.getSessions} and 18011 * {@link AuthenticationProvider.createSession} call. 18012 */ 18013 export interface AuthenticationProviderSessionOptions { 18014 /** 18015 * The account that is being asked about. If this is passed in, the provider should 18016 * attempt to return the sessions that are only related to this account. 18017 */ 18018 account?: AuthenticationSessionAccountInformation; 18019 } 18020 18021 /** 18022 * A provider for performing authentication to a service. 18023 */ 18024 export interface AuthenticationProvider { 18025 /** 18026 * An {@link Event} which fires when the array of sessions has changed, or data 18027 * within a session has changed. 18028 */ 18029 readonly onDidChangeSessions: Event<AuthenticationProviderAuthenticationSessionsChangeEvent>; 18030 18031 /** 18032 * Get a list of sessions. 18033 * @param scopes An optional list of scopes. If provided, the sessions returned should match 18034 * these permissions, otherwise all sessions should be returned. 18035 * @param options Additional options for getting sessions. 18036 * @returns A promise that resolves to an array of authentication sessions. 18037 */ 18038 getSessions(scopes: readonly string[] | undefined, options: AuthenticationProviderSessionOptions): Thenable<AuthenticationSession[]>; 18039 18040 /** 18041 * Prompts a user to login. 18042 * 18043 * If login is successful, the onDidChangeSessions event should be fired. 18044 * 18045 * If login fails, a rejected promise should be returned. 18046 * 18047 * If the provider has specified that it does not support multiple accounts, 18048 * then this should never be called if there is already an existing session matching these 18049 * scopes. 18050 * @param scopes A list of scopes, permissions, that the new session should be created with. 18051 * @param options Additional options for creating a session. 18052 * @returns A promise that resolves to an authentication session. 18053 */ 18054 createSession(scopes: readonly string[], options: AuthenticationProviderSessionOptions): Thenable<AuthenticationSession>; 18055 18056 /** 18057 * Removes the session corresponding to session id. 18058 * 18059 * If the removal is successful, the onDidChangeSessions event should be fired. 18060 * 18061 * If a session cannot be removed, the provider should reject with an error message. 18062 * @param sessionId The id of the session to remove. 18063 */ 18064 removeSession(sessionId: string): Thenable<void>; 18065 } 18066 18067 18068 /** 18069 * Namespace for authentication. 18070 */ 18071 export namespace authentication { 18072 /** 18073 * Get an authentication session matching the desired scopes or satisfying the WWW-Authenticate request. Rejects if 18074 * a provider with providerId is not registered, or if the user does not consent to sharing authentication information 18075 * with the extension. If there are multiple sessions with the same scopes, the user will be shown a quickpick to 18076 * select which account they would like to use. 18077 * 18078 * Built-in auth providers include: 18079 * * 'github' - For GitHub.com 18080 * * 'microsoft' For both personal & organizational Microsoft accounts 18081 * * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server 18082 * * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds 18083 * 18084 * @param providerId The id of the provider to use 18085 * @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider. 18086 * @param options The {@link AuthenticationGetSessionOptions} to use 18087 * @returns A thenable that resolves to an authentication session 18088 */ 18089 export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options: AuthenticationGetSessionOptions & { /** */createIfNone: true | AuthenticationGetSessionPresentationOptions }): Thenable<AuthenticationSession>; 18090 18091 /** 18092 * Get an authentication session matching the desired scopes or request. Rejects if a provider with providerId is not 18093 * registered, or if the user does not consent to sharing authentication information with the extension. If there 18094 * are multiple sessions with the same scopes, the user will be shown a quickpick to select which account they would like to use. 18095 * 18096 * Built-in auth providers include: 18097 * * 'github' - For GitHub.com 18098 * * 'microsoft' For both personal & organizational Microsoft accounts 18099 * * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server 18100 * * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds 18101 * 18102 * @param providerId The id of the provider to use 18103 * @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider. 18104 * @param options The {@link AuthenticationGetSessionOptions} to use 18105 * @returns A thenable that resolves to an authentication session 18106 */ 18107 export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options: AuthenticationGetSessionOptions & { /** literal-type defines return type */forceNewSession: true | AuthenticationGetSessionPresentationOptions | AuthenticationForceNewSessionOptions }): Thenable<AuthenticationSession>; 18108 18109 /** 18110 * Get an authentication session matching the desired scopes or request. Rejects if a provider with providerId is not 18111 * registered, or if the user does not consent to sharing authentication information with the extension. If there 18112 * are multiple sessions with the same scopes, the user will be shown a quickpick to select which account they would like to use. 18113 * 18114 * Built-in auth providers include: 18115 * * 'github' - For GitHub.com 18116 * * 'microsoft' For both personal & organizational Microsoft accounts 18117 * * (less common) 'github-enterprise' - for alternative GitHub hostings, GHE.com, GitHub Enterprise Server 18118 * * (less common) 'microsoft-sovereign-cloud' - for alternative Microsoft clouds 18119 * 18120 * @param providerId The id of the provider to use 18121 * @param scopeListOrRequest A scope list of permissions requested or a WWW-Authenticate request. These are dependent on the authentication provider. 18122 * @param options The {@link AuthenticationGetSessionOptions} to use 18123 * @returns A thenable that resolves to an authentication session or undefined if a silent flow was used and no session was found 18124 */ 18125 export function getSession(providerId: string, scopeListOrRequest: ReadonlyArray<string> | AuthenticationWwwAuthenticateRequest, options?: AuthenticationGetSessionOptions): Thenable<AuthenticationSession | undefined>; 18126 18127 /** 18128 * Get all accounts that the user is logged in to for the specified provider. 18129 * Use this paired with {@link getSession} in order to get an authentication session for a specific account. 18130 * 18131 * Currently, there are only two authentication providers that are contributed from built in extensions 18132 * to the editor that implement GitHub and Microsoft authentication: their providerId's are 'github' and 'microsoft'. 18133 * 18134 * Note: Getting accounts does not imply that your extension has access to that account or its authentication sessions. You can verify access to the account by calling {@link getSession}. 18135 * 18136 * @param providerId The id of the provider to use 18137 * @returns A thenable that resolves to a readonly array of authentication accounts. 18138 */ 18139 export function getAccounts(providerId: string): Thenable<readonly AuthenticationSessionAccountInformation[]>; 18140 18141 /** 18142 * An {@link Event} which fires when the authentication sessions of an authentication provider have 18143 * been added, removed, or changed. 18144 */ 18145 export const onDidChangeSessions: Event<AuthenticationSessionsChangeEvent>; 18146 18147 /** 18148 * Register an authentication provider. 18149 * 18150 * There can only be one provider per id and an error is being thrown when an id 18151 * has already been used by another provider. Ids are case-sensitive. 18152 * 18153 * @param id The unique identifier of the provider. 18154 * @param label The human-readable name of the provider. 18155 * @param provider The authentication provider provider. 18156 * @param options Additional options for the provider. 18157 * @returns A {@link Disposable} that unregisters this provider when being disposed. 18158 */ 18159 export function registerAuthenticationProvider(id: string, label: string, provider: AuthenticationProvider, options?: AuthenticationProviderOptions): Disposable; 18160 } 18161 18162 /** 18163 * Namespace for localization-related functionality in the extension API. To use this properly, 18164 * you must have `l10n` defined in your extension manifest and have bundle.l10n.<language>.json files. 18165 * For more information on how to generate bundle.l10n.<language>.json files, check out the 18166 * [vscode-l10n repo](https://github.com/microsoft/vscode-l10n). 18167 * 18168 * Note: Built-in extensions (for example, Git, TypeScript Language Features, GitHub Authentication) 18169 * are excluded from the `l10n` property requirement. In other words, they do not need to specify 18170 * a `l10n` in the extension manifest because their translated strings come from Language Packs. 18171 */ 18172 export namespace l10n { 18173 /** 18174 * Marks a string for localization. If a localized bundle is available for the language specified by 18175 * {@link env.language} and the bundle has a localized value for this message, then that localized 18176 * value will be returned (with injected {@link args} values for any templated values). 18177 * 18178 * @param message - The message to localize. Supports index templating where strings like `{0}` and `{1}` are 18179 * replaced by the item at that index in the {@link args} array. 18180 * @param args - The arguments to be used in the localized string. The index of the argument is used to 18181 * match the template placeholder in the localized string. 18182 * @returns localized string with injected arguments. 18183 * 18184 * @example 18185 * l10n.t('Hello {0}!', 'World'); 18186 */ 18187 export function t(message: string, ...args: Array<string | number | boolean>): string; 18188 18189 /** 18190 * Marks a string for localization. If a localized bundle is available for the language specified by 18191 * {@link env.language} and the bundle has a localized value for this message, then that localized 18192 * value will be returned (with injected {@link args} values for any templated values). 18193 * 18194 * @param message The message to localize. Supports named templating where strings like `{foo}` and `{bar}` are 18195 * replaced by the value in the Record for that key (foo, bar, etc). 18196 * @param args The arguments to be used in the localized string. The name of the key in the record is used to 18197 * match the template placeholder in the localized string. 18198 * @returns localized string with injected arguments. 18199 * 18200 * @example 18201 * l10n.t('Hello {name}', { name: 'Erich' }); 18202 */ 18203 export function t(message: string, args: Record<string, string | number | boolean>): string; 18204 /** 18205 * Marks a string for localization. If a localized bundle is available for the language specified by 18206 * {@link env.language} and the bundle has a localized value for this message, then that localized 18207 * value will be returned (with injected args values for any templated values). 18208 * 18209 * @param options The options to use when localizing the message. 18210 * @returns localized string with injected arguments. 18211 */ 18212 export function t(options: { 18213 /** 18214 * The message to localize. If {@link options.args args} is an array, this message supports index templating where strings like 18215 * `{0}` and `{1}` are replaced by the item at that index in the {@link options.args args} array. If `args` is a `Record`, 18216 * this supports named templating where strings like `{foo}` and `{bar}` are replaced by the value in 18217 * the Record for that key (foo, bar, etc). 18218 */ 18219 message: string; 18220 /** 18221 * The arguments to be used in the localized string. As an array, the index of the argument is used to 18222 * match the template placeholder in the localized string. As a `Record`, the key is used to match the template 18223 * placeholder in the localized string. 18224 */ 18225 args?: Array<string | number | boolean> | Record<string, string | number | boolean>; 18226 /** 18227 * A comment to help translators understand the context of the message. 18228 */ 18229 comment: string | string[]; 18230 }): string; 18231 /** 18232 * The bundle of localized strings that have been loaded for the extension. 18233 * It's undefined if no bundle has been loaded. The bundle is typically not loaded if 18234 * there was no bundle found or when we are running with the default language. 18235 */ 18236 export const bundle: { [key: string]: string } | undefined; 18237 /** 18238 * The URI of the localization bundle that has been loaded for the extension. 18239 * It's undefined if no bundle has been loaded. The bundle is typically not loaded if 18240 * there was no bundle found or when we are running with the default language. 18241 */ 18242 export const uri: Uri | undefined; 18243 } 18244 18245 /** 18246 * Namespace for testing functionality. Tests are published by registering 18247 * {@link TestController} instances, then adding {@link TestItem TestItems}. 18248 * Controllers may also describe how to run tests by creating one or more 18249 * {@link TestRunProfile} instances. 18250 */ 18251 export namespace tests { 18252 /** 18253 * Creates a new test controller. 18254 * 18255 * @param id Identifier for the controller, must be globally unique. 18256 * @param label A human-readable label for the controller. 18257 * @returns An instance of the {@link TestController}. 18258 */ 18259 export function createTestController(id: string, label: string): TestController; 18260 } 18261 18262 /** 18263 * The kind of executions that {@link TestRunProfile TestRunProfiles} control. 18264 */ 18265 export enum TestRunProfileKind { 18266 /** 18267 * The `Run` test profile kind. 18268 */ 18269 Run = 1, 18270 /** 18271 * The `Debug` test profile kind. 18272 */ 18273 Debug = 2, 18274 /** 18275 * The `Coverage` test profile kind. 18276 */ 18277 Coverage = 3, 18278 } 18279 18280 /** 18281 * Tags can be associated with {@link TestItem TestItems} and 18282 * {@link TestRunProfile TestRunProfiles}. A profile with a tag can only 18283 * execute tests that include that tag in their {@link TestItem.tags} array. 18284 */ 18285 export class TestTag { 18286 /** 18287 * ID of the test tag. `TestTag` instances with the same ID are considered 18288 * to be identical. 18289 */ 18290 readonly id: string; 18291 18292 /** 18293 * Creates a new TestTag instance. 18294 * @param id ID of the test tag. 18295 */ 18296 constructor(id: string); 18297 } 18298 18299 /** 18300 * A TestRunProfile describes one way to execute tests in a {@link TestController}. 18301 */ 18302 export interface TestRunProfile { 18303 /** 18304 * Label shown to the user in the UI. 18305 * 18306 * Note that the label has some significance if the user requests that 18307 * tests be re-run in a certain way. For example, if tests were run 18308 * normally and the user requests to re-run them in debug mode, the editor 18309 * will attempt use a configuration with the same label of the `Debug` 18310 * kind. If there is no such configuration, the default will be used. 18311 */ 18312 label: string; 18313 18314 /** 18315 * Configures what kind of execution this profile controls. If there 18316 * are no profiles for a kind, it will not be available in the UI. 18317 */ 18318 readonly kind: TestRunProfileKind; 18319 18320 /** 18321 * Controls whether this profile is the default action that will 18322 * be taken when its kind is actioned. For example, if the user clicks 18323 * the generic "run all" button, then the default profile for 18324 * {@link TestRunProfileKind.Run} will be executed, although the 18325 * user can configure this. 18326 * 18327 * Changes the user makes in their default profiles will be reflected 18328 * in this property after a {@link onDidChangeDefault} event. 18329 */ 18330 isDefault: boolean; 18331 18332 /** 18333 * Fired when a user has changed whether this is a default profile. The 18334 * event contains the new value of {@link isDefault} 18335 */ 18336 readonly onDidChangeDefault: Event<boolean>; 18337 18338 /** 18339 * Whether this profile supports continuous running of requests. If so, 18340 * then {@link TestRunRequest.continuous} may be set to `true`. Defaults 18341 * to false. 18342 */ 18343 supportsContinuousRun: boolean; 18344 18345 /** 18346 * Associated tag for the profile. If this is set, only {@link TestItem} 18347 * instances with the same tag will be eligible to execute in this profile. 18348 */ 18349 tag: TestTag | undefined; 18350 18351 /** 18352 * If this method is present, a configuration gear will be present in the 18353 * UI, and this method will be invoked when it's clicked. When called, 18354 * you can take other editor actions, such as showing a quick pick or 18355 * opening a configuration file. 18356 */ 18357 configureHandler: (() => void) | undefined; 18358 18359 /** 18360 * Handler called to start a test run. When invoked, the function should call 18361 * {@link TestController.createTestRun} at least once, and all test runs 18362 * associated with the request should be created before the function returns 18363 * or the returned promise is resolved. 18364 * 18365 * If {@link supportsContinuousRun} is set, then {@link TestRunRequest.continuous} 18366 * may be `true`. In this case, the profile should observe changes to 18367 * source code and create new test runs by calling {@link TestController.createTestRun}, 18368 * until the cancellation is requested on the `token`. 18369 * 18370 * @param request Request information for the test run. 18371 * @param cancellationToken Token that signals the used asked to abort the 18372 * test run. If cancellation is requested on this token, all {@link TestRun} 18373 * instances associated with the request will be 18374 * automatically cancelled as well. 18375 */ 18376 runHandler: (request: TestRunRequest, token: CancellationToken) => Thenable<void> | void; 18377 18378 /** 18379 * An extension-provided function that provides detailed statement and 18380 * function-level coverage for a file. The editor will call this when more 18381 * detail is needed for a file, such as when it's opened in an editor or 18382 * expanded in the **Test Coverage** view. 18383 * 18384 * The {@link FileCoverage} object passed to this function is the same instance 18385 * emitted on {@link TestRun.addCoverage} calls associated with this profile. 18386 */ 18387 loadDetailedCoverage?: (testRun: TestRun, fileCoverage: FileCoverage, token: CancellationToken) => Thenable<FileCoverageDetail[]>; 18388 18389 /** 18390 * An extension-provided function that provides detailed statement and 18391 * function-level coverage for a single test in a file. This is the per-test 18392 * sibling of {@link TestRunProfile.loadDetailedCoverage}, called only if 18393 * a test item is provided in {@link FileCoverage.includesTests} and only 18394 * for files where such data is reported. 18395 * 18396 * Often {@link TestRunProfile.loadDetailedCoverage} will be called first 18397 * when a user opens a file, and then this method will be called if they 18398 * drill down into specific per-test coverage information. This method 18399 * should then return coverage data only for statements and declarations 18400 * executed by the specific test during the run. 18401 * 18402 * The {@link FileCoverage} object passed to this function is the same 18403 * instance emitted on {@link TestRun.addCoverage} calls associated with this profile. 18404 * 18405 * @param testRun The test run that generated the coverage data. 18406 * @param fileCoverage The file coverage object to load detailed coverage for. 18407 * @param fromTestItem The test item to request coverage information for. 18408 * @param token A cancellation token that indicates the operation should be cancelled. 18409 */ 18410 loadDetailedCoverageForTest?: (testRun: TestRun, fileCoverage: FileCoverage, fromTestItem: TestItem, token: CancellationToken) => Thenable<FileCoverageDetail[]>; 18411 18412 /** 18413 * Deletes the run profile. 18414 */ 18415 dispose(): void; 18416 } 18417 18418 /** 18419 * Entry point to discover and execute tests. It contains {@link TestController.items} which 18420 * are used to populate the editor UI, and is associated with 18421 * {@link TestController.createRunProfile run profiles} to allow 18422 * for tests to be executed. 18423 */ 18424 export interface TestController { 18425 /** 18426 * The id of the controller passed in {@link tests.createTestController}. 18427 * This must be globally unique. 18428 */ 18429 readonly id: string; 18430 18431 /** 18432 * Human-readable label for the test controller. 18433 */ 18434 label: string; 18435 18436 /** 18437 * A collection of "top-level" {@link TestItem} instances, which can in 18438 * turn have their own {@link TestItem.children children} to form the 18439 * "test tree." 18440 * 18441 * The extension controls when to add tests. For example, extensions should 18442 * add tests for a file when {@link workspace.onDidOpenTextDocument} 18443 * fires in order for decorations for tests within a file to be visible. 18444 * 18445 * However, the editor may sometimes explicitly request children using the 18446 * {@link resolveHandler} See the documentation on that method for more details. 18447 */ 18448 readonly items: TestItemCollection; 18449 18450 /** 18451 * Creates a profile used for running tests. Extensions must create 18452 * at least one profile in order for tests to be run. 18453 * @param label A human-readable label for this profile. 18454 * @param kind Configures what kind of execution this profile manages. 18455 * @param runHandler Function called to start a test run. 18456 * @param isDefault Whether this is the default action for its kind. 18457 * @param tag Profile test tag. 18458 * @param supportsContinuousRun Whether the profile supports continuous running. 18459 * @returns An instance of a {@link TestRunProfile}, which is automatically 18460 * associated with this controller. 18461 */ 18462 createRunProfile(label: string, kind: TestRunProfileKind, runHandler: (request: TestRunRequest, token: CancellationToken) => Thenable<void> | void, isDefault?: boolean, tag?: TestTag, supportsContinuousRun?: boolean): TestRunProfile; 18463 18464 /** 18465 * A function provided by the extension that the editor may call to request 18466 * children of a test item, if the {@link TestItem.canResolveChildren} is 18467 * `true`. When called, the item should discover children and call 18468 * {@link TestController.createTestItem} as children are discovered. 18469 * 18470 * Generally the extension manages the lifecycle of test items, but under 18471 * certain conditions the editor may request the children of a specific 18472 * item to be loaded. For example, if the user requests to re-run tests 18473 * after reloading the editor, the editor may need to call this method 18474 * to resolve the previously-run tests. 18475 * 18476 * The item in the explorer will automatically be marked as "busy" until 18477 * the function returns or the returned thenable resolves. 18478 * 18479 * @param item An unresolved test item for which children are being 18480 * requested, or `undefined` to resolve the controller's initial {@link TestController.items items}. 18481 */ 18482 resolveHandler?: (item: TestItem | undefined) => Thenable<void> | void; 18483 18484 /** 18485 * If this method is present, a refresh button will be present in the 18486 * UI, and this method will be invoked when it's clicked. When called, 18487 * the extension should scan the workspace for any new, changed, or 18488 * removed tests. 18489 * 18490 * It's recommended that extensions try to update tests in realtime, using 18491 * a {@link FileSystemWatcher} for example, and use this method as a fallback. 18492 * 18493 * @returns A thenable that resolves when tests have been refreshed. 18494 */ 18495 refreshHandler: ((token: CancellationToken) => Thenable<void> | void) | undefined; 18496 18497 /** 18498 * Creates a {@link TestRun}. This should be called by the 18499 * {@link TestRunProfile} when a request is made to execute tests, and may 18500 * also be called if a test run is detected externally. Once created, tests 18501 * that are included in the request will be moved into the queued state. 18502 * 18503 * All runs created using the same `request` instance will be grouped 18504 * together. This is useful if, for example, a single suite of tests is 18505 * run on multiple platforms. 18506 * 18507 * @param request Test run request. Only tests inside the `include` may be 18508 * modified, and tests in its `exclude` are ignored. 18509 * @param name The human-readable name of the run. This can be used to 18510 * disambiguate multiple sets of results in a test run. It is useful if 18511 * tests are run across multiple platforms, for example. 18512 * @param persist Whether the results created by the run should be 18513 * persisted in the editor. This may be false if the results are coming from 18514 * a file already saved externally, such as a coverage information file. 18515 * @returns An instance of the {@link TestRun}. It will be considered "running" 18516 * from the moment this method is invoked until {@link TestRun.end} is called. 18517 */ 18518 createTestRun(request: TestRunRequest, name?: string, persist?: boolean): TestRun; 18519 18520 /** 18521 * Creates a new managed {@link TestItem} instance. It can be added into 18522 * the {@link TestItem.children} of an existing item, or into the 18523 * {@link TestController.items}. 18524 * 18525 * @param id Identifier for the TestItem. The test item's ID must be unique 18526 * in the {@link TestItemCollection} it's added to. 18527 * @param label Human-readable label of the test item. 18528 * @param uri URI this TestItem is associated with. May be a file or directory. 18529 */ 18530 createTestItem(id: string, label: string, uri?: Uri): TestItem; 18531 18532 /** 18533 * Marks an item's results as being outdated. This is commonly called when 18534 * code or configuration changes and previous results should no longer 18535 * be considered relevant. The same logic used to mark results as outdated 18536 * may be used to drive {@link TestRunRequest.continuous continuous test runs}. 18537 * 18538 * If an item is passed to this method, test results for the item and all of 18539 * its children will be marked as outdated. If no item is passed, then all 18540 * test owned by the TestController will be marked as outdated. 18541 * 18542 * Any test runs started before the moment this method is called, including 18543 * runs which may still be ongoing, will be marked as outdated and deprioritized 18544 * in the editor's UI. 18545 * 18546 * @param items Item to mark as outdated. If undefined, all the controller's items are marked outdated. 18547 */ 18548 invalidateTestResults(items?: TestItem | readonly TestItem[]): void; 18549 18550 /** 18551 * Unregisters the test controller, disposing of its associated tests 18552 * and unpersisted results. 18553 */ 18554 dispose(): void; 18555 } 18556 18557 /** 18558 * A TestRunRequest is a precursor to a {@link TestRun}, which in turn is 18559 * created by passing a request to {@link TestController.createTestRun}. The 18560 * TestRunRequest contains information about which tests should be run, which 18561 * should not be run, and how they are run (via the {@link TestRunRequest.profile profile}). 18562 * 18563 * In general, TestRunRequests are created by the editor and pass to 18564 * {@link TestRunProfile.runHandler}, however you can also create test 18565 * requests and runs outside of the `runHandler`. 18566 */ 18567 export class TestRunRequest { 18568 /** 18569 * A filter for specific tests to run. If given, the extension should run 18570 * all of the included tests and all their children, excluding any tests 18571 * that appear in {@link TestRunRequest.exclude}. If this property is 18572 * undefined, then the extension should simply run all tests. 18573 * 18574 * The process of running tests should resolve the children of any test 18575 * items who have not yet been resolved. 18576 */ 18577 readonly include: readonly TestItem[] | undefined; 18578 18579 /** 18580 * An array of tests the user has marked as excluded from the test included 18581 * in this run; exclusions should apply after inclusions. 18582 * 18583 * May be omitted if no exclusions were requested. Test controllers should 18584 * not run excluded tests or any children of excluded tests. 18585 */ 18586 readonly exclude: readonly TestItem[] | undefined; 18587 18588 /** 18589 * The profile used for this request. This will always be defined 18590 * for requests issued from the editor UI, though extensions may 18591 * programmatically create requests not associated with any profile. 18592 */ 18593 readonly profile: TestRunProfile | undefined; 18594 18595 /** 18596 * Whether the profile should run continuously as source code changes. Only 18597 * relevant for profiles that set {@link TestRunProfile.supportsContinuousRun}. 18598 */ 18599 readonly continuous?: boolean; 18600 18601 /** 18602 * Controls how test Test Results view is focused. If true, the editor 18603 * will keep the maintain the user's focus. If false, the editor will 18604 * prefer to move focus into the Test Results view, although 18605 * this may be configured by users. 18606 */ 18607 readonly preserveFocus: boolean; 18608 18609 /** 18610 * @param include Array of specific tests to run, or undefined to run all tests 18611 * @param exclude An array of tests to exclude from the run. 18612 * @param profile The run profile used for this request. 18613 * @param continuous Whether to run tests continuously as source changes. 18614 * @param preserveFocus Whether to preserve the user's focus when the run is started 18615 */ 18616 constructor(include?: readonly TestItem[], exclude?: readonly TestItem[], profile?: TestRunProfile, continuous?: boolean, preserveFocus?: boolean); 18617 } 18618 18619 /** 18620 * A TestRun represents an in-progress or completed test run and 18621 * provides methods to report the state of individual tests in the run. 18622 */ 18623 export interface TestRun { 18624 /** 18625 * The human-readable name of the run. This can be used to 18626 * disambiguate multiple sets of results in a test run. It is useful if 18627 * tests are run across multiple platforms, for example. 18628 */ 18629 readonly name: string | undefined; 18630 18631 /** 18632 * A cancellation token which will be triggered when the test run is 18633 * canceled from the UI. 18634 */ 18635 readonly token: CancellationToken; 18636 18637 /** 18638 * Whether the test run will be persisted across reloads by the editor. 18639 */ 18640 readonly isPersisted: boolean; 18641 18642 /** 18643 * Indicates a test is queued for later execution. 18644 * @param test Test item to update. 18645 */ 18646 enqueued(test: TestItem): void; 18647 18648 /** 18649 * Indicates a test has started running. 18650 * @param test Test item to update. 18651 */ 18652 started(test: TestItem): void; 18653 18654 /** 18655 * Indicates a test has been skipped. 18656 * @param test Test item to update. 18657 */ 18658 skipped(test: TestItem): void; 18659 18660 /** 18661 * Indicates a test has failed. You should pass one or more 18662 * {@link TestMessage TestMessages} to describe the failure. 18663 * @param test Test item to update. 18664 * @param message Messages associated with the test failure. 18665 * @param duration How long the test took to execute, in milliseconds. 18666 */ 18667 failed(test: TestItem, message: TestMessage | readonly TestMessage[], duration?: number): void; 18668 18669 /** 18670 * Indicates a test has errored. You should pass one or more 18671 * {@link TestMessage TestMessages} to describe the failure. This differs 18672 * from the "failed" state in that it indicates a test that couldn't be 18673 * executed at all, from a compilation error for example. 18674 * @param test Test item to update. 18675 * @param message Messages associated with the test failure. 18676 * @param duration How long the test took to execute, in milliseconds. 18677 */ 18678 errored(test: TestItem, message: TestMessage | readonly TestMessage[], duration?: number): void; 18679 18680 /** 18681 * Indicates a test has passed. 18682 * @param test Test item to update. 18683 * @param duration How long the test took to execute, in milliseconds. 18684 */ 18685 passed(test: TestItem, duration?: number): void; 18686 18687 /** 18688 * Appends raw output from the test runner. On the user's request, the 18689 * output will be displayed in a terminal. ANSI escape sequences, 18690 * such as colors and text styles, are supported. New lines must be given 18691 * as CRLF (`\r\n`) rather than LF (`\n`). 18692 * 18693 * @param output Output text to append. 18694 * @param location Indicate that the output was logged at the given 18695 * location. 18696 * @param test Test item to associate the output with. 18697 */ 18698 appendOutput(output: string, location?: Location, test?: TestItem): void; 18699 18700 /** 18701 * Adds coverage for a file in the run. 18702 */ 18703 addCoverage(fileCoverage: FileCoverage): void; 18704 18705 /** 18706 * Signals the end of the test run. Any tests included in the run whose 18707 * states have not been updated will have their state reset. 18708 */ 18709 end(): void; 18710 18711 /** 18712 * An event fired when the editor is no longer interested in data 18713 * associated with the test run. 18714 */ 18715 readonly onDidDispose: Event<void>; 18716 } 18717 18718 /** 18719 * Collection of test items, found in {@link TestItem.children} and 18720 * {@link TestController.items}. 18721 */ 18722 export interface TestItemCollection extends Iterable<[id: string, testItem: TestItem]> { 18723 /** 18724 * Gets the number of items in the collection. 18725 */ 18726 readonly size: number; 18727 18728 /** 18729 * Replaces the items stored by the collection. 18730 * @param items Items to store. 18731 */ 18732 replace(items: readonly TestItem[]): void; 18733 18734 /** 18735 * Iterate over each entry in this collection. 18736 * 18737 * @param callback Function to execute for each entry. 18738 * @param thisArg The `this` context used when invoking the handler function. 18739 */ 18740 forEach(callback: (item: TestItem, collection: TestItemCollection) => unknown, thisArg?: any): void; 18741 18742 /** 18743 * Adds the test item to the children. If an item with the same ID already 18744 * exists, it'll be replaced. 18745 * @param item Item to add. 18746 */ 18747 add(item: TestItem): void; 18748 18749 /** 18750 * Removes a single test item from the collection. 18751 * @param itemId Item ID to delete. 18752 */ 18753 delete(itemId: string): void; 18754 18755 /** 18756 * Efficiently gets a test item by ID, if it exists, in the children. 18757 * @param itemId Item ID to get. 18758 * @returns The found item or undefined if it does not exist. 18759 */ 18760 get(itemId: string): TestItem | undefined; 18761 } 18762 18763 /** 18764 * An item shown in the "test explorer" view. 18765 * 18766 * A `TestItem` can represent either a test suite or a test itself, since 18767 * they both have similar capabilities. 18768 */ 18769 export interface TestItem { 18770 /** 18771 * Identifier for the `TestItem`. This is used to correlate 18772 * test results and tests in the document with those in the workspace 18773 * (test explorer). This cannot change for the lifetime of the `TestItem`, 18774 * and must be unique among its parent's direct children. 18775 */ 18776 readonly id: string; 18777 18778 /** 18779 * URI this `TestItem` is associated with. May be a file or directory. 18780 */ 18781 readonly uri: Uri | undefined; 18782 18783 /** 18784 * The children of this test item. For a test suite, this may contain the 18785 * individual test cases or nested suites. 18786 */ 18787 readonly children: TestItemCollection; 18788 18789 /** 18790 * The parent of this item. It's set automatically, and is undefined 18791 * top-level items in the {@link TestController.items} and for items that 18792 * aren't yet included in another item's {@link TestItem.children children}. 18793 */ 18794 readonly parent: TestItem | undefined; 18795 18796 /** 18797 * Tags associated with this test item. May be used in combination with 18798 * {@link TestRunProfile.tag tags}, or simply as an organizational feature. 18799 */ 18800 tags: readonly TestTag[]; 18801 18802 /** 18803 * Indicates whether this test item may have children discovered by resolving. 18804 * 18805 * If true, this item is shown as expandable in the Test Explorer view and 18806 * expanding the item will cause {@link TestController.resolveHandler} 18807 * to be invoked with the item. 18808 * 18809 * Default to `false`. 18810 */ 18811 canResolveChildren: boolean; 18812 18813 /** 18814 * Controls whether the item is shown as "busy" in the Test Explorer view. 18815 * This is useful for showing status while discovering children. 18816 * 18817 * Defaults to `false`. 18818 */ 18819 busy: boolean; 18820 18821 /** 18822 * Display name describing the test case. 18823 */ 18824 label: string; 18825 18826 /** 18827 * Optional description that appears next to the label. 18828 */ 18829 description?: string; 18830 18831 /** 18832 * A string that should be used when comparing this item 18833 * with other items. When `falsy` the {@link TestItem.label label} 18834 * is used. 18835 */ 18836 sortText?: string | undefined; 18837 18838 /** 18839 * Location of the test item in its {@link TestItem.uri uri}. 18840 * 18841 * This is only meaningful if the `uri` points to a file. 18842 */ 18843 range: Range | undefined; 18844 18845 /** 18846 * Optional error encountered while loading the test. 18847 * 18848 * Note that this is not a test result and should only be used to represent errors in 18849 * test discovery, such as syntax errors. 18850 */ 18851 error: string | MarkdownString | undefined; 18852 } 18853 18854 /** 18855 * A stack frame found in the {@link TestMessage.stackTrace}. 18856 */ 18857 export class TestMessageStackFrame { 18858 /** 18859 * The location of this stack frame. This should be provided as a URI if the 18860 * location of the call frame can be accessed by the editor. 18861 */ 18862 uri?: Uri; 18863 18864 /** 18865 * Position of the stack frame within the file. 18866 */ 18867 position?: Position; 18868 18869 /** 18870 * The name of the stack frame, typically a method or function name. 18871 */ 18872 label: string; 18873 18874 /** 18875 * @param label The name of the stack frame 18876 * @param file The file URI of the stack frame 18877 * @param position The position of the stack frame within the file 18878 */ 18879 constructor(label: string, uri?: Uri, position?: Position); 18880 } 18881 18882 /** 18883 * Message associated with the test state. Can be linked to a specific 18884 * source range -- useful for assertion failures, for example. 18885 */ 18886 export class TestMessage { 18887 /** 18888 * Human-readable message text to display. 18889 */ 18890 message: string | MarkdownString; 18891 18892 /** 18893 * Expected test output. If given with {@link TestMessage.actualOutput actualOutput }, a diff view will be shown. 18894 */ 18895 expectedOutput?: string; 18896 18897 /** 18898 * Actual test output. If given with {@link TestMessage.expectedOutput expectedOutput }, a diff view will be shown. 18899 */ 18900 actualOutput?: string; 18901 18902 /** 18903 * Associated file location. 18904 */ 18905 location?: Location; 18906 18907 /** 18908 * Context value of the test item. This can be used to contribute message- 18909 * specific actions to the test peek view. The value set here can be found 18910 * in the `testMessage` property of the following `menus` contribution points: 18911 * 18912 * - `testing/message/context` - context menu for the message in the results tree 18913 * - `testing/message/content` - a prominent button overlaying editor content where 18914 * the message is displayed. 18915 * 18916 * For example: 18917 * 18918 * ```json 18919 * "contributes": { 18920 * "menus": { 18921 * "testing/message/content": [ 18922 * { 18923 * "command": "extension.deleteCommentThread", 18924 * "when": "testMessage == canApplyRichDiff" 18925 * } 18926 * ] 18927 * } 18928 * } 18929 * ``` 18930 * 18931 * The command will be called with an object containing: 18932 * - `test`: the {@link TestItem} the message is associated with, *if* it 18933 * is still present in the {@link TestController.items} collection. 18934 * - `message`: the {@link TestMessage} instance. 18935 */ 18936 contextValue?: string; 18937 18938 /** 18939 * The stack trace associated with the message or failure. 18940 */ 18941 stackTrace?: TestMessageStackFrame[]; 18942 18943 /** 18944 * Creates a new TestMessage that will present as a diff in the editor. 18945 * @param message Message to display to the user. 18946 * @param expected Expected output. 18947 * @param actual Actual output. 18948 */ 18949 static diff(message: string | MarkdownString, expected: string, actual: string): TestMessage; 18950 18951 /** 18952 * Creates a new TestMessage instance. 18953 * @param message The message to show to the user. 18954 */ 18955 constructor(message: string | MarkdownString); 18956 } 18957 18958 /** 18959 * A class that contains information about a covered resource. A count can 18960 * be give for lines, branches, and declarations in a file. 18961 */ 18962 export class TestCoverageCount { 18963 /** 18964 * Number of items covered in the file. 18965 */ 18966 covered: number; 18967 /** 18968 * Total number of covered items in the file. 18969 */ 18970 total: number; 18971 18972 /** 18973 * @param covered Value for {@link TestCoverageCount.covered} 18974 * @param total Value for {@link TestCoverageCount.total} 18975 */ 18976 constructor(covered: number, total: number); 18977 } 18978 18979 /** 18980 * Contains coverage metadata for a file. 18981 */ 18982 export class FileCoverage { 18983 /** 18984 * File URI. 18985 */ 18986 readonly uri: Uri; 18987 18988 /** 18989 * Statement coverage information. If the reporter does not provide statement 18990 * coverage information, this can instead be used to represent line coverage. 18991 */ 18992 statementCoverage: TestCoverageCount; 18993 18994 /** 18995 * Branch coverage information. 18996 */ 18997 branchCoverage?: TestCoverageCount; 18998 18999 /** 19000 * Declaration coverage information. Depending on the reporter and 19001 * language, this may be types such as functions, methods, or namespaces. 19002 */ 19003 declarationCoverage?: TestCoverageCount; 19004 19005 /** 19006 * A list of {@link TestItem test cases} that generated coverage in this 19007 * file. If set, then {@link TestRunProfile.loadDetailedCoverageForTest} 19008 * should also be defined in order to retrieve detailed coverage information. 19009 */ 19010 includesTests?: TestItem[]; 19011 19012 /** 19013 * Creates a {@link FileCoverage} instance with counts filled in from 19014 * the coverage details. 19015 * @param uri Covered file URI 19016 * @param details Detailed coverage information 19017 */ 19018 static fromDetails(uri: Uri, details: readonly FileCoverageDetail[]): FileCoverage; 19019 19020 /** 19021 * @param uri Covered file URI 19022 * @param statementCoverage Statement coverage information. If the reporter 19023 * does not provide statement coverage information, this can instead be 19024 * used to represent line coverage. 19025 * @param branchCoverage Branch coverage information 19026 * @param declarationCoverage Declaration coverage information 19027 * @param includesTests Test cases included in this coverage report, see {@link FileCoverage.includesTests} 19028 */ 19029 constructor( 19030 uri: Uri, 19031 statementCoverage: TestCoverageCount, 19032 branchCoverage?: TestCoverageCount, 19033 declarationCoverage?: TestCoverageCount, 19034 includesTests?: TestItem[], 19035 ); 19036 } 19037 19038 /** 19039 * Contains coverage information for a single statement or line. 19040 */ 19041 export class StatementCoverage { 19042 /** 19043 * The number of times this statement was executed, or a boolean indicating 19044 * whether it was executed if the exact count is unknown. If zero or false, 19045 * the statement will be marked as un-covered. 19046 */ 19047 executed: number | boolean; 19048 19049 /** 19050 * Statement location. 19051 */ 19052 location: Position | Range; 19053 19054 /** 19055 * Coverage from branches of this line or statement. If it's not a 19056 * conditional, this will be empty. 19057 */ 19058 branches: BranchCoverage[]; 19059 19060 /** 19061 * @param location The statement position. 19062 * @param executed The number of times this statement was executed, or a 19063 * boolean indicating whether it was executed if the exact count is 19064 * unknown. If zero or false, the statement will be marked as un-covered. 19065 * @param branches Coverage from branches of this line. If it's not a 19066 * conditional, this should be omitted. 19067 */ 19068 constructor(executed: number | boolean, location: Position | Range, branches?: BranchCoverage[]); 19069 } 19070 19071 /** 19072 * Contains coverage information for a branch of a {@link StatementCoverage}. 19073 */ 19074 export class BranchCoverage { 19075 /** 19076 * The number of times this branch was executed, or a boolean indicating 19077 * whether it was executed if the exact count is unknown. If zero or false, 19078 * the branch will be marked as un-covered. 19079 */ 19080 executed: number | boolean; 19081 19082 /** 19083 * Branch location. 19084 */ 19085 location?: Position | Range; 19086 19087 /** 19088 * Label for the branch, used in the context of "the ${label} branch was 19089 * not taken," for example. 19090 */ 19091 label?: string; 19092 19093 /** 19094 * @param executed The number of times this branch was executed, or a 19095 * boolean indicating whether it was executed if the exact count is 19096 * unknown. If zero or false, the branch will be marked as un-covered. 19097 * @param location The branch position. 19098 */ 19099 constructor(executed: number | boolean, location?: Position | Range, label?: string); 19100 } 19101 19102 /** 19103 * Contains coverage information for a declaration. Depending on the reporter 19104 * and language, this may be types such as functions, methods, or namespaces. 19105 */ 19106 export class DeclarationCoverage { 19107 /** 19108 * Name of the declaration. 19109 */ 19110 name: string; 19111 19112 /** 19113 * The number of times this declaration was executed, or a boolean 19114 * indicating whether it was executed if the exact count is unknown. If 19115 * zero or false, the declaration will be marked as un-covered. 19116 */ 19117 executed: number | boolean; 19118 19119 /** 19120 * Declaration location. 19121 */ 19122 location: Position | Range; 19123 19124 /** 19125 * @param executed The number of times this declaration was executed, or a 19126 * boolean indicating whether it was executed if the exact count is 19127 * unknown. If zero or false, the declaration will be marked as un-covered. 19128 * @param location The declaration position. 19129 */ 19130 constructor(name: string, executed: number | boolean, location: Position | Range); 19131 } 19132 19133 /** 19134 * Coverage details returned from {@link TestRunProfile.loadDetailedCoverage}. 19135 */ 19136 export type FileCoverageDetail = StatementCoverage | DeclarationCoverage; 19137 19138 /** 19139 * The tab represents a single text based resource. 19140 */ 19141 export class TabInputText { 19142 /** 19143 * The uri represented by the tab. 19144 */ 19145 readonly uri: Uri; 19146 /** 19147 * Constructs a text tab input with the given URI. 19148 * @param uri The URI of the tab. 19149 */ 19150 constructor(uri: Uri); 19151 } 19152 19153 /** 19154 * The tab represents two text based resources 19155 * being rendered as a diff. 19156 */ 19157 export class TabInputTextDiff { 19158 /** 19159 * The uri of the original text resource. 19160 */ 19161 readonly original: Uri; 19162 /** 19163 * The uri of the modified text resource. 19164 */ 19165 readonly modified: Uri; 19166 /** 19167 * Constructs a new text diff tab input with the given URIs. 19168 * @param original The uri of the original text resource. 19169 * @param modified The uri of the modified text resource. 19170 */ 19171 constructor(original: Uri, modified: Uri); 19172 } 19173 19174 /** 19175 * The tab represents a custom editor. 19176 */ 19177 export class TabInputCustom { 19178 /** 19179 * The uri that the tab is representing. 19180 */ 19181 readonly uri: Uri; 19182 /** 19183 * The type of custom editor. 19184 */ 19185 readonly viewType: string; 19186 /** 19187 * Constructs a custom editor tab input. 19188 * @param uri The uri of the tab. 19189 * @param viewType The viewtype of the custom editor. 19190 */ 19191 constructor(uri: Uri, viewType: string); 19192 } 19193 19194 /** 19195 * The tab represents a webview. 19196 */ 19197 export class TabInputWebview { 19198 /** 19199 * The type of webview. Maps to {@linkcode WebviewPanel.viewType WebviewPanel's viewType} 19200 */ 19201 readonly viewType: string; 19202 /** 19203 * Constructs a webview tab input with the given view type. 19204 * @param viewType The type of webview. Maps to {@linkcode WebviewPanel.viewType WebviewPanel's viewType} 19205 */ 19206 constructor(viewType: string); 19207 } 19208 19209 /** 19210 * The tab represents a notebook. 19211 */ 19212 export class TabInputNotebook { 19213 /** 19214 * The uri that the tab is representing. 19215 */ 19216 readonly uri: Uri; 19217 /** 19218 * The type of notebook. Maps to {@linkcode NotebookDocument.notebookType NotebookDocuments's notebookType} 19219 */ 19220 readonly notebookType: string; 19221 /** 19222 * Constructs a new tab input for a notebook. 19223 * @param uri The uri of the notebook. 19224 * @param notebookType The type of notebook. Maps to {@linkcode NotebookDocument.notebookType NotebookDocuments's notebookType} 19225 */ 19226 constructor(uri: Uri, notebookType: string); 19227 } 19228 19229 /** 19230 * The tabs represents two notebooks in a diff configuration. 19231 */ 19232 export class TabInputNotebookDiff { 19233 /** 19234 * The uri of the original notebook. 19235 */ 19236 readonly original: Uri; 19237 /** 19238 * The uri of the modified notebook. 19239 */ 19240 readonly modified: Uri; 19241 /** 19242 * The type of notebook. Maps to {@linkcode NotebookDocument.notebookType NotebookDocuments's notebookType} 19243 */ 19244 readonly notebookType: string; 19245 /** 19246 * Constructs a notebook diff tab input. 19247 * @param original The uri of the original unmodified notebook. 19248 * @param modified The uri of the modified notebook. 19249 * @param notebookType The type of notebook. Maps to {@linkcode NotebookDocument.notebookType NotebookDocuments's notebookType} 19250 */ 19251 constructor(original: Uri, modified: Uri, notebookType: string); 19252 } 19253 19254 /** 19255 * The tab represents a terminal in the editor area. 19256 */ 19257 export class TabInputTerminal { 19258 /** 19259 * Constructs a terminal tab input. 19260 */ 19261 constructor(); 19262 } 19263 19264 /** 19265 * Represents a tab within a {@link TabGroup group of tabs}. 19266 * Tabs are merely the graphical representation within the editor area. 19267 * A backing editor is not a guarantee. 19268 */ 19269 export interface Tab { 19270 19271 /** 19272 * The text displayed on the tab. 19273 */ 19274 readonly label: string; 19275 19276 /** 19277 * The group which the tab belongs to. 19278 */ 19279 readonly group: TabGroup; 19280 19281 /** 19282 * Defines the structure of the tab i.e. text, notebook, custom, etc. 19283 * Resource and other useful properties are defined on the tab kind. 19284 */ 19285 readonly input: TabInputText | TabInputTextDiff | TabInputCustom | TabInputWebview | TabInputNotebook | TabInputNotebookDiff | TabInputTerminal | unknown; 19286 19287 /** 19288 * Whether or not the tab is currently active. 19289 * This is dictated by being the selected tab in the group. 19290 */ 19291 readonly isActive: boolean; 19292 19293 /** 19294 * Whether or not the dirty indicator is present on the tab. 19295 */ 19296 readonly isDirty: boolean; 19297 19298 /** 19299 * Whether or not the tab is pinned (pin icon is present). 19300 */ 19301 readonly isPinned: boolean; 19302 19303 /** 19304 * Whether or not the tab is in preview mode. 19305 */ 19306 readonly isPreview: boolean; 19307 } 19308 19309 /** 19310 * An event describing change to tabs. 19311 */ 19312 export interface TabChangeEvent { 19313 /** 19314 * The tabs that have been opened. 19315 */ 19316 readonly opened: readonly Tab[]; 19317 /** 19318 * The tabs that have been closed. 19319 */ 19320 readonly closed: readonly Tab[]; 19321 /** 19322 * Tabs that have changed, e.g have changed 19323 * their {@link Tab.isActive active} state. 19324 */ 19325 readonly changed: readonly Tab[]; 19326 } 19327 19328 /** 19329 * An event describing changes to tab groups. 19330 */ 19331 export interface TabGroupChangeEvent { 19332 /** 19333 * Tab groups that have been opened. 19334 */ 19335 readonly opened: readonly TabGroup[]; 19336 /** 19337 * Tab groups that have been closed. 19338 */ 19339 readonly closed: readonly TabGroup[]; 19340 /** 19341 * Tab groups that have changed, e.g have changed 19342 * their {@link TabGroup.isActive active} state. 19343 */ 19344 readonly changed: readonly TabGroup[]; 19345 } 19346 19347 /** 19348 * Represents a group of tabs. A tab group itself consists of multiple tabs. 19349 */ 19350 export interface TabGroup { 19351 /** 19352 * Whether or not the group is currently active. 19353 * 19354 * *Note* that only one tab group is active at a time, but that multiple tab 19355 * groups can have an {@link activeTab active tab}. 19356 * 19357 * @see {@link Tab.isActive} 19358 */ 19359 readonly isActive: boolean; 19360 19361 /** 19362 * The view column of the group. 19363 */ 19364 readonly viewColumn: ViewColumn; 19365 19366 /** 19367 * The active {@link Tab tab} in the group. This is the tab whose contents are currently 19368 * being rendered. 19369 * 19370 * *Note* that there can be one active tab per group but there can only be one {@link TabGroups.activeTabGroup active group}. 19371 */ 19372 readonly activeTab: Tab | undefined; 19373 19374 /** 19375 * The list of tabs contained within the group. 19376 * This can be empty if the group has no tabs open. 19377 */ 19378 readonly tabs: readonly Tab[]; 19379 } 19380 19381 /** 19382 * Represents the main editor area which consists of multiple groups which contain tabs. 19383 */ 19384 export interface TabGroups { 19385 /** 19386 * All the groups within the group container. 19387 */ 19388 readonly all: readonly TabGroup[]; 19389 19390 /** 19391 * The currently active group. 19392 */ 19393 readonly activeTabGroup: TabGroup; 19394 19395 /** 19396 * An {@link Event event} which fires when {@link TabGroup tab groups} have changed. 19397 */ 19398 readonly onDidChangeTabGroups: Event<TabGroupChangeEvent>; 19399 19400 /** 19401 * An {@link Event event} which fires when {@link Tab tabs} have changed. 19402 */ 19403 readonly onDidChangeTabs: Event<TabChangeEvent>; 19404 19405 /** 19406 * Closes the tab. This makes the tab object invalid and the tab 19407 * should no longer be used for further actions. 19408 * Note: In the case of a dirty tab, a confirmation dialog will be shown which may be cancelled. If cancelled the tab is still valid 19409 * 19410 * @param tab The tab to close. 19411 * @param preserveFocus When `true` focus will remain in its current position. If `false` it will jump to the next tab. 19412 * @returns A promise that resolves to `true` when all tabs have been closed. 19413 */ 19414 close(tab: Tab | readonly Tab[], preserveFocus?: boolean): Thenable<boolean>; 19415 19416 /** 19417 * Closes the tab group. This makes the tab group object invalid and the tab group 19418 * should no longer be used for further actions. 19419 * @param tabGroup The tab group to close. 19420 * @param preserveFocus When `true` focus will remain in its current position. 19421 * @returns A promise that resolves to `true` when all tab groups have been closed. 19422 */ 19423 close(tabGroup: TabGroup | readonly TabGroup[], preserveFocus?: boolean): Thenable<boolean>; 19424 } 19425 19426 /** 19427 * A special value wrapper denoting a value that is safe to not clean. 19428 * This is to be used when you can guarantee no identifiable information is contained in the value and the cleaning is improperly redacting it. 19429 */ 19430 export class TelemetryTrustedValue<T = any> { 19431 19432 /** 19433 * The value that is trusted to not contain PII. 19434 */ 19435 readonly value: T; 19436 19437 /** 19438 * Creates a new telemetry trusted value. 19439 * 19440 * @param value A value to trust 19441 */ 19442 constructor(value: T); 19443 } 19444 19445 /** 19446 * A telemetry logger which can be used by extensions to log usage and error telemetry. 19447 * 19448 * A logger wraps around an {@link TelemetrySender sender} but it guarantees that 19449 * - user settings to disable or tweak telemetry are respected, and that 19450 * - potential sensitive data is removed 19451 * 19452 * It also enables an "echo UI" that prints whatever data is send and it allows the editor 19453 * to forward unhandled errors to the respective extensions. 19454 * 19455 * To get an instance of a `TelemetryLogger`, use 19456 * {@link env.createTelemetryLogger `createTelemetryLogger`}. 19457 */ 19458 export interface TelemetryLogger { 19459 19460 /** 19461 * An {@link Event} which fires when the enablement state of usage or error telemetry changes. 19462 */ 19463 readonly onDidChangeEnableStates: Event<TelemetryLogger>; 19464 19465 /** 19466 * Whether or not usage telemetry is enabled for this logger. 19467 */ 19468 readonly isUsageEnabled: boolean; 19469 19470 /** 19471 * Whether or not error telemetry is enabled for this logger. 19472 */ 19473 readonly isErrorsEnabled: boolean; 19474 19475 /** 19476 * Log a usage event. 19477 * 19478 * After completing cleaning, telemetry setting checks, and data mix-in calls `TelemetrySender.sendEventData` to log the event. 19479 * Automatically supports echoing to extension telemetry output channel. 19480 * @param eventName The event name to log 19481 * @param data The data to log 19482 */ 19483 logUsage(eventName: string, data?: Record<string, any | TelemetryTrustedValue>): void; 19484 19485 /** 19486 * Log an error event. 19487 * 19488 * After completing cleaning, telemetry setting checks, and data mix-in calls `TelemetrySender.sendEventData` to log the event. Differs from `logUsage` in that it will log the event if the telemetry setting is Error+. 19489 * Automatically supports echoing to extension telemetry output channel. 19490 * @param eventName The event name to log 19491 * @param data The data to log 19492 */ 19493 logError(eventName: string, data?: Record<string, any | TelemetryTrustedValue>): void; 19494 19495 /** 19496 * Log an error event. 19497 * 19498 * Calls `TelemetrySender.sendErrorData`. Does cleaning, telemetry checks, and data mix-in. 19499 * Automatically supports echoing to extension telemetry output channel. 19500 * Will also automatically log any exceptions thrown within the extension host process. 19501 * @param error The error object which contains the stack trace cleaned of PII 19502 * @param data Additional data to log alongside the stack trace 19503 */ 19504 logError(error: Error, data?: Record<string, any | TelemetryTrustedValue>): void; 19505 19506 /** 19507 * Dispose this object and free resources. 19508 */ 19509 dispose(): void; 19510 } 19511 19512 /** 19513 * The telemetry sender is the contract between a telemetry logger and some telemetry service. **Note** that extensions must NOT 19514 * call the methods of their sender directly as the logger provides extra guards and cleaning. 19515 * 19516 * ```js 19517 * const sender: vscode.TelemetrySender = {...}; 19518 * const logger = vscode.env.createTelemetryLogger(sender); 19519 * 19520 * // GOOD - uses the logger 19521 * logger.logUsage('myEvent', { myData: 'myValue' }); 19522 * 19523 * // BAD - uses the sender directly: no data cleansing, ignores user settings, no echoing to the telemetry output channel etc 19524 * sender.logEvent('myEvent', { myData: 'myValue' }); 19525 * ``` 19526 */ 19527 export interface TelemetrySender { 19528 /** 19529 * Function to send event data without a stacktrace. Used within a {@link TelemetryLogger} 19530 * 19531 * @param eventName The name of the event which you are logging 19532 * @param data A serializable key value pair that is being logged 19533 */ 19534 sendEventData(eventName: string, data?: Record<string, any>): void; 19535 19536 /** 19537 * Function to send an error. Used within a {@link TelemetryLogger} 19538 * 19539 * @param error The error being logged 19540 * @param data Any additional data to be collected with the exception 19541 */ 19542 sendErrorData(error: Error, data?: Record<string, any>): void; 19543 19544 /** 19545 * Optional flush function which will give this sender a chance to send any remaining events 19546 * as its {@link TelemetryLogger} is being disposed 19547 */ 19548 flush?(): void | Thenable<void>; 19549 } 19550 19551 /** 19552 * Options for creating a {@link TelemetryLogger} 19553 */ 19554 export interface TelemetryLoggerOptions { 19555 /** 19556 * Whether or not you want to avoid having the built-in common properties such as os, extension name, etc injected into the data object. 19557 * Defaults to `false` if not defined. 19558 */ 19559 readonly ignoreBuiltInCommonProperties?: boolean; 19560 19561 /** 19562 * Whether or not unhandled errors on the extension host caused by your extension should be logged to your sender. 19563 * Defaults to `false` if not defined. 19564 */ 19565 readonly ignoreUnhandledErrors?: boolean; 19566 19567 /** 19568 * Any additional common properties which should be injected into the data object. 19569 */ 19570 readonly additionalCommonProperties?: Record<string, any>; 19571 } 19572 19573 /** 19574 * Represents a user request in chat history. 19575 */ 19576 export class ChatRequestTurn { 19577 /** 19578 * The prompt as entered by the user. 19579 * 19580 * Information about references used in this request is stored in {@link ChatRequestTurn.references}. 19581 * 19582 * *Note* that the {@link ChatParticipant.name name} of the participant and the {@link ChatCommand.name command} 19583 * are not part of the prompt. 19584 */ 19585 readonly prompt: string; 19586 19587 /** 19588 * The id of the chat participant to which this request was directed. 19589 */ 19590 readonly participant: string; 19591 19592 /** 19593 * The name of the {@link ChatCommand command} that was selected for this request. 19594 */ 19595 readonly command?: string; 19596 19597 /** 19598 * The references that were used in this message. 19599 */ 19600 readonly references: ChatPromptReference[]; 19601 19602 /** 19603 * The list of tools were attached to this request. 19604 */ 19605 readonly toolReferences: readonly ChatLanguageModelToolReference[]; 19606 19607 /** 19608 * @hidden 19609 */ 19610 private constructor(prompt: string, command: string | undefined, references: ChatPromptReference[], participant: string, toolReferences: ChatLanguageModelToolReference[]); 19611 } 19612 19613 /** 19614 * Represents a chat participant's response in chat history. 19615 */ 19616 export class ChatResponseTurn { 19617 /** 19618 * The content that was received from the chat participant. Only the stream parts that represent actual content (not metadata) are represented. 19619 */ 19620 readonly response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>; 19621 19622 /** 19623 * The result that was received from the chat participant. 19624 */ 19625 readonly result: ChatResult; 19626 19627 /** 19628 * The id of the chat participant that this response came from. 19629 */ 19630 readonly participant: string; 19631 19632 /** 19633 * The name of the command that this response came from. 19634 */ 19635 readonly command?: string; 19636 19637 /** 19638 * @hidden 19639 */ 19640 private constructor(response: ReadonlyArray<ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart | ChatResponseCommandButtonPart>, result: ChatResult, participant: string); 19641 } 19642 19643 /** 19644 * Extra context passed to a participant. 19645 */ 19646 export interface ChatContext { 19647 /** 19648 * All of the chat messages so far in the current chat session. Currently, only chat messages for the current participant are included. 19649 */ 19650 readonly history: ReadonlyArray<ChatRequestTurn | ChatResponseTurn>; 19651 } 19652 19653 /** 19654 * Represents an error result from a chat request. 19655 */ 19656 export interface ChatErrorDetails { 19657 /** 19658 * An error message that is shown to the user. 19659 */ 19660 message: string; 19661 19662 /** 19663 * If set to true, the response will be partly blurred out. 19664 */ 19665 responseIsFiltered?: boolean; 19666 } 19667 19668 /** 19669 * The result of a chat request. 19670 */ 19671 export interface ChatResult { 19672 /** 19673 * If the request resulted in an error, this property defines the error details. 19674 */ 19675 errorDetails?: ChatErrorDetails; 19676 19677 /** 19678 * Arbitrary metadata for this result. Can be anything, but must be JSON-stringifyable. 19679 */ 19680 readonly metadata?: { readonly [key: string]: any }; 19681 } 19682 19683 /** 19684 * Represents the type of user feedback received. 19685 */ 19686 export enum ChatResultFeedbackKind { 19687 /** 19688 * The user marked the result as unhelpful. 19689 */ 19690 Unhelpful = 0, 19691 19692 /** 19693 * The user marked the result as helpful. 19694 */ 19695 Helpful = 1, 19696 } 19697 19698 /** 19699 * Represents user feedback for a result. 19700 */ 19701 export interface ChatResultFeedback { 19702 /** 19703 * The ChatResult for which the user is providing feedback. 19704 * This object has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance. 19705 */ 19706 readonly result: ChatResult; 19707 19708 /** 19709 * The kind of feedback that was received. 19710 */ 19711 readonly kind: ChatResultFeedbackKind; 19712 } 19713 19714 /** 19715 * A followup question suggested by the participant. 19716 */ 19717 export interface ChatFollowup { 19718 /** 19719 * The message to send to the chat. 19720 */ 19721 prompt: string; 19722 19723 /** 19724 * A title to show the user. The prompt will be shown by default, when this is unspecified. 19725 */ 19726 label?: string; 19727 19728 /** 19729 * By default, the followup goes to the same participant/command. But this property can be set to invoke a different participant by ID. 19730 * Followups can only invoke a participant that was contributed by the same extension. 19731 */ 19732 participant?: string; 19733 19734 /** 19735 * By default, the followup goes to the same participant/command. But this property can be set to invoke a different command. 19736 */ 19737 command?: string; 19738 } 19739 19740 /** 19741 * Will be invoked once after each request to get suggested followup questions to show the user. The user can click the followup to send it to the chat. 19742 */ 19743 export interface ChatFollowupProvider { 19744 /** 19745 * Provide followups for the given result. 19746 * 19747 * @param result This object has the same properties as the result returned from the participant callback, including `metadata`, but is not the same instance. 19748 * @param context Extra context passed to a participant. 19749 * @param token A cancellation token. 19750 */ 19751 provideFollowups(result: ChatResult, context: ChatContext, token: CancellationToken): ProviderResult<ChatFollowup[]>; 19752 } 19753 19754 /** 19755 * A chat request handler is a callback that will be invoked when a request is made to a chat participant. 19756 */ 19757 export type ChatRequestHandler = (request: ChatRequest, context: ChatContext, response: ChatResponseStream, token: CancellationToken) => ProviderResult<ChatResult | void>; 19758 19759 /** 19760 * A chat participant can be invoked by the user in a chat session, using the `@` prefix. When it is invoked, it handles the chat request and is solely 19761 * responsible for providing a response to the user. A ChatParticipant is created using {@link chat.createChatParticipant}. 19762 */ 19763 export interface ChatParticipant { 19764 /** 19765 * A unique ID for this participant. 19766 */ 19767 readonly id: string; 19768 19769 /** 19770 * An icon for the participant shown in UI. 19771 */ 19772 iconPath?: IconPath; 19773 19774 /** 19775 * The handler for requests to this participant. 19776 */ 19777 requestHandler: ChatRequestHandler; 19778 19779 /** 19780 * This provider will be called once after each request to retrieve suggested followup questions. 19781 */ 19782 followupProvider?: ChatFollowupProvider; 19783 19784 /** 19785 * An event that fires whenever feedback for a result is received, e.g. when a user up- or down-votes 19786 * a result. 19787 * 19788 * The passed {@link ChatResultFeedback.result result} is guaranteed to have the same properties as the result that was 19789 * previously returned from this chat participant's handler. 19790 */ 19791 readonly onDidReceiveFeedback: Event<ChatResultFeedback>; 19792 19793 /** 19794 * Dispose this participant and free resources. 19795 */ 19796 dispose(): void; 19797 } 19798 19799 /** 19800 * A reference to a value that the user added to their chat request. 19801 */ 19802 export interface ChatPromptReference { 19803 /** 19804 * A unique identifier for this kind of reference. 19805 */ 19806 readonly id: string; 19807 19808 /** 19809 * The start and end index of the reference in the {@link ChatRequest.prompt prompt}. When undefined, the reference was not part of the prompt text. 19810 * 19811 * *Note* that the indices take the leading `#`-character into account which means they can 19812 * used to modify the prompt as-is. 19813 */ 19814 readonly range?: [start: number, end: number]; 19815 19816 /** 19817 * A description of this value that could be used in an LLM prompt. 19818 */ 19819 readonly modelDescription?: string; 19820 19821 /** 19822 * The value of this reference. The `string | Uri | Location` types are used today, but this could expand in the future. 19823 */ 19824 readonly value: string | Uri | Location | unknown; 19825 } 19826 19827 /** 19828 * A request to a chat participant. 19829 */ 19830 export interface ChatRequest { 19831 /** 19832 * The prompt as entered by the user. 19833 * 19834 * Information about references used in this request is stored in {@link ChatRequest.references}. 19835 * 19836 * *Note* that the {@link ChatParticipant.name name} of the participant and the {@link ChatCommand.name command} 19837 * are not part of the prompt. 19838 */ 19839 readonly prompt: string; 19840 19841 /** 19842 * The name of the {@link ChatCommand command} that was selected for this request. 19843 */ 19844 readonly command: string | undefined; 19845 19846 /** 19847 * The list of references and their values that are referenced in the prompt. 19848 * 19849 * *Note* that the prompt contains references as authored and that it is up to the participant 19850 * to further modify the prompt, for instance by inlining reference values or creating links to 19851 * headings which contain the resolved values. References are sorted in reverse by their range 19852 * in the prompt. That means the last reference in the prompt is the first in this list. This simplifies 19853 * string-manipulation of the prompt. 19854 */ 19855 readonly references: readonly ChatPromptReference[]; 19856 19857 /** 19858 * The list of tools that the user attached to their request. 19859 * 19860 * When a tool reference is present, the chat participant should make a chat request using 19861 * {@link LanguageModelChatToolMode.Required} to force the language model to generate input for the tool. Then, the 19862 * participant can use {@link lm.invokeTool} to use the tool attach the result to its request for the user's prompt. The 19863 * tool may contribute useful extra context for the user's request. 19864 */ 19865 readonly toolReferences: readonly ChatLanguageModelToolReference[]; 19866 19867 /** 19868 * A token that can be passed to {@link lm.invokeTool} when invoking a tool inside the context of handling a chat request. 19869 * This associates the tool invocation to a chat session. 19870 */ 19871 readonly toolInvocationToken: ChatParticipantToolToken; 19872 19873 /** 19874 * This is the model that is currently selected in the UI. Extensions can use this or use {@link lm.selectChatModels} to 19875 * pick another model. Don't hold onto this past the lifetime of the request. 19876 */ 19877 readonly model: LanguageModelChat; 19878 } 19879 19880 /** 19881 * The ChatResponseStream is how a participant is able to return content to the chat view. It provides several methods for streaming different types of content 19882 * which will be rendered in an appropriate way in the chat view. A participant can use the helper method for the type of content it wants to return, or it 19883 * can instantiate a {@link ChatResponsePart} and use the generic {@link ChatResponseStream.push} method to return it. 19884 */ 19885 export interface ChatResponseStream { 19886 /** 19887 * Push a markdown part to this stream. Short-hand for 19888 * `push(new ChatResponseMarkdownPart(value))`. 19889 * 19890 * @see {@link ChatResponseStream.push} 19891 * @param value A markdown string or a string that should be interpreted as markdown. The boolean form of {@link MarkdownString.isTrusted} is NOT supported. 19892 */ 19893 markdown(value: string | MarkdownString): void; 19894 19895 /** 19896 * Push an anchor part to this stream. Short-hand for 19897 * `push(new ChatResponseAnchorPart(value, title))`. 19898 * An anchor is an inline reference to some type of resource. 19899 * 19900 * @param value A uri or location. 19901 * @param title An optional title that is rendered with value. 19902 */ 19903 anchor(value: Uri | Location, title?: string): void; 19904 19905 /** 19906 * Push a command button part to this stream. Short-hand for 19907 * `push(new ChatResponseCommandButtonPart(value, title))`. 19908 * 19909 * @param command A Command that will be executed when the button is clicked. 19910 */ 19911 button(command: Command): void; 19912 19913 /** 19914 * Push a filetree part to this stream. Short-hand for 19915 * `push(new ChatResponseFileTreePart(value))`. 19916 * 19917 * @param value File tree data. 19918 * @param baseUri The base uri to which this file tree is relative. 19919 */ 19920 filetree(value: ChatResponseFileTree[], baseUri: Uri): void; 19921 19922 /** 19923 * Push a progress part to this stream. Short-hand for 19924 * `push(new ChatResponseProgressPart(value))`. 19925 * 19926 * @param value A progress message 19927 */ 19928 progress(value: string): void; 19929 19930 /** 19931 * Push a reference to this stream. Short-hand for 19932 * `push(new ChatResponseReferencePart(value))`. 19933 * 19934 * *Note* that the reference is not rendered inline with the response. 19935 * 19936 * @param value A uri or location 19937 * @param iconPath Icon for the reference shown in UI 19938 */ 19939 reference(value: Uri | Location, iconPath?: IconPath): void; 19940 19941 /** 19942 * Pushes a part to this stream. 19943 * 19944 * @param part A response part, rendered or metadata 19945 */ 19946 push(part: ChatResponsePart): void; 19947 } 19948 19949 /** 19950 * Represents a part of a chat response that is formatted as Markdown. 19951 */ 19952 export class ChatResponseMarkdownPart { 19953 /** 19954 * A markdown string or a string that should be interpreted as markdown. 19955 */ 19956 value: MarkdownString; 19957 19958 /** 19959 * Create a new ChatResponseMarkdownPart. 19960 * 19961 * @param value A markdown string or a string that should be interpreted as markdown. The boolean form of {@link MarkdownString.isTrusted} is NOT supported. 19962 */ 19963 constructor(value: string | MarkdownString); 19964 } 19965 19966 /** 19967 * Represents a file tree structure in a chat response. 19968 */ 19969 export interface ChatResponseFileTree { 19970 /** 19971 * The name of the file or directory. 19972 */ 19973 name: string; 19974 19975 /** 19976 * An array of child file trees, if the current file tree is a directory. 19977 */ 19978 children?: ChatResponseFileTree[]; 19979 } 19980 19981 /** 19982 * Represents a part of a chat response that is a file tree. 19983 */ 19984 export class ChatResponseFileTreePart { 19985 /** 19986 * File tree data. 19987 */ 19988 value: ChatResponseFileTree[]; 19989 19990 /** 19991 * The base uri to which this file tree is relative 19992 */ 19993 baseUri: Uri; 19994 19995 /** 19996 * Create a new ChatResponseFileTreePart. 19997 * @param value File tree data. 19998 * @param baseUri The base uri to which this file tree is relative. 19999 */ 20000 constructor(value: ChatResponseFileTree[], baseUri: Uri); 20001 } 20002 20003 /** 20004 * Represents a part of a chat response that is an anchor, that is rendered as a link to a target. 20005 */ 20006 export class ChatResponseAnchorPart { 20007 /** 20008 * The target of this anchor. 20009 */ 20010 value: Uri | Location; 20011 20012 /** 20013 * An optional title that is rendered with value. 20014 */ 20015 title?: string; 20016 20017 /** 20018 * Create a new ChatResponseAnchorPart. 20019 * @param value A uri or location. 20020 * @param title An optional title that is rendered with value. 20021 */ 20022 constructor(value: Uri | Location, title?: string); 20023 } 20024 20025 /** 20026 * Represents a part of a chat response that is a progress message. 20027 */ 20028 export class ChatResponseProgressPart { 20029 /** 20030 * The progress message 20031 */ 20032 value: string; 20033 20034 /** 20035 * Create a new ChatResponseProgressPart. 20036 * @param value A progress message 20037 */ 20038 constructor(value: string); 20039 } 20040 20041 /** 20042 * Represents a part of a chat response that is a reference, rendered separately from the content. 20043 */ 20044 export class ChatResponseReferencePart { 20045 /** 20046 * The reference target. 20047 */ 20048 value: Uri | Location; 20049 20050 /** 20051 * The icon for the reference. 20052 */ 20053 iconPath?: IconPath; 20054 20055 /** 20056 * Create a new ChatResponseReferencePart. 20057 * @param value A uri or location 20058 * @param iconPath Icon for the reference shown in UI 20059 */ 20060 constructor(value: Uri | Location, iconPath?: IconPath); 20061 } 20062 20063 /** 20064 * Represents a part of a chat response that is a button that executes a command. 20065 */ 20066 export class ChatResponseCommandButtonPart { 20067 /** 20068 * The command that will be executed when the button is clicked. 20069 */ 20070 value: Command; 20071 20072 /** 20073 * Create a new ChatResponseCommandButtonPart. 20074 * @param value A Command that will be executed when the button is clicked. 20075 */ 20076 constructor(value: Command); 20077 } 20078 20079 /** 20080 * Represents the different chat response types. 20081 */ 20082 export type ChatResponsePart = ChatResponseMarkdownPart | ChatResponseFileTreePart | ChatResponseAnchorPart 20083 | ChatResponseProgressPart | ChatResponseReferencePart | ChatResponseCommandButtonPart; 20084 20085 20086 /** 20087 * Namespace for chat functionality. Users interact with chat participants by sending messages 20088 * to them in the chat view. Chat participants can respond with markdown or other types of content 20089 * via the {@link ChatResponseStream}. 20090 */ 20091 export namespace chat { 20092 /** 20093 * Create a new {@link ChatParticipant chat participant} instance. 20094 * 20095 * @param id A unique identifier for the participant. 20096 * @param handler A request handler for the participant. 20097 * @returns A new chat participant 20098 */ 20099 export function createChatParticipant(id: string, handler: ChatRequestHandler): ChatParticipant; 20100 } 20101 20102 /** 20103 * Represents the role of a chat message. This is either the user or the assistant. 20104 */ 20105 export enum LanguageModelChatMessageRole { 20106 /** 20107 * The user role, e.g the human interacting with a language model. 20108 */ 20109 User = 1, 20110 20111 /** 20112 * The assistant role, e.g. the language model generating responses. 20113 */ 20114 Assistant = 2 20115 } 20116 20117 /** 20118 * Represents a message in a chat. Can assume different roles, like user or assistant. 20119 */ 20120 export class LanguageModelChatMessage { 20121 20122 /** 20123 * Utility to create a new user message. 20124 * 20125 * @param content The content of the message. 20126 * @param name The optional name of a user for the message. 20127 */ 20128 static User(content: string | Array<LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelDataPart>, name?: string): LanguageModelChatMessage; 20129 20130 /** 20131 * Utility to create a new assistant message. 20132 * 20133 * @param content The content of the message. 20134 * @param name The optional name of a user for the message. 20135 */ 20136 static Assistant(content: string | Array<LanguageModelTextPart | LanguageModelToolCallPart | LanguageModelDataPart>, name?: string): LanguageModelChatMessage; 20137 20138 /** 20139 * The role of this message. 20140 */ 20141 role: LanguageModelChatMessageRole; 20142 20143 /** 20144 * A string or heterogeneous array of things that a message can contain as content. Some parts may be message-type 20145 * specific for some models. 20146 */ 20147 content: Array<LanguageModelInputPart>; 20148 20149 /** 20150 * The optional name of a user for this message. 20151 */ 20152 name: string | undefined; 20153 20154 /** 20155 * Create a new user message. 20156 * 20157 * @param role The role of the message. 20158 * @param content The content of the message. 20159 * @param name The optional name of a user for the message. 20160 */ 20161 constructor(role: LanguageModelChatMessageRole, content: string | Array<LanguageModelInputPart>, name?: string); 20162 } 20163 20164 /** 20165 * Represents a language model response. 20166 * 20167 * @see {@link ChatRequest} 20168 */ 20169 export interface LanguageModelChatResponse { 20170 20171 /** 20172 * An async iterable that is a stream of text and tool-call parts forming the overall response. A 20173 * {@link LanguageModelTextPart} is part of the assistant's response to be shown to the user. A 20174 * {@link LanguageModelToolCallPart} is a request from the language model to call a tool. The latter will 20175 * only be returned if tools were passed in the request via {@link LanguageModelChatRequestOptions.tools}. The 20176 * `unknown`-type is used as a placeholder for future parts, like image data parts. 20177 * 20178 * *Note* that this stream will error when during data receiving an error occurs. Consumers of the stream should handle 20179 * the errors accordingly. 20180 * 20181 * To cancel the stream, the consumer can {@link CancellationTokenSource.cancel cancel} the token that was used to make 20182 * the request or break from the for-loop. 20183 * 20184 * @example 20185 * ```ts 20186 * try { 20187 * // consume stream 20188 * for await (const chunk of response.stream) { 20189 * if (chunk instanceof LanguageModelTextPart) { 20190 * console.log("TEXT", chunk); 20191 * } else if (chunk instanceof LanguageModelToolCallPart) { 20192 * console.log("TOOL CALL", chunk); 20193 * } 20194 * } 20195 * 20196 * } catch(e) { 20197 * // stream ended with an error 20198 * console.error(e); 20199 * } 20200 * ``` 20201 */ 20202 stream: AsyncIterable<LanguageModelTextPart | LanguageModelToolCallPart | LanguageModelDataPart | unknown>; 20203 20204 /** 20205 * This is equivalent to filtering everything except for text parts from a {@link LanguageModelChatResponse.stream}. 20206 * 20207 * @see {@link LanguageModelChatResponse.stream} 20208 */ 20209 text: AsyncIterable<string>; 20210 } 20211 20212 /** 20213 * Represents a language model for making chat requests. 20214 * 20215 * @see {@link lm.selectChatModels} 20216 */ 20217 export interface LanguageModelChat { 20218 20219 /** 20220 * Human-readable name of the language model. 20221 */ 20222 readonly name: string; 20223 20224 /** 20225 * Opaque identifier of the language model. 20226 */ 20227 readonly id: string; 20228 20229 /** 20230 * A well-known identifier of the vendor of the language model. An example is `copilot`, but 20231 * values are defined by extensions contributing chat models and need to be looked up with them. 20232 */ 20233 readonly vendor: string; 20234 20235 /** 20236 * Opaque family-name of the language model. Values might be `gpt-3.5-turbo`, `gpt4`, `phi2`, or `llama` 20237 * but they are defined by extensions contributing languages and subject to change. 20238 */ 20239 readonly family: string; 20240 20241 /** 20242 * Opaque version string of the model. This is defined by the extension contributing the language model 20243 * and subject to change. 20244 */ 20245 readonly version: string; 20246 20247 /** 20248 * The maximum number of tokens that can be sent to the model in a single request. 20249 */ 20250 readonly maxInputTokens: number; 20251 20252 /** 20253 * Make a chat request using a language model. 20254 * 20255 * *Note* that language model use may be subject to access restrictions and user consent. Calling this function 20256 * for the first time (for an extension) will show a consent dialog to the user and because of that this function 20257 * must _only be called in response to a user action!_ Extensions can use {@link LanguageModelAccessInformation.canSendRequest} 20258 * to check if they have the necessary permissions to make a request. 20259 * 20260 * This function will return a rejected promise if making a request to the language model is not 20261 * possible. Reasons for this can be: 20262 * 20263 * - user consent not given, see {@link LanguageModelError.NoPermissions `NoPermissions`} 20264 * - model does not exist anymore, see {@link LanguageModelError.NotFound `NotFound`} 20265 * - quota limits exceeded, see {@link LanguageModelError.Blocked `Blocked`} 20266 * - other issues in which case extension must check {@link LanguageModelError.cause `LanguageModelError.cause`} 20267 * 20268 * An extension can make use of language model tool calling by passing a set of tools to 20269 * {@link LanguageModelChatRequestOptions.tools}. The language model will return a {@link LanguageModelToolCallPart} and 20270 * the extension can invoke the tool and make another request with the result. 20271 * 20272 * @param messages An array of message instances. 20273 * @param options Options that control the request. 20274 * @param token A cancellation token which controls the request. See {@link CancellationTokenSource} for how to create one. 20275 * @returns A thenable that resolves to a {@link LanguageModelChatResponse}. The promise will reject when the request couldn't be made. 20276 */ 20277 sendRequest(messages: LanguageModelChatMessage[], options?: LanguageModelChatRequestOptions, token?: CancellationToken): Thenable<LanguageModelChatResponse>; 20278 20279 /** 20280 * Count the number of tokens in a message using the model specific tokenizer-logic. 20281 20282 * @param text A string or a message instance. 20283 * @param token Optional cancellation token. See {@link CancellationTokenSource} for how to create one. 20284 * @returns A thenable that resolves to the number of tokens. 20285 */ 20286 countTokens(text: string | LanguageModelChatMessage, token?: CancellationToken): Thenable<number>; 20287 } 20288 20289 /** 20290 * Describes how to select language models for chat requests. 20291 * 20292 * @see {@link lm.selectChatModels} 20293 */ 20294 export interface LanguageModelChatSelector { 20295 20296 /** 20297 * A vendor of language models. 20298 * @see {@link LanguageModelChat.vendor} 20299 */ 20300 vendor?: string; 20301 20302 /** 20303 * A family of language models. 20304 * @see {@link LanguageModelChat.family} 20305 */ 20306 family?: string; 20307 20308 /** 20309 * The version of a language model. 20310 * @see {@link LanguageModelChat.version} 20311 */ 20312 version?: string; 20313 20314 /** 20315 * The identifier of a language model. 20316 * @see {@link LanguageModelChat.id} 20317 */ 20318 id?: string; 20319 } 20320 20321 /** 20322 * An error type for language model specific errors. 20323 * 20324 * Consumers of language models should check the code property to determine specific 20325 * failure causes, like `if(someError.code === vscode.LanguageModelError.NotFound.name) {...}` 20326 * for the case of referring to an unknown language model. For unspecified errors the `cause`-property 20327 * will contain the actual error. 20328 */ 20329 export class LanguageModelError extends Error { 20330 20331 /** 20332 * The requestor does not have permissions to use this 20333 * language model 20334 */ 20335 static NoPermissions(message?: string): LanguageModelError; 20336 20337 /** 20338 * The requestor is blocked from using this language model. 20339 */ 20340 static Blocked(message?: string): LanguageModelError; 20341 20342 /** 20343 * The language model does not exist. 20344 */ 20345 static NotFound(message?: string): LanguageModelError; 20346 20347 /** 20348 * A code that identifies this error. 20349 * 20350 * Possible values are names of errors, like {@linkcode LanguageModelError.NotFound NotFound}, 20351 * or `Unknown` for unspecified errors from the language model itself. In the latter case the 20352 * `cause`-property will contain the actual error. 20353 */ 20354 readonly code: string; 20355 } 20356 20357 /** 20358 * Options for making a chat request using a language model. 20359 * 20360 * @see {@link LanguageModelChat.sendRequest} 20361 */ 20362 export interface LanguageModelChatRequestOptions { 20363 20364 /** 20365 * A human-readable message that explains why access to a language model is needed and what feature is enabled by it. 20366 */ 20367 justification?: string; 20368 20369 /** 20370 * A set of options that control the behavior of the language model. These options are specific to the language model 20371 * and need to be looked up in the respective documentation. 20372 */ 20373 modelOptions?: { [name: string]: any }; 20374 20375 /** 20376 * An optional list of tools that are available to the language model. These could be registered tools available via 20377 * {@link lm.tools}, or private tools that are just implemented within the calling extension. 20378 * 20379 * If the LLM requests to call one of these tools, it will return a {@link LanguageModelToolCallPart} in 20380 * {@link LanguageModelChatResponse.stream}. It's the caller's responsibility to invoke the tool. If it's a tool 20381 * registered in {@link lm.tools}, that means calling {@link lm.invokeTool}. 20382 * 20383 * Then, the tool result can be provided to the LLM by creating an Assistant-type {@link LanguageModelChatMessage} with a 20384 * {@link LanguageModelToolCallPart}, followed by a User-type message with a {@link LanguageModelToolResultPart}. 20385 */ 20386 tools?: LanguageModelChatTool[]; 20387 20388 /** 20389 * The tool-selecting mode to use. {@link LanguageModelChatToolMode.Auto} by default. 20390 */ 20391 toolMode?: LanguageModelChatToolMode; 20392 } 20393 20394 /** 20395 * McpStdioServerDefinition represents an MCP server available by running 20396 * a local process and operating on its stdin and stdout streams. The process 20397 * will be spawned as a child process of the extension host and by default 20398 * will not run in a shell environment. 20399 */ 20400 export class McpStdioServerDefinition { 20401 /** 20402 * The human-readable name of the server. 20403 */ 20404 readonly label: string; 20405 20406 /** 20407 * The working directory used to start the server. 20408 */ 20409 cwd?: Uri; 20410 20411 /** 20412 * The command used to start the server. Node.js-based servers may use 20413 * `process.execPath` to use the editor's version of Node.js to run the script. 20414 */ 20415 command: string; 20416 20417 /** 20418 * Additional command-line arguments passed to the server. 20419 */ 20420 args: string[]; 20421 20422 /** 20423 * Optional additional environment information for the server. Variables 20424 * in this environment will overwrite or remove (if null) the default 20425 * environment variables of the editor's extension host. 20426 */ 20427 env: Record<string, string | number | null>; 20428 20429 /** 20430 * Optional version identification for the server. If this changes, the 20431 * editor will indicate that tools have changed and prompt to refresh them. 20432 */ 20433 version?: string; 20434 20435 /** 20436 * @param label The human-readable name of the server. 20437 * @param command The command used to start the server. 20438 * @param args Additional command-line arguments passed to the server. 20439 * @param env Optional additional environment information for the server. 20440 * @param version Optional version identification for the server. 20441 */ 20442 constructor(label: string, command: string, args?: string[], env?: Record<string, string | number | null>, version?: string); 20443 } 20444 20445 /** 20446 * McpHttpServerDefinition represents an MCP server available using the 20447 * Streamable HTTP transport. 20448 */ 20449 export class McpHttpServerDefinition { 20450 /** 20451 * The human-readable name of the server. 20452 */ 20453 readonly label: string; 20454 20455 /** 20456 * The URI of the server. The editor will make a POST request to this URI 20457 * to begin each session. 20458 */ 20459 uri: Uri; 20460 20461 /** 20462 * Optional additional heads included with each request to the server. 20463 */ 20464 headers: Record<string, string>; 20465 20466 /** 20467 * Optional version identification for the server. If this changes, the 20468 * editor will indicate that tools have changed and prompt to refresh them. 20469 */ 20470 version?: string; 20471 20472 /** 20473 * @param label The human-readable name of the server. 20474 * @param uri The URI of the server. 20475 * @param headers Optional additional heads included with each request to the server. 20476 */ 20477 constructor(label: string, uri: Uri, headers?: Record<string, string>, version?: string); 20478 } 20479 20480 /** 20481 * Definitions that describe different types of Model Context Protocol servers, 20482 * which can be returned from the {@link McpServerDefinitionProvider}. 20483 */ 20484 export type McpServerDefinition = McpStdioServerDefinition | McpHttpServerDefinition; 20485 20486 /** 20487 * A type that can provide Model Context Protocol server definitions. This 20488 * should be registered using {@link lm.registerMcpServerDefinitionProvider} 20489 * during extension activation. 20490 */ 20491 export interface McpServerDefinitionProvider<T extends McpServerDefinition = McpServerDefinition> { 20492 /** 20493 * Optional event fired to signal that the set of available servers has changed. 20494 */ 20495 readonly onDidChangeMcpServerDefinitions?: Event<void>; 20496 20497 /** 20498 * Provides available MCP servers. The editor will call this method eagerly 20499 * to ensure the availability of servers for the language model, and so 20500 * extensions should not take actions which would require user 20501 * interaction, such as authentication. 20502 * 20503 * @param token A cancellation token. 20504 * @returns An array of MCP available MCP servers 20505 */ 20506 provideMcpServerDefinitions(token: CancellationToken): ProviderResult<T[]>; 20507 20508 /** 20509 * This function will be called when the editor needs to start a MCP server. 20510 * At this point, the extension may take any actions which may require user 20511 * interaction, such as authentication. Any non-`readonly` property of the 20512 * server may be modified, and the extension should return the resolved server. 20513 * 20514 * The extension may return undefined to indicate that the server 20515 * should not be started, or throw an error. If there is a pending tool 20516 * call, the editor will cancel it and return an error message to the 20517 * language model. 20518 * 20519 * @param server The MCP server to resolve 20520 * @param token A cancellation token. 20521 * @returns The resolved server or thenable that resolves to such. This may 20522 * be the given `server` definition with non-readonly properties filled in. 20523 */ 20524 resolveMcpServerDefinition?(server: T, token: CancellationToken): ProviderResult<T>; 20525 } 20526 20527 /** 20528 * The provider version of {@linkcode LanguageModelChatRequestOptions} 20529 */ 20530 export interface ProvideLanguageModelChatResponseOptions { 20531 /** 20532 * A set of options that control the behavior of the language model. These options are specific to the language model. 20533 */ 20534 readonly modelOptions?: { readonly [name: string]: any }; 20535 20536 /** 20537 * An optional list of tools that are available to the language model. These could be registered tools available via 20538 * {@link lm.tools}, or private tools that are just implemented within the calling extension. 20539 * 20540 * If the LLM requests to call one of these tools, it will return a {@link LanguageModelToolCallPart} in 20541 * {@link LanguageModelChatResponse.stream}. It's the caller's responsibility to invoke the tool. If it's a tool 20542 * registered in {@link lm.tools}, that means calling {@link lm.invokeTool}. 20543 * 20544 * Then, the tool result can be provided to the LLM by creating an Assistant-type {@link LanguageModelChatMessage} with a 20545 * {@link LanguageModelToolCallPart}, followed by a User-type message with a {@link LanguageModelToolResultPart}. 20546 */ 20547 readonly tools?: readonly LanguageModelChatTool[]; 20548 20549 /** 20550 * The tool-selecting mode to use. The provider must implement respecting this. 20551 */ 20552 readonly toolMode: LanguageModelChatToolMode; 20553 } 20554 20555 /** 20556 * Represents a language model provided by a {@linkcode LanguageModelChatProvider}. 20557 */ 20558 export interface LanguageModelChatInformation { 20559 20560 /** 20561 * Unique identifier for the language model. Must be unique per provider, but not required to be globally unique. 20562 */ 20563 readonly id: string; 20564 20565 /** 20566 * Human-readable name of the language model. 20567 */ 20568 readonly name: string; 20569 20570 /** 20571 * Opaque family-name of the language model. Values might be `gpt-3.5-turbo`, `gpt4`, `phi2`, or `llama` 20572 */ 20573 readonly family: string; 20574 20575 /** 20576 * The tooltip to render when hovering the model. Used to provide more information about the model. 20577 */ 20578 readonly tooltip?: string; 20579 20580 /** 20581 * An optional, human-readable string which will be rendered alongside the model. 20582 * Useful for distinguishing models of the same name in the UI. 20583 */ 20584 readonly detail?: string; 20585 20586 /** 20587 * Opaque version string of the model. 20588 * This is used as a lookup value in {@linkcode LanguageModelChatSelector.version} 20589 * An example is how GPT 4o has multiple versions like 2024-11-20 and 2024-08-06 20590 */ 20591 readonly version: string; 20592 20593 /** 20594 * The maximum number of tokens the model can accept as input. 20595 */ 20596 readonly maxInputTokens: number; 20597 20598 /** 20599 * The maximum number of tokens the model is capable of producing. 20600 */ 20601 readonly maxOutputTokens: number; 20602 20603 /** 20604 * Various features that the model supports such as tool calling or image input. 20605 */ 20606 readonly capabilities: LanguageModelChatCapabilities; 20607 } 20608 20609 /** 20610 * Various features that the {@link LanguageModelChatInformation} supports such as tool calling or image input. 20611 */ 20612 export interface LanguageModelChatCapabilities { 20613 /** 20614 * Whether image input is supported by the model. 20615 * Common supported images are jpg and png, but each model will vary in supported mimetypes. 20616 */ 20617 readonly imageInput?: boolean; 20618 20619 /** 20620 * Whether tool calling is supported by the model. 20621 * If a number is provided, that is the maximum number of tools that can be provided in a request to the model. 20622 */ 20623 readonly toolCalling?: boolean | number; 20624 } 20625 20626 /** 20627 * The provider version of {@linkcode LanguageModelChatMessage}. 20628 */ 20629 export interface LanguageModelChatRequestMessage { 20630 /** 20631 * The role of this message. 20632 */ 20633 readonly role: LanguageModelChatMessageRole; 20634 20635 /** 20636 * A heterogeneous array of things that a message can contain as content. Some parts may be message-type 20637 * specific for some models. 20638 */ 20639 readonly content: ReadonlyArray<LanguageModelInputPart | unknown>; 20640 20641 /** 20642 * The optional name of a user for this message. 20643 */ 20644 readonly name: string | undefined; 20645 } 20646 20647 /** 20648 * The various message types which a {@linkcode LanguageModelChatProvider} can emit in the chat response stream 20649 */ 20650 export type LanguageModelResponsePart = LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart | LanguageModelDataPart; 20651 20652 /** 20653 * The various message types which can be sent via {@linkcode LanguageModelChat.sendRequest } and processed by a {@linkcode LanguageModelChatProvider} 20654 */ 20655 export type LanguageModelInputPart = LanguageModelTextPart | LanguageModelToolResultPart | LanguageModelToolCallPart | LanguageModelDataPart; 20656 20657 /** 20658 * A LanguageModelChatProvider implements access to language models, which users can then use through the chat view, or through extension API by acquiring a LanguageModelChat. 20659 * An example of this would be an OpenAI provider that provides models like gpt-5, o3, etc. 20660 */ 20661 export interface LanguageModelChatProvider<T extends LanguageModelChatInformation = LanguageModelChatInformation> { 20662 20663 /** 20664 * An optional event fired when the available set of language models changes. 20665 */ 20666 readonly onDidChangeLanguageModelChatInformation?: Event<void>; 20667 20668 /** 20669 * Get the list of available language models provided by this provider 20670 * @param options Options which specify the calling context of this function 20671 * @param token A cancellation token 20672 * @returns The list of available language models 20673 */ 20674 provideLanguageModelChatInformation(options: PrepareLanguageModelChatModelOptions, token: CancellationToken): ProviderResult<T[]>; 20675 20676 /** 20677 * Returns the response for a chat request, passing the results to the progress callback. 20678 * The {@linkcode LanguageModelChatProvider} must emit the response parts to the progress callback as they are received from the language model. 20679 * @param model The language model to use 20680 * @param messages The messages to include in the request 20681 * @param options Options for the request 20682 * @param progress The progress to emit the streamed response chunks to 20683 * @param token A cancellation token 20684 * @returns A promise that resolves when the response is complete. Results are actually passed to the progress callback. 20685 */ 20686 provideLanguageModelChatResponse(model: T, messages: readonly LanguageModelChatRequestMessage[], options: ProvideLanguageModelChatResponseOptions, progress: Progress<LanguageModelResponsePart>, token: CancellationToken): Thenable<void>; 20687 20688 /** 20689 * Returns the number of tokens for a given text using the model-specific tokenizer logic 20690 * @param model The language model to use 20691 * @param text The text to count tokens for 20692 * @param token A cancellation token 20693 * @returns The number of tokens 20694 */ 20695 provideTokenCount(model: T, text: string | LanguageModelChatRequestMessage, token: CancellationToken): Thenable<number>; 20696 } 20697 20698 /** 20699 * The list of options passed into {@linkcode LanguageModelChatProvider.provideLanguageModelChatInformation} 20700 */ 20701 export interface PrepareLanguageModelChatModelOptions { 20702 /** 20703 * Whether or not the user should be prompted via some UI flow, or if models should be attempted to be resolved silently. 20704 * If silent is true, all models may not be resolved due to lack of info such as API keys. 20705 */ 20706 readonly silent: boolean; 20707 } 20708 20709 /** 20710 * Namespace for language model related functionality. 20711 */ 20712 export namespace lm { 20713 20714 /** 20715 * An event that is fired when the set of available chat models changes. 20716 */ 20717 export const onDidChangeChatModels: Event<void>; 20718 20719 /** 20720 * Select chat models by a {@link LanguageModelChatSelector selector}. This can yield multiple or no chat models and 20721 * extensions must handle these cases, esp. when no chat model exists, gracefully. 20722 * 20723 * ```ts 20724 * const models = await vscode.lm.selectChatModels({ family: 'gpt-3.5-turbo' }); 20725 * if (models.length > 0) { 20726 * const [first] = models; 20727 * const response = await first.sendRequest(...) 20728 * // ... 20729 * } else { 20730 * // NO chat models available 20731 * } 20732 * ``` 20733 * 20734 * A selector can be written to broadly match all models of a given vendor or family, or it can narrowly select one model by ID. 20735 * Keep in mind that the available set of models will change over time, but also that prompts may perform differently in 20736 * different models. 20737 * 20738 * *Note* that extensions can hold on to the results returned by this function and use them later. However, when the 20739 * {@link onDidChangeChatModels}-event is fired the list of chat models might have changed and extensions should re-query. 20740 * 20741 * @param selector A chat model selector. When omitted all chat models are returned. 20742 * @returns An array of chat models, can be empty! 20743 */ 20744 export function selectChatModels(selector?: LanguageModelChatSelector): Thenable<LanguageModelChat[]>; 20745 20746 /** 20747 * Register a LanguageModelTool. The tool must also be registered in the package.json `languageModelTools` contribution 20748 * point. A registered tool is available in the {@link lm.tools} list for any extension to see. But in order for it to 20749 * be seen by a language model, it must be passed in the list of available tools in {@link LanguageModelChatRequestOptions.tools}. 20750 * @returns A {@link Disposable} that unregisters the tool when disposed. 20751 */ 20752 export function registerTool<T>(name: string, tool: LanguageModelTool<T>): Disposable; 20753 20754 /** 20755 * A list of all available tools that were registered by all extensions using {@link lm.registerTool}. They can be called 20756 * with {@link lm.invokeTool} with input that match their declared `inputSchema`. 20757 */ 20758 export const tools: readonly LanguageModelToolInformation[]; 20759 20760 /** 20761 * Invoke a tool listed in {@link lm.tools} by name with the given input. The input will be validated against 20762 * the schema declared by the tool 20763 * 20764 * A tool can be invoked by a chat participant, in the context of handling a chat request, or globally by any extension in 20765 * any custom flow. 20766 * 20767 * In the former case, the caller shall pass the 20768 * {@link LanguageModelToolInvocationOptions.toolInvocationToken toolInvocationToken}, which comes from a 20769 * {@link ChatRequest.toolInvocationToken chat request}. This makes sure the chat UI shows the tool invocation for the 20770 * correct conversation. 20771 * 20772 * A tool {@link LanguageModelToolResult result} is an array of {@link LanguageModelTextPart text-} and 20773 * {@link LanguageModelPromptTsxPart prompt-tsx}-parts. If the tool caller is using `@vscode/prompt-tsx`, it can 20774 * incorporate the response parts into its prompt using a `ToolResult`. If not, the parts can be passed along to the 20775 * {@link LanguageModelChat} via a user message with a {@link LanguageModelToolResultPart}. 20776 * 20777 * If a chat participant wants to preserve tool results for requests across multiple turns, it can store tool results in 20778 * the {@link ChatResult.metadata} returned from the handler and retrieve them on the next turn from 20779 * {@link ChatResponseTurn.result}. 20780 * 20781 * @param name The name of the tool to call. 20782 * @param options The options to use when invoking the tool. 20783 * @param token A cancellation token. See {@link CancellationTokenSource} for how to create one. 20784 * @returns The result of the tool invocation. 20785 */ 20786 export function invokeTool(name: string, options: LanguageModelToolInvocationOptions<object>, token?: CancellationToken): Thenable<LanguageModelToolResult>; 20787 20788 /** 20789 * Registers a provider that publishes Model Context Protocol servers for the editor to 20790 * consume. This allows MCP servers to be dynamically provided to the editor in 20791 * addition to those the user creates in their configuration files. 20792 * 20793 * Before calling this method, extensions must register the `contributes.mcpServerDefinitionProviders` 20794 * extension point with the corresponding {@link id}, for example: 20795 * 20796 * ```js 20797 * "contributes": { 20798 * "mcpServerDefinitionProviders": [ 20799 * { 20800 * "id": "cool-cloud-registry.mcp-servers", 20801 * "label": "Cool Cloud Registry", 20802 * } 20803 * ] 20804 * } 20805 * ``` 20806 * 20807 * When a new McpServerDefinitionProvider is available, the editor will, by default, 20808 * automatically invoke it to discover new servers and tools when a chat message is 20809 * submitted. To enable this flow, extensions should call 20810 * `registerMcpServerDefinitionProvider` during activation. 20811 * 20812 * @param id The ID of the provider, which is unique to the extension. 20813 * @param provider The provider to register 20814 * @returns A disposable that unregisters the provider when disposed. 20815 */ 20816 export function registerMcpServerDefinitionProvider(id: string, provider: McpServerDefinitionProvider): Disposable; 20817 20818 /** 20819 * Registers a {@linkcode LanguageModelChatProvider} 20820 * Note: You must also define the language model chat provider via the `languageModelChatProviders` contribution point in package.json 20821 * @param vendor The vendor for this provider. Must be globally unique. An example is `copilot` or `openai`. 20822 * @param provider The provider to register 20823 * @returns A disposable that unregisters the provider when disposed 20824 */ 20825 export function registerLanguageModelChatProvider(vendor: string, provider: LanguageModelChatProvider): Disposable; 20826 } 20827 20828 /** 20829 * Represents extension specific information about the access to language models. 20830 */ 20831 export interface LanguageModelAccessInformation { 20832 20833 /** 20834 * An event that fires when access information changes. 20835 */ 20836 readonly onDidChange: Event<void>; 20837 20838 /** 20839 * Checks if a request can be made to a language model. 20840 * 20841 * *Note* that calling this function will not trigger a consent UI but just checks for a persisted state. 20842 * 20843 * @param chat A language model chat object. 20844 * @return `true` if a request can be made, `false` if not, `undefined` if the language 20845 * model does not exist or consent hasn't been asked for. 20846 */ 20847 canSendRequest(chat: LanguageModelChat): boolean | undefined; 20848 } 20849 20850 /** 20851 * A tool that is available to the language model via {@link LanguageModelChatRequestOptions}. A language model uses all the 20852 * properties of this interface to decide which tool to call, and how to call it. 20853 */ 20854 export interface LanguageModelChatTool { 20855 /** 20856 * The name of the tool. 20857 */ 20858 name: string; 20859 20860 /** 20861 * The description of the tool. 20862 */ 20863 description: string; 20864 20865 /** 20866 * A JSON schema for the input this tool accepts. 20867 */ 20868 inputSchema?: object | undefined; 20869 } 20870 20871 /** 20872 * A tool-calling mode for the language model to use. 20873 */ 20874 export enum LanguageModelChatToolMode { 20875 /** 20876 * The language model can choose to call a tool or generate a message. Is the default. 20877 */ 20878 Auto = 1, 20879 20880 /** 20881 * The language model must call one of the provided tools. Note- some models only support a single tool when using this 20882 * mode. 20883 */ 20884 Required = 2 20885 } 20886 20887 /** 20888 * A language model response part indicating a tool call, returned from a {@link LanguageModelChatResponse}, and also can be 20889 * included as a content part on a {@link LanguageModelChatMessage}, to represent a previous tool call in a chat request. 20890 */ 20891 export class LanguageModelToolCallPart { 20892 /** 20893 * The ID of the tool call. This is a unique identifier for the tool call within the chat request. 20894 */ 20895 callId: string; 20896 20897 /** 20898 * The name of the tool to call. 20899 */ 20900 name: string; 20901 20902 /** 20903 * The input with which to call the tool. 20904 */ 20905 input: object; 20906 20907 /** 20908 * Create a new LanguageModelToolCallPart. 20909 * 20910 * @param callId The ID of the tool call. 20911 * @param name The name of the tool to call. 20912 * @param input The input with which to call the tool. 20913 */ 20914 constructor(callId: string, name: string, input: object); 20915 } 20916 20917 /** 20918 * The result of a tool call. This is the counterpart of a {@link LanguageModelToolCallPart tool call} and 20919 * it can only be included in the content of a User message 20920 */ 20921 export class LanguageModelToolResultPart { 20922 /** 20923 * The ID of the tool call. 20924 * 20925 * *Note* that this should match the {@link LanguageModelToolCallPart.callId callId} of a tool call part. 20926 */ 20927 callId: string; 20928 20929 /** 20930 * The value of the tool result. 20931 */ 20932 content: Array<LanguageModelTextPart | LanguageModelPromptTsxPart | LanguageModelDataPart | unknown>; 20933 20934 /** 20935 * @param callId The ID of the tool call. 20936 * @param content The content of the tool result. 20937 */ 20938 constructor(callId: string, content: Array<LanguageModelTextPart | LanguageModelPromptTsxPart | LanguageModelDataPart | unknown>); 20939 } 20940 20941 /** 20942 * A language model response part containing a piece of text, returned from a {@link LanguageModelChatResponse}. 20943 */ 20944 export class LanguageModelTextPart { 20945 /** 20946 * The text content of the part. 20947 */ 20948 value: string; 20949 20950 /** 20951 * Construct a text part with the given content. 20952 * @param value The text content of the part. 20953 */ 20954 constructor(value: string); 20955 } 20956 20957 /** 20958 * A language model response part containing a PromptElementJSON from `@vscode/prompt-tsx`. 20959 * @see {@link LanguageModelToolResult} 20960 */ 20961 export class LanguageModelPromptTsxPart { 20962 /** 20963 * The value of the part. 20964 */ 20965 value: unknown; 20966 20967 /** 20968 * Construct a prompt-tsx part with the given content. 20969 * @param value The value of the part, the result of `renderElementJSON` from `@vscode/prompt-tsx`. 20970 */ 20971 constructor(value: unknown); 20972 } 20973 20974 /** 20975 * A result returned from a tool invocation. If using `@vscode/prompt-tsx`, this result may be rendered using a `ToolResult`. 20976 */ 20977 export class LanguageModelToolResult { 20978 /** 20979 * A list of tool result content parts. Includes `unknown` because this list may be extended with new content types in 20980 * the future. 20981 * @see {@link lm.invokeTool}. 20982 */ 20983 content: Array<LanguageModelTextPart | LanguageModelPromptTsxPart | LanguageModelDataPart | unknown>; 20984 20985 /** 20986 * Create a LanguageModelToolResult 20987 * @param content A list of tool result content parts 20988 */ 20989 constructor(content: Array<LanguageModelTextPart | LanguageModelPromptTsxPart | LanguageModelDataPart | unknown>); 20990 } 20991 20992 /** 20993 * A language model response part containing arbitrary data. Can be used in {@link LanguageModelChatResponse responses}, 20994 * {@link LanguageModelChatMessage chat messages}, {@link LanguageModelToolResult tool results}, and other language model interactions. 20995 */ 20996 export class LanguageModelDataPart { 20997 /** 20998 * Create a new {@linkcode LanguageModelDataPart} for an image. 20999 * @param data Binary image data 21000 * @param mime The MIME type of the image. Common values are `image/png` and `image/jpeg`. 21001 */ 21002 static image(data: Uint8Array, mime: string): LanguageModelDataPart; 21003 21004 /** 21005 * Create a new {@linkcode LanguageModelDataPart} for a json. 21006 * 21007 * *Note* that this function is not expecting "stringified JSON" but 21008 * an object that can be stringified. This function will throw an error 21009 * when the passed value cannot be JSON-stringified. 21010 * @param value A JSON-stringifyable value. 21011 * @param mime Optional MIME type, defaults to `application/json` 21012 */ 21013 static json(value: any, mime?: string): LanguageModelDataPart; 21014 21015 /** 21016 * Create a new {@linkcode LanguageModelDataPart} for text. 21017 * 21018 * *Note* that an UTF-8 encoder is used to create bytes for the string. 21019 * @param value Text data 21020 * @param mime The MIME type if any. Common values are `text/plain` and `text/markdown`. 21021 */ 21022 static text(value: string, mime?: string): LanguageModelDataPart; 21023 21024 /** 21025 * The mime type which determines how the data property is interpreted. 21026 */ 21027 mimeType: string; 21028 21029 /** 21030 * The byte data for this part. 21031 */ 21032 data: Uint8Array; 21033 21034 /** 21035 * Construct a generic data part with the given content. 21036 * @param data The byte data for this part. 21037 * @param mimeType The mime type of the data. 21038 */ 21039 constructor(data: Uint8Array, mimeType: string); 21040 } 21041 21042 /** 21043 * A token that can be passed to {@link lm.invokeTool} when invoking a tool inside the context of handling a chat request. 21044 */ 21045 export type ChatParticipantToolToken = never; 21046 21047 /** 21048 * Options provided for tool invocation. 21049 */ 21050 export interface LanguageModelToolInvocationOptions<T> { 21051 /** 21052 * An opaque object that ties a tool invocation to a chat request from a {@link ChatParticipant chat participant}. 21053 * 21054 * The _only_ way to get a valid tool invocation token is using the provided {@link ChatRequest.toolInvocationToken toolInvocationToken} 21055 * from a chat request. In that case, a progress bar will be automatically shown for the tool invocation in the chat response view, and if 21056 * the tool requires user confirmation, it will show up inline in the chat view. 21057 * 21058 * If the tool is being invoked outside of a chat request, `undefined` should be passed instead, and no special UI except for 21059 * confirmations will be shown. 21060 * 21061 * *Note* that a tool that invokes another tool during its invocation, can pass along the `toolInvocationToken` that it received. 21062 */ 21063 toolInvocationToken: ChatParticipantToolToken | undefined; 21064 21065 /** 21066 * The input with which to invoke the tool. The input must match the schema defined in 21067 * {@link LanguageModelToolInformation.inputSchema} 21068 */ 21069 input: T; 21070 21071 /** 21072 * Options to hint at how many tokens the tool should return in its response, and enable the tool to count tokens 21073 * accurately. 21074 */ 21075 tokenizationOptions?: LanguageModelToolTokenizationOptions; 21076 } 21077 21078 /** 21079 * Options related to tokenization for a tool invocation. 21080 */ 21081 export interface LanguageModelToolTokenizationOptions { 21082 /** 21083 * If known, the maximum number of tokens the tool should emit in its result. 21084 */ 21085 tokenBudget: number; 21086 21087 /** 21088 * Count the number of tokens in a message using the model specific tokenizer-logic. 21089 * @param text A string. 21090 * @param token Optional cancellation token. See {@link CancellationTokenSource} for how to create one. 21091 * @returns A thenable that resolves to the number of tokens. 21092 */ 21093 countTokens(text: string, token?: CancellationToken): Thenable<number>; 21094 } 21095 21096 /** 21097 * Information about a registered tool available in {@link lm.tools}. 21098 */ 21099 export interface LanguageModelToolInformation { 21100 /** 21101 * A unique name for the tool. 21102 */ 21103 readonly name: string; 21104 21105 /** 21106 * A description of this tool that may be passed to a language model. 21107 */ 21108 readonly description: string; 21109 21110 /** 21111 * A JSON schema for the input this tool accepts. 21112 */ 21113 readonly inputSchema: object | undefined; 21114 21115 /** 21116 * A set of tags, declared by the tool, that roughly describe the tool's capabilities. A tool user may use these to filter 21117 * the set of tools to just ones that are relevant for the task at hand. 21118 */ 21119 readonly tags: readonly string[]; 21120 } 21121 21122 /** 21123 * Options for {@link LanguageModelTool.prepareInvocation}. 21124 */ 21125 export interface LanguageModelToolInvocationPrepareOptions<T> { 21126 /** 21127 * The input that the tool is being invoked with. 21128 */ 21129 input: T; 21130 } 21131 21132 /** 21133 * A tool that can be invoked by a call to a {@link LanguageModelChat}. 21134 */ 21135 export interface LanguageModelTool<T> { 21136 /** 21137 * Invoke the tool with the given input and return a result. 21138 * 21139 * The provided {@link LanguageModelToolInvocationOptions.input} has been validated against the declared schema. 21140 */ 21141 invoke(options: LanguageModelToolInvocationOptions<T>, token: CancellationToken): ProviderResult<LanguageModelToolResult>; 21142 21143 /** 21144 * Called once before a tool is invoked. It's recommended to implement this to customize the progress message that appears 21145 * while the tool is running, and to provide a more useful message with context from the invocation input. Can also 21146 * signal that a tool needs user confirmation before running, if appropriate. 21147 * 21148 * * *Note 1:* Must be free of side-effects. 21149 * * *Note 2:* A call to `prepareInvocation` is not necessarily followed by a call to `invoke`. 21150 */ 21151 prepareInvocation?(options: LanguageModelToolInvocationPrepareOptions<T>, token: CancellationToken): ProviderResult<PreparedToolInvocation>; 21152 } 21153 21154 /** 21155 * When this is returned in {@link PreparedToolInvocation}, the user will be asked to confirm before running the tool. These 21156 * messages will be shown with buttons that say "Continue" and "Cancel". 21157 */ 21158 export interface LanguageModelToolConfirmationMessages { 21159 /** 21160 * The title of the confirmation message. 21161 */ 21162 title: string; 21163 21164 /** 21165 * The body of the confirmation message. 21166 */ 21167 message: string | MarkdownString; 21168 } 21169 21170 /** 21171 * The result of a call to {@link LanguageModelTool.prepareInvocation}. 21172 */ 21173 export interface PreparedToolInvocation { 21174 /** 21175 * A customized progress message to show while the tool runs. 21176 */ 21177 invocationMessage?: string | MarkdownString; 21178 21179 /** 21180 * The presence of this property indicates that the user should be asked to confirm before running the tool. The user 21181 * should be asked for confirmation for any tool that has a side-effect or may potentially be dangerous. 21182 */ 21183 confirmationMessages?: LanguageModelToolConfirmationMessages; 21184 } 21185 21186 /** 21187 * A reference to a tool that the user manually attached to their request, either using the `#`-syntax inline, or as an 21188 * attachment via the paperclip button. 21189 */ 21190 export interface ChatLanguageModelToolReference { 21191 /** 21192 * The tool name. Refers to a tool listed in {@link lm.tools}. 21193 */ 21194 readonly name: string; 21195 21196 /** 21197 * The start and end index of the reference in the {@link ChatRequest.prompt prompt}. When undefined, the reference was 21198 * not part of the prompt text. 21199 * 21200 * *Note* that the indices take the leading `#`-character into account which means they can be used to modify the prompt 21201 * as-is. 21202 */ 21203 readonly range?: [start: number, end: number]; 21204 } 21205 } 21206 21207 /** 21208 * Thenable is a common denominator between ES6 promises, Q, jquery.Deferred, WinJS.Promise, 21209 * and others. This API makes no assumption about what promise library is being used which 21210 * enables reusing existing code without migrating to a specific promise implementation. Still, 21211 * we recommend the use of native promises which are available in this editor. 21212 */ 21213 interface Thenable<T> extends PromiseLike<T> { } 21214