Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back to hiedb for invalid srcspan paths #1918

Merged
merged 3 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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