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

Formatters block on session setup #4168

Open
michaelpj opened this issue Apr 9, 2024 · 2 comments · May be fixed by #4170
Open

Formatters block on session setup #4168

michaelpj opened this issue Apr 9, 2024 · 2 comments · May be fixed by #4170
Labels
Hackathon This issue is suitable for hackathon sessions type: enhancement New feature or request

Comments

@michaelpj
Copy link
Collaborator

At the moment, most of our formatter plugins require the GHC session in order to acquire the DynFlags for a module. This is even true for the CLI modes - most of the plugins still get the flags so that they can pass them to the CLI executable.

This means that formatting is generally going to block until the session is set up. This isn't great: in particular, it's not uncommon to have some kind of format-on-save set up, and that means you can't save a file until HLS is finished setting up! (I think there's also a client problem there: I think it should be the client's responsibility to time out formatting in that case)

So it would be nice if this didn't happen. The best thing I can think of doing is just to let the formatters do whatever they do if they don't get the flags specified. That presumably means guessing them from cabal files etc, but crucially in a way that doesn't block on HLS. It would also make them more likely to line up with how a CLI formatter would operate. Or at least if we're in the CLI mode I think we shouldn't take the flags from HLS, since the whole point is to match what the CLI formatter does.

Thoughts from formatting plugin maintainers? @georgefst @peterbecich ?

@michaelpj michaelpj added the type: enhancement New feature or request label Apr 9, 2024
Profpatsch added a commit to Profpatsch/haskell-language-server that referenced this issue Apr 9, 2024
Probably not the best solution.

When ormolu is requested from the command line, it should do its own
detection of cabal features. If it has to set up the GhcSession just
to get some flags, it blocks saving a file (`formatOnSave = true`),
which is a horrible user experience in cases where the session takes a
minute or more to set up.

Instead, now the plugin only depends on ormolu and the file itself.

Fixes haskell#4168
@michaelpj
Copy link
Collaborator Author

See #4170

@michaelpj
Copy link
Collaborator Author

We could also have an option, of course, although generally better to just do the right thing.

@michaelpj michaelpj added the Hackathon This issue is suitable for hackathon sessions label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hackathon This issue is suitable for hackathon sessions type: enhancement New feature or request
Projects
Development

Successfully merging a pull request may close this issue.

1 participant