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

Allow users to specify whether to use cabal's multi-repl feature #4179

Merged
merged 1 commit into from
Apr 23, 2024

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Apr 16, 2024

We add an option to Config that allows clients to specify how HLS should load components.

The three options are:

  • SessionLoadSingleComponent: Always load only a single component when a new component is discovered.
  • SessionLoadMultipleComponents: Always allow the cradle to load multiple components at once. This might not be always possible, e.g., if the tool doesn't support multiple components loading. The cradle can decide how to handle these situations.
  • SessionAuto: Leave the decision to the individual cradle type. Some cradles have good support for loading multiple components, while others do not. So use multiple components loading for tools, such as cabal, and force single component loading for tools that do not support multiple components, such as stack.

This allows users to opt-out of cabal multi-repl whenever they want and vice versa.

Closes #4178

Depends on haskell/hie-bios#433

Sibling PR for vscode-haskell: haskell/vscode-haskell#1077

@fendor fendor force-pushed the wip/configure-multi-repl branch 2 times, most recently from 99563a5 to 35a22ad Compare April 16, 2024 17:04
@fendor
Copy link
Collaborator Author

fendor commented Apr 16, 2024

The only thing is kind of bad is that changing the load style requires a restart of the language server. We could track when the config changes and unload all components instead.

@fendor fendor force-pushed the wip/configure-multi-repl branch 2 times, most recently from 989d7c1 to dce9b8b Compare April 17, 2024 11:32
@michaelpj
Copy link
Collaborator

The only thing is kind of bad is that changing the load style requires a restart of the language server. We could track when the config changes and unload all components instead.

Yeah, we already do something like this when e.g. we have a change to a cabal file. Can we do the same here?

@fendor
Copy link
Collaborator Author

fendor commented Apr 17, 2024

Can we do the same here?

Yeah, I believe we can.

@wz1000
Copy link
Collaborator

wz1000 commented Apr 22, 2024

I'm skeptical about the utility of the auto configuration option, but other than that it seems like it is OK to move ahead with this. We should produce an hie-bios release before merging though.

@fendor
Copy link
Collaborator Author

fendor commented Apr 22, 2024

I'm skeptical about the utility of the auto configuration option, but other than that it seems like it is OK to move ahead with this. We should produce an hie-bios release before merging though.

Yes, after some more discussion, I agree that the auto feature is overkill for now. I propose the following changes to the PR:

  • Single Component: Default option
  • Multiple Components: Allow the usage of mutli-repl: True if the cabal cradle allows it.

@michaelpj
Copy link
Collaborator

michaelpj commented Apr 22, 2024

Then isn't this really just a flag saying "use cabal multi-repl if available: yes/no"? I continue to be a little suspicious of pretending that it's more general than it is.

@fendor
Copy link
Collaborator Author

fendor commented Apr 22, 2024

Yes it is, and the docs can make this clear, but there is nothing that is specific to cabal cradles right now. bios cradles could implement the same mechanism, we just didn't do it yet in hie-bios.

@fendor fendor force-pushed the wip/configure-multi-repl branch 6 times, most recently from d3029e3 to a47b398 Compare April 23, 2024 09:34
hls-plugin-api/src/Ide/Types.hs Outdated Show resolved Hide resolved
test/testdata/schema/ghc98/default-config.golden.json Outdated Show resolved Hide resolved
@@ -194,6 +197,7 @@ instance Default Config where
-- , cabalFormattingProvider = "cabal-fmt"
-- this string value needs to kept in sync with the value provided in HlsPlugins
, maxCompletions = 40
, sessionLoading = SessionLoadSingleComponent
Copy link
Collaborator

Choose a reason for hiding this comment

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

I do think we should make the default multi-component. We want people to benefit from this without knowing they have to turn it on! The main thing is that they can turn it off if they need to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

People have raised the concern that this is basically an untested cabal feature that may contain many hard to understand bugs, so we should disable it by default, and then enable it by default in the next release.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm okay.

ghcide/session-loader/Development/IDE/Session.hs Outdated Show resolved Hide resolved
@@ -461,6 +469,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
runningCradle <- newVar dummyAs :: IO (Var (Async (IdeResult HscEnvEq,[FilePath])))

return $ do
clientConfig <- getClientConfigAction
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure this actually works? This will get the client config at this point, but we consult it inside consultCradle which is an IO function that maybe runs later? So might we just always see a stale version of the config? I think we might need to get the config in IO inside consultCradle.

Copy link
Collaborator Author

@fendor fendor Apr 23, 2024

Choose a reason for hiding this comment

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

It does work, in combination with invalidating the GhcSessionIO rule.

This new dependency seems to be working: https://github.com/haskell/haskell-language-server/pull/4179/files#diff-65a56362c2b3593800cd8369e6cfab1e92c347a9be97d1f0b8793f0e5dd9d524R711

And it doesn't invalidate the whole session on config changes.

ghcide/session-loader/Development/IDE/Session.hs Outdated Show resolved Hide resolved
@fendor fendor force-pushed the wip/configure-multi-repl branch 4 times, most recently from 8d700ea to 095c04b Compare April 23, 2024 11:54
@fendor fendor requested review from michaelpj and wz1000 April 23, 2024 11:55
We add an option to `Config` that allows clients to specify how HLS
should load components.

We support two loading strategies:

* SessionLoadSingleComponent: Always load only a single component
    when a new component is discovered.
* SessionLoadMultipleComponents: Always allow the cradle to load
    multiple components at once. This might not be always possible,
    e.g., if the tool doesn't support multiple components loading.
    The cradle decides how to handle these situations.

By default, we use the conservative `SessionLoadSingleComponent` mode.

Additionally, changing the config at run-time leads to a reload of the
GHC session, allowing users to switch between the modes without
restarting the full server.
Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this!

@michaelpj michaelpj enabled auto-merge (squash) April 23, 2024 13:03
@michaelpj michaelpj merged commit a6f0008 into haskell:master Apr 23, 2024
38 checks passed
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.

Users should be able to specify multi-repl support and opt-out of it, if unsupported.
3 participants