Skip to content

Commit 395faf3

Browse files
committed
Rewrite filter with more restricts
1 parent dc2134c commit 395faf3

File tree

1 file changed

+2
-15
lines changed
  • plugins/hls-class-plugin/src/Ide/Plugin

1 file changed

+2
-15
lines changed

plugins/hls-class-plugin/src/Ide/Plugin/Class.hs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Data.List
2121
import qualified Data.Map.Strict as Map
2222
import Data.Maybe
2323
import qualified Data.Text as T
24+
import qualified Data.Set as Set
2425
import Development.IDE hiding (pluginHandlers)
2526
import Development.IDE.Core.PositionMapping (fromCurrentRange,
2627
toCurrentRange)
@@ -217,33 +218,19 @@ codeAction state plId (CodeActionParams _ _ docId _ context) = liftIO $ fmap (fr
217218
HAR {hieAst = hf} ->
218219
pure
219220
$ head . head
220-
#if MIN_VERSION_ghc(9,2,0)
221-
$ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character +~ 1)
222-
(Map.keys . Map.filter isClassNodeIdentifier . Compat.getNodeIds)
223-
#elif MIN_VERSION_ghc(9,0,0)
224221
$ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character -~ 1)
225222
( (Map.keys . Map.filter isClassNodeIdentifier . Compat.getNodeIds)
226223
<=< nodeChildren
227224
)
228-
#else
229-
$ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character -~ 1)
230-
( (Map.keys . Map.filter isClassNodeIdentifier . Compat.getNodeIds)
231-
<=< nodeChildren
232-
)
233-
#endif
234225

235226
findClassFromIdentifier docPath (Right name) = do
236227
(hscEnv -> hscenv, _) <- MaybeT . runAction "classplugin" state $ useWithStale GhcSessionDeps docPath
237228
(tmrTypechecked -> thisMod, _) <- MaybeT . runAction "classplugin" state $ useWithStale TypeCheck docPath
238229
MaybeT . fmap snd . initTcWithGbl hscenv thisMod ghostSpan $ do
239230
tcthing <- tcLookup name
240231
case tcthing of
241-
#if !MIN_VERSION_ghc(9,2,0)
242232
AGlobal (AConLike (RealDataCon con))
243233
| Just cls <- tyConClass_maybe (dataConOrigTyCon con) -> pure cls
244-
#else
245-
AGlobal (ATyCon tycon) | Just cls <- tyConClass_maybe tycon -> pure cls
246-
#endif
247234
_ -> panic "Ide.Plugin.Class.findClassFromIdentifier"
248235
findClassFromIdentifier _ (Left _) = panic "Ide.Plugin.Class.findClassIdentifier"
249236

@@ -254,7 +241,7 @@ containRange :: Range -> SrcSpan -> Bool
254241
containRange range x = isInsideSrcSpan (range ^. J.start) x || isInsideSrcSpan (range ^. J.end) x
255242

256243
isClassNodeIdentifier :: IdentifierDetails a -> Bool
257-
isClassNodeIdentifier = isNothing . identType
244+
isClassNodeIdentifier ident = (isNothing . identType) ident && Use `Set.member` (identInfo ident)
258245

259246
isClassMethodWarning :: T.Text -> Bool
260247
isClassMethodWarning = T.isPrefixOf "• No explicit implementation for"

0 commit comments

Comments
 (0)