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

Some code actions send more than one snippet text edits #13213

Closed
simrat39 opened this issue Sep 9, 2022 · 3 comments
Closed

Some code actions send more than one snippet text edits #13213

simrat39 opened this issue Sep 9, 2022 · 3 comments
Labels
A-lsp LSP conformance issues and missing features C-bug Category: bug

Comments

@simrat39
Copy link
Contributor

simrat39 commented Sep 9, 2022

rust-analyzer version: rust-analyzer 1 (67920f7 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:

@matklad
Copy link
Member

matklad commented Sep 13, 2022

VS Code got first-class impl, we should align with that: microsoft/vscode#145374 (comment)

@Veykril Veykril added the A-lsp LSP conformance issues and missing features label Sep 13, 2022
@nemethf
Copy link
Contributor

nemethf commented Sep 28, 2022

Isn't this a duplicate of #11006?

@Veykril Veykril added the C-bug Category: bug label Feb 13, 2023
@DropDemBits
Copy link
Contributor

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. 😁

@Veykril Veykril closed this as completed Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lsp LSP conformance issues and missing features C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

5 participants