Skip to content

Commit

Permalink
Fall back to hiedb for invalid srcspan paths (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepeiborra authored Jun 14, 2021
1 parent be2071e commit 369373e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ jobs:
- if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: untar
run: |
mkdir -p ~/.cabal
tar xzf workspace.tar.gz
tar xzf cabal.tar.gz --directory ~/.cabal
Expand Down
2 changes: 1 addition & 1 deletion ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cabal-version: 2.4
build-type: Simple
category: Development
name: ghcide
version: 1.4.0.0
version: 1.4.0.1
license: Apache-2.0
license-file: LICENSE
author: Digital Asset and Ghcide contributors
Expand Down
16 changes: 14 additions & 2 deletions ghcide/src/Development/IDE/Spans/AtPoint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import Data.List (isSuffixOf)
import Data.List.Extra (dropEnd1, nubOrd)

import HieDb hiding (pointCommand)
import System.Directory (doesFileExist)

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

0 comments on commit 369373e

Please sign in to comment.