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

How to use configuration found in .rustfmt.toml when running Rust format? #503

Open
MitchTurner opened this issue Nov 2, 2023 · 1 comment

Comments

@MitchTurner
Copy link

  • rust.vim version: Whatever comes automatically by including "rust-lang/rust.vim" in my plugins.lua file
  • nvchad distro of Neovim.

Steps to reproduce:

In my plugin directory I currently have:

  {
    "rust-lang/rust.vim",
    ft = "rust",
    init = function ()
      vim.rustfmt_options = "+nightly"
      vim.g.rustfmt_autosave = 1
    end
  },

This is working inasmuch as it's reformatting my code on save.

However, it's ignoring the configurations I have set in the .rustfmt.toml in the parent directory.

For example:

imports_layout = "Vertical"

should result in the imports being stacked, but the formatting from rust.vim is undoing that.

Expected vs. actual behavior:

This isn't a bug as much as a gap in my knowledge. I'd hope to find a solution that recognizes my .rustfmt.toml and includes the configuration. Perhaps I could include a lua script that checks if it exists and includes it in the rustfmt_options?

@MitchTurner
Copy link
Author

MitchTurner commented Nov 3, 2023

It looks like you are in fact doing a search for it:

function! s:RustfmtConfigOptions()
let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';')
if l:rustfmt_toml !=# ''
return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p"))
endif
let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';')
if l:_rustfmt_toml !=# ''
return '--config-path '.shellescape(fnamemodify(l:_rustfmt_toml, ":p"))
endif
" Default to edition 2018 in case no rustfmt.toml was found.
return '--edition 2018'
endfunction

So there must be something else wrong with my config. Or possibly related to how I'm invoking +nightly.

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

No branches or pull requests

1 participant