Skip to content

Add Julia formatter #230

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

Merged
merged 5 commits into from
Nov 24, 2023
Merged

Add Julia formatter #230

merged 5 commits into from
Nov 24, 2023

Conversation

flwyd
Copy link
Contributor

@flwyd flwyd commented Nov 15, 2023

This formatter uses a script wrapping the JuliaFormatter.jl library. This "formatter script in the plugin" approach hasn't been taken before in vim-codefmt, so let me know if you'd prefer a different approach or to reorganize things. (The JuliaFormatter.jl library ships with an executable script, but it only works on file paths (not stdin) and can't handle line ranges. I'm also not sure how to get the path of a bin directory in your Julia environment, which doesn't work like executables in a package management system like npm.)

If the user hasn't installed the JuliaFormatter package, instructions will point to an install script in the same directory as the formatter script. I've tested the shell version of this script, but don't have a Windows machine to test the .cmd version.

The line-range handling is a bit of a hack: the underlying library doesn't expose this functionality, so I used comments to enable/disable the formatter around relevant blocks. I found some edge case behaviors that I've hopefully documented clearly.

The script will use the same .JuliaFormatter.toml files in the parent directory hierarchy of the source file being edited to determine the formatter options like style, indent, and line width. This is the same behavior that running the executable from JuliaFormatter.

flwyd and others added 3 commits November 10, 2023 01:52
@flwyd
Copy link
Contributor Author

flwyd commented Nov 22, 2023

Added vroom test.

Copy link
Contributor

@dbarnett dbarnett left a comment

Choose a reason for hiding this comment

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

This "formatter script in the plugin" approach hasn't been taken before in vim-codefmt

I think it's fine but do wonder what the steps look like if someone wants to invoke identical formatting outside of vim.

@flwyd
Copy link
Contributor Author

flwyd commented Nov 23, 2023

Yeah, I was a little concerned about breaking new ground with a plugin-local formatter script. I don't think this should result in different formatting results within vim vs. outside of vim. While the script looks kind of long, most of it is handling line ranges. The rest is setting up and acting on command line flags. If formatting decisions are encoded in .JuliaFormatter.toml files in the source repository, the results should be the same.

It's worth noting that the JuliaFormatter.vim plugin also ships with Julia code which calls the JuliaFormatter library rather than executing the script which ships with the library.

One can also run JuliaFormatter.format_file("mycode.jl") from the Julia REPL, and it seems like this kind of thing is encouraged, so I'm guessing that formatting choices are done via config rather than by the executable that invokes the library. I'm new to Julia, though, so if we get feedback from Julia users that this script approach is awkward, we can pursue another approach.

@dbarnett dbarnett merged commit 22e551a into google:master Nov 24, 2023
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

Successfully merging this pull request may close these issues.

2 participants