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

Don't auto_attach for buffer without an actual file? #268

Closed
tomtomjhj opened this issue Mar 2, 2024 · 1 comment · Fixed by #272
Closed

Don't auto_attach for buffer without an actual file? #268

tomtomjhj opened this issue Mar 2, 2024 · 1 comment · Fixed by #272
Labels
enhancement New feature or request

Comments

@tomtomjhj
Copy link
Contributor

Feature description

When I :setf rust in a new buffer without name (e.g., created by :new), rust-analyzer panics with error msg like this:

thread 'LspServer' panicked at crates/paths/src/lib.rs:79:36:
expected absolute path, got 

The reason is that rust-analyzer expects usual file path, but rustaceanvim unconditionally attempts to attach any rust buffer even if its name is not an actual file path. This also happens for other kind of buffers with rust filetype, such as vim-fugitive's blob buffer, which has a name of form fugitive:///path/to/file.rs.

To avoid this, I ended up adding something like this in my config:

    auto_attach = function()
      -- Only attach to buf with actual file. rust-analyzer expects real path and panics otherwise.
      local b = vim.api.nvim_get_current_buf()
      local path = vim.fs.normalize(vim.api.nvim_buf_get_name(b), { expand_env = false })
      return vim.bo[b].buftype == '' and path:sub(1,1) == '/'
    end,

While this worked for me, I believe this should be handled in rustaceanvim itself.

@tomtomjhj tomtomjhj added the enhancement New feature or request label Mar 2, 2024
@mrcjkb
Copy link
Owner

mrcjkb commented Mar 2, 2024

Hey again 😄

Thanks for the suggestion. It sounds reasonable off the top of my head.
I will have to make sure this also works for Windows, which can have paths that start with drive letters.

@mrcjkb mrcjkb linked a pull request Mar 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants