vim.lsp.buf
Methods22
function M.hover(config: vim.lsp.buf.hover.Opts | nil) -> nil
Displays hover information about the symbol under the cursor in a floating window. The window will be dismissed on cursor move. Calling the function twice will jump into the floating window (thus by default, "KK" will open the hover window and focus it). In the floating window, all commands and mappings are available as usual, except that "q" dismisses the window. You can scroll the contents the same as you would any other buffer.
Note: to disable hover highlights, add the following to your config:
vim.api.nvim_create_autocmd('ColorScheme', {
callback = function()
vim.api.nvim_set_hl(0, 'LspReferenceTarget', {})
end,
})
function M.declaration(opts: vim.lsp.ListOpts | nil) -> nil
Jumps to the declaration of the symbol under the cursor.
@note Many servers do not implement this method. Generally, see |vim.lsp.buf.definition()| instead.
function M.definition(opts: vim.lsp.ListOpts | nil) -> nil
Jumps to the definition of the symbol under the cursor.
function M.type_definition(opts: vim.lsp.ListOpts | nil) -> nil
Jumps to the definition of the type of the symbol under the cursor.
function M.implementation(opts: vim.lsp.ListOpts | nil) -> nil
Lists all the implementations for the symbol under the cursor in the quickfix window.
function M.signature_help(config: vim.lsp.buf.signature_help.Opts | nil) -> nil
Displays signature information about the symbol under the cursor in a floating window. Allows cycling through signature overloads with <C-s>, which can be remapped via <Plug>(nvim.lsp.ctrl-s)
Example:
vim.keymap.set('n', '<C-b>', '<Plug>(nvim.lsp.ctrl-s)')
function M.format(opts: vim.lsp.buf.format.Opts | nil) -> nil
Formats a buffer using the attached (and optionally filtered) language server clients.
function M.rename(new_name: nil | string, opts: vim.lsp.buf.rename.Opts | nil) -> nil
Renames all references to the symbol under the cursor.
new_namenil | stringIf not provided, the user will be prompted for a new name using |vim.ui.input()|.
optsvim.lsp.buf.rename.Opts | nilAdditional options:
- nil
function M.references(context: lsp.ReferenceContext | nil, opts: vim.lsp.ListOpts | nil) -> nil
Lists all the references to the symbol under the cursor in the quickfix window.
contextlsp.ReferenceContext | nilContext for the request
optsvim.lsp.ListOpts | nil
- nil
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
function M.document_symbol(opts: vim.lsp.ListOpts | nil) -> nil
Lists all symbols in the current buffer in the |location-list|.
function M.incoming_calls() -> nil
Lists all the call sites of the symbol under the cursor in the |quickfix| window. If the symbol can resolve to multiple items, the user can pick one in the |inputlist()|.
function M.outgoing_calls() -> nil
Lists all the items that are called by the symbol under the cursor in the |quickfix| window. If the symbol can resolve to multiple items, the user can pick one in the |inputlist()|.
function M.typehierarchy(kind: "subtypes" | "supertypes") -> nil
Lists all the subtypes or supertypes of the symbol under the cursor in the |quickfix| window. If the symbol can resolve to multiple items, the user can pick one using |vim.ui.select()|.
function M.list_workspace_folders() -> table
List workspace folders.
function M.add_workspace_folder(workspace_folder: nil | string) -> nil
Add the folder at path to the workspace folders. If {path} is not provided, the user will be prompted for a path using |input()|.
function M.remove_workspace_folder(workspace_folder: nil | string) -> nil
Remove the folder at path from the workspace folders. If {path} is not provided, the user will be prompted for a path using |input()|.
function M.workspace_symbol(query: nil | string, opts: vim.lsp.ListOpts | nil) -> nil
Lists all symbols in the current workspace in the quickfix window.
The list is filtered against {query}; if the argument is omitted from the call, the user is prompted to enter a string on the command line. An empty string means no filtering is done.
querynil | stringoptional
optsvim.lsp.ListOpts | nil
- nil
function M.workspace_diagnostics(opts: vim.lsp.WorkspaceDiagnosticsOpts | nil) -> nil
Request workspace-wide diagnostics.
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_diagnostic
function M.document_highlight() -> nil
Send request to the server to resolve document highlights for the current text document position. This request can be triggered by a key mapping or by events such as CursorHold, e.g.:
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
Note: Usage of |vim.lsp.buf.document_highlight()| requires the following highlight groups to be defined or you won't be able to see the actual highlights. |hl-LspReferenceText| |hl-LspReferenceRead| |hl-LspReferenceWrite|
function M.clear_references() -> nil
Removes document highlights from current buffer.
function M.code_action(opts: vim.lsp.buf.code_action.Opts | nil) -> nil
Selects a code action (LSP: "textDocument/codeAction" request) available at cursor position.
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction vim.lsp.protocol.CodeActionTriggerKind
function M.selection_range(direction: integer, timeout_ms: nil | integer) -> nil
Expands or contracts a |Visual| selection at cursor, based on ranges given by LSP. The direction parameter specifies the number of times to expand the selection. Negative values will shrink the selection.
directionintegertimeout_msnil | integer(default:
1000) Maximum time (milliseconds) to wait for a result.
- nil