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

When applying code action escape character is inserted before } #303

Closed
5 tasks done
AradiPatrik opened this issue Mar 19, 2024 · 13 comments · Fixed by #338
Closed
5 tasks done

When applying code action escape character is inserted before } #303

AradiPatrik opened this issue Mar 19, 2024 · 13 comments · Fixed by #338
Labels

Comments

@AradiPatrik
Copy link

Have you read the docs and searched existing issues?

Neovim version (nvim -v)

v0.9.5

Operating system/version

macOS 14.3.1 (23D60)

Output of :checkhealth rustaceanvim

rustaceanvim: require("rustaceanvim.health").check()

Checking for Lua dependencies ~
- OK [mfussenegger/nvim-dap](https://github.com/mfussenegger/nvim-dap) installed.

Checking external dependencies ~
- OK rust-analyzer: found rust-analyzer 0.0.0 (5346002d0 2024-02-25)
- OK Cargo: found cargo 1.76.0 (c84b36747 2024-01-18)
- OK rustc: found rustc 1.76.0 (07dca489a 2024-02-04)
- OK lldb: found lldb-1500.0.404.7

Checking config ~
- OK No errors found in config.

Checking for conflicting plugins ~
- OK No conflicting plugins detected.

Checking for tree-sitter parser ~
- OK tree-sitter parser for Rust detected.

How to reproduce the issue

mkdir -p /tmp/minimal/
NVIM_DATA_MINIMAL="/tmp/minimal" NVIM_APP_NAME="nvim-minimal" nvim -u NORC -u minimal.lua
:edit main.rs
/impl<CR>
:lua vim.lua.buf.code_action()<CR>
1<CR>

Expected behaviour

code_action_issue.mov

The expected behavior is to have regular closing braces generated }.
Please check the video issue. It should be quite obvious.

Actual behaviour

Right now closing braces are escaped for some reason \} instead of }
Please check the attached video.

The minimal config used to reproduce this issue.

The minimal config linked in the troubleshooting
@AradiPatrik AradiPatrik added the bug Something isn't working label Mar 19, 2024
@AradiPatrik
Copy link
Author

The code to demonstrate the issue main.rs

trait Messenger {
    fn send(&self, message: &str);
}

struct LimitTracker<'a, T: Messenger> {
    messenger: &'a T,
    value: u32,
    limit: u32,
}

impl<'a, T: Messenger> LimitTracker<'a, T> {
    fn set_value(&mut self, value: u32) {
        if self.limit as f32 / value as f32 > 0.5f32 {
            self.messenger.send("You've consumed half of your quota");
        } else if self.limit as f32 / value as f32 > 0.75f32 {
            self.messenger
                .send("Warning! You've consumed 75% of your quota");
        } else if self.limit as f32 / value as f32 > 0.9f32 {
            self.messenger
                .send("Urgent! You've consumed 90% of your quota");
        }

        self.value = value
    }
}

fn main() {}

@mrcjkb
Copy link
Owner

mrcjkb commented Mar 19, 2024

Hey 👋

Thanks for the detailed report. This is a rust-analyzer bug: rust-lang/rust-analyzer#16607

@mrcjkb mrcjkb closed this as completed Mar 19, 2024
@mrcjkb mrcjkb added upstream and removed bug Something isn't working labels Mar 19, 2024
@rami3l
Copy link

rami3l commented Mar 20, 2024

@mrcjkb Looks like the problem is more complicated than it seems...

Coming exactly from rust-lang/rust-analyzer#16867, I made my own tests and saw that even on Neovim v0.10 I can still reproduce this issue with this plugin enabled. However, if I disable this plugin, then the completion works fine.

@mrcjkb
Copy link
Owner

mrcjkb commented Mar 20, 2024

@mrcjkb Looks like the problem is more complicated than it seems...

Coming exactly from rust-lang/rust-analyzer#16867, I made my own tests and saw that even on Neovim v0.10 I can still reproduce this issue with this plugin enabled. However, if I disable this plugin, then the completion works fine.

🤔 vim.lua.buf.code_action() isn't implemented by this plugin. It's a core neovim function.
So that sounds very fishy.

Are you sure you're using the same rust-analyzer version in both cases? Many neovim distributions use mason.nvim to install it.

@rami3l
Copy link

rami3l commented Mar 20, 2024

@mrcjkb Thanks a lot for your timely reply! I did some more research and it did point me to a different direction.

Are you sure you're using the same rust-analyzer version in both cases?

I'm quite sure about this one. Initially I thought it was an r-a problem so that was my first thing to look into. However I do think the latest version of r-a is now generating the correct output.

🤔 vim.lua.buf.code_action() isn't implemented by this plugin. It's a core neovim function. So that sounds very fishy.

That's why I didn't think of disabling this plugin at first. However I'm not suggesting it's directly causing the problem.

I'm thinking in theory this plugin should do no harm to the whole code action thing, except it somehow puts r-a into an output mode Neovim cannot handle properly.

After some more research I've found fannheyward/coc-rust-analyzer@5059573 to support this theory. Looks like it has something to do with:

snippetTextEdit = true,

If this is the case, probably there're some problems remaining even with the updated Neovim after all.

@mrcjkb
Copy link
Owner

mrcjkb commented Mar 20, 2024

@rami3l wow thanks for the thorough research! 😀

If I have some time in the next days, I'll see if can find the issue in neovim.

In the meantime, you should be able to work around this by explicitly setting the capability to false via vim.g.rustaceanvim.server.capabilities.

@rami3l
Copy link

rami3l commented Mar 20, 2024

@rami3l wow thanks for the thorough research! 😀

If I have some time in the next days, I'll see if can find the issue in neovim.

In the meantime, you should be able to work around this by explicitly setting the capability to false via vim.g.rustaceanvim.server.capabilities.

@mrcjkb Thanks for your pointers! Now I can 100% confirm that this problem can be worked around by setting vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false.

@mrcjkb
Copy link
Owner

mrcjkb commented Mar 24, 2024

🤔 I can't reproduce this with my personal config, but I can with a minimal one.
I wonder if there's a neovim setting or plugin that is fixing it in my config.

@elithrade
Copy link

@rami3l wow thanks for the thorough research! 😀
If I have some time in the next days, I'll see if can find the issue in neovim.
In the meantime, you should be able to work around this by explicitly setting the capability to false via vim.g.rustaceanvim.server.capabilities.

@mrcjkb Thanks for your pointers! Now I can 100% confirm that this problem can be worked around by setting vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false.

@rami3l can I please ask how do you set vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false? I am using LazyVim.

@mrcjkb
Copy link
Owner

mrcjkb commented Mar 30, 2024

@rami3l wow thanks for the thorough research! 😀
If I have some time in the next days, I'll see if can find the issue in neovim.
In the meantime, you should be able to work around this by explicitly setting the capability to false via vim.g.rustaceanvim.server.capabilities.

@mrcjkb Thanks for your pointers! Now I can 100% confirm that this problem can be worked around by setting vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false.

@rami3l can I please ask how do you set vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false? I am using LazyVim.

See :h rustaceanvim.config and the LazyVim documentation on the rust extension pack.

@rami3l
Copy link

rami3l commented Mar 30, 2024

@rami3l wow thanks for the thorough research! 😀
If I have some time in the next days, I'll see if can find the issue in neovim.
In the meantime, you should be able to work around this by explicitly setting the capability to false via vim.g.rustaceanvim.server.capabilities.

@mrcjkb Thanks for your pointers! Now I can 100% confirm that this problem can be worked around by setting vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false.

@rami3l can I please ask how do you set vim.g.rustaceanvim.server.capabilities.experimental.snippetTextEdit to false? I am using LazyVim.

@elithrade You seem to be using lazy.nvim to install this plugin, so you should be good to go after simply adding that assignment to this plugin's config function.

ctx: https://github.com/folke/lazy.nvim?tab=readme-ov-file#-plugin-spec

@rami3l
Copy link

rami3l commented Mar 30, 2024

🤔 I can't reproduce this with my personal config, but I can with a minimal one. I wonder if there's a neovim setting or plugin that is fixing it in my config.

@mrcjkb Thanks again for your efforts! Would you like to share the minimal reproduction with Neovim? I guess it's still a problem to be addressed on their side...

@mrcjkb
Copy link
Owner

mrcjkb commented Mar 30, 2024

🤔 I can't reproduce this with my personal config, but I can with a minimal one. I wonder if there's a neovim setting or plugin that is fixing it in my config.

@mrcjkb Thanks again for your efforts! Would you like to share the minimal reproduction with Neovim? I guess it's still a problem to be addressed on their side...

I am planning to look into it, but haven't had the time yet 😃
Since it's related to an experimental rust-analyzer feature, I don't think it's worth opening an issue with Neovim yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants