@@ -31,9 +31,7 @@ import Development.IDE.Types.Location
3131import GHC.Iface.Ext.Types (Identifier )
3232import qualified HieDb
3333import Language.LSP.Protocol.Types (DocumentHighlight (.. ),
34- SymbolInformation (.. ),
35- normalizedFilePathToUri ,
36- uriToNormalizedFilePath )
34+ SymbolInformation (.. ))
3735
3836-- IMPORTANT NOTE : make sure all rules `useWithStaleFastMT`d by these have a "Persistent Stale" rule defined,
3937-- so we can quickly answer as soon as the IDE is opened
@@ -43,16 +41,16 @@ import Language.LSP.Protocol.Types (DocumentHighlight (..),
4341-- block waiting for the rule to be properly computed.
4442
4543-- | Try to get hover text for the name under point.
46- getAtPoint :: NormalizedFilePath -> Position -> IdeAction (Maybe (Maybe Range , [T. Text ]))
47- getAtPoint file pos = runMaybeT $ do
44+ getAtPoint :: NormalizedUri -> Position -> IdeAction (Maybe (Maybe Range , [T. Text ]))
45+ getAtPoint uri pos = runMaybeT $ do
4846 ide <- ask
4947 opts <- liftIO $ getIdeOptionsIO ide
5048
51- (hf, mapping) <- useWithStaleFastMT GetHieAst file
49+ (hf, mapping) <- useWithStaleFastMT GetHieAst uri
5250 shakeExtras <- lift askShake
5351
54- env <- hscEnv . fst <$> useWithStaleFastMT GhcSession file
55- dkMap <- lift $ maybe (DKMap mempty mempty mempty ) fst <$> runMaybeT (useWithStaleFastMT GetDocMap file )
52+ env <- hscEnv . fst <$> useWithStaleFastMT GhcSession uri
53+ dkMap <- lift $ maybe (DKMap mempty mempty mempty ) fst <$> runMaybeT (useWithStaleFastMT GetDocMap uri )
5654
5755 ! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
5856
@@ -63,79 +61,78 @@ getAtPoint file pos = runMaybeT $ do
6361-- taking into account changes that may have occurred due to edits.
6462toCurrentLocation
6563 :: PositionMapping
66- -> NormalizedFilePath
64+ -> NormalizedUri
6765 -> Location
6866 -> IdeAction (Maybe Location )
69- toCurrentLocation mapping file (Location uri range ) =
67+ toCurrentLocation mapping uri (Location locUri locRange ) =
7068 -- The Location we are going to might be in a different
7169 -- file than the one we are calling gotoDefinition from.
7270 -- So we check that the location file matches the file
7371 -- we are in.
74- if nUri == normalizedFilePathToUri file
72+ if nUri == uri
7573 -- The Location matches the file, so use the PositionMapping
7674 -- we have.
77- then pure $ Location uri <$> toCurrentRange mapping range
75+ then pure $ Location locUri <$> toCurrentRange mapping locRange
7876 -- The Location does not match the file, so get the correct
7977 -- PositionMapping and use that instead.
8078 else do
8179 otherLocationMapping <- fmap (fmap snd ) $ runMaybeT $ do
82- otherLocationFile <- MaybeT $ pure $ uriToNormalizedFilePath nUri
83- useWithStaleFastMT GetHieAst otherLocationFile
84- pure $ Location uri <$> (flip toCurrentRange range =<< otherLocationMapping)
80+ useWithStaleFastMT GetHieAst nUri
81+ pure $ Location locUri <$> (flip toCurrentRange locRange =<< otherLocationMapping)
8582 where
8683 nUri :: NormalizedUri
87- nUri = toNormalizedUri uri
84+ nUri = toNormalizedUri locUri
8885
8986-- | Goto Definition.
90- getDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [(Location , Identifier )])
91- getDefinition file pos = runMaybeT $ do
87+ getDefinition :: NormalizedUri -> Position -> IdeAction (Maybe [(Location , Identifier )])
88+ getDefinition uri pos = runMaybeT $ do
9289 ide@ ShakeExtras { withHieDb, hiedbWriter } <- ask
9390 opts <- liftIO $ getIdeOptionsIO ide
94- (hf, mapping) <- useWithStaleFastMT GetHieAst file
95- (ImportMap imports, _) <- useWithStaleFastMT GetImportMap file
91+ (hf, mapping) <- useWithStaleFastMT GetHieAst uri
92+ (ImportMap imports, _) <- useWithStaleFastMT GetImportMap uri
9693 ! pos' <- MaybeT (pure $ fromCurrentPosition mapping pos)
9794 locationsWithIdentifier <- AtPoint. gotoDefinition withHieDb (lookupMod hiedbWriter) opts imports hf pos'
9895 mapMaybeM (\ (location, identifier) -> do
99- fixedLocation <- MaybeT $ toCurrentLocation mapping file location
96+ fixedLocation <- MaybeT $ toCurrentLocation mapping uri location
10097 pure $ Just (fixedLocation, identifier)
10198 ) locationsWithIdentifier
10299
103100
104- getTypeDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [(Location , Identifier )])
105- getTypeDefinition file pos = runMaybeT $ do
101+ getTypeDefinition :: NormalizedUri -> Position -> IdeAction (Maybe [(Location , Identifier )])
102+ getTypeDefinition uri pos = runMaybeT $ do
106103 ide@ ShakeExtras { withHieDb, hiedbWriter } <- ask
107104 opts <- liftIO $ getIdeOptionsIO ide
108- (hf, mapping) <- useWithStaleFastMT GetHieAst file
105+ (hf, mapping) <- useWithStaleFastMT GetHieAst uri
109106 ! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
110107 locationsWithIdentifier <- AtPoint. gotoTypeDefinition withHieDb (lookupMod hiedbWriter) opts hf pos'
111108 mapMaybeM (\ (location, identifier) -> do
112- fixedLocation <- MaybeT $ toCurrentLocation mapping file location
109+ fixedLocation <- MaybeT $ toCurrentLocation mapping uri location
113110 pure $ Just (fixedLocation, identifier)
114111 ) locationsWithIdentifier
115112
116- getImplementationDefinition :: NormalizedFilePath -> Position -> IdeAction (Maybe [Location ])
117- getImplementationDefinition file pos = runMaybeT $ do
113+ getImplementationDefinition :: NormalizedUri -> Position -> IdeAction (Maybe [Location ])
114+ getImplementationDefinition uri pos = runMaybeT $ do
118115 ide@ ShakeExtras { withHieDb, hiedbWriter } <- ask
119116 opts <- liftIO $ getIdeOptionsIO ide
120- (hf, mapping) <- useWithStaleFastMT GetHieAst file
117+ (hf, mapping) <- useWithStaleFastMT GetHieAst uri
121118 ! pos' <- MaybeT (pure $ fromCurrentPosition mapping pos)
122119 locs <- AtPoint. gotoImplementation withHieDb (lookupMod hiedbWriter) opts hf pos'
123- traverse (MaybeT . toCurrentLocation mapping file ) locs
120+ traverse (MaybeT . toCurrentLocation mapping uri ) locs
124121
125- highlightAtPoint :: NormalizedFilePath -> Position -> IdeAction (Maybe [DocumentHighlight ])
126- highlightAtPoint file pos = runMaybeT $ do
127- (HAR _ hf rf _ _,mapping) <- useWithStaleFastMT GetHieAst file
122+ highlightAtPoint :: NormalizedUri -> Position -> IdeAction (Maybe [DocumentHighlight ])
123+ highlightAtPoint uri pos = runMaybeT $ do
124+ (HAR _ hf rf _ _,mapping) <- useWithStaleFastMT GetHieAst uri
128125 ! pos' <- MaybeT (return $ fromCurrentPosition mapping pos)
129126 let toCurrentHighlight (DocumentHighlight range t) = flip DocumentHighlight t <$> toCurrentRange mapping range
130127 mapMaybe toCurrentHighlight <$> AtPoint. documentHighlight hf rf pos'
131128
132129-- Refs are not an IDE action, so it is OK to be slow and (more) accurate
133- refsAtPoint :: NormalizedFilePath -> Position -> Action [Location ]
134- refsAtPoint file pos = do
130+ refsAtPoint :: NormalizedUri -> Position -> Action [Location ]
131+ refsAtPoint uri pos = do
135132 ShakeExtras {withHieDb} <- getShakeExtras
136133 fs <- HM. keys <$> getFilesOfInterestUntracked
137134 asts <- HM. fromList . mapMaybe sequence . zip fs <$> usesWithStale GetHieAst fs
138- AtPoint. referencesAtPoint withHieDb file pos (AtPoint. FOIReferences asts)
135+ AtPoint. referencesAtPoint withHieDb uri pos (AtPoint. BOIReferences asts)
139136
140137workspaceSymbols :: T. Text -> IdeAction (Maybe [SymbolInformation ])
141138workspaceSymbols query = runMaybeT $ do
0 commit comments