Skip to content

Commit daf4736

Browse files
authored
Debugger: provide breakpoint ranges for short lambdas (#19067)
* Debugger: provide breakpoint ranges for short lambdas
1 parent 3c30609 commit daf4736

File tree

6 files changed

+71
-2
lines changed

6 files changed

+71
-2
lines changed

docs/release-notes/.FSharp.Compiler.Service/11.0.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
### Added
1515

1616
* Add FSharpCodeCompletionOptions ([PR #19030](https://github.com/dotnet/fsharp/pull/19030))
17+
* Debugger: provide breakpoint ranges for short lambdas ([#19067](https://github.com/dotnet/fsharp/pull/19067))
1718

1819
### Changed
1920

src/Compiler/Service/FSharpParseFileResults.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
525525
match expr with
526526
| SynExpr.ArbitraryAfterError _
527527
| SynExpr.LongIdent _
528-
| SynExpr.DotLambda _
529528
| SynExpr.LibraryOnlyILAssembly _
530529
| SynExpr.LibraryOnlyStaticOptimization _
531530
| SynExpr.Null _
@@ -762,6 +761,8 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
762761
yield! walkExpr false e2
763762
yield! walkExpr false e3
764763

764+
| SynExpr.DotLambda(_, m, _) -> yield! checkRange m
765+
765766
]
766767

767768
// Process a class declaration or F# type declaration
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
module FSharp.Compiler.Service.Tests.BreakpointLocationTests
2+
3+
open FSharp.Compiler.Text
4+
open FSharp.Compiler.Text.Range
5+
open FSharp.Test.Assert
6+
open Xunit
7+
8+
let assertBreakpointRange ((startLine, startCol), (endLine, endCol)) markedSource =
9+
let context, parseResults = Checker.getParseResultsWithContext markedSource
10+
let breakpointRange = parseResults.ValidateBreakpointLocation(context.CaretPos).Value
11+
12+
let startPos = Position.mkPos startLine startCol
13+
let endPod = Position.mkPos endLine endCol
14+
let expectedRange = mkFileIndexRange breakpointRange.FileIndex startPos endPod
15+
16+
breakpointRange |> shouldEqual expectedRange
17+
18+
[<Fact>]
19+
let ``Let - Function - Body 01`` () =
20+
assertBreakpointRange ((3, 4), (3, 5)) """
21+
let f () =
22+
1{caret}
23+
"""
24+
25+
[<Fact>]
26+
let ``Seq 01`` () =
27+
assertBreakpointRange ((3, 4), (3, 5)) """
28+
do
29+
1{caret}
30+
2
31+
"""
32+
33+
[<Fact>]
34+
let ``Seq 02`` () =
35+
assertBreakpointRange ((4, 4), (4, 5)) """
36+
do
37+
1
38+
2{caret}
39+
"""
40+
41+
[<Fact>]
42+
let ``Lambda 01`` () =
43+
assertBreakpointRange ((2, 27), (2, 35)) """
44+
[""] |> List.map (fun s -> s.Lenght{caret})
45+
"""
46+
47+
[<Fact>]
48+
let ``Dot lambda 01`` () =
49+
assertBreakpointRange ((2, 17), (2, 25)) """
50+
[""] |> List.map _.Lenght{caret}
51+
"""
52+
53+
[<Fact>]
54+
let ``Dot lambda 02`` () =
55+
assertBreakpointRange ((2, 17), (2, 36)) """
56+
[""] |> List.map _.ToString().Length{caret}
57+
"""

tests/FSharp.Compiler.Service.Tests/Checker.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ module Checker =
147147
let names = plid.QualifyingIdents @ [plid.PartialIdent]
148148
{ SourceContext = context; Pos = context.CaretPos; PartialIdentifier = plid }
149149

150+
let getParseResultsWithContext (markedSource: string) =
151+
let context = SourceContext.fromMarkedSource markedSource
152+
let parseResults = getParseFileResults "Test.fsx" context.Source
153+
context, parseResults
154+
150155
let getCheckedResolveContext (markedSource: string) =
151156
let context = getResolveContext markedSource
152157
let _, checkResults = getParseAndCheckResults context.Source

tests/FSharp.Compiler.Service.Tests/Common.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ let parseAndCheckScript50 (file, input) = parseAndCheckScriptWithOptions (file,
188188
let parseAndCheckScript70 (file, input) = parseAndCheckScriptWithOptions (file, input, [| "--langversion:7.0" |])
189189
let parseAndCheckScriptPreview (file, input) = parseAndCheckScriptWithOptions (file, input, [| "--langversion:preview" |])
190190

191-
let parseSourceCode (name: string, code: string) =
191+
let getParseFileResults (name: string) (code: string) =
192192
let location = Path.Combine(Path.GetTempPath(),"test"+string(hash (name, code)))
193193
try Directory.CreateDirectory(location) |> ignore with _ -> ()
194194
let filePath = Path.Combine(location, name)
@@ -197,6 +197,10 @@ let parseSourceCode (name: string, code: string) =
197197
let options, _errors = checker.GetParsingOptionsFromCommandLineArgs(List.ofArray args)
198198
let parseResults = checker.ParseFile(filePath, SourceText.ofString code, options) |> Async.RunImmediate
199199
Range.setTestSource filePath code
200+
parseResults
201+
202+
let parseSourceCode (name: string, code: string) : ParsedInput =
203+
let parseResults = getParseFileResults name code
200204
parseResults.ParseTree
201205

202206
let matchBraces (name: string, code: string) =

tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<Compile Include="Checker.fs" />
2929
<Compile Include="TypeChecker\TypeCheckerRecoveryTests.fs" />
3030
<Compile Include="GeneratedCodeSymbolsTests.fs" />
31+
<Compile Include="BreakpointLocationTests.fs" />
3132
<Compile Include="AssemblyReaderShim.fs" />
3233
<Compile Include="ModuleReaderCancellationTests.fs" />
3334
<Compile Include="EditorTests.fs" />

0 commit comments

Comments
 (0)