Home Explore Blog CI



neovim

31th chunk of `runtime/doc/lsp.txt`
b2dfe929c5836f73a8f79343bd86b0484a5b3499de8d78520000000100000fc3
 completion candidate using `<c-y>` applies side effects like
      expanding snippets, text edits (e.g. insert import statements) and
      executing associated commands. This works for completions triggered via
      autotrigger, omnifunc or completion.get()

    Example: |lsp-attach| |lsp-completion|

    Note: the behavior of `autotrigger=true` is controlled by the LSP
    `triggerCharacters` field. You can override it on LspAttach, see
    |lsp-autocompletion|.

    Parameters: ~
      • {enable}     (`boolean`) True to enable, false to disable
      • {client_id}  (`integer`) Client ID
      • {bufnr}      (`integer`) Buffer handle, or 0 for the current buffer
      • {opts}       (`table?`) A table with the following fields:
                     • {autotrigger}? (`boolean`) (default: false) When true,
                       completion triggers automatically based on the server's
                       `triggerCharacters`.
                     • {convert}? (`fun(item: lsp.CompletionItem): table`)
                       Transforms an LSP CompletionItem to |complete-items|.

get({opts})                                         *vim.lsp.completion.get()*
    Triggers LSP completion once in the current buffer, if LSP completion is
    enabled (see |lsp-attach| |lsp-completion|).

    Used by the default LSP |omnicompletion| provider |vim.lsp.omnifunc()|,
    thus |i_CTRL-X_CTRL-O| invokes this in LSP-enabled buffers. Use CTRL-Y to
    select an item from the completion menu. |complete_CTRL-Y|

    To invoke manually with CTRL-space, use this mapping: >lua
        -- Use CTRL-space to trigger LSP completion.
        -- Use CTRL-Y to select an item. |complete_CTRL-Y|
        vim.keymap.set('i', '<c-space>', function()
          vim.lsp.completion.get()
        end)
<

    Parameters: ~
      • {opts}  (`table?`) A table with the following fields:
                • {ctx}? (`lsp.CompletionContext`) Completion context.
                  Defaults to a trigger kind of `invoked`.


==============================================================================
Lua module: vim.lsp.inlay_hint                                *lsp-inlay_hint*

enable({enable}, {filter})                       *vim.lsp.inlay_hint.enable()*
    Enables or disables inlay hints for the {filter}ed scope.

    To "toggle", pass the inverse of `is_enabled()`: >lua
        vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled())
<

    Attributes: ~
        Since: 0.10.0

    Parameters: ~
      • {enable}  (`boolean?`) true/nil to enable, false to disable
      • {filter}  (`table?`) Optional filters |kwargs|, or `nil` for all.
                  • {bufnr} (`integer?`) Buffer number, or 0 for current
                    buffer, or nil for all.

get({filter})                                       *vim.lsp.inlay_hint.get()*
    Get the list of inlay hints, (optionally) restricted by buffer or range.

    Example usage: >lua
        local hint = vim.lsp.inlay_hint.get({ bufnr = 0 })[1] -- 0 for current buffer

        local client = vim.lsp.get_client_by_id(hint.client_id)
        local resp = client:request_sync('inlayHint/resolve', hint.inlay_hint, 100, 0)
        local resolved_hint = assert(resp and resp.result, resp.err)
        vim.lsp.util.apply_text_edits(resolved_hint.textEdits, 0, client.encoding)

        location = resolved_hint.label[1].location
        client:request('textDocument/hover', {
          textDocument = { uri = location.uri },
          position = location.range.start,
        })
<

    Attributes: ~
        Since: 0.10.0

    Parameters: ~
      • {filter}  (`table?`) Optional filters |kwargs|:
                  • {bufnr} (`integer?`)
                  • {range} (`lsp.Range?`)

    Return: ~
        (`table[]`) A list of objects with the following fields:
        • {bufnr} (`integer`)
        • {client_id} (`integer`)
        • {inlay_hint} (`lsp.InlayHint`)

is_enabled({filter})                         *vim.lsp.inlay_hint.is_enabled()*

Title: vim.lsp.completion Functions (continued) and Introduction to vim.lsp.inlay_hint
Summary
This section continues detailing the `vim.lsp.completion` module with the `get` function, which triggers LSP completion once in the current buffer, and is used by the default LSP omnicompletion provider. It also includes how to map CTRL-space to manually trigger completion. The section then introduces the `vim.lsp.inlay_hint` module. It starts with the `enable` function for enabling or disabling inlay hints and explains the optional filters. It proceeds with the `get` function used to retrieve a list of inlay hints.