Skip to content

Improve duration until format is possible #3282

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

Closed
andys8 opened this issue Oct 11, 2022 · 7 comments
Closed

Improve duration until format is possible #3282

andys8 opened this issue Oct 11, 2022 · 7 comments
Labels

Comments

@andys8
Copy link
Collaborator

andys8 commented Oct 11, 2022

Is your enhancement request related to a problem? Please describe.

It takes quite some time until the language server can be used to format a file. This is likely due to the way haskell-language-server loads a session and does multiple things on initialization. But: Especially formatting could be possible early. Especially if a process is forked to do the work (fourmolu). E.g. purescript-language-server allows formatting and still shows that initialization is in progress. So in theory it could be possible to format files before HLS has finished initialization.

Demo

Here is a demo with a small project (https://github.com/andys8/git-brunch).

screencast-2022-10-11_14.43.53.mp4

Format is possible after 13 seconds. For larger projects or without caches this should take longer.
For comparison haskell-language-server-wrapper . takes 16 seconds.

Describe the solution you'd like

Allow formatting files earlier (if possible) while the session is still being loaded.

Describe alternatives you've considered

An alternative is to use a separate plugin to use format files. But in that case we wouldn't need any integration of formatters in HLS. So I wouldn't consider this being an alternative solution.

Another alternative would be to focus on general improvements to make the startup time faster.

Additional context

haskell-language-server-wrapper --probe-tools
haskell-language-server version: 1.8.0.0 (GHC: 9.2.4) (PATH: /home/andreas/.ghcup/bin/haskell-language-server-wrapper-1.8.0.0)
Tool versions found on the $PATH
cabal:          3.8.1.0
stack:          2.9.1
ghc:            9.2.4

Tool versions in your project
ghc:            9.2.4
@michaelpj
Copy link
Collaborator

My guess is that we block everything on initializing the cradle, which takes a while. After that so long as the formatter doesn't depend on e.g. the typechecked source it should be fast.

Note that many of our formatters rely on knowing the extensions that are in use in a file, which I think we ultimately get from the GHC flags for the file, which does depend on the build tool giving us the build flags. So it may be a genuine dependency.

@andys8
Copy link
Collaborator Author

andys8 commented Oct 11, 2022

Mhm, like this:

dyn <- fmap (ms_hspp_opts . msrModSummary) $ liftIO $ runAction "stylish-haskell" ide $ use_ GetModSummary fp

@michaelpj
Copy link
Collaborator

Yeah, that's pretty explicitly depending on GHC stuff being done for the module. Interestingly, in that case I think you could rearrange it so we don't even run the rule at all if we get the extensions from the config file... but in general I think this is going to be a pretty common dependency path for formatters.

@andys8
Copy link
Collaborator Author

andys8 commented Oct 11, 2022

Do you think the issue can realistically be improved or should it rather be closed?

@fendor
Copy link
Collaborator

fendor commented Oct 11, 2022

I don't think this can be realistically improved, without sacrificing usability or correctness. E.g., configs might contain language extensions, but who knows whether it lists all? If the behaviour isn't uniform, I think usability suffers.

However, maybe we can cache the last known ghc-options for a filepath and use that for formatting on subsequent starts? Might affect correctness, though.

@michaelpj
Copy link
Collaborator

I guess I would say that there's a big topic which is something like "time until usable". There are probably things we can do there, but they're probably going to be ones that improve things generally, I don't think we can do anything much for formatters specifically 🤷

@andys8
Copy link
Collaborator Author

andys8 commented Oct 11, 2022

Since formatting doesn't seem to be independent of information we're gathering on initialization, I also think the ticket should be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants