UNPKG

coc.nvim

Version:

LSP based intellisense engine for neovim & vim8.

1,663 lines (1,582 loc) 345 kB
/****************************************************************** MIT License http://www.opensource.org/licenses/mit-license.php Author Qiming Zhao <chemzqm@gmail> (https://github.com/chemzqm) *******************************************************************/ /// <reference types="node" /> import cp from 'child_process' import { URL } from 'url' declare module 'coc.nvim' { // Language server protocol interfaces {{ export interface Thenable<T> { then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult> // eslint-disable-next-line @typescript-eslint/unified-signatures then<TResult>(onfulfilled?: (value: T) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult> } export interface Disposable { /** * Dispose this object. */ dispose(): void } export namespace Disposable { function create(func: () => void): Disposable } /** * The declaration of a symbol representation as one or many [locations](#Location). */ export type Declaration = Location | Location[] /** * Information about where a symbol is declared. * * Provides additional metadata over normal [location](#Location) declarations, including the range of * the declaring symbol. * * Servers should prefer returning `DeclarationLink` over `Declaration` if supported * by the client. */ export type DeclarationLink = LocationLink export type ProgressToken = number | string export interface WorkDoneProgressBegin { kind: 'begin' /** * Mandatory title of the progress operation. Used to briefly inform about * the kind of operation being performed. * * Examples: "Indexing" or "Linking dependencies". */ title: string /** * Controls if a cancel button should show to allow the user to cancel the * long running operation. Clients that don't support cancellation are allowed * to ignore the setting. */ cancellable?: boolean /** * Optional, more detailed associated progress message. Contains * complementary information to the `title`. * * Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". * If unset, the previous progress message (if any) is still valid. */ message?: string /** * Optional progress percentage to display (value 100 is considered 100%). * If not provided infinite progress is assumed and clients are allowed * to ignore the `percentage` value in subsequent in report notifications. * * The value should be steadily rising. Clients are free to ignore values * that are not following this rule. */ percentage?: number } export interface WorkDoneProgressReport { kind: 'report' /** * Controls enablement state of a cancel button. This property is only valid if a cancel * button got requested in the `WorkDoneProgressStart` payload. * * Clients that don't support cancellation or don't support control the button's * enablement state are allowed to ignore the setting. */ cancellable?: boolean /** * Optional, more detailed associated progress message. Contains * complementary information to the `title`. * * Examples: "3/25 files", "project/src/module2", "node_modules/some_dep". * If unset, the previous progress message (if any) is still valid. */ message?: string /** * Optional progress percentage to display (value 100 is considered 100%). * If not provided infinite progress is assumed and clients are allowed * to ignore the `percentage` value in subsequent in report notifications. * * The value should be steadily rising. Clients are free to ignore values * that are not following this rule. */ percentage?: number } /** * The file event type */ export namespace FileChangeType { /** * The file got created. */ const Created = 1 /** * The file got changed. */ const Changed = 2 /** * The file got deleted. */ const Deleted = 3 } export type FileChangeType = 1 | 2 | 3 /** * An event describing a file change. */ export interface FileEvent { /** * The file's uri. */ uri: string /** * The change type. */ type: FileChangeType } export interface WorkDoneProgressEnd { kind: 'end' /** * Optional, a final message indicating to for example indicate the outcome * of the operation. */ message?: string } /** * A literal to identify a text document in the client. */ export interface TextDocumentIdentifier { /** * The text document's uri. */ uri: string } /** * A parameter literal used in requests to pass a text document and a position inside that * document. */ export interface TextDocumentPositionParams { /** * The text document. */ textDocument: TextDocumentIdentifier /** * The position inside the text document. */ position: Position } export interface WorkspaceFolder { /** * The associated URI for this workspace folder. */ uri: string /** * The name of the workspace folder. Used to refer to this * workspace folder in the user interface. */ name: string } /** * An event describing a change to a text document. */ export interface TextDocumentContentChange { /** * The range of the document that changed. */ range: Range /** * The new text for the provided range. */ text: string } /** * The workspace folder change event. */ export interface WorkspaceFoldersChangeEvent { /** * The array of added workspace folders */ added: WorkspaceFolder[] /** * The array of the removed workspace folders */ removed: WorkspaceFolder[] } /** * An event that is fired when a [document](#LinesTextDocument) will be saved. * * To make modifications to the document before it is being saved, call the * [`waitUntil`](#TextDocumentWillSaveEvent.waitUntil)-function with a thenable * that resolves to an array of [text edits](#TextEdit). */ export interface TextDocumentWillSaveEvent { /** * The document that will be saved. */ document: LinesTextDocument /** * The reason why save was triggered. */ reason: 1 | 2 | 3 } /** * A document filter denotes a document by different properties like * the [language](#LinesTextDocument.languageId), the [scheme](#Uri.scheme) of * its resource, or a glob-pattern that is applied to the [path](#LinesTextDocument.fileName). * * Glob patterns can have the following syntax: * - `*` to match one or more characters in a path segment * - `?` to match on one character in a path segment * - `**` to match any number of path segments, including none * - `{}` to group conditions (e.g. `**​/*.{ts,js}` matches all TypeScript and JavaScript files) * - `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …) * - `[!...]` 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`) * * @sample A language filter that applies to typescript files on disk: `{ language: 'typescript', scheme: 'file' }` * @sample A language filter that applies to all package.json paths: `{ language: 'json', pattern: '**package.json' }` */ export type DocumentFilter = { /** A language id, like `typescript`. */ language: string /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */ scheme?: string /** A glob pattern, like `*.{ts,js}`. */ pattern?: string } | { /** A language id, like `typescript`. */ language?: string /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */ scheme: string /** A glob pattern, like `*.{ts,js}`. */ pattern?: string } | { /** A language id, like `typescript`. */ language?: string /** A Uri [scheme](#Uri.scheme), like `file` or `untitled`. */ scheme?: string /** A glob pattern, like `*.{ts,js}`. */ pattern: string } /** * A document selector is the combination of one or many document filters. * * @sample `let sel:DocumentSelector = [{ language: 'typescript' }, { language: 'json', pattern: '**∕tsconfig.json' }]`; */ export type DocumentSelector = (string | DocumentFilter)[] /** * A selection range represents a part of a selection hierarchy. A selection range * may have a parent selection range that contains it. */ export interface SelectionRange { /** * The [range](#Range) of this selection range. */ range: Range /** * The parent selection range containing this range. Therefore `parent.range` must contain `this.range`. */ parent?: SelectionRange } /** * MarkedString can be used to render human readable text. It is either a markdown string * or a code-block that provides a language and a code snippet. The language identifier * is semantically equal to the optional language identifier in fenced code blocks in GitHub * issues. See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting * * The pair of a language and a value is an equivalent to markdown: * ```${language} * ${value} * ``` * * Note that markdown strings will be sanitized - that means html will be escaped. * @deprecated use MarkupContent instead. */ export type MarkedString = string | { language: string value: string } /** * The result of a hover request. */ export interface Hover { /** * The hover's content */ contents: MarkupContent | MarkedString | MarkedString[] /** * An optional range */ range?: Range } /** * The definition of a symbol represented as one or many [locations](#Location). * For most programming languages there is only one location at which a symbol is * defined. * * Servers should prefer returning `DefinitionLink` over `Definition` if supported * by the client. */ export type Definition = Location | Location[] /** * Information about where a symbol is defined. * * Provides additional metadata over normal [location](#Location) definitions, including the range of * the defining symbol */ export type DefinitionLink = LocationLink /** * How a signature help was triggered. */ export namespace SignatureHelpTriggerKind { /** * Signature help was invoked manually by the user or by a command. */ const Invoked: 1 /** * Signature help was triggered by a trigger character. */ const TriggerCharacter: 2 /** * Signature help was triggered by the cursor moving or by the document content changing. */ const ContentChange: 3 } export type SignatureHelpTriggerKind = 1 | 2 | 3 /** * Represents the signature of something callable. A signature * can have a label, like a function-name, a doc-comment, and * a set of parameters. */ export interface SignatureInformation { /** * The label of this signature. Will be shown in * the UI. */ label: string /** * The human-readable doc-comment of this signature. Will be shown * in the UI but can be omitted. */ documentation?: string | MarkupContent /** * The parameters of this signature. */ parameters?: ParameterInformation[] /** * The index of the active parameter. * * If provided, this is used in place of `SignatureHelp.activeParameter`. * * @since 3.16.0 */ activeParameter?: number } /** * Represents a parameter of a callable-signature. A parameter can * have a label and a doc-comment. */ export interface ParameterInformation { /** * The label of this parameter information. * * Either a string or an inclusive start and exclusive end offsets within its containing * signature label. (see SignatureInformation.label). The offsets are based on a UTF-16 * string representation as `Position` and `Range` does. * * *Note*: a label of type string should be a substring of its containing signature label. * Its intended use case is to highlight the parameter label part in the `SignatureInformation.label`. */ label: string | [number, number] /** * The human-readable doc-comment of this signature. Will be shown * in the UI but can be omitted. */ documentation?: string | MarkupContent } /** * Signature help represents the signature of something * callable. There can be multiple signature but only one * active and only one active parameter. */ export interface SignatureHelp { /** * One or more signatures. */ signatures: SignatureInformation[] /** * The active signature. Set to `null` if no * signatures exist. */ activeSignature: number | null /** * The active parameter of the active signature. Set to `null` * if the active signature has no parameters. */ activeParameter: number | null } /** * Additional information about the context in which a signature help request was triggered. * * @since 3.15.0 */ export interface SignatureHelpContext { /** * Action that caused signature help to be triggered. */ triggerKind: SignatureHelpTriggerKind /** * Character that caused signature help to be triggered. * * This is undefined when `triggerKind !== SignatureHelpTriggerKind.TriggerCharacter` */ triggerCharacter?: string /** * `true` if signature help was already showing when it was triggered. * * Retriggers occur when the signature help is already active and can be caused by actions such as * typing a trigger character, a cursor move, or document content changes. */ isRetrigger: boolean /** * The currently active `SignatureHelp`. * * The `activeSignatureHelp` has its `SignatureHelp.activeSignature` field updated based on * the user navigating through available signatures. */ activeSignatureHelp?: SignatureHelp } /** * Represents a folding range. */ export interface FoldingRange { /** * The zero-based line number from where the folded range starts. */ startLine: number /** * The zero-based character offset from where the folded range starts. If not defined, defaults to the length of the start line. */ startCharacter?: number /** * The zero-based line number where the folded range ends. */ endLine: number /** * The zero-based character offset before the folded range ends. If not defined, defaults to the length of the end line. */ endCharacter?: number /** * Describes the kind of the folding range such as `comment' or 'region'. The kind * is used to categorize folding ranges and used by commands like 'Fold all comments'. See * [FoldingRangeKind](#FoldingRangeKind) for an enumeration of standardized kinds. */ kind?: string } /** * A symbol kind. */ export namespace SymbolKind { const File: 1 const Module: 2 const Namespace: 3 const Package: 4 const Class: 5 const Method: 6 const Property: 7 const Field: 8 const Constructor: 9 const Enum: 10 const Interface: 11 const Function: 12 const Variable: 13 const Constant: 14 const String: 15 const Number: 16 const Boolean: 17 const Array: 18 const Object: 19 const Key: 20 const Null: 21 const EnumMember: 22 const Struct: 23 const Event: 24 const Operator: 25 const TypeParameter: 26 } export type SymbolKind = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 /** * Represents information about programming constructs like variables, classes, * interfaces etc. */ export interface SymbolInformation { /** * The name of this symbol. */ name: string /** * The kind of this symbol. */ kind: SymbolKind /** * Indicates if this symbol is deprecated. */ deprecated?: boolean /** * The location of this symbol. The location's range is used by a tool * to reveal the location in the editor. If the symbol is selected in the * tool the range's start information is used to position the cursor. So * the range usually spans more than the actual symbol's name and does * normally include thinks like visibility modifiers. * * The range doesn't have to denote a node range in the sense of a abstract * syntax tree. It can therefore not be used to re-construct a hierarchy of * the symbols. */ location: Location /** * The name of the symbol containing this symbol. This information is for * user interface purposes (e.g. to render a qualifier in the user interface * if necessary). It can't be used to re-infer a hierarchy for the document * symbols. */ containerName?: string } /** * Represents programming constructs like variables, classes, interfaces etc. * that appear in a document. Document symbols can be hierarchical and they * have two ranges: one that encloses its definition and one that points to * its most interesting range, e.g. the range of an identifier. */ export interface DocumentSymbol { /** * The name of this symbol. Will be displayed in the user interface and therefore must not be * an empty string or a string only consisting of white spaces. */ name: string /** * More detail for this symbol, e.g the signature of a function. */ detail?: string /** * The kind of this symbol. */ kind: SymbolKind /** * Indicates if this symbol is deprecated. */ deprecated?: boolean /** * The range enclosing this symbol not including leading/trailing whitespace but everything else * like comments. This information is typically used to determine if the the clients cursor is * inside the symbol to reveal in the symbol in the UI. */ range: Range /** * The range that should be selected and revealed when this symbol is being picked, e.g the name of a function. * Must be contained by the the `range`. */ selectionRange: Range /** * Children of this symbol, e.g. properties of a class. */ children?: DocumentSymbol[] } export interface FormattingOptions { /** * If indentation is based on spaces (`insertSpaces` = true), the number of spaces that make an indent. */ tabSize: number /** * Is indentation based on spaces? */ insertSpaces: boolean /** * Trim trailing whitespaces on a line. * * @since 3.15.0 */ trimTrailingWhitespace?: boolean /** * Insert a newline character at the end of the file if one does not exist. * * @since 3.15.0 */ insertFinalNewline?: boolean /** * Trim all newlines after the final newline at the end of the file. * * @since 3.15.0 */ trimFinalNewlines?: boolean } /** * The reason why code actions were requested. * * @since 3.17.0 */ export namespace CodeActionTriggerKind { /** * Code actions were explicitly requested by the user or by an extension. */ const Invoked: 1 /** * Code actions were requested automatically. * * This typically happens when current selection in a file changes, but can * also be triggered when file content changes. */ const Automatic: 2 } export type CodeActionTriggerKind = 1 | 2 /** * Contains additional diagnostic information about the context in which * a [code action](#CodeActionProvider.provideCodeActions) is run. */ export interface CodeActionContext { /** * An array of diagnostics known on the client side overlapping the range provided to the * `textDocument/codeAction` request. They are provided so that the server knows which * errors are currently presented to the user for the given range. There is no guarantee * that these accurately reflect the error state of the resource. The primary parameter * to compute code actions is the provided range. */ diagnostics: Diagnostic[] /** * Requested kind of actions to return. * * Actions not of this kind are filtered out by the client before being shown. So servers * can omit computing them. */ only?: string[] /** * The reason why code actions were requested. * * @since 3.17.0 */ triggerKind?: CodeActionTriggerKind } /** * A document highlight kind. */ export namespace DocumentHighlightKind { /** * A textual occurrence. */ const Text: 1 /** * Read-access of a symbol, like reading a variable. */ const Read: 2 /** * Write-access of a symbol, like writing to a variable. */ const Write: 3 } export type DocumentHighlightKind = 1 | 2 | 3 /** * A document highlight is a range inside a text document which deserves * special attention. Usually a document highlight is visualized by changing * the background color of its range. */ export interface DocumentHighlight { /** * The range this highlight applies to. */ range: Range /** * The highlight kind, default is [text](#DocumentHighlightKind.Text). */ kind?: DocumentHighlightKind } /** * A document link is a range in a text document that links to an internal or external resource, like another * text document or a web site. */ export interface DocumentLink { /** * The range this link applies to. */ range: Range /** * The uri this link points to. */ target?: string /** * The tooltip text when you hover over this link. * * If a tooltip is provided, is will be displayed in a string that includes instructions on how to * trigger the link, such as `{0} (ctrl + click)`. The specific instructions vary depending on OS, * user settings, and localization. * * @since 3.15.0 */ tooltip?: string /** * A data entry field that is preserved on a document link between a * DocumentLinkRequest and a DocumentLinkResolveRequest. */ data?: any } /** * Represents a color in RGBA space. */ export interface Color { /** * The red component of this color in the range [0-1]. */ readonly red: number /** * The green component of this color in the range [0-1]. */ readonly green: number /** * The blue component of this color in the range [0-1]. */ readonly blue: number /** * The alpha component of this color in the range [0-1]. */ readonly alpha: number } /** * Represents a color range from a document. */ export interface ColorInformation { /** * The range in the document where this color appears. */ range: Range /** * The actual color value for this color range. */ color: Color } export interface ColorPresentation { /** * The label of this color presentation. It will be shown on the color * picker header. By default this is also the text that is inserted when selecting * this color presentation. */ label: string /** * An [edit](#TextEdit) which is applied to a document when selecting * this presentation for the color. When `falsy` the [label](#ColorPresentation.label) * is used. */ textEdit?: TextEdit /** * An optional array of additional [text edits](#TextEdit) that are applied when * selecting this color presentation. Edits must not overlap with the main [edit](#ColorPresentation.textEdit) nor with themselves. */ additionalTextEdits?: TextEdit[] } /** * A code lens represents a [command](#Command) that should be shown along with * source text, like the number of references, a way to run tests, etc. * * A code lens is _unresolved_ when no command is associated to it. For performance * reasons the creation of a code lens and resolving should be done to two stages. */ export interface CodeLens { /** * The range in which this code lens is valid. Should only span a single line. */ range: Range /** * The command this code lens represents. */ command?: Command /** * An data entry field that is preserved on a code lens item between * a [CodeLensRequest](#CodeLensRequest) and a [CodeLensResolveRequest] * (#CodeLensResolveRequest) */ data?: any } /** * Represents the connection of two locations. Provides additional metadata over normal [locations](#Location), * including an origin range. */ export interface LocationLink { /** * Span of the origin of this link. * * Used as the underlined span for mouse definition hover. Defaults to the word range at * the definition position. */ originSelectionRange?: Range /** * The target resource identifier of this link. */ targetUri: string /** * The full target range of this link. If the target for example is a symbol then target range is the * range enclosing this symbol not including leading/trailing whitespace but everything else * like comments. This information is typically used to highlight the range in the editor. */ targetRange: Range /** * The range that should be selected and revealed when this link is being followed, e.g the name of a function. * Must be contained by the the `targetRange`. See also `DocumentSymbol#range` */ targetSelectionRange: Range } /** * The LocationLink namespace provides helper functions to work with * [LocationLink](#LocationLink) literals. */ export namespace LocationLink { /** * Creates a LocationLink literal. * @param targetUri The definition's uri. * @param targetRange The full range of the definition. * @param targetSelectionRange The span of the symbol definition at the target. * @param originSelectionRange The span of the symbol being defined in the originating source file. */ function create(targetUri: string, targetRange: Range, targetSelectionRange: Range, originSelectionRange?: Range): LocationLink /** * Checks whether the given literal conforms to the [LocationLink](#LocationLink) interface. */ function is(value: any): value is LocationLink } export type MarkupKind = 'plaintext' | 'markdown' /** * Describes the content type that a client supports in various * result literals like `Hover`, `ParameterInfo` or `CompletionItem`. * * Please note that `MarkupKinds` must not start with a `$`. This kinds * are reserved for internal usage. */ export namespace MarkupKind { /** * Plain text is supported as a content format */ const PlainText: 'plaintext' /** * Markdown is supported as a content format */ const Markdown: 'markdown' } /** * A `MarkupContent` literal represents a string value which content is interpreted base on its * kind flag. Currently the protocol supports `plaintext` and `markdown` as markup kinds. * * If the kind is `markdown` then the value can contain fenced code blocks like in GitHub issues. * See https://help.github.com/articles/creating-and-highlighting-code-blocks/#syntax-highlighting * * Here is an example how such a string can be constructed using JavaScript / TypeScript: * ```ts * let markdown: MarkdownContent = { * kind: MarkupKind.Markdown, * value: [ * '# Header', * 'Some text', * '```typescript', * 'someCode();', * '```' * ].join('\n') * }; * ``` * * *Please Note* that clients might sanitize the return markdown. A client could decide to * remove HTML from the markdown to avoid script execution. */ export interface MarkupContent { /** * The type of the Markup */ kind: MarkupKind /** * The content itself */ value: string } /** * The kind of a completion entry. */ export namespace CompletionItemKind { const Text: 1 const Method: 2 const Function: 3 const Constructor: 4 const Field: 5 const Variable: 6 const Class: 7 const Interface: 8 const Module: 9 const Property: 10 const Unit: 11 const Value: 12 const Enum: 13 const Keyword: 14 const Snippet: 15 const Color: 16 const File: 17 const Reference: 18 const Folder: 19 const EnumMember: 20 const Constant: 21 const Struct: 22 const Event: 23 const Operator: 24 const TypeParameter: 25 } export type CompletionItemKind = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 /** * Defines whether the insert text in a completion item should be interpreted as * plain text or a snippet. */ export namespace InsertTextFormat { /** * The primary text to be inserted is treated as a plain string. */ const PlainText: 1 /** * The primary text to be inserted is treated as a snippet. * * A snippet can define tab stops and placeholders with `$1`, `$2` * and `${3:foo}`. `$0` defines the final tab stop, it defaults to * the end of the snippet. Placeholders with equal identifiers are linked, * that is typing in one will update others too. * * See also: https://github.com/microsoft/vscode/blob/main/src/vs/editor/contrib/snippet/snippet.md */ const Snippet: 2 } export type InsertTextFormat = 1 | 2 /** * A completion item represents a text snippet that is * proposed to complete text that is being typed. */ export interface CompletionItem { /** * The label of this completion item. By default * also the text that is inserted when selecting * this completion. */ label: string /** * The kind of this completion item. Based of the kind * an icon is chosen by the editor. */ kind?: CompletionItemKind /** * Tags for this completion item. * * @since 3.15.0 */ tags?: number[] /** * A human-readable string with additional information * about this item, like type or symbol information. */ detail?: string /** * A human-readable string that represents a doc-comment. */ documentation?: string | MarkupContent /** * Indicates if this item is deprecated. * @deprecated Use `tags` instead. */ deprecated?: boolean /** * Select this item when showing. * * *Note* that only one completion item can be selected and that the * tool / client decides which item that is. The rule is that the *first* * item of those that match best is selected. */ preselect?: boolean /** * A string that should be used when comparing this item * with other items. When `falsy` the [label](#CompletionItem.label) * is used. */ sortText?: string /** * A string that should be used when filtering a set of * completion items. When `falsy` the [label](#CompletionItem.label) * is used. */ filterText?: string /** * A string that should be inserted into a document when selecting * this completion. When `falsy` the [label](#CompletionItem.label) * is used. * * The `insertText` is subject to interpretation by the client side. * Some tools might not take the string literally. For example * VS Code when code complete is requested in this example `con<cursor position>` * and a completion item with an `insertText` of `console` is provided it * will only insert `sole`. Therefore it is recommended to use `textEdit` instead * since it avoids additional client side interpretation. */ insertText?: string /** * The format of the insert text. The format applies to both the `insertText` property * and the `newText` property of a provided `textEdit`. If omitted defaults to * `InsertTextFormat.PlainText`. */ insertTextFormat?: InsertTextFormat /** * An [edit](#TextEdit) which is applied to a document when selecting * this completion. When an edit is provided the value of * [insertText](#CompletionItem.insertText) is ignored. * * *Note:* The text edit's range must be a [single line] and it must contain the position * at which completion has been requested. */ textEdit?: TextEdit /** * An optional array of additional [text edits](#TextEdit) that are applied when * selecting this completion. Edits must not overlap (including the same insert position) * with the main [edit](#CompletionItem.textEdit) nor with themselves. * * Additional text edits should be used to change text unrelated to the current cursor position * (for example adding an import statement at the top of the file if the completion item will * insert an unqualified type). */ additionalTextEdits?: TextEdit[] /** * An optional set of characters that when pressed while this completion is active will accept it first and * then type that character. *Note* that all commit characters should have `length=1` and that superfluous * characters will be ignored. */ commitCharacters?: string[] /** * An optional [command](#Command) that is executed *after* inserting this completion. *Note* that * additional modifications to the current document should be described with the * [additionalTextEdits](#CompletionItem.additionalTextEdits)-property. */ command?: Command /** * An data entry field that is preserved on a completion item between * a [CompletionRequest](#CompletionRequest) and a [CompletionResolveRequest] * (#CompletionResolveRequest) */ data?: any } /** * Represents a collection of [completion items](#CompletionItem) to be presented * in the editor. */ export interface CompletionList { /** * This list it not complete. Further typing results in recomputing this list. */ isIncomplete: boolean /** * The completion items. */ items: CompletionItem[] } /** * How a completion was triggered */ export namespace CompletionTriggerKind { /** * Completion was triggered by typing an identifier (24x7 code * complete), manual invocation (e.g Ctrl+Space) or via API. */ const Invoked: 1 /** * Completion was triggered by a trigger character specified by * the `triggerCharacters` properties of the `CompletionRegistrationOptions`. */ const TriggerCharacter: 2 /** * Completion was re-triggered as current completion list is incomplete */ const TriggerForIncompleteCompletions: 3 } export type CompletionTriggerKind = 1 | 2 | 3 /** * Contains additional information about the context in which a completion request is triggered. */ export interface CompletionContext { /** * How the completion was triggered. */ triggerKind: CompletionTriggerKind, /** * The trigger character (a single character) that has trigger code complete. * Is undefined if `triggerKind !== CompletionTriggerKind.TriggerCharacter` */ triggerCharacter?: string option?: CompleteOption } /** * Represents a reference to a command. Provides a title which * will be used to represent a command in the UI and, optionally, * an array of arguments which will be passed to the command handler * function when invoked. */ export interface Command { /** * Title of the command, like `save`. */ title: string /** * The identifier of the actual command handler. */ command: string /** * Arguments that the command handler should be * invoked with. */ arguments?: any[] } export interface TextDocumentEdit { /** * The text document to change. */ textDocument: { uri: string version: number | null } /** * The edits to be applied. */ edits: TextEdit[] } /** * A workspace edit represents changes to many resources managed in the workspace. The edit * should either provide `changes` or `documentChanges`. If documentChanges are present * they are preferred over `changes` if the client can handle versioned document edits. */ export interface WorkspaceEdit { /** * Holds changes to existing resources. */ changes?: { [uri: string]: TextEdit[] } /** * Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes * are either an array of `TextDocumentEdit`s to express changes to n different text documents * where each text document edit addresses a specific version of a text document. Or it can contain * above `TextDocumentEdit`s mixed with create, rename and delete file / folder operations. * * Whether a client supports versioned document edits is expressed via * `workspace.workspaceEdit.documentChanges` client capability. * * If a client neither supports `documentChanges` nor `workspace.workspaceEdit.resourceOperations` then * only plain `TextEdit`s using the `changes` property are supported. */ documentChanges?: (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[] } interface ResourceOperation { kind: string } /** * Delete file options */ export interface DeleteFileOptions { /** * Delete the content recursively if a folder is denoted. */ recursive?: boolean /** * Ignore the operation if the file doesn't exist. */ ignoreIfNotExists?: boolean } /** * Delete file operation */ export interface DeleteFile extends ResourceOperation { /** * A delete */ kind: 'delete' /** * The file to delete. */ uri: string /** * Delete options. */ options?: DeleteFileOptions } /** * Options to create a file. */ export interface CreateFileOptions { /** * Overwrite existing file. Overwrite wins over `ignoreIfExists` */ overwrite?: boolean /** * Ignore if exists. */ ignoreIfExists?: boolean } /** * Create file operation. */ export interface CreateFile extends ResourceOperation { /** * A create */ kind: 'create' /** * The resource to create. */ uri: string /** * Additional options */ options?: CreateFileOptions } /** * Rename file options */ export interface RenameFileOptions { /** * Overwrite target if existing. Overwrite wins over `ignoreIfExists` */ overwrite?: boolean /** * Ignores if target exists. */ ignoreIfExists?: boolean } /** * Rename file operation */ export interface RenameFile extends ResourceOperation { /** * A rename */ kind: 'rename' /** * The old (existing) location. */ oldUri: string /** * The new location. */ newUri: string /** * Rename options. */ options?: RenameFileOptions } /** * Represents a related message and source code location for a diagnostic. This should be * used to point to code locations that cause or related to a diagnostics, e.g when duplicating * a symbol in a scope. */ export interface DiagnosticRelatedInformation { /** * The location of this related diagnostic information. */ location: Location /** * The message of this related diagnostic information. */ message: string } /** * The diagnostic's severity. */ export namespace DiagnosticSeverity { /** * Reports an error. */ const Error: 1 /** * Reports a warning. */ const Warning: 2 /** * Reports an information. */ const Information: 3 /** * Reports a hint. */ const Hint: 4 } export type DiagnosticSeverity = 1 | 2 | 3 | 4 /** * The diagnostic tags. * * @since 3.15.0 */ export namespace DiagnosticTag { /** * Unused or unnecessary code. * * Clients are allowed to render diagnostics with this tag faded out instead of having * an error squiggle. */ const Unnecessary: 1 /** * Deprecated or obsolete code. * * Clients are allowed to rendered diagnostics with this tag strike through. */ const Deprecated: 2 } export type DiagnosticTag = 1 | 2 /** * Represents a diagnostic, such as a compiler error or warning. Diagnostic objects * are only valid in the scope of a resource. */ export interface Diagnostic { /** * The range at which the message applies */ range: Range /** * The diagnostic's severity. Can be omitted. If omitted it is up to the * client to interpret diagnostics as error, warning, info or hint. */ severity?: DiagnosticSeverity /** * The diagnostic's code, which usually appear in the user interface. */ code?: number | string /** * A human-readable string describing the source of this * diagnostic, e.g. 'typescript' or 'super lint'. It usually * appears in the user interface. */ source?: string /** * The diagnostic's message. It usually appears in the user interface */ message: string /** * Additional metadata about the diagnostic. */ tags?: DiagnosticTag[] /** * An array of related diagnostic information, e.g. when symbol-names within * a scope collide all definitions can be marked via this property. */ relatedInformation?: DiagnosticRelatedInformation[] } /** * The Diagnostic namespace provides helper functions to work with * [Diagnostic](#Diagnostic) literals. */ export namespace Diagnostic { /** * Creates a new Diagnostic literal. */ function create(range: Range, message: string, severity?: DiagnosticSeverity, code?: number | string, source?: string, relatedInformation?: DiagnosticRelatedInformation[]): Diagnostic /** * Checks whether the given literal conforms to the [Diagnostic](#Diagnostic) interface. */ function is(value: any): value is Diagnostic } /** * A code action represents a change that can be performed in code, e.g. to fix a problem or * to refactor code. * * A CodeAction must set either `edit` and/or a `command`. If both are supplied, the `edit` is applied first, then the `command` is executed. */ export interface CodeAction { /** * A short, human-readable, title for this code action. */ title: string /** * The kind of the code action. * * Used to filter code actions. */ kind?: CodeActionKind /** * The diagnostics that this code action resolves. */ diagnostics?: Diagnostic[] /** * Marks this as a preferred action. Preferred actions are used by the `auto fix` command and can be targeted * by keybindings. * * A quick fix should be marked preferred if it properly addresses the underlying error. * A refactoring should be marked preferred if it is the most reasonable choice of actions to take. * * @since 3.15.0 */ isPreferred?: boolean /** * The workspace edit this code action performs. */ edit?: WorkspaceEdit /** * A command this code action executes. If a code action * provides a edit and a command, first the edit is * executed and then the command. */ command?: Command /** * Id of client that provide codeAction. */ clientId?: string } /** * The kind of a code action. * * Kinds are a hierarchical list of identifiers separated by `.`, e.g. `"refactor.extract.function"`. * * The set of kinds is open and client needs to announce the kinds it supports to the server during * initialization. */ export type CodeActionKind = string /** * A set of predefined code action kinds */ export namespace CodeActionKind { /** * Empty kind. */ const Empty: CodeActionKind /** * Base kind for quickfix actions: 'quickfix' */ const QuickFix: CodeActionKind /** * Base kind for refactoring actions: 'refactor' */ const Refactor: CodeActionKind /** * Base kind for refactoring extraction actions: 'refactor.extract' * * Example extract actions: * * - Extract method * - Extract function * - Extract variable * - Extract interface from class * - ... */ const RefactorExtract: CodeActionKind /** * Base kind for refactoring inline actions: 'refactor.inline' * * Example inline actions: * * - Inline function * - Inline variable * - Inline constant * - ... */ const RefactorInline: CodeActionKind /** * Base kind for refactoring rewrite actions: 'refactor.rewrite' * * Example rewrite actions: * * - Convert JavaScript function to class * - Add or remove parameter * - Encapsulate field * - Make method static * - Move method to base class * - ... */ const RefactorRewrite: CodeActionKind /** * Base kind for source actions: `source` * * Source code actions apply to the entire file. */ const Source: CodeActionKind /** * Base kind for an organize imports source action: `source.organizeImports` */ const SourceOrganizeImports: CodeActionKind /** * Base kind for auto-fix source actions: `source.fixAll`. * * Fix all actions automatically fix errors that have a clear fix that do not require user input. * They should not suppress errors or perform unsafe fixes such as generating new types or classes. * * @since 3.15.0 */ const SourceFixAll: CodeActionKind } /** * Position in a text document expressed as zero-based line and character offset. * The offsets are based on a UTF-16 string representation. So a string of the form * `a𐐀b` the character offset of the character `a` is 0, the character offset of `𐐀` * is 1 and the character offset of b is 3 since `𐐀` is represented using two code * units in UTF-16. * * Positions are line end character agnostic. So you can not specify a position that * denotes `\r|\n` or `\n|` where `|` represents the character offset. */ export interface Position { /** * Line position in a document (zero-based). * If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document. * If a line number is negative, it defaults to 0. */ line: number /** * Character offset on a line in a document (zero-based). Assuming that the line is * represented as a string, the `character` value represents the gap between the * `character` and `character + 1`. * * If the character value is greater than the line length it defaults back to the * line length. * If a line number is negative, it defaults to 0. */ character: number } /** * The Position namespace provides helper functions to work with * [Position](#Position) literals. */ export namespace Position { /** * Creates a new Position literal from the given line and character. * @param line The position's line. * @param character The position's character. */ function create(line: number, character: number): Position /** * Checks whether the given liternal conforms to the [Position](#Position) interface. */ function is(value: any): value is Position } /** * Represents a typed event. * * A function that represents an event to which you subscribe by calling it with * a listener function as argument. * * @example * item.onDidChange(function(event) { console.log("Event happened: " + event); }); */ export interface Event<T> { /** * A function that represents an event to which you subscribe by calling it with * a listener function as argument. * * @param listener The listener function will be called when the event happens. * @param thisArgs The `this`-argument which will be used when calling the event listener. * @param disposables An array to which a [disposable](#Disposable) will be added. * @return A disposable which unsubscribes the event listener. */ (listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable } export namespace Event { const None: Event<any> } export interface EmitterOptions { onFirstListenerAdd?: Function onLastListenerRemove?: Function } export class Emitter<T> { constructor(_options?: EmitterOptions | undefined) /** * For the public to allow to subscribe * to events from this Emitter */ get event(): Event<T> /** * To be kept private to fire an event to * subscribers */ fire(event: T): any dispose(): void }