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

vim.lsp.formatOnSave doesn't work when rust has an async function #589

Open
1 task done
JamyGolden opened this issue Jan 27, 2025 · 7 comments
Open
1 task done
Assignees
Labels
bug Something isn't working

Comments

@JamyGolden
Copy link

⚠️ Please verify that this bug has NOT been reported before.

  • I checked all existing issues and didn't find a similar issue

Description

vim.lsp.formatOnSave doesn't work when there is an async function in the file.

👟 Reproduction steps

  1. Create example.rs

    pub(crate) async fn example_fn(
    ) -> Result<(), Box<(dyn std::error::Error + 'static)>> {
    println!("hello world");
    
        Ok(())
    }

    Saving this file doesn't run vim.lsp.buf.format() (lua). When i run that manually :lua vim.lsp.buf.format() it formats correctly.

  2. Removing the async keyword enables the formatting:

    pub(crate) fn example_fn(
    ) -> Result<(), Box<(dyn std::error::Error + 'static)>> {
    println!("hello world");
    
        Ok(())
    }

    Saving this file formats correctly indenting the println!("hello world"); line.

👀 Expected behavior

Format correctly with async keyword present in file.

😓 Actual Behavior

Only formats when async keyword doesn't exist in file.

💻 Metadata

  • system: "x86_64-linux" - host os: Linux 6.9.3-76060903-generic, Pop!_OS, 22.04 LTS, nobuild - multi-user?: no - sandbox: yes - version: nix-env (Nix) 2.25.2 - nixpkgs: /home/user/.nix-defexpr/channels/nixpkgs

📝 Relevant log output

n/a
@JamyGolden JamyGolden added the bug Something isn't working label Jan 27, 2025
@NotAShelf
Copy link
Owner

Okay I can certainly reproduce this, but I'm not exactly sure where this comes from. I'll need to look into this further, but I currently lack the time.

I'll try to bump plugin inputs tomorrow and see if that helps, my guess would be that rustaceanvim screwed up somewhere (since it provides LSP formatting capabilities) or none-ls is overriding something, incorrectly.

@NotAShelf NotAShelf self-assigned this Jan 27, 2025
@NotAShelf
Copy link
Owner

I've updated rustaceanvim in a recent commit, could you see if it resolves the issue?

  'github:mrcjkb/rustaceanvim/51c097ebfb65d83baa71f48000b1e5c0a8dcc4fb' (2024-12-29)
  → 'github:mrcjkb/rustaceanvim/4a2f2d2cc04f5b0aa0981f98bb7d002c898318ad' (2025-01-29)

does not inspire much confidence, but since I have not noticed breakage with async before chances are it's an issue with Neovim 0.10.3 >

@JamyGolden
Copy link
Author

I've tested and still getting the same issue. I don't get this bug with rustaceanvim on my dotfiles setup (with neovim 0.10.3), but I use lsp-zero and formatOnSave set to rust-analyzer. If the issue is with null-ls, I'm guessing the issue is here to stay since it was deprecated in 2023.

@NotAShelf
Copy link
Owner

We've since switched to the maintained fork, none-ls, but I not entirely conviced that it is where the issue resides.

Regardless, we'll be dropping none-ls in favor of conform and nvim-lint very soon.

@cramt
Copy link

cramt commented Feb 10, 2025

i also seem to be having this issue in rust

@NotAShelf
Copy link
Owner

Yes, I've confirmed the issue but have not been able to determine the root cause yet. My two guesses are

  1. nixpkgs & rustfmt
  2. none-ls doing something weird (more likely)

Progress is being made in #593, which introduces a new formatter framework. It's halted for the time, but I'll try to complete it over this week.

@cramt
Copy link

cramt commented Feb 10, 2025

when i come home i'll try out the branch and see if solves it for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants