-
-
Notifications
You must be signed in to change notification settings - Fork 387
fix isClassNodeIdentifier in hls-class-plugin #4020
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
Changes from all commits
0c87468
af8e290
19b3791
7a7e8b5
919d78a
7ab3646
78d8cc7
fc37c93
b7e1f17
a252542
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,7 @@ codeAction recorder state plId (CodeActionParams _ _ docId _ context) = do | |
$ listToMaybe | ||
$ mapMaybe listToMaybe | ||
$ pointCommand hf instancePosition | ||
( (Map.keys . Map.filter isClassNodeIdentifier . getNodeIds) | ||
( (Map.keys . Map.filterWithKey isClassNodeIdentifier . getNodeIds) | ||
<=< nodeChildren | ||
) | ||
|
||
|
@@ -198,8 +198,10 @@ codeAction recorder state plId (CodeActionParams _ _ docId _ context) = do | |
_ -> fail "Ide.Plugin.Class.findClassFromIdentifier" | ||
findClassFromIdentifier _ (Left _) = throwError (PluginInternalError "Ide.Plugin.Class.findClassIdentifier") | ||
|
||
isClassNodeIdentifier :: IdentifierDetails a -> Bool | ||
isClassNodeIdentifier ident = (isNothing . identType) ident && Use `Set.member` identInfo ident | ||
-- see https://hackage.haskell.org/package/ghc-9.8.1/docs/src/GHC.Types.Name.Occurrence.html#mkClassDataConOcc | ||
isClassNodeIdentifier :: Identifier -> IdentifierDetails a -> Bool | ||
isClassNodeIdentifier (Right i) ident | 'C':':':_ <- unpackFS $ occNameFS $ occName i = (isNothing . identType) ident && Use `Set.member` identInfo ident | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you could use something like: https://hackage.haskell.org/package/ghc-9.8.1/docs/src/GHC.Types.Name.Occurrence.html#isTcOcc on the occName to check if it's a name of a type class, rather than all the unpacking.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not see there is a isTcOcc equivalent function of checking data constructor for class. 🤔。eventhough DataName appears so, but it should be for all data constructors and not only data constructors for class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a little obscure - worth a comment. Perhaps @wz1000 can verify if this is indeed the best way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nag @wz1000 |
||
isClassNodeIdentifier _ _ = False | ||
|
||
isClassMethodWarning :: T.Text -> Bool | ||
isClassMethodWarning = T.isPrefixOf "• No explicit implementation for" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{-# LANGUAGE DeriveAnyClass #-} | ||
|
||
module Ticket3942one where | ||
|
||
class C a where | ||
foo :: a -> Int | ||
|
||
newtype Foo = MkFoo Int deriving (C) | ||
instance Show Foo where | ||
|
||
|
||
main :: IO () | ||
main = return () |
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.
Were you able to reproduce the bug? It would be great (and shouldn't be that hard) to add a test that reproduces the original issue and confirms this fix works.
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.
There are many holes in this plugin.
I should mark this pull request as a partial fix, which solve 1.
Currently, I do not see a way to trigger the bug in 1 without 2.