kilbd / nova-rust

A Rust extension for the Nova text editor, using the Rust Analyzer language server.
MIT License
29 stars 5 forks source link

[BUG] Formatting looks for rustfmt.toml in the wrong directory #43

Closed edwardloveall closed 1 year ago

edwardloveall commented 1 year ago

Describe the bug

When formatting on save, my custom rustfmt settings set in rustfmt.toml at the root of the project are not respected. I think this code in rust-formatter.ts is the culprit. If I do something similar in a javascript console I get the parent directory:

const path = "/path/to/project-dir"
path.substring(0, path.lastIndexOf('/')) // returns '/path/to'

To Reproduce Steps to reproduce the behavior:

  1. cargo new test-project
  2. cd test-project
  3. echo 'tab_spaces = 2' > rustfmt.toml (or whatever format that's not standard)
  4. Open project nova .
  5. Ensure Format on save is enabled
  6. Open src/main.rs
  7. Save

Expected behavior

The 4-space indent becomes a 2-space indent

Versions (please complete the following information):

Additional context

I was able to get this to work if I put the rustfmt.toml in the directory above my project directory. I thought that maybe the project was expecting the dir to have a slash at the end, so I tried opening it with nova ./ instead of my normal nova . but that didn't help.

I also tried to run the extension locally, but typescript would not build on account of some mismatched nova types.

kilbd commented 1 year ago

Thank you for reporting this issue! Thanks also for all the detail and letting me know what you've tried. I'll admit I haven't been good about including a rustfmt.toml in recent projects so I didn't experience this bug. 😅

You were close to the source, but the real issue was this conditional. In one case I return the file path, and in another I return a directory path. I must have been careless when I tried to get format on save to find the Rust edition for the project (rustfmt defaults to 2015 edition for some reason).

Fix is coming shortly!

edwardloveall commented 1 year ago

Amazing, and thank you! Updated and it works great. I'll close the issue.