-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE GADTs      #-}
{-# LANGUAGE RankNTypes #-}

-- | Display information on hover.
module Development.IDE.LSP.HoverDefinition
    ( setIdeHandlers
    -- * For haskell-language-server
    , hover
    , gotoDefinition
    , gotoTypeDefinition
    ) where

import           Control.Monad.IO.Class
import           Development.IDE.Core.Actions
import           Development.IDE.Core.Rules
import           Development.IDE.Core.Shake
import           Development.IDE.LSP.Server
import           Development.IDE.Types.Location
import           Development.IDE.Types.Logger
import qualified Language.LSP.Server            as LSP
import           Language.LSP.Types

import qualified Data.Text                      as T

gotoDefinition :: IdeState -> TextDocumentPositionParams -> LSP.LspM c (Either ResponseError (ResponseResult TextDocumentDefinition))
hover          :: IdeState -> TextDocumentPositionParams -> LSP.LspM c (Either ResponseError (Maybe Hover))
gotoTypeDefinition :: IdeState -> TextDocumentPositionParams -> LSP.LspM c (Either ResponseError (ResponseResult TextDocumentTypeDefinition))
documentHighlight :: IdeState -> TextDocumentPositionParams -> LSP.LspM c (Either ResponseError (List DocumentHighlight))
gotoDefinition :: IdeState
-> TextDocumentPositionParams
-> LspM
     c (Either ResponseError (ResponseResult 'TextDocumentDefinition))
gotoDefinition = Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe [Location]))
-> (Location |? (List Location |? List LocationLink))
-> ([Location] -> Location |? (List Location |? List LocationLink))
-> IdeState
-> TextDocumentPositionParams
-> LspM
     c
     (Either
        ResponseError (Location |? (List Location |? List LocationLink)))
forall a b c.
Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
-> b
-> (a -> b)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError b)
request Text
"Definition" NormalizedFilePath -> Position -> IdeAction (Maybe [Location])
getDefinition ((List Location |? List LocationLink)
-> Location |? (List Location |? List LocationLink)
forall a b. b -> a |? b
InR ((List Location |? List LocationLink)
 -> Location |? (List Location |? List LocationLink))
-> (List Location |? List LocationLink)
-> Location |? (List Location |? List LocationLink)
forall a b. (a -> b) -> a -> b
$ List Location -> List Location |? List LocationLink
forall a b. a -> a |? b
InL (List Location -> List Location |? List LocationLink)
-> List Location -> List Location |? List LocationLink
forall a b. (a -> b) -> a -> b
$ [Location] -> List Location
forall a. [a] -> List a
List []) ((List Location |? List LocationLink)
-> Location |? (List Location |? List LocationLink)
forall a b. b -> a |? b
InR ((List Location |? List LocationLink)
 -> Location |? (List Location |? List LocationLink))
-> ([Location] -> List Location |? List LocationLink)
-> [Location]
-> Location |? (List Location |? List LocationLink)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List Location -> List Location |? List LocationLink
forall a b. a -> a |? b
InL (List Location -> List Location |? List LocationLink)
-> ([Location] -> List Location)
-> [Location]
-> List Location |? List LocationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Location] -> List Location
forall a. [a] -> List a
List)
gotoTypeDefinition :: IdeState
-> TextDocumentPositionParams
-> LspM
     c
     (Either ResponseError (ResponseResult 'TextDocumentTypeDefinition))
gotoTypeDefinition = Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe [Location]))
-> (Location |? (List Location |? List LocationLink))
-> ([Location] -> Location |? (List Location |? List LocationLink))
-> IdeState
-> TextDocumentPositionParams
-> LspM
     c
     (Either
        ResponseError (Location |? (List Location |? List LocationLink)))
forall a b c.
Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
-> b
-> (a -> b)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError b)
request Text
"TypeDefinition" NormalizedFilePath -> Position -> IdeAction (Maybe [Location])
getTypeDefinition ((List Location |? List LocationLink)
-> Location |? (List Location |? List LocationLink)
forall a b. b -> a |? b
InR ((List Location |? List LocationLink)
 -> Location |? (List Location |? List LocationLink))
-> (List Location |? List LocationLink)
-> Location |? (List Location |? List LocationLink)
forall a b. (a -> b) -> a -> b
$ List Location -> List Location |? List LocationLink
forall a b. a -> a |? b
InL (List Location -> List Location |? List LocationLink)
-> List Location -> List Location |? List LocationLink
forall a b. (a -> b) -> a -> b
$ [Location] -> List Location
forall a. [a] -> List a
List []) ((List Location |? List LocationLink)
-> Location |? (List Location |? List LocationLink)
forall a b. b -> a |? b
InR ((List Location |? List LocationLink)
 -> Location |? (List Location |? List LocationLink))
-> ([Location] -> List Location |? List LocationLink)
-> [Location]
-> Location |? (List Location |? List LocationLink)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List Location -> List Location |? List LocationLink
forall a b. a -> a |? b
InL (List Location -> List Location |? List LocationLink)
-> ([Location] -> List Location)
-> [Location]
-> List Location |? List LocationLink
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Location] -> List Location
forall a. [a] -> List a
List)
hover :: IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError (Maybe Hover))
hover          = Text
-> (NormalizedFilePath
    -> Position -> IdeAction (Maybe (Maybe Range, [Text])))
-> Maybe Hover
-> ((Maybe Range, [Text]) -> Maybe Hover)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError (Maybe Hover))
forall a b c.
Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
-> b
-> (a -> b)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError b)
request Text
"Hover"      NormalizedFilePath
-> Position -> IdeAction (Maybe (Maybe Range, [Text]))
getAtPoint     Maybe Hover
forall a. Maybe a
Nothing      (Maybe Range, [Text]) -> Maybe Hover
foundHover
documentHighlight :: IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError (List DocumentHighlight))
documentHighlight = Text
-> (NormalizedFilePath
    -> Position -> IdeAction (Maybe [DocumentHighlight]))
-> List DocumentHighlight
-> ([DocumentHighlight] -> List DocumentHighlight)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError (List DocumentHighlight))
forall a b c.
Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
-> b
-> (a -> b)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError b)
request Text
"DocumentHighlight" NormalizedFilePath
-> Position -> IdeAction (Maybe [DocumentHighlight])
highlightAtPoint ([DocumentHighlight] -> List DocumentHighlight
forall a. [a] -> List a
List []) [DocumentHighlight] -> List DocumentHighlight
forall a. [a] -> List a
List

references :: IdeState -> ReferenceParams -> LSP.LspM c (Either ResponseError (List Location))
references :: IdeState
-> ReferenceParams -> LspM c (Either ResponseError (List Location))
references IdeState
ide (ReferenceParams (TextDocumentIdentifier Uri
uri) Position
pos Maybe ProgressToken
_ Maybe ProgressToken
_ ReferenceContext
_) = IO (Either ResponseError (List Location))
-> LspM c (Either ResponseError (List Location))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ResponseError (List Location))
 -> LspM c (Either ResponseError (List Location)))
-> IO (Either ResponseError (List Location))
-> LspM c (Either ResponseError (List Location))
forall a b. (a -> b) -> a -> b
$
  case Uri -> Maybe FilePath
uriToFilePath' Uri
uri of
    Just FilePath
path -> do
      let filePath :: NormalizedFilePath
filePath = FilePath -> NormalizedFilePath
toNormalizedFilePath' FilePath
path
      Logger -> Text -> IO ()
logDebug (IdeState -> Logger
ideLogger IdeState
ide) (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$
        Text
"References request at position " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack (Position -> FilePath
showPosition Position
pos) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
        Text
" in file: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack FilePath
path
      List Location -> Either ResponseError (List Location)
forall a b. b -> Either a b
Right (List Location -> Either ResponseError (List Location))
-> ([Location] -> List Location)
-> [Location]
-> Either ResponseError (List Location)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Location] -> List Location
forall a. [a] -> List a
List ([Location] -> Either ResponseError (List Location))
-> IO [Location] -> IO (Either ResponseError (List Location))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (FilePath -> IdeState -> Action [Location] -> IO [Location]
forall a. FilePath -> IdeState -> Action a -> IO a
runAction FilePath
"references" IdeState
ide (Action [Location] -> IO [Location])
-> Action [Location] -> IO [Location]
forall a b. (a -> b) -> a -> b
$ NormalizedFilePath -> Position -> Action [Location]
refsAtPoint NormalizedFilePath
filePath Position
pos)
    Maybe FilePath
Nothing -> Either ResponseError (List Location)
-> IO (Either ResponseError (List Location))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either ResponseError (List Location)
 -> IO (Either ResponseError (List Location)))
-> Either ResponseError (List Location)
-> IO (Either ResponseError (List Location))
forall a b. (a -> b) -> a -> b
$ ResponseError -> Either ResponseError (List Location)
forall a b. a -> Either a b
Left (ResponseError -> Either ResponseError (List Location))
-> ResponseError -> Either ResponseError (List Location)
forall a b. (a -> b) -> a -> b
$ ErrorCode -> Text -> Maybe Value -> ResponseError
ResponseError ErrorCode
InvalidParams (Text
"Invalid URI " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack (Uri -> FilePath
forall a. Show a => a -> FilePath
show Uri
uri)) Maybe Value
forall a. Maybe a
Nothing

wsSymbols :: IdeState -> WorkspaceSymbolParams -> LSP.LspM c (Either ResponseError (List SymbolInformation))
wsSymbols :: IdeState
-> WorkspaceSymbolParams
-> LspM c (Either ResponseError (List SymbolInformation))
wsSymbols IdeState
ide (WorkspaceSymbolParams Maybe ProgressToken
_ Maybe ProgressToken
_ Text
query) = IO (Either ResponseError (List SymbolInformation))
-> LspM c (Either ResponseError (List SymbolInformation))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ResponseError (List SymbolInformation))
 -> LspM c (Either ResponseError (List SymbolInformation)))
-> IO (Either ResponseError (List SymbolInformation))
-> LspM c (Either ResponseError (List SymbolInformation))
forall a b. (a -> b) -> a -> b
$ do
  Logger -> Text -> IO ()
logDebug (IdeState -> Logger
ideLogger IdeState
ide) (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$ Text
"Workspace symbols request: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
query
  FilePath
-> ShakeExtras
-> IdeAction (Either ResponseError (List SymbolInformation))
-> IO (Either ResponseError (List SymbolInformation))
forall a. FilePath -> ShakeExtras -> IdeAction a -> IO a
runIdeAction FilePath
"WorkspaceSymbols" (IdeState -> ShakeExtras
shakeExtras IdeState
ide) (IdeAction (Either ResponseError (List SymbolInformation))
 -> IO (Either ResponseError (List SymbolInformation)))
-> IdeAction (Either ResponseError (List SymbolInformation))
-> IO (Either ResponseError (List SymbolInformation))
forall a b. (a -> b) -> a -> b
$ List SymbolInformation
-> Either ResponseError (List SymbolInformation)
forall a b. b -> Either a b
Right (List SymbolInformation
 -> Either ResponseError (List SymbolInformation))
-> (Maybe [SymbolInformation] -> List SymbolInformation)
-> Maybe [SymbolInformation]
-> Either ResponseError (List SymbolInformation)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List SymbolInformation
-> ([SymbolInformation] -> List SymbolInformation)
-> Maybe [SymbolInformation]
-> List SymbolInformation
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([SymbolInformation] -> List SymbolInformation
forall a. [a] -> List a
List []) [SymbolInformation] -> List SymbolInformation
forall a. [a] -> List a
List (Maybe [SymbolInformation]
 -> Either ResponseError (List SymbolInformation))
-> IdeAction (Maybe [SymbolInformation])
-> IdeAction (Either ResponseError (List SymbolInformation))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> IdeAction (Maybe [SymbolInformation])
workspaceSymbols Text
query

foundHover :: (Maybe Range, [T.Text]) -> Maybe Hover
foundHover :: (Maybe Range, [Text]) -> Maybe Hover
foundHover (Maybe Range
mbRange, [Text]
contents) =
  Hover -> Maybe Hover
forall a. a -> Maybe a
Just (Hover -> Maybe Hover) -> Hover -> Maybe Hover
forall a b. (a -> b) -> a -> b
$ HoverContents -> Maybe Range -> Hover
Hover (MarkupContent -> HoverContents
HoverContents (MarkupContent -> HoverContents) -> MarkupContent -> HoverContents
forall a b. (a -> b) -> a -> b
$ MarkupKind -> Text -> MarkupContent
MarkupContent MarkupKind
MkMarkdown (Text -> MarkupContent) -> Text -> MarkupContent
forall a b. (a -> b) -> a -> b
$ Text -> [Text] -> Text
T.intercalate Text
sectionSeparator [Text]
contents) Maybe Range
mbRange

setIdeHandlers :: LSP.Handlers (ServerM c)
setIdeHandlers :: Handlers (ServerM c)
setIdeHandlers = [Handlers (ServerM c)] -> Handlers (ServerM c)
forall a. Monoid a => [a] -> a
mconcat
  [ SMethod 'TextDocumentDefinition
-> (IdeState
    -> MessageParams 'TextDocumentDefinition
    -> LspM
         c (Either ResponseError (ResponseResult 'TextDocumentDefinition)))
-> Handlers (ServerM c)
forall (m :: Method 'FromClient 'Request) c.
HasTracing (MessageParams m) =>
SMethod m
-> (IdeState
    -> MessageParams m
    -> LspM c (Either ResponseError (ResponseResult m)))
-> Handlers (ServerM c)
requestHandler SMethod 'TextDocumentDefinition
STextDocumentDefinition ((IdeState
  -> MessageParams 'TextDocumentDefinition
  -> LspM
       c (Either ResponseError (ResponseResult 'TextDocumentDefinition)))
 -> Handlers (ServerM c))
-> (IdeState
    -> MessageParams 'TextDocumentDefinition
    -> LspM
         c (Either ResponseError (ResponseResult 'TextDocumentDefinition)))
-> Handlers (ServerM c)
forall a b. (a -> b) -> a -> b
$ \IdeState
ide DefinitionParams{..} ->
      IdeState
-> TextDocumentPositionParams
-> LspM
     c (Either ResponseError (ResponseResult 'TextDocumentDefinition))
forall c.
IdeState
-> TextDocumentPositionParams
-> LspM
     c (Either ResponseError (ResponseResult 'TextDocumentDefinition))
gotoDefinition IdeState
ide TextDocumentPositionParams :: TextDocumentIdentifier -> Position -> TextDocumentPositionParams
TextDocumentPositionParams{TextDocumentIdentifier
Position
$sel:_textDocument:TextDocumentPositionParams :: TextDocumentIdentifier
$sel:_position:TextDocumentPositionParams :: Position
_position :: Position
_textDocument :: TextDocumentIdentifier
..}
  , SMethod 'TextDocumentTypeDefinition
-> (IdeState
    -> MessageParams 'TextDocumentTypeDefinition
    -> LspM
         c
         (Either
            ResponseError (ResponseResult 'TextDocumentTypeDefinition)))
-> Handlers (ServerM c)
forall (m :: Method 'FromClient 'Request) c.
HasTracing (MessageParams m) =>
SMethod m
-> (IdeState
    -> MessageParams m
    -> LspM c (Either ResponseError (ResponseResult m)))
-> Handlers (ServerM c)
requestHandler SMethod 'TextDocumentTypeDefinition
STextDocumentTypeDefinition ((IdeState
  -> MessageParams 'TextDocumentTypeDefinition
  -> LspM
       c
       (Either
          ResponseError (ResponseResult 'TextDocumentTypeDefinition)))
 -> Handlers (ServerM c))
-> (IdeState
    -> MessageParams 'TextDocumentTypeDefinition
    -> LspM
         c
         (Either
            ResponseError (ResponseResult 'TextDocumentTypeDefinition)))
-> Handlers (ServerM c)
forall a b. (a -> b) -> a -> b
$ \IdeState
ide TypeDefinitionParams{..} ->
      IdeState
-> TextDocumentPositionParams
-> LspM
     c
     (Either ResponseError (ResponseResult 'TextDocumentTypeDefinition))
forall c.
IdeState
-> TextDocumentPositionParams
-> LspM
     c
     (Either ResponseError (ResponseResult 'TextDocumentTypeDefinition))
gotoTypeDefinition IdeState
ide TextDocumentPositionParams :: TextDocumentIdentifier -> Position -> TextDocumentPositionParams
TextDocumentPositionParams{TextDocumentIdentifier
Position
_position :: Position
_textDocument :: TextDocumentIdentifier
$sel:_textDocument:TextDocumentPositionParams :: TextDocumentIdentifier
$sel:_position:TextDocumentPositionParams :: Position
..}
  , SMethod 'TextDocumentDocumentHighlight
-> (IdeState
    -> MessageParams 'TextDocumentDocumentHighlight
    -> LspM
         c
         (Either
            ResponseError (ResponseResult 'TextDocumentDocumentHighlight)))
-> Handlers (ServerM c)
forall (m :: Method 'FromClient 'Request) c.
HasTracing (MessageParams m) =>
SMethod m
-> (IdeState
    -> MessageParams m
    -> LspM c (Either ResponseError (ResponseResult m)))
-> Handlers (ServerM c)
requestHandler SMethod 'TextDocumentDocumentHighlight
STextDocumentDocumentHighlight ((IdeState
  -> MessageParams 'TextDocumentDocumentHighlight
  -> LspM
       c
       (Either
          ResponseError (ResponseResult 'TextDocumentDocumentHighlight)))
 -> Handlers (ServerM c))
-> (IdeState
    -> MessageParams 'TextDocumentDocumentHighlight
    -> LspM
         c
         (Either
            ResponseError (ResponseResult 'TextDocumentDocumentHighlight)))
-> Handlers (ServerM c)
forall a b. (a -> b) -> a -> b
$ \IdeState
ide DocumentHighlightParams{..} ->
      IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError (List DocumentHighlight))
forall c.
IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError (List DocumentHighlight))
documentHighlight IdeState
ide TextDocumentPositionParams :: TextDocumentIdentifier -> Position -> TextDocumentPositionParams
TextDocumentPositionParams{TextDocumentIdentifier
Position
_position :: Position
_textDocument :: TextDocumentIdentifier
$sel:_textDocument:TextDocumentPositionParams :: TextDocumentIdentifier
$sel:_position:TextDocumentPositionParams :: Position
..}
  , SMethod 'TextDocumentReferences
-> (IdeState
    -> MessageParams 'TextDocumentReferences
    -> LspM
         c (Either ResponseError (ResponseResult 'TextDocumentReferences)))
-> Handlers (ServerM c)
forall (m :: Method 'FromClient 'Request) c.
HasTracing (MessageParams m) =>
SMethod m
-> (IdeState
    -> MessageParams m
    -> LspM c (Either ResponseError (ResponseResult m)))
-> Handlers (ServerM c)
requestHandler SMethod 'TextDocumentReferences
STextDocumentReferences IdeState
-> MessageParams 'TextDocumentReferences
-> LspM
     c (Either ResponseError (ResponseResult 'TextDocumentReferences))
forall c.
IdeState
-> ReferenceParams -> LspM c (Either ResponseError (List Location))
references
  , SMethod 'WorkspaceSymbol
-> (IdeState
    -> MessageParams 'WorkspaceSymbol
    -> LspM c (Either ResponseError (ResponseResult 'WorkspaceSymbol)))
-> Handlers (ServerM c)
forall (m :: Method 'FromClient 'Request) c.
HasTracing (MessageParams m) =>
SMethod m
-> (IdeState
    -> MessageParams m
    -> LspM c (Either ResponseError (ResponseResult m)))
-> Handlers (ServerM c)
requestHandler SMethod 'WorkspaceSymbol
SWorkspaceSymbol IdeState
-> MessageParams 'WorkspaceSymbol
-> LspM c (Either ResponseError (ResponseResult 'WorkspaceSymbol))
forall c.
IdeState
-> WorkspaceSymbolParams
-> LspM c (Either ResponseError (List SymbolInformation))
wsSymbols
  ]

-- | Respond to and log a hover or go-to-definition request
request
  :: T.Text
  -> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
  -> b
  -> (a -> b)
  -> IdeState
  -> TextDocumentPositionParams
  -> LSP.LspM c (Either ResponseError b)
request :: Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
-> b
-> (a -> b)
-> IdeState
-> TextDocumentPositionParams
-> LspM c (Either ResponseError b)
request Text
label NormalizedFilePath -> Position -> IdeAction (Maybe a)
getResults b
notFound a -> b
found IdeState
ide (TextDocumentPositionParams (TextDocumentIdentifier Uri
uri) Position
pos) = IO (Either ResponseError b) -> LspM c (Either ResponseError b)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either ResponseError b) -> LspM c (Either ResponseError b))
-> IO (Either ResponseError b) -> LspM c (Either ResponseError b)
forall a b. (a -> b) -> a -> b
$ do
    Maybe a
mbResult <- case Uri -> Maybe FilePath
uriToFilePath' Uri
uri of
        Just FilePath
path -> Text
-> (NormalizedFilePath -> Position -> IdeAction (Maybe a))
-> IdeState
-> Position
-> FilePath
-> IO (Maybe a)
forall b.
Text
-> (NormalizedFilePath -> Position -> IdeAction b)
-> IdeState
-> Position
-> FilePath
-> IO b
logAndRunRequest Text
label NormalizedFilePath -> Position -> IdeAction (Maybe a)
getResults IdeState
ide Position
pos FilePath
path
        Maybe FilePath
Nothing   -> Maybe a -> IO (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
    pure $ b -> Either ResponseError b
forall a b. b -> Either a b
Right (b -> Either ResponseError b) -> b -> Either ResponseError b
forall a b. (a -> b) -> a -> b
$ b -> (a -> b) -> Maybe a -> b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
notFound a -> b
found Maybe a
mbResult

logAndRunRequest :: T.Text -> (NormalizedFilePath -> Position -> IdeAction b) -> IdeState -> Position -> String -> IO b
logAndRunRequest :: Text
-> (NormalizedFilePath -> Position -> IdeAction b)
-> IdeState
-> Position
-> FilePath
-> IO b
logAndRunRequest Text
label NormalizedFilePath -> Position -> IdeAction b
getResults IdeState
ide Position
pos FilePath
path = do
  let filePath :: NormalizedFilePath
filePath = FilePath -> NormalizedFilePath
toNormalizedFilePath' FilePath
path
  Logger -> Text -> IO ()
logDebug (IdeState -> Logger
ideLogger IdeState
ide) (Text -> IO ()) -> Text -> IO ()
forall a b. (a -> b) -> a -> b
$
    Text
label Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" request at position " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack (Position -> FilePath
showPosition Position
pos) Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>
    Text
" in file: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> FilePath -> Text
T.pack FilePath
path
  FilePath -> ShakeExtras -> IdeAction b -> IO b
forall a. FilePath -> ShakeExtras -> IdeAction a -> IO a
runIdeAction (Text -> FilePath
T.unpack Text
label) (IdeState -> ShakeExtras
shakeExtras IdeState
ide) (NormalizedFilePath -> Position -> IdeAction b
getResults NormalizedFilePath
filePath Position
pos)