rust-analyzer
rust-analyzer copied to clipboard
Some code actions send more than one snippet text edits
rust-analyzer version: rust-analyzer 1 (67920f797 2022-09-04)
rustc version: rustc 1.57.0 (f1edd0429 2021-11-29)
minimal repro:
- Have this struct
#[derive(Debug)]
struct Bruh {
a: i32,
}
- Request code actions when hovered on Debug
- Chose "Convert to manual impl..."
expected result: Only one snippetTextEdit is sent, like in the docs
actual result: More than one snippetTextEdit is sent
|| { {
|| insertTextFormat = 2,
|| newText = "",
|| range = {
|| end = {
|| character = 16,
|| line = 2
|| },
|| start = {
|| character = 0,
|| line = 2
|| }
|| }
|| }, {
|| insertTextFormat = 2,
|| newText = "",
|| range = {
|| end = {
|| character = 0,
|| line = 3
|| },
|| start = {
|| character = 16,
|| line = 2
|| }
|| }
|| }, {
|| insertTextFormat = 2,
|| newText = "\n\nimpl std::fmt::Debug for Bruh {\n $0fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n f.debug_struct(\"Bruh\").field(\"a\", &self.a).finish()\n }\n}",
|| range = {
|| end = {
|| character = 1,
|| line = 5
|| },
|| start = {
|| character = 1,
|| line = 5
|| }
|| }
|| } }
(insertTextFormat 2 is a snippetTextEdit)
References:
- https://github.com/L3MON4D3/LuaSnip/issues/235
VS Code got first-class impl, we should align with that: https://github.com/microsoft/vscode/issues/145374#event-7376292737
Isn't this a duplicate of #11006?
As of #15876, code actions may send more than one edit as a snippet text edit (e.g. generate_trait_from_impl
), but only one document may have snippets applied to it. I think this can be closed now that that has been clarified.
Note that we should never generate a snippet text edit that doesn't have placeholders or tabstops in the new text (i.e. the empty snippet edit new text was considered a bug), which the current snippet rendering implementation should never do. 😁