Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 40d4782

Browse files
cartermpnosami
authored andcommitted
Cherry Pick into 16.9 - Fix triggering the outer application's signature help when triggering an inner application inside a lambda (dotnet#10954) (dotnet#10973)
* Fix issue where sighelp triggered in lambda gave outer signature help * Updates
1 parent 02dabea commit 40d4782

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

src/fsharp/service/ServiceUntypedParse.fs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,18 @@ type FSharpParseFileResults(errors: FSharpDiagnostic[], input: ParsedInput optio
170170
member _.VisitExpr(_, _, defaultTraverse, expr) =
171171
match expr with
172172
| SynExpr.App (_, _, SynExpr.App(_, true, SynExpr.Ident ident, _, _), argExpr, _) when rangeContainsPos argExpr.Range pos ->
173-
if ident.idText = "op_PipeRight" then
174-
Some (ident, 1)
175-
elif ident.idText = "op_PipeRight2" then
176-
Some (ident, 2)
177-
elif ident.idText = "op_PipeRight3" then
178-
Some (ident, 3)
179-
else
173+
match argExpr with
174+
| SynExpr.App(_, _, _, SynExpr.Paren(expr, _, _, _), _) when rangeContainsPos expr.Range pos ->
180175
None
176+
| _ ->
177+
if ident.idText = "op_PipeRight" then
178+
Some (ident, 1)
179+
elif ident.idText = "op_PipeRight2" then
180+
Some (ident, 2)
181+
elif ident.idText = "op_PipeRight3" then
182+
Some (ident, 3)
183+
else
184+
None
181185
| _ -> defaultTraverse expr
182186
})
183187
| None -> None
@@ -216,6 +220,10 @@ type FSharpParseFileResults(errors: FSharpDiagnostic[], input: ParsedInput optio
216220
match argExpr with
217221
| SynExpr.App (_, _, _, _, range) when rangeContainsPos range pos ->
218222
getIdentRangeForFuncExprInApp traverseSynExpr argExpr pos
223+
224+
| SynExpr.Paren(SynExpr.Lambda(_, _, _args, body, _, _), _, _, _) when rangeContainsPos body.Range pos ->
225+
getIdentRangeForFuncExprInApp traverseSynExpr body pos
226+
219227
| _ ->
220228
match funcExpr with
221229
| SynExpr.App (_, true, _, _, _) when rangeContainsPos argExpr.Range pos ->
@@ -227,6 +235,17 @@ type FSharpParseFileResults(errors: FSharpDiagnostic[], input: ParsedInput optio
227235
// Generally, we want to dive into the func expr to get the range
228236
// of the identifier of the function we're after
229237
getIdentRangeForFuncExprInApp traverseSynExpr funcExpr pos
238+
239+
| SynExpr.LetOrUse(_, _, bindings, body, range) when rangeContainsPos range pos ->
240+
let binding =
241+
bindings
242+
|> List.tryFind (fun x -> rangeContainsPos x.RangeOfBindingAndRhs pos)
243+
match binding with
244+
| Some(SynBinding.Binding(_, _, _, _, _, _, _, _, _, expr, _, _)) ->
245+
getIdentRangeForFuncExprInApp traverseSynExpr expr pos
246+
| None ->
247+
getIdentRangeForFuncExprInApp traverseSynExpr body pos
248+
230249
| expr ->
231250
traverseSynExpr expr
232251
|> Option.map (fun expr -> expr)

tests/service/ServiceUntypedParseTests.fs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,26 @@ async {
835835
|> tups
836836
|> shouldEqual ((4, 11), (4, 16))
837837

838+
[<Test>]
839+
let ``TryRangeOfFunctionOrMethodBeingApplied - inside lambda``() =
840+
let source = """
841+
let add n1 n2 = n1 + n2
842+
let lst = [1; 2; 3]
843+
let mapped =
844+
lst |> List.map (fun n ->
845+
let sum = add
846+
n.ToString()
847+
)
848+
"""
849+
let parseFileResults, _ = getParseAndCheckResults source
850+
let res = parseFileResults.TryRangeOfFunctionOrMethodBeingApplied (mkPos 6 21)
851+
match res with
852+
| None -> Assert.Fail("Expected 'add' but got nothing")
853+
| Some range ->
854+
range
855+
|> tups
856+
|> shouldEqual ((6, 18), (6, 21))
857+
838858
module PipelinesAndArgs =
839859
[<Test>]
840860
let ``TryIdentOfPipelineContainingPosAndNumArgsApplied - No pipeline, no infix app``() =
@@ -897,6 +917,21 @@ let square x = x *
897917
| None ->
898918
Assert.Fail("No pipeline found")
899919

920+
[<Test>]
921+
let ``TryIdentOfPipelineContainingPosAndNumArgsApplied - none when inside lambda``() =
922+
let source = """
923+
let add n1 n2 = n1 + n2
924+
let lst = [1; 2; 3]
925+
let mapped =
926+
lst |> List.map (fun n ->
927+
let sum = add 1
928+
n.ToString()
929+
)
930+
"""
931+
let parseFileResults, _ = getParseAndCheckResults source
932+
let res = parseFileResults.TryIdentOfPipelineContainingPosAndNumArgsApplied (mkPos 6 22)
933+
Assert.IsTrue(res.IsNone, "Inside a lambda but counted the pipeline outside of that lambda.")
934+
900935
[<Test>]
901936
let ``TryRangeOfExprInYieldOrReturn - not contained``() =
902937
let source = """

0 commit comments

Comments
 (0)