11{-# LANGUAGE QuasiQuotes #-}
22
33import Control.Exception (throw )
4- import Control.Lens ((^.) )
4+ import Control.Lens ((%~) , ( ^.) )
55import Data.Maybe (fromJust )
66import Data.Text (Text )
77import qualified Data.Text as T
@@ -13,6 +13,7 @@ import Test.Hls.FileSystem (VirtualFileTree,
1313 directCradle , file ,
1414 mkVirtualFileTree ,
1515 text )
16+ import Text.Regex.TDFA ((=~) )
1617
1718
1819main :: IO ()
@@ -154,7 +155,7 @@ main =
154155 ^ ^
155156 |]
156157 [ Nothing ,
157- Just $ SignatureHelp [SignatureInformation " pure :: forall (f :: Type -> Type) a. Applicative f => a -> f a" Nothing ( Just [ParameterInformation (InR (55 ,56 )) Nothing ]) (Just (InL 0 )), SignatureInformation " pure :: Bool -> IO Bool" Nothing ( Just [ParameterInformation (InR (8 ,12 )) Nothing ]) (Just (InL 0 )), SignatureInformation " pure :: forall a. a -> IO a" Nothing (Just [ParameterInformation (InR (18 ,19 )) Nothing ]) (Just (InL 0 ))] (Just 0 ) (Just (InL 0 ))
158+ Just $ SignatureHelp [SignatureInformation " pure :: forall (f :: Type -> Type) a. Applicative f => a -> f a" ( Just $ InR $ MarkupContent MarkupKind_Markdown " \n\n Lift a value. \n\n\\ [Documentation \\ ] \\ (file://.* \\ ) \n\n\\ [Source \\ ] \\ (file://.* \\ ) \n\n " ) ( Just [ParameterInformation (InR (55 ,56 )) Nothing ]) (Just (InL 0 )), SignatureInformation " pure :: Bool -> IO Bool" ( Just $ InR $ MarkupContent MarkupKind_Markdown " \n\n Lift a value. \n\n\\ [Documentation \\ ] \\ (file://.* \\ ) \n\n\\ [Source \\ ] \\ (file://.* \\ ) \n\n " ) ( Just [ParameterInformation (InR (8 ,12 )) Nothing ]) (Just (InL 0 )), SignatureInformation " pure :: forall a. a -> IO a" ( Just $ InR $ MarkupContent MarkupKind_Markdown " \n\n Lift a value. \n\n\\ [Documentation \\ ] \\ (file://.* \\ ) \n\n\\ [Source \\ ] \\ (file://.* \\ ) \n\n " ) (Just [ParameterInformation (InR (18 ,19 )) Nothing ]) (Just (InL 0 ))] (Just 0 ) (Just (InL 0 ))
158159 ],
159160 mkTest
160161 " 2 type constraints"
@@ -334,7 +335,28 @@ getSignatureHelpFromSession sourceCode (PosPrefixInfo _ _ _ position) =
334335 virtualFileTree = mkVirtualFileTreeWithSingleFile fileName sourceCode
335336 in runSessionWithServerInTmpDir def plugin virtualFileTree $ do
336337 doc <- openDoc fileName " haskell"
337- getSignatureHelp doc position
338+ (fmap . fmap ) mkReproducibleSignatureHelp (getSignatureHelp doc position)
339+
340+ mkReproducibleSignatureHelp :: SignatureHelp -> SignatureHelp
341+ mkReproducibleSignatureHelp = L. signatures . traverse . L. documentation %~ unifyLocalFilePath
342+ where
343+ unifyLocalFilePath (Just (InR (MarkupContent MarkupKind_Markdown doc))) =
344+ let (prefix, match, suffix) = doc =~ documentationRegex :: (Text , Text , Text )
345+ (prefix', match', suffix') = suffix =~ sourceRegex :: (Text , Text , Text )
346+ reproducibleDoc =
347+ if T. null match
348+ then prefix
349+ else
350+ prefix
351+ <> documentationRegex
352+ <> ( if T. null match'
353+ then prefix'
354+ else prefix' <> sourceRegex <> suffix'
355+ )
356+ in Just $ InR $ MarkupContent MarkupKind_Markdown reproducibleDoc
357+ unifyLocalFilePath mDoc = mDoc
358+ documentationRegex = " \\ [Documentation\\ ]\\ (file://.*\\ )\n\n "
359+ sourceRegex = " \\ [Source\\ ]\\ (file://.*\\ )\n\n "
338360
339361mkVirtualFileTreeWithSingleFile :: FilePath -> Text -> VirtualFileTree
340362mkVirtualFileTreeWithSingleFile fileName sourceCode =
0 commit comments