Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace for participating in language-specific editor features, like IntelliSense, code actions, diagnostics etc.

Many programming languages exist and there is huge variety in syntaxes, semantics, and paradigms. Despite that, features like automatic word-completion, code navigation, or code checking have become popular across different tools for different programming languages.

The editor provides an API that makes it simple to provide such common features by having all UI and actions already in place and by allowing you to participate by providing data only. For instance, to contribute a hover all you have to do is provide a function that can be called with a TextDocument and a Position returning hover info. The rest, like tracking the mouse, positioning the hover, keeping the hover stable etc. is taken care of by the editor.

languages.registerHoverProvider('javascript', {
    provideHover(document, position, token) {
        return new Hover('I am a hover!');
    }
});

Registration is done using a document selector which is either a language id, like javascript or a more complex filter like { language: 'typescript', scheme: 'file' }. Matching a document against such a selector will result in a score that is used to determine if and how a provider shall be used. When scores are equal the provider that came last wins. For features that allow full arity, like hover, the score is only checked to be >0, for other features, like IntelliSense the score is used for determining the order in which providers are asked to participate.

maintainer

@youngjuning

索引

Functions(34)

getLanguages

  • Return the identifiers of all known languages.

    Returns Thenable<string[]>

    Promise resolving to an array of identifier strings.

setTextDocumentLanguage

match

  • Compute the match between a document selector and a document. Values greater than zero mean the selector matches the document.

    A match is computed according to these rules:

    1. When DocumentSelector is an array, compute the match for each contained DocumentFilter or language identifier and take the maximum value.
    2. A string will be desugared to become the language-part of a DocumentFilter, so "fooLang" is like { language: "fooLang" }.
    3. A DocumentFilter will be matched against the document by comparing its parts with the document. The following rules apply:
    4. When the DocumentFilter is empty ({}) the result is 0
    5. When scheme, language, or pattern are defined but one doesn’t match, the result is 0
    6. Matching against * gives a score of 5, matching via equality or via a glob-pattern gives a score of 10
    7. The result is the maximum value of each match

    Samples:

    // default document from disk (file-scheme)
    doc.uri; //'file:///my/file.js'
    doc.languageId; // 'javascript'
    match('javascript', doc); // 10;
    match({language: 'javascript'}, doc); // 10;
    match({language: 'javascript', scheme: 'file'}, doc); // 10;
    match('*', doc); // 5
    match('fooLang', doc); // 0
    match(['fooLang', '*'], doc); // 5
    
    // virtual document, e.g. from git-index
    doc.uri; // 'git:/my/file.js'
    doc.languageId; // 'javascript'
    match('javascript', doc); // 10;
    match({language: 'javascript', scheme: 'git'}, doc); // 10;
    match('*', doc); // 5
    

    Parameters

    Returns number

    A number >0 when the selector matches and 0 when the selector does not match.

Const onDidChangeDiagnostics

getDiagnostics

createDiagnosticCollection

registerCompletionItemProvider

  • Register a completion provider.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and groups of equal score are sequentially asked for completion items. The process stops when one or many providers of a group return a result. A failing provider (rejected promise or exception) will not fail the whole operation.

    A completion item provider can be associated with a set of triggerCharacters. When trigger characters are being typed, completions are requested but only from providers that registered the typed character. Because of that trigger characters should be different than word characters, a common trigger character is . to trigger member completions.

    Parameters

    • selector: DocumentSelector

      A selector that defines the documents this provider is applicable to.

    • provider: CompletionItemProvider

      A completion provider.

    • Rest ...triggerCharacters: string[]

      Trigger completion when the user types one of the characters.

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerCodeActionsProvider

  • Register a code action provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerCodeLensProvider

  • Register a code lens provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDefinitionProvider

  • Register a definition provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerImplementationProvider

  • Register an implementation provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerTypeDefinitionProvider

  • Register a type definition provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDeclarationProvider

  • Register a declaration provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerHoverProvider

  • Register a hover provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerEvaluatableExpressionProvider

  • Register a provider that locates evaluatable expressions in text documents. The editor will evaluate the expression in the active debug session and will show the result in the debug hover.

    If multiple providers are registered for a language an arbitrary provider will be used.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerInlineValuesProvider

  • Register a provider that returns data for the debugger's 'inline value' feature. Whenever the generic debugger has stopped in a source file, providers registered for the language of the file are called to return textual data that will be shown in the editor at the end of lines.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDocumentHighlightProvider

  • Register a document highlight provider.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and groups sequentially asked for document highlights. The process stops when a provider returns a non-falsy or non-failure result.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDocumentSymbolProvider

  • Register a document symbol provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerWorkspaceSymbolProvider

  • Register a workspace symbol provider.

    Multiple providers can be registered. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerReferenceProvider

  • Register a reference provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerRenameProvider

  • Register a rename provider.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and asked in sequence. The first provider producing a result defines the result of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDocumentSemanticTokensProvider

  • Register a semantic tokens provider for a whole document.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and the best-matching provider is used. Failure of the selected provider will cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDocumentRangeSemanticTokensProvider

  • Register a semantic tokens provider for a document range.

    Note: If a document has both a DocumentSemanticTokensProvider and a DocumentRangeSemanticTokensProvider, the range provider will be invoked only initially, for the time in which the full document provider takes to resolve the first request. Once the full document provider resolves the first request, the semantic tokens provided via the range provider will be discarded and from that point forward, only the document provider will be used.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and the best-matching provider is used. Failure of the selected provider will cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDocumentFormattingEditProvider

  • Register a formatting provider for a document.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and the best-matching provider is used. Failure of the selected provider will cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerDocumentRangeFormattingEditProvider

  • Register a formatting provider for a document range.

    Note: A document range provider is also a document formatter which means there is no need to register a document formatter when also registering a range provider.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and the best-matching provider is used. Failure of the selected provider will cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerOnTypeFormattingEditProvider

  • Register a formatting provider that works on type. The provider is active when the user enables the setting editor.formatOnType.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and the best-matching provider is used. Failure of the selected provider will cause a failure of the whole operation.

    Parameters

    • selector: DocumentSelector

      A selector that defines the documents this provider is applicable to.

    • provider: OnTypeFormattingEditProvider

      An on type formatting edit provider.

    • firstTriggerCharacter: string

      A character on which formatting should be triggered, like }.

    • Rest ...moreTriggerCharacter: string[]

      More trigger characters.

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerSignatureHelpProvider

registerDocumentLinkProvider

  • Register a document link provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerColorProvider

  • Register a color provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerFoldingRangeProvider

  • Register a folding range provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. If multiple folding ranges start at the same position, only the range of the first registered provider is used. If a folding range overlaps with an other range that has a smaller position, it is also ignored.

    A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerSelectionRangeProvider

  • Register a selection range provider.

    Multiple providers can be registered for a language. In that case providers are asked in parallel and the results are merged. A failing provider (rejected promise or exception) will not cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

registerCallHierarchyProvider

registerLinkedEditingRangeProvider

  • Register a linked editing range provider.

    Multiple providers can be registered for a language. In that case providers are sorted by their score and the best-matching provider that has a result is used. Failure of the selected provider will cause a failure of the whole operation.

    Parameters

    Returns Disposable

    A Disposable that unregisters this provider when being disposed.

setLanguageConfiguration

友链:VS Code 中文文档 | VS Code 官网文档 | VS Code 扩展市场

Generated by TypeDoc. Maintained by 洛竹