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