aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
Commit message (Collapse)AuthorAge
* fix(lsp): directly rename the existing buffers when renaming (#27690)Jaehwang Jung2024-03-02
| | | | | | | | | | | | | | | | Problem: `vim.lsp.util.rename()` deletes the buffers that are affected by renaming. This has undesireable side effects. For example, when renaming a directory, all buffers under that directory are deleted and windows displaying those buffers are closed. Also, buffer options may change after renaming. Solution: Rename the buffers with :saveas. An alternative approach is to record all the relevant states and restore it after renaming, but that seems to be more complex. In fact, the older version was attempting to restore the states but only partially and incorrectly.
* docs: improve/add documentation of Lua typesLewis Russell2024-03-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added `@inlinedoc` so single use Lua types can be inlined into the functions docs. E.g. ```lua --- @class myopts --- @inlinedoc --- --- Documentation for some field --- @field somefield integer --- @param opts myOpts function foo(opts) end ``` Will be rendered as ``` foo(opts) Parameters: - {opts} (table) Object with the fields: - somefield (integer) Documentation for some field ``` - Marked many classes with with `@nodoc` or `(private)`. We can eventually introduce these when we want to.
* fix(lsp): rename undofile when renaming (#27684)Jaehwang Jung2024-03-01
| | | | | | | Problem: After `rename()`, the undo information for the renamed file(s) are lost. Solution: Rename the undofile as well.
* fix(lsp): remove unnecessary file load/write when renaming (#27621)Jaehwang Jung2024-02-28
| | | | | | | | | Previously rename would unconditionally read the to-be-renamed file from the disk and write it to the disk. This is redundant in some cases If the file is not already loaded, it's not attached to lsp client, so nvim doesn't need to care about this file. If the file is loaded but has no change, it doesn't need to be written.
* feat(lsp): support completion itemDefaultsMaria José Solano2024-02-27
|
* feat(docs): replace lua2dox.luaLewis Russell2024-02-27
| | | | | | | | | | | | | | | | | | | | | | | | | | Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change).
* fix(lsp): add assertion for explicit bufnr in apply_text_edits (#27614)Gregory Anders2024-02-24
| | | | | Assert that the buffer number passed to apply_text_edits is fully resolved (not 0 or null). Pass the known buffer number to apply_text_edits from lsp.formatexpr().
* fix(lsp): when renaming directory, check path prefix of buffer names (#27603)Jaehwang Jung2024-02-24
| | | | | For example, when renaming /path/to/dir, buffers like fern://drawer/file:///path/to/dir, /path/to/dir123 should not be matched.
* refactor(lsp): remove redundant code (#27601)Jaehwang Jung2024-02-24
| | | | * use builtin function * buffer:// was removed in 236c20795eb9f11e21e0719b735ea741711acc08.
* fix(lsp): rename: load and list new buffer if attached to window (#27408)Tomasz N2024-02-14
|
* fix(lsp): rename fails on missing parent directory #27291Tomasz N2024-02-08
| | | | | | | | Problem: If a rename results in a path that has missing parent directory(s), it will fail. Solution: Do a recursive mkdir before attempting the rename.
* refactor: create function for deferred loadingdundargoc2024-02-03
| | | | | | | | | | | | | | | | The benefit of this is that users only pay for what they use. If e.g. only `vim.lsp.buf_get_clients()` is called then they don't need to load all modules under `vim.lsp` which could lead to significant startuptime saving. Also `vim.lsp.module` is a bit nicer to user compared to `require("vim.lsp.module")`. This isn't used for some nested modules such as `filetype` as it breaks tests with error messages such as "attempt to index field 'detect'". It's not entirely certain the reason for this, but it is likely it is due to filetype being precompiled which would imply deferred loading isn't needed for performance reasons.
* refactor(lsp): deprecate `vim.lsp.util.lookup_section`Jongwook Choi2024-01-16
| | | | | | | | This function is used only in the `workspace/configuration` handler, and does not warrant a public API because of its confusing return types. The only caller `vim.lsp.handlers["workspace.configuration"]` is also refactored to use `vim.tbl_get()` instead.
* docs: add lua typing for `vim.NIL`Jongwook Choi2024-01-15
|
* fix(doc): improve doc generation of types using lpegLewis Russell2024-01-11
| | | | Added a lpeg grammar for LuaCATS and use it in lua2dox.lua
* fix(docs): clean up non-docstring comments for vimdoc genJongwook Choi2024-01-02
| | | | | These non-docstring comments can be included into doxygen's brief description and then appear in the succeeding function documentation.
* revert: "fix: correct versions in deprecation warnings"dundargoc2023-12-27
| | | | | | | | | | | | | | This reverts commit 5cb906e91cb56302d0737aa80e2d890dde452029. They were intentionally fast-tracked. - `parse_snippet()` because of limited scope, and given that it's kinda semi-broken (arbitrary formatting rules, not that useful for what it was used for) - `extract_completion_items()` doesn't work if we want to add the LSP completionlist capability - `text_document_completion_list_to_complete_items()` also doesn't work for completionlist
* fix: correct versions in deprecation warningsdundargoc2023-12-27
| | | | | | | | | The following functions should be removed in 0.12 according to the deprecation strategy in MAINTAIN.md: - vim.lsp.util.extract_completion_items() - vim.lsp.util.parse_snippet() - vim.lsp.util.text_document_completion_list_to_complete_items()
* refactor: use vim.deprecate on all deprecated functionsdundargoc2023-12-27
|
* feat(lsp): add type annotations for lsp.util.locations_to_items (#26694)Mathias Fußenegger2023-12-22
| | | | Problem: luals reported many warnings Solution: Add type annotations
* feat(lsp): more annotationsLewis Russell2023-12-14
|
* 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