-
-
Notifications
You must be signed in to change notification settings - Fork 407
Implement signature help #4626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement signature help #4626
Changes from 1 commit
7a54a1d
9168b74
4d7fa57
622c8ec
62fbccf
a6635ca
bf0b4d5
c95d6e4
3dc1ec8
dca1311
471958f
d603ec4
faa4e48
9bea0e3
db5e59e
fdd5acd
c6ece42
fe2d618
c3224d7
081ea8f
a522e88
d826d06
62f2e41
35399e7
c0f7844
eeeb283
f1d19ba
433a8ad
d3d7d12
e0a7e8b
e6702b7
3d7a67b
800f908
cb84480
c7931a2
b6d4617
9a1de4e
5925c1c
9c97238
195db18
f5a9858
9c87ef4
8d6b1bb
757d4a5
b5c13a3
d0200a4
01ff52a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
jian-lin marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: different hightlighting strategies for "reading code" and "writing code". By "writing code", I mean the cursor is at the end of the function application and we intend to write more args to that function application. Other cases are "reading code". Currently, the highlight strategy for "reading code" works well. For example, Currently, the highlight strategy for "writing code" is problematic. Case 1: only the function itself is written Case 2: the function itself and at least 1 arg have been written There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sounds to me like your two strategies are the same? In both cases the strategy is "highlight the next argument after the cursor position (which may not exist)"? Presumably in this situation we will highlight the second argument, though:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
|
||
module Ide.Plugin.SignatureHelp (descriptor) where | ||
|
||
import Control.Monad.Trans (lift) | ||
import qualified Data.List.NonEmpty as NL | ||
import qualified Data.Text as T | ||
import Development.IDE | ||
import Development.IDE.Core.PluginUtils (runIdeActionE, | ||
useWithStaleFastE) | ||
import Development.IDE.Spans.AtPoint (getNamesAtPoint) | ||
import Ide.Plugin.Error | ||
import Ide.Types | ||
import Language.LSP.Protocol.Message | ||
import Language.LSP.Protocol.Types | ||
import Text.Regex.TDFA ((=~)) | ||
|
||
data Log = LogDummy | ||
|
||
instance Pretty Log where | ||
pretty = \case | ||
LogDummy -> "TODO(@linj) remove this dummy log" | ||
|
||
descriptor :: Recorder (WithPriority Log) -> PluginId -> PluginDescriptor IdeState | ||
descriptor _recorder pluginId = | ||
(defaultPluginDescriptor pluginId "Provides signature help of something callable") | ||
{ pluginHandlers = mkPluginHandler SMethod_TextDocumentSignatureHelp signatureHelpProvider | ||
} | ||
|
||
-- get src info | ||
-- function | ||
-- which arg is under the cursor | ||
-- get function type (and arg doc) | ||
-- assemble result | ||
-- TODO(@linj) | ||
signatureHelpProvider :: PluginMethodHandler IdeState Method_TextDocumentSignatureHelp | ||
signatureHelpProvider ideState _pluginId (SignatureHelpParams (TextDocumentIdentifier uri) position _mProgreeToken _mContext) = do | ||
nfp <- getNormalizedFilePathE uri | ||
names <- runIdeActionE "signatureHelp" (shakeExtras ideState) $ do | ||
(HAR {hieAst}, positionMapping) <- useWithStaleFastE GetHieAst nfp | ||
let ns = getNamesAtPoint hieAst position positionMapping | ||
pure ns | ||
mRangeAndDoc <- | ||
runIdeActionE | ||
"signatureHelp.getDoc" | ||
(shakeExtras ideState) | ||
(lift (getAtPoint nfp position)) | ||
let (_mRange, contents) = case mRangeAndDoc of | ||
Just (mRange, contents) -> (mRange, contents) | ||
Nothing -> (Nothing, []) | ||
|
||
pure $ | ||
InL $ | ||
SignatureHelp | ||
( case mkSignatureHelpLabel names contents of | ||
Just label -> | ||
[ SignatureInformation | ||
label | ||
Nothing | ||
(Just [ParameterInformation (InR (5, 8)) Nothing]) | ||
Nothing | ||
] | ||
Nothing -> [] | ||
) | ||
(Just 0) | ||
(Just $ InL 0) | ||
where | ||
mkSignatureHelpLabel names types = | ||
case (chooseName $ printName <$> names, chooseType types >>= showType) of | ||
(Just name, Just typ) -> Just $ T.pack name <> " :: " <> typ | ||
_ -> Nothing | ||
chooseName names = case names of | ||
[] -> Nothing | ||
name : names' -> Just $ NL.last (name NL.:| names') | ||
chooseType types = case types of | ||
[] -> Nothing | ||
[t] -> Just t | ||
_ -> Just $ types !! (length types - 2) | ||
Check failure on line 79 in plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs
|
||
showType typ = getMatchedType $ typ =~ ("\n```haskell\n(.*) :: (.*)\n```\n" :: T.Text) | ||
getMatchedType :: (T.Text, T.Text, T.Text, [T.Text]) -> Maybe T.Text | ||
getMatchedType (_, _, _, [_, t]) = Just t | ||
getMatchedType _ = Nothing |
Uh oh!
There was an error while loading. Please reload this page.