on 855c18e help sign in
ghcide/src/Development/IDE/LSP/Definition.hs
43 lines 1.4 kB history raw
1-- Copyright (c) 2019 The DAML Authors. All rights reserved.
2-- SPDX-License-Identifier: Apache-2.0
5-- | Go to the definition of a variable.
6module Development.IDE.LSP.Definition
7 ( setHandlersDefinition
8 ) where
10import Language.Haskell.LSP.Types
11import Development.IDE.Types.Location
13import Development.IDE.Types.Logger
14import Development.IDE.Core.Rules
15import Development.IDE.Core.Service
16import Development.IDE.LSP.Server
17import qualified Language.Haskell.LSP.Core as LSP
18import Language.Haskell.LSP.Messages
20import qualified Data.Text as T
22-- | Go to the definition of a variable.
23gotoDefinition
24 :: IdeState
25 -> TextDocumentPositionParams
26 -> IO LocationResponseParams
27gotoDefinition ide (TextDocumentPositionParams (TextDocumentIdentifier uri) pos) = do
28 mbResult <- case uriToFilePath' uri of
29 Just path -> do
30 logInfo (ideLogger ide) $
31 "Definition request at position " <> T.pack (showPosition pos) <>
32 " in file: " <> T.pack path
33 runAction ide $ getDefinition (toNormalizedFilePath path) pos
34 Nothing -> pure Nothing
35 pure $ case mbResult of
36 Nothing -> MultiLoc []
37 Just loc -> SingleLoc loc
40setHandlersDefinition :: PartialHandlers
41setHandlersDefinition = PartialHandlers $ \WithMessage{..} x -> return x{
42 LSP.definitionHandler = withResponse RspDefinition $ const gotoDefinition
43 }