Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/11.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Added

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

### Changed

Expand Down
3 changes: 2 additions & 1 deletion src/Compiler/Service/FSharpParseFileResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
match expr with
| SynExpr.ArbitraryAfterError _
| SynExpr.LongIdent _
| SynExpr.DotLambda _
| SynExpr.LibraryOnlyILAssembly _
| SynExpr.LibraryOnlyStaticOptimization _
| SynExpr.Null _
Expand Down Expand Up @@ -762,6 +761,8 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
yield! walkExpr false e2
yield! walkExpr false e3

| SynExpr.DotLambda(_, m, _) -> yield! checkRange m

]

// Process a class declaration or F# type declaration
Expand Down
57 changes: 57 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/BreakpointLocationTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module FSharp.Compiler.Service.Tests.BreakpointLocationTests

open FSharp.Compiler.Text
open FSharp.Compiler.Text.Range
open FSharp.Test.Assert
open Xunit

let assertBreakpointRange ((startLine, startCol), (endLine, endCol)) markedSource =
let context, parseResults = Checker.getParseResultsWithContext markedSource
let breakpointRange = parseResults.ValidateBreakpointLocation(context.CaretPos).Value

let startPos = Position.mkPos startLine startCol
let endPod = Position.mkPos endLine endCol
let expectedRange = mkFileIndexRange breakpointRange.FileIndex startPos endPod

breakpointRange |> shouldEqual expectedRange

[<Fact>]
let ``Let - Function - Body 01`` () =
assertBreakpointRange ((3, 4), (3, 5)) """
let f () =
1{caret}
"""

[<Fact>]
let ``Seq 01`` () =
assertBreakpointRange ((3, 4), (3, 5)) """
do
1{caret}
2
"""

[<Fact>]
let ``Seq 02`` () =
assertBreakpointRange ((4, 4), (4, 5)) """
do
1
2{caret}
"""

[<Fact>]
let ``Lambda 01`` () =
assertBreakpointRange ((2, 27), (2, 35)) """
[""] |> List.map (fun s -> s.Lenght{caret})
"""

[<Fact>]
let ``Dot lambda 01`` () =
assertBreakpointRange ((2, 17), (2, 25)) """
[""] |> List.map _.Lenght{caret}
"""

[<Fact>]
let ``Dot lambda 02`` () =
assertBreakpointRange ((2, 17), (2, 36)) """
[""] |> List.map _.ToString().Length{caret}
"""
5 changes: 5 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/Checker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ module Checker =
let names = plid.QualifyingIdents @ [plid.PartialIdent]
{ SourceContext = context; Pos = context.CaretPos; PartialIdentifier = plid }

let getParseResultsWithContext (markedSource: string) =
let context = SourceContext.fromMarkedSource markedSource
let parseResults = getParseFileResults "Test.fsx" context.Source
context, parseResults

let getCheckedResolveContext (markedSource: string) =
let context = getResolveContext markedSource
let _, checkResults = getParseAndCheckResults context.Source
Expand Down
6 changes: 5 additions & 1 deletion tests/FSharp.Compiler.Service.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ let parseAndCheckScript50 (file, input) = parseAndCheckScriptWithOptions (file,
let parseAndCheckScript70 (file, input) = parseAndCheckScriptWithOptions (file, input, [| "--langversion:7.0" |])
let parseAndCheckScriptPreview (file, input) = parseAndCheckScriptWithOptions (file, input, [| "--langversion:preview" |])

let parseSourceCode (name: string, code: string) =
let getParseFileResults (name: string) (code: string) =
let location = Path.Combine(Path.GetTempPath(),"test"+string(hash (name, code)))
try Directory.CreateDirectory(location) |> ignore with _ -> ()
let filePath = Path.Combine(location, name)
Expand All @@ -197,6 +197,10 @@ let parseSourceCode (name: string, code: string) =
let options, _errors = checker.GetParsingOptionsFromCommandLineArgs(List.ofArray args)
let parseResults = checker.ParseFile(filePath, SourceText.ofString code, options) |> Async.RunImmediate
Range.setTestSource filePath code
parseResults

let parseSourceCode (name: string, code: string) : ParsedInput =
let parseResults = getParseFileResults name code
parseResults.ParseTree

let matchBraces (name: string, code: string) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Compile Include="Checker.fs" />
<Compile Include="TypeChecker\TypeCheckerRecoveryTests.fs" />
<Compile Include="GeneratedCodeSymbolsTests.fs" />
<Compile Include="BreakpointLocationTests.fs" />
<Compile Include="AssemblyReaderShim.fs" />
<Compile Include="ModuleReaderCancellationTests.fs" />
<Compile Include="EditorTests.fs" />
Expand Down
Loading