Skip to content

Commit 72b5f6e

Browse files
committed
Development.IDE.Spans.AtPoint: pointCommand: explain
1 parent 9639bd0 commit 72b5f6e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

ghcide/src/Development/IDE/Spans/AtPoint.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,11 @@ defRowToSymbolInfo (DefRow{..}:.(modInfoSrcFile -> Just srcFile))
386386
end = Position (defELine - 1) (defECol - 1)
387387
defRowToSymbolInfo _ = Nothing
388388

389-
pointCommand :: HieASTs t -> Position -> (HieAST t -> a) -> [a]
390-
pointCommand hf pos k =
389+
pointCommand :: HieASTs t -- ^ Get AST
390+
-> Position -- ^ point at position
391+
-> (HieAST t -> a) -- ^ extact data with a getter
392+
-> [a] -- ^ all data recieved
393+
pointCommand hf pos getter =
391394
catMaybes $ M.elems $ flip M.mapWithKey (getAsts hf) $ \fs ast ->
392395
-- Since GHC 9.2:
393396
-- getAsts :: Map HiePath (HieAst a)
@@ -399,9 +402,8 @@ pointCommand hf pos k =
399402
--
400403
-- 'coerce' here to avoid an additional function for maintaining
401404
-- backwards compatibility.
402-
case selectSmallestContaining (sp $ coerce fs) ast of
403-
Nothing -> Nothing
404-
Just ast' -> Just $ k ast'
405+
let smallestRange = selectSmallestContaining (sp $ coerce fs) ast in
406+
fmap getter smallestRange
405407
where
406408
sloc fs = mkRealSrcLoc fs (line+1) (cha+1)
407409
sp fs = mkRealSrcSpan (sloc fs) (sloc fs)

0 commit comments

Comments
 (0)