Skip to content

Commit c95d6e4

Browse files
committed
Call extractInfoFromSmallestContainingFunctionApplicationAst once
This improves performance. It also improves correctness because functionName, functionType and argumentNumber are extracted from the same AST.
1 parent bf0b4d5 commit c95d6e4

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

plugins/hls-signature-help-plugin/src/Ide/Plugin/SignatureHelp.hs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,31 +74,26 @@ descriptor _recorder pluginId =
7474
signatureHelpProvider :: PluginMethodHandler IdeState Method_TextDocumentSignatureHelp
7575
signatureHelpProvider ideState _pluginId (SignatureHelpParams (TextDocumentIdentifier uri) position _mProgreeToken _mContext) = do
7676
nfp <- getNormalizedFilePathE uri
77-
mResult <- runIdeActionE "signatureHelp" (shakeExtras ideState) $ do
77+
results <- runIdeActionE "signatureHelp" (shakeExtras ideState) $ do
7878
-- TODO(@linj) why HAR {hieAst} may have more than one AST?
7979
(HAR {hieAst, hieKind}, positionMapping) <- useWithStaleFastE GetHieAst nfp
8080
case fromCurrentPosition positionMapping position of
81-
Nothing -> pure Nothing
81+
Nothing -> pure []
8282
Just oldPosition -> do
83-
let functionName =
84-
extractInfoFromSmallestContainingFunctionApplicationAst
85-
oldPosition
86-
hieAst
87-
(\span -> getLeftMostNode >>> getNodeName span)
88-
functionType =
89-
extractInfoFromSmallestContainingFunctionApplicationAst
90-
oldPosition
91-
hieAst
92-
(\span -> getLeftMostNode >>> getNodeType hieKind span)
93-
argumentNumber =
94-
extractInfoFromSmallestContainingFunctionApplicationAst
95-
oldPosition
96-
hieAst
97-
getArgumentNumber
98-
pure $ Just (functionName, functionType, argumentNumber)
99-
case mResult of
100-
-- TODO(@linj) what do non-singleton lists mean?
101-
Just (functionName : _, functionType : _, argumentNumber : _) -> do
83+
pure $
84+
extractInfoFromSmallestContainingFunctionApplicationAst
85+
oldPosition
86+
hieAst
87+
( \span hieAst -> do
88+
let functionNode = getLeftMostNode hieAst
89+
functionName <- getNodeName span functionNode
90+
functionType <- getNodeType hieKind span functionNode
91+
argumentNumber <- getArgumentNumber span hieAst
92+
Just (functionName, functionType, argumentNumber)
93+
)
94+
case results of
95+
-- TODO(@linj) what does non-singleton list mean?
96+
[(functionName, functionType, argumentNumber)] ->
10297
pure $ InL $ mkSignatureHelp functionName functionType (fromIntegral argumentNumber - 1)
10398
_ -> pure $ InR Null
10499

0 commit comments

Comments
 (0)