nvim_runtime_lua

vim.lsp.util

Methods26

function M.apply_text_edits(text_edits: lsp.TextEdit | lsp.AnnotatedTextEdit[], bufnr: integer, position_encoding: "utf-8" | "utf-16" | "utf-32", change_annotations: {string, lsp.ChangeAnnotation} | nil) -> nil

Applies a list of text edits to a buffer. Note: this mutates text_edits (sorts in-place and adds _index fields).

Parameters
bufnrinteger

Buffer id

position_encoding"utf-8" | "utf-16" | "utf-32"
change_annotations{string, lsp.ChangeAnnotation} | nil
Returns
nil
See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit

function M.apply_text_document_edit(text_document_edit: lsp.TextDocumentEdit, index: nil | integer, position_encoding: "utf-8" | "utf-16" | "utf-32", change_annotations: {string, lsp.ChangeAnnotation} | nil) -> nil

Applies a TextDocumentEdit, which is a list of changes to a single document.

Parameters
text_document_editlsp.TextDocumentEdit
indexnil | integer

: Optional index of the edit, if from a list of edits (or nil, if not from a list)

position_encoding"utf-8" | "utf-16" | "utf-32"
change_annotations{string, lsp.ChangeAnnotation} | nil
Returns
nil
See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit

function M.rename(old_fname: string, new_fname: string, opts: vim.lsp.util.rename.Opts | nil) -> nil

Rename oldfname to newfname

Existing buffers are renamed as well, while maintaining their bufnr.

It deletes existing buffers that conflict with the renamed file name only when

  • opts requests overwriting; or
  • the conflicting buffers are not loaded, so that deleting them does not result in data loss.
Parameters
old_fnamestring
new_fnamestring
optsvim.lsp.util.rename.Opts | nil

Options:

Returns
nil
function M.apply_workspace_edit(workspace_edit: lsp.WorkspaceEdit, position_encoding: "utf-8" | "utf-16" | "utf-32") -> nil

Applies a WorkspaceEdit.

Parameters
workspace_editlsp.WorkspaceEdit
position_encoding"utf-8" | "utf-16" | "utf-32"

(required)

Returns
nil
See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit

function M.convert_input_to_markdown_lines(input: lsp.MarkedString | lsp.MarkedString[] | lsp.MarkupContent, contents: string[] | nil) -> extended string[]

Converts any of MarkedString | MarkedString[] | MarkupContent into a list of lines containing valid markdown. Useful to populate the hover window for textDocument/hover, for parsing the result of textDocument/signatureHelp, and potentially others.

Note that if the input is of type MarkupContent and its kind is plaintext, then the corresponding value is returned without further modifications.

Parameters
contentsstring[] | nil

List of strings to extend with converted lines. Defaults to {}.

Returns
extendedstring[]

with lines of converted markdown.

See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover

function M.convert_signature_help_to_markdown_lines(signature_help: lsp.SignatureHelp, ft: nil | string, triggers: string[] | nil) -> (string[] | nil, Range4 | nil)

Converts textDocument/signatureHelp response to markdown lines.

Parameters
signature_helplsp.SignatureHelp

Response of textDocument/SignatureHelp

ftnil | string

filetype that will be use as the lang for the label markdown code block

triggersstring[] | nil

list of trigger characters from the lsp server. used to better determine parameter offsets

Returns
string[] | nil

lines of converted markdown.

Range4 | nil

highlight range for the active parameter

See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp

function M.make_floating_popup_options(width: integer, height: integer, opts: vim.lsp.util.open_floating_preview.Opts | nil) -> vim.api.keyset.win_config

Creates a table with sensible default options for a floating window. The table can be passed to |nvimopenwin()|.

Parameters
widthinteger

window width (in character cells)

heightinteger

window height (in character cells)

function M.show_document(location: lsp.Location | lsp.LocationLink, position_encoding: "utf-8" | "utf-16" | "utf-32", opts: vim.lsp.util.show_document.Opts | nil) -> boolean

Shows document and optionally jumps to the location.

Parameters
position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
boolean

true if succeeded

function M.preview_location(location: lsp.Location | lsp.LocationLink, opts: vim.lsp.util.open_floating_preview.Opts | nil) -> (buffer nil | integer, window nil | integer)

Previews a location in a floating window

behavior depends on type of location:

  • for Location, range is shown (e.g., function definition)
  • for LocationLink, targetRange is shown (e.g., body of function definition)
Returns
buffernil | integer

id of float window

windownil | integer

id of float window

function M.stylize_markdown(bufnr: integer, contents: string[], opts: nil | table) -> stripped table
Deprecated
Parameters
bufnrinteger
contentsstring[]

of lines to show in window

optsnil | table

with optional fields

  • height of floating window
  • max_height maximal height of floating window
  • max_width maximal width of floating window
  • separator insert separator after code block
  • width of floating window
  • wrap_at character to wrap at for computing height
Returns
strippedtable

content

Deprecated
function M._normalize_markdown(contents: string[], opts: vim.lsp.util._normalize_markdown.Opts | nil) -> table string[]

Normalizes Markdown input to a canonical form.

The returned Markdown adheres to the GitHub Flavored Markdown (GFM) specification, as required by the LSP.

The following transformations are made:

  1. Carriage returns ('r') and empty lines at the beginning and end are removed
  2. Successive empty lines are collapsed into a single empty line
  3. Thematic breaks are expanded to the given width
Parameters
contentsstring[]
Returns
tablestring[]

of lines containing normalized Markdown

See:

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#markupContent https://github.github.com/gfm

function M._make_floating_popup_size(contents: string[], opts: vim.lsp.util.open_floating_preview.Opts | nil) -> (width integer, height integer)

Computes size of float needed to show contents (with optional wrapping)

Parameters
contentsstring[]

of lines to show in window

Returns
widthinteger

size of float

heightinteger

size of float

function M.open_floating_preview(contents: table, syntax: string, opts: vim.lsp.util.open_floating_preview.Opts | nil) -> (bufnr integer, winid integer)

Shows contents in a floating window.

Parameters
contentstable

of lines to show in window

syntaxstring

of syntax to set for opened buffer

optsvim.lsp.util.open_floating_preview.Opts | nil

with optional fields (additional keys are filtered with |vim.lsp.util.makefloatingpopup_options()| before they are passed on to |nvimopenwin()|)

Returns
bufnrinteger

of newly created float window

winidinteger

of newly created float window preview window

function M.buf_clear_references(bufnr: nil | integer) -> nil

Removes document highlights from a buffer.

Parameters
bufnrnil | integer

Buffer id

Returns
nil
function M.buf_highlight_references(bufnr: integer, references: lsp.DocumentHighlight[], position_encoding: "utf-8" | "utf-16" | "utf-32") -> nil

Shows a list of document highlights for a certain buffer.

Parameters
bufnrinteger

Buffer id

referenceslsp.DocumentHighlight[]

objects to highlight

position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
nil
See:

https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent

function M.locations_to_items(locations: lsp.Location[] | lsp.LocationLink[], position_encoding: "utf-8" | "utf-16" | "utf-32") -> vim.quickfix.entry[]

Returns the items with the byte position calculated correctly and in sorted order, for display in quickfix and location lists.

The user_data field of each resulting item will contain the original Location or LocationLink it was computed from.

The result can be passed to the {list} argument of |setqflist()| or |setloclist()|.

Parameters
position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
vim.quickfix.entry[]

See |setqflist()| for the format

function M.symbols_to_items(symbols: lsp.DocumentSymbol[] | lsp.SymbolInformation[] | lsp.WorkspaceSymbol[], bufnr: nil | integer, position_encoding: "utf-8" | "utf-16" | "utf-32") -> vim.quickfix.entry[]

Converts symbols to quickfix list items.

Parameters
bufnrnil | integer

buffer handle or 0 for current, defaults to current

position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
vim.quickfix.entry[]

See |setqflist()| for the format

function M.make_position_params(win: nil | integer, position_encoding: "utf-8" | "utf-16" | "utf-32") -> lsp.TextDocumentPositionParams

Creates a TextDocumentPositionParams object for the current buffer and cursor position.

Parameters
winnil | integer

: |window-ID| or 0 for current, defaults to current

position_encoding"utf-8" | "utf-16" | "utf-32"
See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams

function M.make_range_params(win: nil | integer, position_encoding: "utf-8" | "utf-16" | "utf-32") -> { range: lsp.Range, textDocument: { uri: lsp.DocumentUri } }

Using the current position in the current buffer, creates an object that can be used as a building block for several LSP requests, such as textDocument/codeAction, textDocument/colorPresentation, textDocument/rangeFormatting.

Parameters
winnil | integer

: |window-ID| or 0 for current, defaults to current

position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
{ range: lsp.Range, textDocument: { uri: lsp.DocumentUri } }
function M.make_given_range_params(start_pos: (integer, integer) | nil, end_pos: (integer, integer) | nil, bufnr: nil | integer, position_encoding: "utf-8" | "utf-16" | "utf-32") -> { range: lsp.Range, textDocument: { uri: lsp.DocumentUri } }

Using the given range in the current buffer, creates an object that is similar to |vim.lsp.util.makerangeparams()|.

Parameters
start_pos(integer, integer) | nil

{row,col} mark-indexed position. Defaults to the start of the last visual selection.

end_pos(integer, integer) | nil

{row,col} mark-indexed position. Defaults to the end of the last visual selection.

bufnrnil | integer

buffer handle or 0 for current, defaults to current

position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
{ range: lsp.Range, textDocument: { uri: lsp.DocumentUri } }
function M.make_text_document_params(bufnr: nil | integer) -> lsp.TextDocumentIdentifier

Creates a TextDocumentIdentifier object for the current buffer.

Parameters
bufnrnil | integer

: Buffer handle, defaults to current

See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier

function M.make_workspace_params(added: lsp.WorkspaceFolder[], removed: lsp.WorkspaceFolder[]) -> lsp.DidChangeWorkspaceFoldersParams

Create the workspace params

function M.get_effective_tabstop(bufnr: nil | integer) -> indentation integer

Returns indentation size.

Parameters
bufnrnil | integer

: Buffer handle, defaults to current

Returns
indentationinteger

size

See:

'shiftwidth'

function M.make_formatting_params(options: lsp.FormattingOptions | nil) -> object lsp.DocumentFormattingParams

Creates a DocumentFormattingParams object for the current buffer and cursor position.

Parameters
optionslsp.FormattingOptions | nil

with valid FormattingOptions entries

See:

https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting

function M.character_offset(buf: integer, row: integer, col: integer, position_encoding: "utf-8" | "utf-16" | "utf-32") -> integer
Deprecated

Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer.

Parameters
bufinteger

buffer number (0 for current)

rowinteger

0-indexed line

colinteger

0-indexed byte offset in line

position_encoding"utf-8" | "utf-16" | "utf-32"
Returns
integer

position_encoding index of the character in line {row} column {col} in buffer {buf}

Deprecated
function M._cancel_requests(filter: vim.lsp.util._cancel_requests.Filter | nil) -> nil

Cancel all {filter}ed requests.

Fields1

M.buf_versions : {integer, integer}

@nodoc