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).
text_editslsp.TextEdit | lsp.AnnotatedTextEdit[]bufnrintegerBuffer id
position_encoding"utf-8" | "utf-16" | "utf-32"change_annotations{string, lsp.ChangeAnnotation} | nil
- nil
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.
text_document_editlsp.TextDocumentEditindexnil | 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
- nil
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
optsrequests overwriting; or- the conflicting buffers are not loaded, so that deleting them does not result in data loss.
old_fnamestringnew_fnamestringoptsvim.lsp.util.rename.Opts | nilOptions:
- nil
function M.apply_workspace_edit(workspace_edit: lsp.WorkspaceEdit, position_encoding: "utf-8" | "utf-16" | "utf-32") -> nil
Applies a WorkspaceEdit.
workspace_editlsp.WorkspaceEditposition_encoding"utf-8" | "utf-16" | "utf-32"(required)
- nil
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.
inputlsp.MarkedString | lsp.MarkedString[] | lsp.MarkupContentcontentsstring[] | nilList of strings to extend with converted lines. Defaults to {}.
extendedstring[]with lines of converted markdown.
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.
signature_helplsp.SignatureHelpResponse of
textDocument/SignatureHelpftnil | stringfiletype that will be use as the
langfor the label markdown code blocktriggersstring[] | nillist of trigger characters from the lsp server. used to better determine parameter offsets
- string[] | nil
lines of converted markdown.
- Range4 | nil
highlight range for the active parameter
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()|.
widthintegerwindow width (in character cells)
heightintegerwindow height (in character cells)
optsvim.lsp.util.open_floating_preview.Opts | nil
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.
locationlsp.Location | lsp.LocationLinkposition_encoding"utf-8" | "utf-16" | "utf-32"optsvim.lsp.util.show_document.Opts | nil
- boolean
trueif 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)
locationlsp.Location | lsp.LocationLinkoptsvim.lsp.util.open_floating_preview.Opts | nil
buffernil | integerid of float window
windownil | integerid of float window
function M.stylize_markdown(bufnr: integer, contents: string[], opts: nil | table) -> stripped table
Deprecated
bufnrintegercontentsstring[]of lines to show in window
optsnil | tablewith 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
strippedtablecontent
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:
- Carriage returns ('r') and empty lines at the beginning and end are removed
- Successive empty lines are collapsed into a single empty line
- Thematic breaks are expanded to the given width
contentsstring[]optsvim.lsp.util._normalize_markdown.Opts | nil
tablestring[]of lines containing normalized Markdown
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)
contentsstring[]of lines to show in window
optsvim.lsp.util.open_floating_preview.Opts | nil
widthintegersize of float
heightintegersize 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.
contentstableof lines to show in window
syntaxstringof syntax to set for opened buffer
optsvim.lsp.util.open_floating_preview.Opts | nilwith optional fields (additional keys are filtered with |vim.lsp.util.makefloatingpopup_options()| before they are passed on to |nvimopenwin()|)
bufnrintegerof newly created float window
winidintegerof newly created float window preview window
function M.buf_clear_references(bufnr: nil | integer) -> nil
Removes document highlights from a buffer.
bufnrnil | integerBuffer id
- 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.
bufnrintegerBuffer id
referenceslsp.DocumentHighlight[]objects to highlight
position_encoding"utf-8" | "utf-16" | "utf-32"
- nil
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()|.
locationslsp.Location[] | lsp.LocationLink[]position_encoding"utf-8" | "utf-16" | "utf-32"
- 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.
symbolslsp.DocumentSymbol[] | lsp.SymbolInformation[] | lsp.WorkspaceSymbol[]list of symbols
bufnrnil | integerbuffer handle or 0 for current, defaults to current
position_encoding"utf-8" | "utf-16" | "utf-32"
- 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.
winnil | integer: |window-ID| or 0 for current, defaults to current
position_encoding"utf-8" | "utf-16" | "utf-32"
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.
winnil | integer: |window-ID| or 0 for current, defaults to current
position_encoding"utf-8" | "utf-16" | "utf-32"
- { 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()|.
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 | integerbuffer handle or 0 for current, defaults to current
position_encoding"utf-8" | "utf-16" | "utf-32"
- { 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.
bufnrnil | integer: Buffer handle, defaults to current
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.
bufnrnil | integer: Buffer handle, defaults to current
indentationintegersize
'shiftwidth'
function M.make_formatting_params(options: lsp.FormattingOptions | nil) -> object lsp.DocumentFormattingParams
Creates a DocumentFormattingParams object for the current buffer and cursor position.
optionslsp.FormattingOptions | nilwith valid
FormattingOptionsentries
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.
bufintegerbuffer number (0 for current)
rowinteger0-indexed line
colinteger0-indexed byte offset in line
position_encoding"utf-8" | "utf-16" | "utf-32"
- integer
position_encodingindex of the character in line {row} column {col} in buffer {buf}
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