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

use which on formatter command #8064

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

zaucy
Copy link
Contributor

@zaucy zaucy commented Aug 25, 2023

This allows my formatter command to work on Windows and Linux without having to edit my config between machines. Example:

[[language]]
name = "typescript"
formatter = { command = './node_modules/.bin/prettier', args = ["--parser", "typescript"] }

I'm unsure if this is breaking expected behaviour, but to me this seems like a non-breaking improvement especially for Windows users who often have to switch between operating systems.

@zaucy zaucy force-pushed the feat/which-formatter-command branch 2 times, most recently from a84e850 to 449181f Compare August 25, 2023 20:55
@Masynchin
Copy link

You can get rid of .unwrap()'s by converting Result to Option. I wrote this code sample as an example of it, haven't test it though. You can use it if it is improves readability.

let fmt_cmd = |formatter| which::which(&formatter.command)
    .ok()
    .and_then(|cmd| cmd.into_os_string().into_string())

if let Some((fmt_cmd, fmt_args)) = self
    .language_config()
    .and_then(|c| c.formatter.clone())
    .and_then(|formatter| fmt_cmd(formatter).map(|cmd| (cmd, formatter.args.clone())))

@zaucy zaucy force-pushed the feat/which-formatter-command branch from 4160705 to 722bada Compare August 25, 2023 21:36
@zaucy
Copy link
Contributor Author

zaucy commented Aug 25, 2023

Thanks! I removed the unwrap calls.

@kirawi
Copy link
Member

kirawi commented Aug 25, 2023

I think #5832 addresses this.

@zaucy
Copy link
Contributor Author

zaucy commented Aug 25, 2023

I personally would prefer to not run through my shell (especially on Windows), but I can see the advantage with environment variables expansion etc.

I think #5538 (comment) is a pretty reasonable instead of forcing use of the editor shell.

@clo4
Copy link
Contributor

clo4 commented Aug 26, 2023

I personally would prefer to not run through my shell (especially on Windows)

Hmm, yeah I feel the same way - I'd rather not launch my shell just to run the formatter, that seems like unnecessary overhead. I keep my shell launching fast so it's no big deal to me, but there's no reason to run it just for this, and for people that have slower setups it'll definitely be noticeable.

The other issue with launching a shell is that it will very likely cause issues with other people's shell setups. Some people have interactive prompts when they launch a shell regardless of whether it's interactive or not (while working for Fig I saw a surprising amount of people with this 😔). Also seems like it might (?) cause issues with ZSH users that unconditionally prepend their path in ~/.zshenv, for example with Python virtualenvs.

IIRC Helix now has its own reusable variable expansion, right? Could we use that here?

@kirawi
Copy link
Member

kirawi commented Aug 26, 2023

There is, but it only takes in a Path. You would also have to parse the arguments being passed, and correctly replace them with the expanded paths.

https://github.com/helix-editor/helix/blob/master/helix-core/src/shellwords.rs could maybe be used towards that.

@archseer
Copy link
Member

I personally would prefer to not run through my shell

I agree here, if shell expansion is desired the end user can always manually invoke the shell: zsh -c 'formatter $VAR' etc

@archseer
Copy link
Member

Does this also address #5538?

@archseer archseer added this to the next milestone Aug 29, 2023
@pascalkuthe
Copy link
Member

pascalkuthe commented Aug 29, 2023

Does this also address #5538?

I don't think so arguments are not shell expanded here. We could check if an argument starts with a tilde and expands appropriately (or full shell expansion ala https://crates.io/crates/shellexpand).

That seems orthogonal to me tough, this PR makes formatters behave the same as LSP servers which I think is the right thing for now. If we do endup adding such a feature I thing we should do the same thing for LSP servers.

Copy link
Member

@pascalkuthe pascalkuthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah missed somethinmg

@zaucy zaucy force-pushed the feat/which-formatter-command branch from 1c4ad0a to 20fd68a Compare August 29, 2023 17:10
@zaucy zaucy requested a review from pascalkuthe August 29, 2023 17:10
@zaucy
Copy link
Contributor Author

zaucy commented Aug 29, 2023

cargo check is passing locally for me, but the CI is failing. I don't think it's related to my PRs contents. Rebasing against master to see if it is fixed.

@zaucy zaucy force-pushed the feat/which-formatter-command branch from 20fd68a to 953a180 Compare August 29, 2023 17:23
@zaucy zaucy changed the title feat: use which on formatter command use which on formatter command Aug 29, 2023
pascalkuthe
pascalkuthe previously approved these changes Aug 29, 2023
@pascalkuthe pascalkuthe added E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer. labels Aug 29, 2023
@pascalkuthe pascalkuthe merged commit 6bef982 into helix-editor:master Aug 30, 2023
@zaucy zaucy deleted the feat/which-formatter-command branch August 30, 2023 17:14
dgkf pushed a commit to dgkf/helix that referenced this pull request Jan 30, 2024
mtoohey31 pushed a commit to mtoohey31/helix that referenced this pull request Jun 2, 2024
smortime pushed a commit to smortime/helix that referenced this pull request Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Experience needed to fix: Easy / not much S-waiting-on-review Status: Awaiting review from a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants