-
-
Notifications
You must be signed in to change notification settings - Fork 368
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
Hlint plugin using ghc-lib #166
Conversation
Yes, the fact that you can have Haddock XOR tokens is super frustrating. Would be great to get that fixed upstream. I think using reparsing always is quite reasonable, although it means that things like CPP are likely to be worse. Passing the right extensions onward would be great though. |
Note that ghcide HEAD currently returns the raw AST instead of the Haddock one, unlike the hls fork. This means that hovers and completions of identifiers in the same module don't have docs, which is oddly inconsistent and should probably be addressed by returning the Haddock AST instead. |
haskell-language-server.cabal
Outdated
manual: True | ||
description: Force dependency on ghc-lib-parser even if GHC API in the ghc package is supported | ||
|
||
library hls-ghc-lib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does stack cradle work with private library now? I thought it hasn't been fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it won't, thanks for pointing it out, i forgot to warn about that in pr description. Unfortunately afaik we cant convert it in a common stanza cause the main reason is to be able to have its own flags and dependencies.
There are plans to allow plugins live in its own package, i think this one could be one of them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification. Could you direct me to the description of the plan? I may take and/or tackle some parts of the plan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this will fall out of Vlad's haddock work in progress right now. |
4d29002
to
7108e61
Compare
d071ebb
to
f32cde1
Compare
|
haskell-language-server.cabal
Outdated
manual: True | ||
description: Force dependency on ghc-lib-parser even if GHC API in the ghc package is supported | ||
|
||
library hlint-plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted above the private lib does not work for stack based cradle.
Moreover i have to periodically delete the haskell-language-server library from the cabal store due to
exe\Main.hs:147:9: error:
• Couldn't match expected type ‘Ide.Types.PluginDescriptor’
with actual type ‘haskell-language-server-0.2.0.0:Ide.Types.PluginDescriptor’
NB: ‘haskell-language-server-0.2.0.0:Ide.Types.PluginDescriptor’
is defined in ‘Ide.Types’
in package ‘haskell-language-server-0.2.0.0’
‘Ide.Types.PluginDescriptor’
is defined in ‘Ide.Types’
in package ‘haskell-language-server-0.2.0.0’
• In the expression: Hlint.descriptor "hlint"
In the expression:
[GhcIde.descriptor "ghcide", Pragmas.descriptor "pragmas",
Floskell.descriptor "floskell", Ormolu.descriptor "ormolu", ....]
In an equation for ‘basePlugins’:
basePlugins
= [GhcIde.descriptor "ghcide", Pragmas.descriptor "pragmas",
Floskell.descriptor "floskell", ....]
|
147 | , Hlint.descriptor "hlint"
| ^^^^^^^^^^^^^^^^^^^^^^^^
So i think this plugin must be separated in its own package, after the restructuration of the lib (see #164)
let dflags = hsc_dflags hsc | ||
let hscExts = EnumSet.toList (extensionFlags dflags) | ||
logm $ "getIdeas:setExtensions:hscExtensions:" ++ show hscExts | ||
let hlintExts = mapMaybe (GhclibParserEx.readExtension . show) hscExts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to cast the types from the "real" ghc used by ghcide and the ghc-lib used by hlint is not good at all.
Not sure if there is an alternative.
type instance RuleResult GetHlintDiagnostics = () | ||
|
||
rules :: Rules () | ||
rules = do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need Config
here to enable or disable hlint usage. I guess i could get it using getClientConfig :: LSP.LspFuncs Config -> IO Config
but i did not find a way to get LSP.LspFuncs Config
in Rules a
or Action a
.
Or maybe should it be disabled in other higher level place?
//cc @alanz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After further investigation:
- It seems
Config
it is not being stored in the shake graph (or at least i have been not able to find it). ghcide seems to ignore it.- So it cant be used in
Rules
, the actual way to provide diagnostics in the hls plugin api
- So it cant be used in
- The rest of plugin types (completion, renaming, formatting) are not using
Rules
butPartialHandler
s, via custom providers so they have access toLspFuncs Config
- There is a
DiagnosticProvider
defined (from hie) that could be used to get the config but it is not implemented in hls
So, there would be two alternatives:
- Store the lsp config in the shake graph, creating a Rule for it. We should have in account that it can change at any time by the user, so it have to be changed
- Implement the
DiagnosticProvider
and dont use Rules for provide hlint diagnostics
//cc @alanz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of a Shake Rule for the config, that way if the user does change the config the diagnostics should then get updated again right?
The output of
I've posted a bad refactored file example: https://gist.github.com/jneira/70478dee9e9a01d3d10d68218f8fa514#file-hlint-refactored-hs Pending:
|
1916bdf
to
1d3d0d0
Compare
Note that the latest version of the refactor tool has a lot of improvements. I'd check you are on the latest version first. I'd also check line endings on Windows. Perhaps it is broken on Windows style newlines? |
I am afraid i was already using the last released apply-refact version 0.8.1.0, as a lib and the cli executable (they both generate the same wrong results)
I have CRLF in the simple file that is refactored correctly and in the files that fail, but it still could be a factor involved, i will test it Thanks for the help! |
I've tried the refactoring after converting new lines to LF and the result remains the same. The refactoring even has converted the new lines to CRLF again 😞 |
1d3d0d0
to
bd1fd28
Compare
1708ffb
to
8c3fd42
Compare
|
Pending:
|
79210d3
to
1ddacf7
Compare
Gave this a spin and it seems to be working well! I resurrected the old hlint commands for vscode-haskell (expipiplus1/vscode-hie-server@6c1d055) applyAll seems to work but applyOne does not. It's almost certainly on my end though! |
Co-authored-by: Pepe Iborra <[email protected]>
to check if a hlint hint should trigger a code action
61df7a6
to
01f8fd8
Compare
Ok, i gave up on flaky tests and copied the way ghcide run the test suite:
The test suite is retried three times with @ndmitchell when you have some time, could you take one last look? i would prefer to merge with your approval 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! Keen to try it out in practice 😄
It only has diagnostics for now, and it is not testes, only compiles. The plan is add the apply-refact part as welladded!https://github.com/alanz/ghcide/blob/3ee692a4cdb98792c371765c9f8adb5237d0a515/src/Development/IDE/Core/Rules.hs#L239-L246
Pending:
After merging the pr (we will create issues)