Conversation
|
Hey, thanks for your contribution! Did you know there is https://github.com/bram209/leptos-language-server as well? Also, leptosfmt currently only formats the Anyway, this looks good so far, I would gladly merge this feature, am currently traveling so will review when I get back home. |
|
Nope, I will check it out and get it added to Mason if possible :D. For the second thing, I basically just run the leptosfmt null-ls command first, and then the rust-analyzer rustfmt second. This is done because locally I just use: nls.builtins.formatting.rustfmt.with({
extra_args = { "--edition=2021" },
filetypes = { "rust" }
}),
leptosfmt.with({
condition = function(utils)
return utils.root_has_file({ "leptosfmt.toml" })
end,
}),Which only enables leptosfmt if there is a config file, this prevents it from running for arbitrary rust files which doesn't have leptos deps. It could make sense to wrap the rustfmt in leptos, but it seems a bit hacky and would make onboarding to the tool maybe a bit steeper. I.e. that people would have to disable the normal rustfmt when using leptos. That said it could be an easier option. And I am not in a hurry so take your time. I will continue to use my own fork until then =D |
formatter/src/lib.rs
Outdated
| format_file_source(&file, settings) | ||
| } | ||
|
|
||
| pub fn format_stdin(content: &[u8], settings: FormatterSettings) -> Result<String, FormatError> { |
There was a problem hiding this comment.
This is basically a "format utf8 encoded bytes" method, as the formatter crate is not aware / does not care if it comes from stdin or not.
I think I prefer to export format_file_source (pub use format_file_source in lib.rs) and then calling that from the CLI crate, agree?
cli/src/main.rs
Outdated
|
|
||
| fn format_stdin_result(settings: FormatterSettings) -> anyhow::Result<()> { | ||
| let buf = &mut Vec::new(); | ||
| let _ = std::io::stdin().read_to_end(buf)?; |
There was a problem hiding this comment.
you can use read_to_string here: https://doc.rust-lang.org/stable/std/io/trait.Read.html#method.read_to_string
|
Just saw the review comments. I will update with revisions etc. I should get around to it in a few days or so =D |
cli/src/main.rs
Outdated
| #[arg(short, long)] | ||
| config_file: Option<PathBuf>, | ||
|
|
||
| #[arg(short, long, default_missing_value = "false")] |
There was a problem hiding this comment.
I am very interested in this functionality as well, so just a drop by comment
Should these just be of type bool and remove the default_missing_value? Right now it panics if stdin and quiet is not provided as flags. It would also allow to type --stdin instead of --stdin=true which just is redundant IMO
I also feel like quiet should be default to true if stdin is true
There was a problem hiding this comment.
Yep. I agree. I will definitely change it to proper flags when I get around to fixing it xD
dfae3d4 to
0863ce1
Compare
Signed-off-by: kjuulh <contact@kjuulh.io>
Signed-off-by: kjuulh <contact@kjuulh.io>
Signed-off-by: kjuulh <contact@kjuulh.io>
0863ce1 to
8338eb5
Compare
Signed-off-by: kjuulh <contact@kjuulh.io>
Signed-off-by: kjuulh <contact@kjuulh.io>
Signed-off-by: kjuulh <contact@kjuulh.io>
|
Thank you for your contribution! |
Adds quiet and stdin mode, which are useful when integrating with text mode
editors, such as neovim with null-ls.
The code is a bit messy, I could refactor it, but I wanted to see if this was
something you would be interested in