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

Renaming multi component support #2193

Open
jneira opened this issue Sep 14, 2021 · 20 comments
Open

Renaming multi component support #2193

jneira opened this issue Sep 14, 2021 · 20 comments
Labels
component: hls-rename-plugin multi-component Issues relating to multi-component support type: enhancement New feature or request
Milestone

Comments

@jneira
Copy link
Member

jneira commented Sep 14, 2021

//cc @pepeiborra @OliverMadine


After enabling the plugin we will track here the multi component support for renaming here

@OliverMadine
Copy link
Collaborator

OliverMadine commented Sep 14, 2021

It is just disabled due to the limited multi-cradle support.

I've had a temporary solution (just loading all components listed in the hie.yaml) working for a while now but we need #304 and #2009 to be merged first. Both of these PRs seem to be working and ready to merge.

@michaelpj
Copy link
Collaborator

I think if we enabled it with the caveat that it will only work reliably across one component that would be fine. Perhaps slap "(experimental)" after all the code action titles :)

@OliverMadine
Copy link
Collaborator

OliverMadine commented Sep 14, 2021

I think if we enabled it with the caveat that it will only work reliably across one component that would be fine. Perhaps slap "(experimental)" after all the code action titles :)

We don't use a code action since we get the new name directly from the client. So I don't think we have a great way of announcing this caveat to the user without them having to go through HLS logs etc.

It would be nice to have a vscode option (rather than a cabal build flag) so that we could enable the plugin for single-component use more easily, but I'm not really sure how to do this (especially without causing the plugin tests to fail).
Also, hopefully we are close to some form of multi-component support so I'd rather just wait for that.

@jneira
Copy link
Member Author

jneira commented Sep 14, 2021

i am afraid #2009 needs haskell/hie-bios#301 which in turn needs the show-build-info feature which will be avilable in Cabal-3.8 afaik

@OliverMadine
Copy link
Collaborator

OliverMadine commented Sep 14, 2021

i am afraid #2009 needs haskell/hie-bios#301 which in turn needs the show-build-info feature which will be avilable in Cabal-3.8 afaik

It was my understanding that this PR is just concerned with 'loading multiple components' and we were going to use show-build-info to 'get the components to load' later.

If not, this at least seems to be what it is doing currently so maybe we could merge what is done so far ('loading multiple components') then open a new PR to continue the work?
#304 gets the necessary API changes in place for this.

@fendor
Copy link
Collaborator

fendor commented Sep 14, 2021

Sorry, that PR is indeed more a POC for what is possible with show-build-info, not of the general multiple components loading mechanism.

However, it is true that the general issue of loading multiple components can be done independently of show-build-info, just the semantics of the proposed NonEmpty needs to be discussed.

@jneira jneira added this to the 1.5.0 milestone Sep 16, 2021
@jneira
Copy link
Member Author

jneira commented Oct 18, 2021

It would be nice to have a vscode option (rather than a cabal build flag) so that we could enable the plugin for single-component use more easily, but I'm not really sure how to do this (especially without causing the plugin tests to fail).
Also, hopefully we are close to some form of multi-component support so I'd rather just wait for that.

We could add a configuration option in vscode to enable/disable the plugin at runtime and make it disabled by default. In the config description we could note the caveats.
Not sure if we could make the plugin disabled at runtime if no config is provided at all (but i think it should be possible)

//cc @berberman

@berberman
Copy link
Collaborator

Not sure if we could make the plugin disabled at runtime if no config is provided at all (but i think it should be possible)

In order to disable a plugin by default (no corresponding config section provided), we will need to change the behavior of parsing
PluginConfig:

-- TODO: Add API for plugins to expose their own LSP config options
parseConfig :: Config -> Value -> A.Parser Config
parseConfig defValue = A.withObject "Config" $ \v -> do
-- Officially, we use "haskell" as the section name but for
-- backwards compatibility we also accept "languageServerHaskell"
c <- v .: "haskell" <|> v .:? "languageServerHaskell"
case c of
Nothing -> return defValue
Just s -> flip (A.withObject "Config.settings") s $ \o -> Config
<$> (o .:? "checkParents" <|> v .:? "checkParents") .!= checkParents defValue
<*> (o .:? "checkProject" <|> v .:? "checkProject") .!= checkProject defValue
<*> o .:? "hlintOn" .!= hlintOn defValue
<*> o .:? "diagnosticsOnChange" .!= diagnosticsOnChange defValue
<*> o .:? "liquidOn" .!= liquidOn defValue
<*> o .:? "formatOnImportOn" .!= formatOnImportOn defValue
<*> o .:? "formattingProvider" .!= formattingProvider defValue
<*> o .:? "maxCompletions" .!= maxCompletions defValue
<*> o .:? "plugin" .!= plugins defValue

Currently, the following "static" default values will be used if the client does not provide these options:

instance Default PluginConfig where
def = PluginConfig
{ plcGlobalOn = True
, plcCallHierarchyOn = True
, plcCodeActionsOn = True
, plcCodeLensOn = True
, plcDiagnosticsOn = True
, plcHoverOn = True
, plcSymbolsOn = True
, plcCompletionOn = True
, plcRenameOn = True
, plcConfig = mempty
}

I think a easy way would be carrying the information that "the client does not give this value" in parsed config, rather than concealing it with a default value. So in plugin's handler, we could retrieve the config which says no option to enable this plugin is given by the client.

@malteneuss
Copy link

With the new rename plugin implementation in mind, is this plugin now suitable to be enabled? It would create a huge productivity boost, even if still has that one-component-only-caveat.

@jneira
Copy link
Member Author

jneira commented Jan 17, 2022

Yeah, i think the required changes in cabal will take more time and there is no a wip in stack so it is time to enable it, making clear its limitations in docs

@jneira jneira changed the title Enable rename plugin Renaming multi component support Jan 17, 2022
@pepeiborra
Copy link
Collaborator

As a fallback, could we enable the rename plugin on single component projects?

@michaelpj
Copy link
Collaborator

Do we have a way of detecting whether we are in a single- or multi-component project? If so, we could simply make the rename handler fail informatively if it detects it is in a multi-component package.

@fendor
Copy link
Collaborator

fendor commented Mar 27, 2022

Do we have a way of detecting whether we are in a single- or multi-component project?

No, we don't. In the current design of hie-bios, there is no way to enumerate all components / modules of a project.
We definitely want something like it, but no one got around to implement it, yet.

@JoeMShanahan
Copy link

We definitely want something like it, but no one got around to implement it, yet.

Is there an issue somewhere that discusses this... perhaps a potential implementation or plan of attack?

@fendor
Copy link
Collaborator

fendor commented May 3, 2022

Hi!

Yes, there is, and it requires multiple steps. First, we need to be able to actually get multiple components from a build tool. To achieve that for cabal, we have implemented haskell/cabal#7489 and merged haskell/cabal#7498 which means we are more than halfway there! The remaining PR for proper support by cabal is haskell/cabal#7500.
I'd be very happy if someone assists to get this merged. There is nothing difficult about it, currently, just a matter of not enough spare time on my end.

Afterwards, we would like to migrate hie-bios to use the new cabal API to see whether there are any design issues. The initial implementation for an old version of cabal show-build-info can be found here: haskell/hie-bios#301
Before that, we can also try to get this merged: haskell/hie-bios#304 which basically prepares the API to be able to emit multiple components at once.

After that, we can finally come to ghcide! We need to work on the ghcide session-loading logic which is very complicated and tricky to get right: https://github.com/haskell/haskell-language-server/blob/master/ghcide/session-loader/Development/IDE/Session.hs#L405
However, we can also look into the future since GHC multiple home unit support has been merged and will be released with 9.4, we should also look into utilising that.

I can be helpful on every step you want to tackle here, just ask for a couple clarifications and I can give you for cabal/hie-bios stuff step-by-step instructions.

@santiweight
Copy link
Collaborator

I am curious how this is going. As an HLS user, I certainly would love to see this come to fruition!

(Having to load in each component at my work codebase is still a sore spot!)

@georgefst
Copy link
Collaborator

Given that this doesn't appear to be happening any time soon, does anyone know how easy it might be to relax the explicit-export-list restriction for renaming local names? It's quite silly that I can't rename x here:

module M where
f x = ()

@fendor
Copy link
Collaborator

fendor commented Jun 11, 2023

@georgefst it is likely to happen rather soon for ghc versoins > 9.4 once #3462 lands and the next major cabal release.

However, for your specific case, I think it should be easy to lift the restriction.

@georgefst
Copy link
Collaborator

Ah yes, I'd forgotten that this is yet another thing which will be solved by #3462 (although it is actually clear now that I've read the whole thread).

@michaelpj michaelpj added the multi-component Issues relating to multi-component support label Jan 11, 2024
@michaelpj
Copy link
Collaborator

Multiple home unit support now exists, so I think this should now be possible. It would still need some work:

But that seems pretty doable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-rename-plugin multi-component Issues relating to multi-component support type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants