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

Restore eval plugin build for GHC 9.2 #2669

Merged
merged 10 commits into from
Feb 12, 2022

Conversation

guibou
Copy link
Collaborator

@guibou guibou commented Jan 31, 2022

The eval plugin is building again and working partially. The codelens
(and evaluation) only happen for code in module comment, code appearing
in the top level comments / haddock are ignored. I need to walk the AST
to locate them.

This is work in progress for #2179.

HLS_evalplugin

@guibou
Copy link
Collaborator Author

guibou commented Feb 1, 2022

Progress report: I can now find all comments containing code to evaluate.

Tests for the plugin are now:

- 47 out of 59 tests failed (22.39s)
+ 24 out of 59 tests failed (23.53s)

There is two cases of failures:

  • Either changes due to how GHC displays stuffs. That's a GHC 9.2 problem, but not related to the eval plugin. Most of them may be fixable with some -fflags, for example:
     -- >>> :type  +no 42
    --- parse error on input ‘+’
    +-- parse error on input `+'
  • Failures that I don't understand yet: +-- /run/user/1000/TCompare3051912-177.hs: hFlush: illegal operation (handle is closed).

@guibou guibou force-pushed the fix_ghc92_eval_plugin branch 2 times, most recently from 3238e4e to ddb3aaa Compare February 1, 2022 23:34
@guibou guibou force-pushed the fix_ghc92_eval_plugin branch from ddb3aaa to 54e352e Compare February 8, 2022 01:40
@guibou guibou marked this pull request as ready for review February 8, 2022 01:41
@guibou guibou requested a review from jneira as a code owner February 8, 2022 01:41
@guibou
Copy link
Collaborator Author

guibou commented Feb 8, 2022

MR is ready for review. I do have one point to discuss, see inline comments.

Using `HasCallStack`, `testCase` can no pinpoint the call location
instead of pointing inside the utility function.
It restores the eval plugin. Now annotations with comments are found by
walking the AST and locating specific annotations.

In order to fix unit test, I implemented a new golden test function
which accepts a different naming scheme depending on the GHC version.
Eval plugin does not report progress, I don't understand why.
@guibou guibou force-pushed the fix_ghc92_eval_plugin branch from b5d4e65 to 4dcca04 Compare February 10, 2022 22:57
@guibou
Copy link
Collaborator Author

guibou commented Feb 11, 2022

All tests are fixed!

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.

LGTM, although I don't know enough about the exactprint/compat parts to comment on them.

@@ -295,8 +285,7 @@ runEvalCmd plId st EvalParams{..} =
dbg "LOAD RESULT" $ asS loadResult
case loadResult of
Failed -> liftIO $ do
hClose logHandle
err <- readFile logFilename
let err = ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

suspicious

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it is. Previously the err was filled by the logging architecture (see discussion here: #2669 (comment)) and @pepeiborra agreed that it can be removed. We can pull the thread even more by removing this err value, changing the return type from Either to Maybe. I tried to reduce the amount of changes in order to restore this plugin.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If it's something to do in a follow-up PR, please leave a comment. Otherwise future readers (possibly future you :) ) will be mystified.

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 the simplest thing to do is fill the err with asS loadResult, or something even simpler like "failed to load module". I feel like it will be hard to change the Either to a Maybe because type CommandFunction idestate a = ideState a -> LspM Conflg (Either ResponseError Value), unless we're changing CommandFunction which would change lots of things should just put some reason in there instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you, I'll address that in a followup commit.

@@ -53,22 +56,44 @@ queueForEvaluation ide nfp = do
EvaluatingVar var <- getIdeGlobalState ide
modifyIORef var (Set.insert nfp)

#if MIN_VERSION_ghc(9,0,0)
#if MIN_VERSION_ghc(9,2,0)
getAnnotations :: Development.IDE.GHC.Compat.Located HsModule -> [LEpaComment]
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe nest these two in a where clause of apiAnnComments' so that the same names are defined in all versions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll address that in a followup commit.

plugins/hls-eval-plugin/test/Main.hs Show resolved Hide resolved
test/functional/Progress.hs Show resolved Hide resolved
Copy link
Collaborator

@eddiemundo eddiemundo left a comment

Choose a reason for hiding this comment

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

lgtm

test/functional/Progress.hs Show resolved Hide resolved
@pepeiborra pepeiborra merged commit 07623e0 into haskell:master Feb 12, 2022
@guibou guibou deleted the fix_ghc92_eval_plugin branch February 12, 2022 13:42
@guibou
Copy link
Collaborator Author

guibou commented Feb 12, 2022

Thank you for the merge. I was in the middle of addressing the comments of @michaelpj, I'll do that in a followup MR ;)

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.

4 participants