You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DEBUG][2025-02-02 01:33:24] ...m/lsp/client.lua:678 "LSP[rust-analyzer]" "client.request" 1 "completionItem/resolve" { additionalTextEdits = {}, deprecated = false, detail = "const fn(&mut T, T) -> T", documentation = { kind = "markdown", value = "Moves `src` into the referenced `dest`, returning the previous `dest` value.\n\nNeither value is dropped.\n\n* If you want to replace the values of two variables, see [`swap`].\n* If you want to replace with a default value, see [`take`].\n\n# Examples\n\nA simple example:\n\n```rust\nuse std::mem;\n\nlet mut v: Vec<i32> = vec![1, 2];\n\nlet old_v = mem::replace(&mut v, vec![3, 4, 5]);\nassert_eq!(vec![1, 2], old_v);\nassert_eq!(vec![3, 4, 5], v);\n```\n\n`replace` allows consumption of a struct field by replacing it with another value.\nWithout `replace` you can run into issues like these:\n\n```rust\nstruct Buffer<T> { buf: Vec<T> }\n\nimpl<T> Buffer<T> {\n fn replace_index(&mut self, i: usize, v: T) -> T {\n // error: cannot move out of dereference of `&mut`-pointer\n let t = self.buf[i];\n self.buf[i] = v;\n t\n }\n}\n```\n\nNote that `T` does not necessarily implement [`Clone`], so we can't even clone `self.buf[i]` to\navoid the move. But `replace` can be used to disassociate the original value at that index from\n`self`, allowing it to be returned:\n\n```rust\nuse std::mem;\n\nimpl<T> Buffer<T> {\n fn replace_index(&mut self, i: usize, v: T) -> T {\n mem::replace(&mut self.buf[i], v)\n }\n}\n\nlet mut buffer = Buffer { buf: vec![0, 1] };\nassert_eq!(buffer.buf[0], 0);\n\nassert_eq!(buffer.replace_index(0, 2), 0);\nassert_eq!(buffer.buf[0], 2);\n```" }, filterText = "replace", insertTextFormat = 2, kind = 3, label = "replace(…)", labelDetails = { description = "const fn(&mut T, T) -> T" }, preselect = true, score = 32, sortText = "7fffffff", textEdit = { insert = { ["end"] = { character = 16, line = 50 }, start = { character = 13, line = 50 } }, newText = "replace(${1:dest}, ${2:src})$0", replace = { ["end"] = { character = 16, line = 50 }, start = { character = 13, line = 50 } } }} <function 1> 1
Here's how the completion result renders in the editor:
The documentation is difficult to read without the argument names in the function signature.
(Although src and dest could be deduced from the function type alone in this particular example, this would become more of an issue in cases where multiple arguments have the same type signature.)
Potential Solutions:
First option: provide full function signature in detail.
While the spec does permit returning only the function type:
/**
* A human-readable string with additional information
* about this item, like type or symbol information.
*/
detail?: string;
the full function signature + argument names could fall under "symbol information" and better aligns with real-world usage.
Second option: provide full function signature at the beginning of the documentation section. A little verbose, but a solution nonetheless.
Let me know if this would be a good first bug. I'm learning rust and would be happy to give this a go.
The text was updated successfully, but these errors were encountered:
rust-analyzer version: rust-analyzer 1.84.1 (e71f9a9 2025-01-27)
rustc version: rustc 1.84.1 (e71f9a9a9 2025-01-27)
editor or extension: Neovim + blink.cmp
code snippet to reproduce:
Here's the response from Neovim's lsp logs:
Here's how the completion result renders in the editor:
The documentation is difficult to read without the argument names in the function signature.
(Although
src
anddest
could be deduced from the function type alone in this particular example, this would become more of an issue in cases where multiple arguments have the same type signature.)Potential Solutions:
First option: provide full function signature in
detail
.While the spec does permit returning only the function type:
the full function signature + argument names could fall under "symbol information" and better aligns with real-world usage.
Second option: provide full function signature at the beginning of the
documentation
section. A little verbose, but a solution nonetheless.Let me know if this would be a good first bug. I'm learning rust and would be happy to give this a go.
The text was updated successfully, but these errors were encountered: