aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
Commit message (Collapse)AuthorAge
* refactor(lsp): deprecate completion util methodsMathias Fussenegger2023-10-21
| | | | Relates to https://github.com/neovim/neovim/issues/25272
* refactor(lsp): move completion logic into _completion moduleMathias Fussenegger2023-10-21
| | | | | To reduce cross-chatter between modules and for https://github.com/neovim/neovim/issues/25272 Also preparing for https://github.com/neovim/neovim/issues/25714
* feat(lsp): add snippet API (#25301)Maria José Solano2023-10-21
|
* docs: do not hardcode LSP version in URL #25648Maria José Solano2023-10-16
|
* fix(lsp): handle NUL bytes in popup text (#25612)zeertzjq2023-10-12
| | | Fix #25610
* fix(lsp): account for border height in max floating popup height (#25539)LW2023-10-08
|
* feat(lsp)!: replace snippet parser by lpeg grammarMaria José Solano2023-10-02
|
* refactor(lsp): deprecate util methods (#25400)Maria José Solano2023-09-29
|
* fix(lsp): handle absence of a trailing newline #25194Sergey Slipchenko2023-09-21
| | | | | | | | | | | | Fixes #24339 rust-analyzer sends "Invalid offset" error in such cases. Some other servers handle it specially. LSP spec mentions that "A range is comparable to a selection in an editor". Most editors don't handle trailing newlines the same way Neovim/Vim does, it's clearly visible if it's present or not. With that in mind it's understandable why sending end position as simply the start of the line after the last one is considered invalid in such cases.
* fix(lsp)!: deprecate trim_empty_linesMaria José Solano2023-09-19
|
* feat(lsp): use treesitter for stylize markdownMaria José Solano2023-09-19
|
* fix(api): more intuitive cursor updates in nvim_buf_set_textSergey Slipchenko2023-09-11
| | | | Fixes #22526
* feat(lsp): improve control over placement of floating windows (#24494)Grace Petryk2023-09-10
|
* feat(lsp): add original LSP Location as item's user_data in ↵Tom Praschan2023-09-07
| | | | locations_to_items (#23743)
* fix(lsp): only disable inlay hints / diagnostics if no other clients are ↵Chris AtLee2023-08-31
| | | | | | | | | | | | | | | | | | | connected (#24535) This fixes the issue where the LspNotify handlers for inlay_hint / diagnostics would end up refreshing all attached clients. The handler would call util._refresh, which called vim.lsp.buf_request, which calls the method on all attached clients. Now util._refresh takes an optional client_id parameter, which is used to specify a specific client to update. This commit also fixes util._refresh's handling of the `only_visible` flag. Previously if `only_visible` was false, two requests would be made to the server: one for the visible region, and one for the entire file. Co-authored-by: Stanislav Asunkin <1353637+stasjok@users.noreply.github.com> Co-authored-by: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
* fix(lua): improve annotations for stricter luals diagnostics (#24609)Christian Clason2023-08-09
| | | | | | | | | | | | | | | Problem: luals returns stricter diagnostics with bundled luarc.json Solution: Improve some function and type annotations: * use recognized uv.* types * disable diagnostic for global `vim` in shared.lua * docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type) * add type alias for lpeg pattern * fix return annotation for `vim.secure.trust` * rename local Range object in vim.version (shadows `Range` in vim.treesitter) * fix some "missing fields" warnings * add missing required fields for test functions in eval.lua * rename lsp meta files for consistency
* fix(lsp): SignatureHelp docstring is not escaped #16702Christoph Hasse2023-07-25
| | | | | | | | | | | | | Problem: Nvim LSP client always treats signature.documentation as markdown, even if the server returns a plain string. Per https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#signatureInformation in a SignatureInformation response, the documentation field can be either "string" or "MarkupContent". Solution: If signature.documentation is a string, treat it as "plaintext". Closes #16563
* fix(lsp): E403 if doc contains multiple codeblocks #24458Raphael2023-07-25
| | | | | | | | | | | | | | | | | Problem: Content that has codeblocks with different languages, results in multiple calls to: syntax include vim syntax/vim.vim which raises error: E403: syntax sync: line continuations pattern specified twice Before ba8f19ebb67ca27d746f4b1cd902ab3d807eace3, this was avoided by using pcall() to ignore the error. Solution: Restore the use of pcall() to ignore the error. We plan to replace this logic with a treesitter approach, so this is good enough for now. Fix #24431
* fix(lsp): noisy warning about offset_encodings #24441Keith Smiley2023-07-24
| | | | | In the case you hit this warning in a buffer (like with C++ and clangd), this message potentially fires over and over again making it difficult to use the editor at all.
* feat(lsp): implement textDocument/diagnostic (#24128)Chris AtLee2023-07-20
|
* docs(lua): more improvements (#24387)Lewis Russell2023-07-18
| | | | | | | | | | | | | | | | | * docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes <justinkz@gmail.com> --------- Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
* feat(lsp)!: rename vim.lsp.get_active_clients to get_clients (#24113)Mathias Fußenegger2023-07-17
|
* fix(lsp): markdown code fence should allow space before info string #24364Mike2023-07-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: Bash language server returns "hover" markdown content that starts with a code fence and info string of `man` preceded by whitespace, which Nvim does not render properly. See https://github.com/bash-lsp/bash-language-server/blob/0ee73c53cebdc18311d4a4ad9367185ea4d98a03/server/src/server.ts#L821C15-L821C15 ```typescript function getMarkdownContent(documentation: string, language?: string): LSP.MarkupContent { return { value: language ? // eslint-disable-next-line prefer-template ['``` ' + language, documentation, '```'].join('\n') : documentation, kind: LSP.MarkupKind.Markdown, } } ``` For example, ``` ``` man NAME git - the stupid content tracker ``` ``` If I remove the white space, then it is properly formatted. ``` ```man instead of ``` man ``` Per CommonMark Spec https://spec.commonmark.org/0.30/#info-string whitespace is allowed before and after the `info string` which identifies the language in a codeblock. > The line with the opening code fence may optionally contain some text > following the code fence; this is trimmed of leading and trailing > spaces or tabs and called the [info > string](https://spec.commonmark.org/0.30/#info-string). If the [info > string](https://spec.commonmark.org/0.30/#info-string) comes after > a backtick fence, it may not contain any backtick characters. (The > reason for this restriction is that otherwise some inline code would > be incorrectly interpreted as the beginning of a fenced code block.) Solution: Adjust stylize_markdown() to allow whitespace before codeblock info.
* fix(lsp): revert change to buf.clear_references() #24238Raphael2023-07-04
| | | | | | | Problem: in #24046 the signature of buf.clear_references() changed, which indirectly breaks callers that were passing "ignored" args. Solution: because util.buf_clear_references() already defaulted to "current buffer", the change to buf.clear_references() isn't actually needed, so just revert it.
* fix(lsp): lint warnings, default offset_encoding #24046Raphael2023-07-01
| | | | | - fix lint / analysis warnings - locations_to_items(): get default offset_encoding from active client - character_offset(): get default offset_encoding from active client
* fix(docs): vimdoc syntax errorsJustin M. Keyes2023-06-25
| | | | gen_help_html: truncate parse-error sample text
* feat(lsp)!: add vim.lsp.status, client.progress and promote ↵Mathias Fußenegger2023-06-09
| | | | | | | | | | | | | | | | | | | | | LspProgressUpdate (#23958) `client.messages` could grow unbounded because the default handler only added new messages, never removing them. A user either had to consume the messages by calling `vim.lsp.util.get_progress_messages` or by manually removing them from `client.messages.progress`. If they didn't do that, using LSP effectively leaked memory. To fix this, this deprecates the `messages` property and instead adds a `progress` ring buffer that only keeps at most 50 messages. In addition it deprecates `vim.lsp.util.get_progress_messages` in favour of a new `vim.lsp.status()` and also promotes the `LspProgressUpdate` user autocmd to a regular autocmd to allow users to pattern match on the progress kind. Also closes https://github.com/neovim/neovim/pull/20327
* fix(lsp): set extra info only when it has a value (#23868)Raphael2023-06-05
|
* fix(lsp): restore marks after apply_text_edits() #14630Folke Lemaitre2023-06-04
| | | | | | | | | | | | | | | | | | | | | | | | | | | PROBLEM: Whenever any text edits are applied to the buffer, the `marks` part of those lines will be lost. This is mostly problematic for code formatters that format the whole buffer like `prettier`, `luafmt`, ... When doing atomic changes inside a vim doc, vim keeps track of those changes and can update the positions of marks accordingly, but in this case we have a whole doc that changed. There's no simple way to update the positions of all marks from the previous document state to the new document state. SOLUTION: * save marks right before `nvim_buf_set_lines` is called inside `apply_text_edits` * check if any marks were lost after doing `nvim_buf_set_lines` * restore those marks to the previous positions TEST CASE: * have a formatter enabled * open any file * create a couple of marks * indent the whole file to the right * save the file Before this change: all marks will be removed. After this change: they will be preserved. Fixes #14307
* feat(lua): rename vim.loop -> vim.uv (#22846)Lewis Russell2023-06-03
|
* refactor(options): deprecate nvim[_buf|_win]_[gs]et_optionLewis Russell2023-05-21
| | | | | Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: famiu <famiuhaque@protonmail.com>
* perf(lsp): load buffer contents once when processing semantic tokens ↵jdrouhard2023-05-05
| | | | | | | | | | | | | | | | | | | | | | | | | | responses (#23484) perf(lsp): load buffer contents once when processing semantic token responses Using _get_line_byte_from_position() for each token's boundaries was a pretty huge bottleneck, since that function would load individual buffer lines via nvim_buf_get_lines() (plus a lot of extra overhead). So each token caused two calls to nvim_buf_get_lines() (once for the start position, and once for the end position). For semantic tokens, we only attach to buffers that have already been loaded, so we can safely just get all the lines for the entire buffer at once, and lift the rest of the _get_line_byte_from_position() implementation directly while bypassing the part that loads the buffer line. While I was looking at get_lines (used by _get_line_byte_from_position), I noticed that we were checking for non-file URIs before we even looked to see if we already had the buffer loaded. Moving the buffer-loaded check to be the first thing done in get_lines() more than halved the average time spent transforming the token list into highlight ranges vs when it was still using _get_line_byte_from_position. I ended up improving that loop more by not using get_lines, but figured the performance improvement it provided was worth leaving in.
* feat(lua): vim.tbl_contains supports general tables and predicates (#23040)Christian Clason2023-04-14
| | | | | | | | | | | | * feat(lua): vim.tbl_contains supports general tables and predicates Problem: `vim.tbl_contains` only works for list-like tables (integer keys without gaps) and primitive values (in particular, not for nested tables). Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new `vim.tbl_contains` that works for general tables and optionally allows `value` to be a predicate function that is checked for every key.
* refactor: remove modelines from Lua filesGregory Anders2023-04-13
| | | | Now that we have builtin EditorConfig support and a formatting check in CI, these are not necessary.
* feat(lsp): render markdown in docs hover #22766Roberto Pommella Alegro2023-03-25
| | | | | | | | | | | Problem: LSP docs hover (textDocument/hover) doesn't handle HTML escape seqs in markdown. Solution: Convert common HTML escape seqs to a nicer form, to display in the float. closees #22757 Signed-off-by: Kasama <robertoaall@gmail.com>
* fix(lsp): kill buffers after renaming a directory #22618Ivan2023-03-14
| | | | | | | | | | | | | | | Problem: When LSP client renames a directory, opened buffers in the edfitor are not renamed or closed. Then `:wall` shows errors. https://github.com/neovim/neovim/blob/master/runtime/lua/vim/lsp/util.lua#L776 works correctly if you try to rename a single file, but doesn't delete old buffers with `old_fname` is a dir. Solution: Update the logic in runtime/lua/vim/lsp/util.lua:rename() Fixes #22617
* fix(lsp): vim.lsp.util.apply_text_edits cursor validation #22636hrsh7th2023-03-14
| | | | | | | | Problem Using wrong variable when checking the cursor position is valid or not in vim.lsp.util.apply_text_edits. Solution Use the correct variable.
* revert: "fix(lsp): use buffer scheme for files not stored on disk" (#22604)Mathias Fußenegger2023-03-11
| | | | | | | | | | | Although using `buffer://` for unsaved file buffers fixes issues with language servers like eclipse.jdt.ls or ansible-language-server, it breaks completion and signature help for clangd. A regression is worse than a fix for something else, so this reverts commit 896d672736b32a8f4a4fa51844b44f266dcdcc6c. The spec change is also still in dicussion, see https://github.com/microsoft/language-server-protocol/pull/1679#discussion_r1130704886
* docs(lsp): change type annotations from number → integer (#22510)Jaehwang Jung2023-03-07
|
* fix(lsp): use buffer scheme for files not stored on disk (#22407)Mathias Fußenegger2023-03-01
| | | | | | Sending `didOpen` with a `file` scheme causes problems with some language servers because they expect the file to exist on disk. See https://github.com/microsoft/language-server-protocol/pull/1679
* fix(lsp): check if the buffer is a directory before w! it (#22289)Eduard Baturin2023-02-18
|
* docs(lsp): fix type annotation on convert_input_to_markdown_lines (#21772)Chris Kipp2023-01-12
| | | | | This small changes just ensures that if you're using `convert_input_to_markdown_lines` without `contents` you don't get a warning (when using something like neodev) that there is an expected second param, since it can be nil.
* feat(float): open float relative to mouse #21531Sebastian Lyng Johansen2023-01-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Problem: No easy way to position a LSP hover window relative to mouse. Solution: Introduce another option to the `relative` key in `nvim_open_win()`. With this PR it should be possible to override the handler and do something similar to this https://github.com/neovim/neovim/pull/19481#issuecomment-1193248674 to have hover information displayed from the mouse. Test case: ```lua local util = require('vim.lsp.util') local function make_position_param(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) local row, col local mouse = vim.fn.getmousepos() row = mouse.line col = mouse.column offset_encoding = offset_encoding or util._get_offset_encoding(buf) row = row - 1 local line = vim.api.nvim_buf_get_lines(buf, row, row + 1, true)[1] if not line then return { line = 0, character = 0 } end if #line < col then return { line = 0, character = 0 } end col = util._str_utfindex_enc(line, col, offset_encoding) return { line = row, character = col } end local make_params = function(window, offset_encoding) window = window or 0 local buf = vim.api.nvim_win_get_buf(window) offset_encoding = offset_encoding or util._get_offset_encoding(buf) return { textDocument = util.make_text_document_params(buf), position = make_position_param(window, offset_encoding), } end local hover_timer = nil vim.o.mousemoveevent = true vim.keymap.set({ '', 'i' }, '<MouseMove>', function() if hover_timer then hover_timer:close() end hover_timer = vim.defer_fn(function() hover_timer = nil local params = make_params() vim.lsp.buf_request( 0, 'textDocument/hover', params, vim.lsp.with(vim.lsp.handlers.hover, { silent = true, focusable = false, relative = 'mouse', }) ) end, 500) return '<MouseMove>' end, { expr = true }) ```
* docs(lua): adjust some type annotationsnotomo2023-01-04
|
* fix(lsp): fix get_active_clients bufnr parameter (#21366)Mathias Fußenegger2022-12-09
| | | Follow up to https://github.com/neovim/neovim/pull/21337
* refactor(lsp): remove deprecated vim.lsp.buf_get_clients calls (#21337)Raphael2022-12-08
|
* fix(lsp): render <pre>{lang} code blocks and set separator default to false ↵Folke Lemaitre2022-12-03
| | | | (#21271)
* docs: fix typos (#21196)dundargoc2022-11-29
| | | | | Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: Raphael <glephunter@gmail.com> Co-authored-by: Gregory Anders <greg@gpanders.com>
* feat(lsp): support set title in lsp relate floatwindow (#21110)Raphael2022-11-21
|
* fix(lua): properly configure luacheck and remove `local vim = ...` lines ↵Folke Lemaitre2022-10-09
| | | | (#20551)