Skip to content

Commit 2b7517d

Browse files
authored
Always prefer function sig help on space if applicable (#11200)
1 parent a4dfef1 commit 2b7517d

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/fsharp/service/FSharpParseFileResults.fs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
158158
SyntaxTraversal.Traverse(pos, input, { new SyntaxVisitorBase<_>() with
159159
member _.VisitExpr(_, traverseSynExpr, defaultTraverse, expr) =
160160
match expr with
161+
| SynExpr.TypeApp (_, _, _, _, _, _, range) when rangeContainsPos range pos ->
162+
Some range
161163
| SynExpr.App(_, _, _, SynExpr.CompExpr (_, _, expr, _), range) when rangeContainsPos range pos ->
162164
traverseSynExpr expr
163165
| SynExpr.App (_, _, _, _, range) when rangeContainsPos range pos ->
@@ -176,6 +178,9 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
176178
| SynExpr.Paren (expr, _, _, range) when rangeContainsPos range pos ->
177179
getIdentRangeForFuncExprInApp traverseSynExpr expr pos
178180

181+
| SynExpr.TypeApp (expr, _, _, _, _, _, _) ->
182+
getIdentRangeForFuncExprInApp traverseSynExpr expr pos
183+
179184
| SynExpr.App (_, _, funcExpr, argExpr, _) ->
180185
match argExpr with
181186
| SynExpr.App (_, _, _, _, range) when rangeContainsPos range pos ->
@@ -269,6 +274,8 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
269274
SyntaxTraversal.Traverse(pos, input, { new SyntaxVisitorBase<_>() with
270275
member _.VisitExpr(_, traverseSynExpr, defaultTraverse, expr) =
271276
match expr with
277+
| SynExpr.TypeApp (expr, _, _, _, _, _, range) when rangeContainsPos range pos ->
278+
getIdentRangeForFuncExprInApp traverseSynExpr expr pos
272279
| SynExpr.App (_, _, _funcExpr, _, range) as app when rangeContainsPos range pos ->
273280
getIdentRangeForFuncExprInApp traverseSynExpr app pos
274281
| _ -> defaultTraverse expr

tests/service/ServiceUntypedParseTests.fs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ async {
683683
Assert.False(parseFileResults.IsPosContainedInApplication (mkPos 2 5), "Pos should not be in application")
684684

685685
[<Test>]
686-
let ``TryRangeOfFunctionOrMethodBeingApplied - inside CE return - no``() =
686+
let ``IsPosContainedInApplication - inside CE return - no``() =
687687
let source = """
688688
async {
689689
return sqrt
@@ -693,7 +693,7 @@ async {
693693
Assert.False(parseFileResults.IsPosContainedInApplication (mkPos 2 5), "Pos should not be in application")
694694

695695
[<Test>]
696-
let ``TryRangeOfFunctionOrMethodBeingApplied - inside CE - yes``() =
696+
let ``IsPosContainedInApplication - inside CE - yes``() =
697697
let source = """
698698
let myAdd x y = x + y
699699
async {
@@ -703,6 +703,15 @@ async {
703703
let parseFileResults, _ = getParseAndCheckResults source
704704
Assert.False(parseFileResults.IsPosContainedInApplication (mkPos 3 18), "Pos should not be in application")
705705

706+
[<Test>]
707+
let ``IsPosContainedInApplication - inside type application``() =
708+
let source = """
709+
let f<'x> x = ()
710+
f<int>
711+
"""
712+
let parseFileResults, _ = getParseAndCheckResults source
713+
Assert.True(parseFileResults.IsPosContainedInApplication (mkPos 3 6), "A type application is an application, expected True.")
714+
706715
[<Test>]
707716
let ``TryRangeOfFunctionOrMethodBeingApplied - no application``() =
708717
let source = """
@@ -982,6 +991,21 @@ C.Yeet(1, 2, (fun x -> sqrt))
982991
|> tups
983992
|> shouldEqual ((3, 23), (3, 27))
984993

994+
[<Test>]
995+
let ``TryRangeOfFunctionOrMethodBeingApplied - generic-typed app``() =
996+
let source = """
997+
let f<'x> x = ()
998+
f<int>
999+
"""
1000+
let parseFileResults, _ = getParseAndCheckResults source
1001+
let res = parseFileResults.TryRangeOfFunctionOrMethodBeingApplied (mkPos 3 6)
1002+
match res with
1003+
| None -> Assert.Fail("Expected 'f' but got nothing")
1004+
| Some range ->
1005+
range
1006+
|> tups
1007+
|> shouldEqual ((3, 0), (3, 1))
1008+
9851009
module PipelinesAndArgs =
9861010
[<Test>]
9871011
let ``TryIdentOfPipelineContainingPosAndNumArgsApplied - No pipeline, no infix app``() =

vsintegration/src/FSharp.Editor/Completion/SignatureHelp.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ type internal FSharpSignatureHelpProvider
476476
// Generally ' ' indicates a function application, but it's also used commonly after a comma in a method call.
477477
// This means that the adjusted position relative to the caret could be a ',' or a '(' or '<',
478478
// which would mean we're already inside of a method call - not a function argument. So we bail if that's the case.
479-
| Some ' ', None when adjustedColumnChar <> ',' && adjustedColumnChar <> '(' && adjustedColumnChar <> '<' ->
479+
| Some ' ', _ when adjustedColumnChar <> ',' && adjustedColumnChar <> '(' && adjustedColumnChar <> '<' ->
480480
return!
481481
FSharpSignatureHelpProvider.ProvideParametersAsyncAux(
482482
parseResults,

0 commit comments

Comments
 (0)