Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completionItem/resolve response lacks function argument names in detail/documentation #19081

Open
cp289 opened this issue Feb 2, 2025 · 0 comments
Labels
C-bug Category: bug

Comments

@cp289
Copy link

cp289 commented Feb 2, 2025

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:

fn main() {
    mem::replace
}

Here's the response from Neovim's lsp logs:

[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:

Image

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.

@cp289 cp289 added the C-bug Category: bug label Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

1 participant