Skip to content

Implement explicit fixity in ghcide #2973

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
wants to merge 9 commits into from

Conversation

July541
Copy link
Collaborator

@July541 July541 commented Jun 20, 2022

This is a substitute for #2941, which implement in ghcide.

Due to AtPoint.atPoint is a pure function, I insert the fixity in Core/Action.hs as an entrance.

@July541 July541 requested a review from pepeiborra as a code owner June 20, 2022 10:55
@July541 July541 requested a review from michaelpj June 20, 2022 10:55
@@ -203,6 +205,51 @@ gotoDefinition
gotoDefinition withHieDb getHieFile ideOpts imports srcSpans pos
= lift $ locationsAtPoint withHieDb getHieFile ideOpts imports pos srcSpans

fixityAtPoint :: HieAstResult -> HiFileResult -> HscEnv -> Position -> IO (Maybe (Maybe Range, [T.Text]))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it wouldn't be crazy to make atPoint run in MonadIO m: almost every other function in here does.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A little crazy to make a pure function to impure?😉

The pain point to making fixity query be impure is runTcInteractive, I feel it may have a pure method here, worth trying.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, that's generally bad, but most everything here has to run in some monad because it's doing stuff with the GHC API. It's a nice coincidence that atPoint didn't need it, but I don't think it's fundamental.

@July541
Copy link
Collaborator Author

July541 commented Jun 22, 2022

It looks useE with GetModIface crashed the hover. Don't know how to adjust to pass the tests...

Irrelative.

@July541 July541 force-pushed the explicit-fixity branch from 329e4fb to 5956a94 Compare July 7, 2022 14:51
@July541 July541 force-pushed the explicit-fixity branch from 5956a94 to a40c194 Compare July 7, 2022 15:31
, hoverTest "signature" (Position 35 2) "infixr 9 `>>>:`"
, hoverTest "operator" (Position 36 2) "infixr 9 `>>>:`"
, hoverTest "escape" (Position 39 2) "infixl 3 `~\\:`"
-- It will cause error like: "Failed to load interface for \8216Fixity\8217\nIt is not a module in the current program, or in any known package."
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Get fixity from locally defined module failed because something like Failed to load interface for \8216Fixity\8217\nIt is not a module in the current program, or in any known package. It is strange.

It's a trivial case and I think we have an available function even without this.

@July541 July541 force-pushed the explicit-fixity branch from f6e836f to 06b9677 Compare July 8, 2022 08:01
@@ -61,9 +61,24 @@ getAtPoint file pos = runMaybeT $ do
(hf, mapping) <- useE GetHieAst file
env <- hscEnv . fst <$> useE GhcSession file
dkMap <- lift $ maybe (DKMap mempty mempty) fst <$> runMaybeT (useE GetDocMap file)
tcGblEnv <- tmrTypechecked . fst <$> useE TypeCheck file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using TypeCheck here is bad. It will make ghcide hovers slower, and it will break the ability to get hover information at cold startup from the local cache.

Now, if fixity was in a plugin, it would still create all the problems above since his-plugin-api collects all the results before sending the response. But one can:

  1. Disable the fixity plugin
  2. Implement partial responses

I think this is a blocker. Workarounds:

  1. Extract back to a plugin
  2. Introduce a new build rule for fixity information, and give it a persistent implementation with addPersistentRule. The persistent implementation can return some placeholder or you can cache the fixity info in hiedb if desired.

@July541
Copy link
Collaborator Author

July541 commented Aug 12, 2022

Implemented in #2941.

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.

3 participants