Skip to content

Commit 369373e

Browse files
authored
Fall back to hiedb for invalid srcspan paths (#1918)
1 parent be2071e commit 369373e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

.github/workflows/bench.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ jobs:
135135
- if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
136136
name: untar
137137
run: |
138+
mkdir -p ~/.cabal
138139
tar xzf workspace.tar.gz
139140
tar xzf cabal.tar.gz --directory ~/.cabal
140141

ghcide/ghcide.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cabal-version: 2.4
22
build-type: Simple
33
category: Development
44
name: ghcide
5-
version: 1.4.0.0
5+
version: 1.4.0.1
66
license: Apache-2.0
77
license-file: LICENSE
88
author: Digital Asset and Ghcide contributors

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import Data.List (isSuffixOf)
5757
import Data.List.Extra (dropEnd1, nubOrd)
5858

5959
import HieDb hiding (pointCommand)
60+
import System.Directory (doesFileExist)
6061

6162
-- | Gives a Uri for the module, given the .hie file location and the the module info
6263
-- The Bool denotes if it is a boot module
@@ -312,8 +313,19 @@ nameToLocation hiedb lookupModule name = runMaybeT $
312313
case nameSrcSpan name of
313314
sp@(OldRealSrcSpan rsp)
314315
-- Lookup in the db if we got a location in a boot file
315-
| not $ "boot" `isSuffixOf` unpackFS (srcSpanFile rsp) -> MaybeT $ pure $ fmap pure $ srcSpanToLocation sp
316-
sp -> do
316+
| fs <- unpackFS (srcSpanFile rsp)
317+
, not $ "boot" `isSuffixOf` fs
318+
-> do
319+
itExists <- liftIO $ doesFileExist fs
320+
if itExists
321+
then MaybeT $ pure $ fmap pure $ srcSpanToLocation sp
322+
-- When reusing .hie files from a cloud cache,
323+
-- the paths may not match the local file system.
324+
-- Let's fall back to the hiedb in case it contains local paths
325+
else fallbackToDb sp
326+
sp -> fallbackToDb sp
327+
where
328+
fallbackToDb sp = do
317329
guard (sp /= wiredInSrcSpan)
318330
-- This case usually arises when the definition is in an external package.
319331
-- In this case the interface files contain garbage source spans

0 commit comments

Comments
 (0)