{-# LANGUAGE NoApplicativeDo #-}
{-# LANGUAGE TypeFamilies #-}
module Development.IDE.Core.Actions
( getAtPoint
, getDefinition
, getTypeDefinition
, highlightAtPoint
, refsAtPoint
, useE
, useNoFileE
, usesE
, workspaceSymbols
) where
import Control.Monad.Reader
import Control.Monad.Trans.Maybe
import qualified Data.HashMap.Strict as HM
import Data.Maybe
import qualified Data.Text as T
import Data.Tuple.Extra
import Development.IDE.Core.OfInterest
import Development.IDE.Core.PositionMapping
import Development.IDE.Core.RuleTypes
import Development.IDE.Core.Service
import Development.IDE.Core.Shake
import Development.IDE.GHC.Compat hiding (TargetFile,
TargetModule,
parseModule,
typecheckModule,
writeHieFile)
import qualified Development.IDE.Spans.AtPoint as AtPoint
import Development.IDE.Types.Location
import Development.Shake hiding (Diagnostic)
import qualified HieDb
import Language.LSP.Types (DocumentHighlight (..),
SymbolInformation (..))
lookupMod
:: HieDbWriter
-> FilePath
-> ModuleName
-> UnitId
-> Bool
-> MaybeT IdeAction Uri
lookupMod :: HieDbWriter
-> FilePath -> ModuleName -> UnitId -> Bool -> MaybeT IdeAction Uri
lookupMod HieDbWriter
_dbchan FilePath
_hie_f ModuleName
_mod UnitId
_uid Bool
_boot = IdeAction (Maybe Uri) -> MaybeT IdeAction Uri
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (IdeAction (Maybe Uri) -> MaybeT IdeAction Uri)
-> IdeAction (Maybe Uri) -> MaybeT IdeAction Uri
forall a b. (a -> b) -> a -> b
$ Maybe Uri -> IdeAction (Maybe Uri)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Uri
forall a. Maybe a
Nothing
getAtPoint :: NormalizedFilePath -> Position -> IdeAction (Maybe (Maybe Range, [T.Text]))
getAtPoint :: NormalizedFilePath
-> Position -> IdeAction (Maybe (Maybe Range, [Text]))
getAtPoint NormalizedFilePath
file Position
pos = MaybeT IdeAction (Maybe Range, [Text])
-> IdeAction (Maybe (Maybe Range, [Text]))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT IdeAction (Maybe Range, [Text])
-> IdeAction (Maybe (Maybe Range, [Text])))
-> MaybeT IdeAction (Maybe Range, [Text])
-> IdeAction (Maybe (Maybe Range, [Text]))
forall a b. (a -> b) -> a -> b
$ do
ShakeExtras
ide <- MaybeT IdeAction ShakeExtras
forall r (m :: * -> *). MonadReader r m => m r
ask
IdeOptions
opts <- IO IdeOptions -> MaybeT IdeAction IdeOptions
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO IdeOptions -> MaybeT IdeAction IdeOptions)
-> IO IdeOptions -> MaybeT IdeAction IdeOptions
forall a b. (a -> b) -> a -> b
$ ShakeExtras -> IO IdeOptions
getIdeOptionsIO ShakeExtras
ide
(HieAstResult
hf, PositionMapping
mapping) <- GetHieAst
-> NormalizedFilePath
-> MaybeT IdeAction (HieAstResult, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE GetHieAst
GetHieAst NormalizedFilePath
file
DocAndKindMap
dkMap <- IdeAction DocAndKindMap -> MaybeT IdeAction DocAndKindMap
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IdeAction DocAndKindMap -> MaybeT IdeAction DocAndKindMap)
-> IdeAction DocAndKindMap -> MaybeT IdeAction DocAndKindMap
forall a b. (a -> b) -> a -> b
$ DocAndKindMap
-> ((DocAndKindMap, PositionMapping) -> DocAndKindMap)
-> Maybe (DocAndKindMap, PositionMapping)
-> DocAndKindMap
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (DocMap -> KindMap -> DocAndKindMap
DKMap DocMap
forall a. Monoid a => a
mempty KindMap
forall a. Monoid a => a
mempty) (DocAndKindMap, PositionMapping) -> DocAndKindMap
forall a b. (a, b) -> a
fst (Maybe (DocAndKindMap, PositionMapping) -> DocAndKindMap)
-> IdeAction (Maybe (DocAndKindMap, PositionMapping))
-> IdeAction DocAndKindMap
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MaybeT IdeAction (DocAndKindMap, PositionMapping)
-> IdeAction (Maybe (DocAndKindMap, PositionMapping))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT IdeAction (DocAndKindMap, PositionMapping)
-> IdeAction (Maybe (DocAndKindMap, PositionMapping)))
-> MaybeT IdeAction (DocAndKindMap, PositionMapping)
-> IdeAction (Maybe (DocAndKindMap, PositionMapping))
forall a b. (a -> b) -> a -> b
$ GetDocMap
-> NormalizedFilePath
-> MaybeT IdeAction (DocAndKindMap, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE GetDocMap
GetDocMap NormalizedFilePath
file)
!Position
pos' <- IdeAction (Maybe Position) -> MaybeT IdeAction Position
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (Maybe Position -> IdeAction (Maybe Position)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Position -> IdeAction (Maybe Position))
-> Maybe Position -> IdeAction (Maybe Position)
forall a b. (a -> b) -> a -> b
$ PositionMapping -> Position -> Maybe Position
fromCurrentPosition PositionMapping
mapping Position
pos)
IdeAction (Maybe (Maybe Range, [Text]))
-> MaybeT IdeAction (Maybe Range, [Text])
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (IdeAction (Maybe (Maybe Range, [Text]))
-> MaybeT IdeAction (Maybe Range, [Text]))
-> IdeAction (Maybe (Maybe Range, [Text]))
-> MaybeT IdeAction (Maybe Range, [Text])
forall a b. (a -> b) -> a -> b
$ Maybe (Maybe Range, [Text])
-> IdeAction (Maybe (Maybe Range, [Text]))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (Maybe Range, [Text])
-> IdeAction (Maybe (Maybe Range, [Text])))
-> Maybe (Maybe Range, [Text])
-> IdeAction (Maybe (Maybe Range, [Text]))
forall a b. (a -> b) -> a -> b
$ ((Maybe Range, [Text]) -> (Maybe Range, [Text]))
-> Maybe (Maybe Range, [Text]) -> Maybe (Maybe Range, [Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Maybe Range -> Maybe Range)
-> (Maybe Range, [Text]) -> (Maybe Range, [Text])
forall a a' b. (a -> a') -> (a, b) -> (a', b)
first (PositionMapping -> Range -> Maybe Range
toCurrentRange PositionMapping
mapping (Range -> Maybe Range) -> Maybe Range -> Maybe Range
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<)) (Maybe (Maybe Range, [Text]) -> Maybe (Maybe Range, [Text]))
-> Maybe (Maybe Range, [Text]) -> Maybe (Maybe Range, [Text])
forall a b. (a -> b) -> a -> b
$ IdeOptions
-> HieAstResult
-> DocAndKindMap
-> Position
-> Maybe (Maybe Range, [Text])
AtPoint.atPoint IdeOptions
opts HieAstResult
hf DocAndKindMap
dkMap Position
pos'
toCurrentLocations :: PositionMapping -> [Location] -> [Location]
toCurrentLocations :: PositionMapping -> [Location] -> [Location]
toCurrentLocations PositionMapping
mapping = (Location -> Maybe Location) -> [Location] -> [Location]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Location -> Maybe Location
go
where
go :: Location -> Maybe Location
go (Location Uri
uri Range
range) = Uri -> Range -> Location
Location Uri
uri (Range -> Location) -> Maybe Range -> Maybe Location
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PositionMapping -> Range -> Maybe Range
toCurrentRange PositionMapping
mapping Range
range
useE :: IdeRule k v => k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE :: k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE k
k = IdeAction (Maybe (v, PositionMapping))
-> MaybeT IdeAction (v, PositionMapping)
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (IdeAction (Maybe (v, PositionMapping))
-> MaybeT IdeAction (v, PositionMapping))
-> (NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping)))
-> NormalizedFilePath
-> MaybeT IdeAction (v, PositionMapping)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping))
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping))
useWithStaleFast k
k
useNoFileE :: IdeRule k v => IdeState -> k -> MaybeT IdeAction v
useNoFileE :: IdeState -> k -> MaybeT IdeAction v
useNoFileE IdeState
_ide k
k = (v, PositionMapping) -> v
forall a b. (a, b) -> a
fst ((v, PositionMapping) -> v)
-> MaybeT IdeAction (v, PositionMapping) -> MaybeT IdeAction v
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE k
k NormalizedFilePath
emptyFilePath
usesE :: IdeRule k v => k -> [NormalizedFilePath] -> MaybeT IdeAction [(v,PositionMapping)]
usesE :: k
-> [NormalizedFilePath] -> MaybeT IdeAction [(v, PositionMapping)]
usesE k
k = IdeAction (Maybe [(v, PositionMapping)])
-> MaybeT IdeAction [(v, PositionMapping)]
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (IdeAction (Maybe [(v, PositionMapping)])
-> MaybeT IdeAction [(v, PositionMapping)])
-> ([NormalizedFilePath]
-> IdeAction (Maybe [(v, PositionMapping)]))
-> [NormalizedFilePath]
-> MaybeT IdeAction [(v, PositionMapping)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Maybe (v, PositionMapping)] -> Maybe [(v, PositionMapping)])
-> IdeAction [Maybe (v, PositionMapping)]
-> IdeAction (Maybe [(v, PositionMapping)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Maybe (v, PositionMapping)] -> Maybe [(v, PositionMapping)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (IdeAction [Maybe (v, PositionMapping)]
-> IdeAction (Maybe [(v, PositionMapping)]))
-> ([NormalizedFilePath] -> IdeAction [Maybe (v, PositionMapping)])
-> [NormalizedFilePath]
-> IdeAction (Maybe [(v, PositionMapping)])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping)))
-> [NormalizedFilePath] -> IdeAction [Maybe (v, PositionMapping)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (k -> NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping))
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> IdeAction (Maybe (v, PositionMapping))
useWithStaleFast k
k)
getDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location])
getDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location])
getDefinition NormalizedFilePath
file Position
pos = MaybeT IdeAction [Location] -> IdeAction (Maybe [Location])
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT IdeAction [Location] -> IdeAction (Maybe [Location]))
-> MaybeT IdeAction [Location] -> IdeAction (Maybe [Location])
forall a b. (a -> b) -> a -> b
$ do
ShakeExtras
ide <- MaybeT IdeAction ShakeExtras
forall r (m :: * -> *). MonadReader r m => m r
ask
IdeOptions
opts <- IO IdeOptions -> MaybeT IdeAction IdeOptions
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO IdeOptions -> MaybeT IdeAction IdeOptions)
-> IO IdeOptions -> MaybeT IdeAction IdeOptions
forall a b. (a -> b) -> a -> b
$ ShakeExtras -> IO IdeOptions
getIdeOptionsIO ShakeExtras
ide
(HAR Module
_ HieASTs a
hf RefMap a
_ Map Name [RealSrcSpan]
_ HieKind a
_, PositionMapping
mapping) <- GetHieAst
-> NormalizedFilePath
-> MaybeT IdeAction (HieAstResult, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE GetHieAst
GetHieAst NormalizedFilePath
file
(ImportMap Map ModuleName NormalizedFilePath
imports, PositionMapping
_) <- GetImportMap
-> NormalizedFilePath
-> MaybeT IdeAction (ImportMap, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE GetImportMap
GetImportMap NormalizedFilePath
file
!Position
pos' <- IdeAction (Maybe Position) -> MaybeT IdeAction Position
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (Maybe Position -> IdeAction (Maybe Position)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Position -> IdeAction (Maybe Position))
-> Maybe Position -> IdeAction (Maybe Position)
forall a b. (a -> b) -> a -> b
$ PositionMapping -> Position -> Maybe Position
fromCurrentPosition PositionMapping
mapping Position
pos)
HieDb
hiedb <- IdeAction HieDb -> MaybeT IdeAction HieDb
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IdeAction HieDb -> MaybeT IdeAction HieDb)
-> IdeAction HieDb -> MaybeT IdeAction HieDb
forall a b. (a -> b) -> a -> b
$ (ShakeExtras -> HieDb) -> IdeAction HieDb
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks ShakeExtras -> HieDb
hiedb
HieDbWriter
dbWriter <- IdeAction HieDbWriter -> MaybeT IdeAction HieDbWriter
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IdeAction HieDbWriter -> MaybeT IdeAction HieDbWriter)
-> IdeAction HieDbWriter -> MaybeT IdeAction HieDbWriter
forall a b. (a -> b) -> a -> b
$ (ShakeExtras -> HieDbWriter) -> IdeAction HieDbWriter
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks ShakeExtras -> HieDbWriter
hiedbWriter
PositionMapping -> [Location] -> [Location]
toCurrentLocations PositionMapping
mapping ([Location] -> [Location])
-> MaybeT IdeAction [Location] -> MaybeT IdeAction [Location]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HieDb
-> (FilePath
-> ModuleName -> UnitId -> Bool -> MaybeT IdeAction Uri)
-> IdeOptions
-> Map ModuleName NormalizedFilePath
-> HieASTs a
-> Position
-> MaybeT IdeAction [Location]
forall (m :: * -> *) a.
MonadIO m =>
HieDb
-> LookupModule m
-> IdeOptions
-> Map ModuleName NormalizedFilePath
-> HieASTs a
-> Position
-> MaybeT m [Location]
AtPoint.gotoDefinition HieDb
hiedb (HieDbWriter
-> FilePath -> ModuleName -> UnitId -> Bool -> MaybeT IdeAction Uri
lookupMod HieDbWriter
dbWriter) IdeOptions
opts Map ModuleName NormalizedFilePath
imports HieASTs a
hf Position
pos'
getTypeDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location])
getTypeDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location])
getTypeDefinition NormalizedFilePath
file Position
pos = MaybeT IdeAction [Location] -> IdeAction (Maybe [Location])
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT IdeAction [Location] -> IdeAction (Maybe [Location]))
-> MaybeT IdeAction [Location] -> IdeAction (Maybe [Location])
forall a b. (a -> b) -> a -> b
$ do
ShakeExtras
ide <- MaybeT IdeAction ShakeExtras
forall r (m :: * -> *). MonadReader r m => m r
ask
IdeOptions
opts <- IO IdeOptions -> MaybeT IdeAction IdeOptions
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO IdeOptions -> MaybeT IdeAction IdeOptions)
-> IO IdeOptions -> MaybeT IdeAction IdeOptions
forall a b. (a -> b) -> a -> b
$ ShakeExtras -> IO IdeOptions
getIdeOptionsIO ShakeExtras
ide
(HieAstResult
hf, PositionMapping
mapping) <- GetHieAst
-> NormalizedFilePath
-> MaybeT IdeAction (HieAstResult, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE GetHieAst
GetHieAst NormalizedFilePath
file
!Position
pos' <- IdeAction (Maybe Position) -> MaybeT IdeAction Position
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (Maybe Position -> IdeAction (Maybe Position)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Position -> IdeAction (Maybe Position))
-> Maybe Position -> IdeAction (Maybe Position)
forall a b. (a -> b) -> a -> b
$ PositionMapping -> Position -> Maybe Position
fromCurrentPosition PositionMapping
mapping Position
pos)
HieDb
hiedb <- IdeAction HieDb -> MaybeT IdeAction HieDb
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IdeAction HieDb -> MaybeT IdeAction HieDb)
-> IdeAction HieDb -> MaybeT IdeAction HieDb
forall a b. (a -> b) -> a -> b
$ (ShakeExtras -> HieDb) -> IdeAction HieDb
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks ShakeExtras -> HieDb
hiedb
HieDbWriter
dbWriter <- IdeAction HieDbWriter -> MaybeT IdeAction HieDbWriter
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IdeAction HieDbWriter -> MaybeT IdeAction HieDbWriter)
-> IdeAction HieDbWriter -> MaybeT IdeAction HieDbWriter
forall a b. (a -> b) -> a -> b
$ (ShakeExtras -> HieDbWriter) -> IdeAction HieDbWriter
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks ShakeExtras -> HieDbWriter
hiedbWriter
PositionMapping -> [Location] -> [Location]
toCurrentLocations PositionMapping
mapping ([Location] -> [Location])
-> MaybeT IdeAction [Location] -> MaybeT IdeAction [Location]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HieDb
-> (FilePath
-> ModuleName -> UnitId -> Bool -> MaybeT IdeAction Uri)
-> IdeOptions
-> HieAstResult
-> Position
-> MaybeT IdeAction [Location]
forall (m :: * -> *).
MonadIO m =>
HieDb
-> LookupModule m
-> IdeOptions
-> HieAstResult
-> Position
-> MaybeT m [Location]
AtPoint.gotoTypeDefinition HieDb
hiedb (HieDbWriter
-> FilePath -> ModuleName -> UnitId -> Bool -> MaybeT IdeAction Uri
lookupMod HieDbWriter
dbWriter) IdeOptions
opts HieAstResult
hf Position
pos'
highlightAtPoint :: NormalizedFilePath -> Position -> IdeAction (Maybe [DocumentHighlight])
highlightAtPoint :: NormalizedFilePath
-> Position -> IdeAction (Maybe [DocumentHighlight])
highlightAtPoint NormalizedFilePath
file Position
pos = MaybeT IdeAction [DocumentHighlight]
-> IdeAction (Maybe [DocumentHighlight])
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT IdeAction [DocumentHighlight]
-> IdeAction (Maybe [DocumentHighlight]))
-> MaybeT IdeAction [DocumentHighlight]
-> IdeAction (Maybe [DocumentHighlight])
forall a b. (a -> b) -> a -> b
$ do
(HAR Module
_ HieASTs a
hf RefMap a
rf Map Name [RealSrcSpan]
_ HieKind a
_,PositionMapping
mapping) <- GetHieAst
-> NormalizedFilePath
-> MaybeT IdeAction (HieAstResult, PositionMapping)
forall k v.
IdeRule k v =>
k -> NormalizedFilePath -> MaybeT IdeAction (v, PositionMapping)
useE GetHieAst
GetHieAst NormalizedFilePath
file
!Position
pos' <- IdeAction (Maybe Position) -> MaybeT IdeAction Position
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (Maybe Position -> IdeAction (Maybe Position)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Position -> IdeAction (Maybe Position))
-> Maybe Position -> IdeAction (Maybe Position)
forall a b. (a -> b) -> a -> b
$ PositionMapping -> Position -> Maybe Position
fromCurrentPosition PositionMapping
mapping Position
pos)
let toCurrentHighlight :: DocumentHighlight -> Maybe DocumentHighlight
toCurrentHighlight (DocumentHighlight Range
range Maybe DocumentHighlightKind
t) = (Range -> Maybe DocumentHighlightKind -> DocumentHighlight)
-> Maybe DocumentHighlightKind -> Range -> DocumentHighlight
forall a b c. (a -> b -> c) -> b -> a -> c
flip Range -> Maybe DocumentHighlightKind -> DocumentHighlight
DocumentHighlight Maybe DocumentHighlightKind
t (Range -> DocumentHighlight)
-> Maybe Range -> Maybe DocumentHighlight
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PositionMapping -> Range -> Maybe Range
toCurrentRange PositionMapping
mapping Range
range
(DocumentHighlight -> Maybe DocumentHighlight)
-> [DocumentHighlight] -> [DocumentHighlight]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe DocumentHighlight -> Maybe DocumentHighlight
toCurrentHighlight ([DocumentHighlight] -> [DocumentHighlight])
-> MaybeT IdeAction [DocumentHighlight]
-> MaybeT IdeAction [DocumentHighlight]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>HieASTs a
-> RefMap a -> Position -> MaybeT IdeAction [DocumentHighlight]
forall (m :: * -> *) a.
Monad m =>
HieASTs a -> RefMap a -> Position -> MaybeT m [DocumentHighlight]
AtPoint.documentHighlight HieASTs a
hf RefMap a
rf Position
pos'
refsAtPoint :: NormalizedFilePath -> Position -> Action [Location]
refsAtPoint :: NormalizedFilePath -> Position -> Action [Location]
refsAtPoint NormalizedFilePath
file Position
pos = do
ShakeExtras{HieDb
hiedb :: HieDb
hiedb :: ShakeExtras -> HieDb
hiedb} <- Action ShakeExtras
getShakeExtras
[NormalizedFilePath]
fs <- HashMap NormalizedFilePath FileOfInterestStatus
-> [NormalizedFilePath]
forall k v. HashMap k v -> [k]
HM.keys (HashMap NormalizedFilePath FileOfInterestStatus
-> [NormalizedFilePath])
-> Action (HashMap NormalizedFilePath FileOfInterestStatus)
-> Action [NormalizedFilePath]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Action (HashMap NormalizedFilePath FileOfInterestStatus)
getFilesOfInterest
HashMap NormalizedFilePath (HieAstResult, PositionMapping)
asts <- [(NormalizedFilePath, (HieAstResult, PositionMapping))]
-> HashMap NormalizedFilePath (HieAstResult, PositionMapping)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList ([(NormalizedFilePath, (HieAstResult, PositionMapping))]
-> HashMap NormalizedFilePath (HieAstResult, PositionMapping))
-> ([Maybe (HieAstResult, PositionMapping)]
-> [(NormalizedFilePath, (HieAstResult, PositionMapping))])
-> [Maybe (HieAstResult, PositionMapping)]
-> HashMap NormalizedFilePath (HieAstResult, PositionMapping)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((NormalizedFilePath, Maybe (HieAstResult, PositionMapping))
-> Maybe (NormalizedFilePath, (HieAstResult, PositionMapping)))
-> [(NormalizedFilePath, Maybe (HieAstResult, PositionMapping))]
-> [(NormalizedFilePath, (HieAstResult, PositionMapping))]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (NormalizedFilePath, Maybe (HieAstResult, PositionMapping))
-> Maybe (NormalizedFilePath, (HieAstResult, PositionMapping))
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([(NormalizedFilePath, Maybe (HieAstResult, PositionMapping))]
-> [(NormalizedFilePath, (HieAstResult, PositionMapping))])
-> ([Maybe (HieAstResult, PositionMapping)]
-> [(NormalizedFilePath, Maybe (HieAstResult, PositionMapping))])
-> [Maybe (HieAstResult, PositionMapping)]
-> [(NormalizedFilePath, (HieAstResult, PositionMapping))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NormalizedFilePath]
-> [Maybe (HieAstResult, PositionMapping)]
-> [(NormalizedFilePath, Maybe (HieAstResult, PositionMapping))]
forall a b. [a] -> [b] -> [(a, b)]
zip [NormalizedFilePath]
fs ([Maybe (HieAstResult, PositionMapping)]
-> HashMap NormalizedFilePath (HieAstResult, PositionMapping))
-> Action [Maybe (HieAstResult, PositionMapping)]
-> Action
(HashMap NormalizedFilePath (HieAstResult, PositionMapping))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GetHieAst
-> [NormalizedFilePath]
-> Action [Maybe (HieAstResult, PositionMapping)]
forall k v.
IdeRule k v =>
k -> [NormalizedFilePath] -> Action [Maybe (v, PositionMapping)]
usesWithStale GetHieAst
GetHieAst [NormalizedFilePath]
fs
HieDb
-> NormalizedFilePath
-> Position
-> FOIReferences
-> Action [Location]
forall (m :: * -> *).
MonadIO m =>
HieDb
-> NormalizedFilePath -> Position -> FOIReferences -> m [Location]
AtPoint.referencesAtPoint HieDb
hiedb NormalizedFilePath
file Position
pos (HashMap NormalizedFilePath (HieAstResult, PositionMapping)
-> FOIReferences
AtPoint.FOIReferences HashMap NormalizedFilePath (HieAstResult, PositionMapping)
asts)
workspaceSymbols :: T.Text -> IdeAction (Maybe [SymbolInformation])
workspaceSymbols :: Text -> IdeAction (Maybe [SymbolInformation])
workspaceSymbols Text
query = MaybeT IdeAction [SymbolInformation]
-> IdeAction (Maybe [SymbolInformation])
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT IdeAction [SymbolInformation]
-> IdeAction (Maybe [SymbolInformation]))
-> MaybeT IdeAction [SymbolInformation]
-> IdeAction (Maybe [SymbolInformation])
forall a b. (a -> b) -> a -> b
$ do
HieDb
hiedb <- IdeAction HieDb -> MaybeT IdeAction HieDb
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (IdeAction HieDb -> MaybeT IdeAction HieDb)
-> IdeAction HieDb -> MaybeT IdeAction HieDb
forall a b. (a -> b) -> a -> b
$ (ShakeExtras -> HieDb) -> IdeAction HieDb
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks ShakeExtras -> HieDb
hiedb
[Res DefRow]
res <- IO [Res DefRow] -> MaybeT IdeAction [Res DefRow]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Res DefRow] -> MaybeT IdeAction [Res DefRow])
-> IO [Res DefRow] -> MaybeT IdeAction [Res DefRow]
forall a b. (a -> b) -> a -> b
$ HieDb -> FilePath -> IO [Res DefRow]
HieDb.searchDef HieDb
hiedb (FilePath -> IO [Res DefRow]) -> FilePath -> IO [Res DefRow]
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack Text
query
[SymbolInformation] -> MaybeT IdeAction [SymbolInformation]
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([SymbolInformation] -> MaybeT IdeAction [SymbolInformation])
-> [SymbolInformation] -> MaybeT IdeAction [SymbolInformation]
forall a b. (a -> b) -> a -> b
$ (Res DefRow -> Maybe SymbolInformation)
-> [Res DefRow] -> [SymbolInformation]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Res DefRow -> Maybe SymbolInformation
AtPoint.defRowToSymbolInfo [Res DefRow]
res