mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
Support goto definition on symbols in the module export list (#1801)
This commit is contained in:
parent
b438c2ad82
commit
aac3c7b012
@ -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 GHC’s 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
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user