Support goto definition on symbols in the module export list (#1801)

This commit is contained in:
Moritz Kiefer 2019-06-21 16:07:59 +02:00 committed by mergify[bot]
parent b438c2ad82
commit aac3c7b012
3 changed files with 37 additions and 1 deletions

View File

@ -42,13 +42,31 @@ getSpanInfo mods tcm =
ets <- mapM (getTypeLHsExpr tcm) es -- expressions
pts <- mapM (getTypeLPat tcm) ps -- patterns
let imports = importInfo mods
let exprs = imports ++ concat bts ++ catMaybes (ets ++ pts)
let exports = getExports tcm
let exprs = exports ++ imports ++ concat bts ++ catMaybes (ets ++ pts)
return (mapMaybe toSpanInfo (sortBy cmp exprs))
where cmp (_,a,_) (_,b,_)
| a `isSubspanOf` b = LT
| b `isSubspanOf` a = GT
| otherwise = EQ
getExports :: TypecheckedModule -> [(SpanSource, SrcSpan, Maybe Type)]
getExports m
| Just (_, _, Just exports, _) <- renamedSource m =
[ (Named $ unLoc n, getLoc n, Nothing)
| (e, _) <- exports
, n <- ieLNames $ unLoc e
]
getExports _ = []
-- | Variant of GHCs ieNames that produces LIdP instead of IdP
ieLNames :: IE pass -> [LIdP pass]
ieLNames (IEVar _ n ) = [ieLWrappedName n]
ieLNames (IEThingAbs _ n ) = [ieLWrappedName n]
ieLNames (IEThingAll _ n ) = [ieLWrappedName n]
ieLNames (IEThingWith _ n _ ns _) = ieLWrappedName n : map ieLWrappedName ns
ieLNames _ = []
-- | Get the name and type of a binding.
getTypeLHsBind :: (GhcMonad m)
=> TypecheckedModule

View File

@ -421,6 +421,23 @@ goToDefinitionTests mbScenarioService = Tasty.testGroup "Go to definition tests"
expectGoToDefinition (foo,2,[6..13]) (In "Prelude") -- "Optional"
expectGoToDefinition (foo,2,[16..19]) (In "GHC.Types") -- "List"
expectGoToDefinition (foo,2,[21..24]) (In "GHC.Types") -- "Bool"
, testCase' "Go to definition takes export list to definition" $ do
foo <- makeFile "Foo.daml" $ T.unlines
[ "daml 1.2"
, "module Foo (foo, A(B)) where"
, "foo : Int"
, "foo = 0"
, "data A = B Int"
]
setFilesOfInterest [foo]
expectNoErrors
-- foo
expectGoToDefinition (foo,1,[13..14]) (At (foo,3,0))
-- A
expectGoToDefinition (foo,1,[17..17]) (At (foo,4,0))
-- B
expectGoToDefinition (foo,1,[19..19]) (At (foo,4,9))
{-
-- Disabled for now. See issue
-- https://github.com/digital-asset/daml/issues/1582

View File

@ -26,3 +26,4 @@ DAML Integration Kit
~~~~~~~~~~~~~~~~~~~~
- Added additional Ledger API integration tests to Ledger API Test Tool.
- [DAML Studio] Goto definition now works on the export list of modules.