Skip to content

Commit ac31157

Browse files
xperiandriclaude
andcommitted
Keep getOutliningRanges taking string[] and add a slice entry beside it
Changing the signature made every FSharp.Compiler.Service consumer of the outlining API pay for a caller the editor alone has. The scanner now sits behind two entry points: the public one keeps its string[] parameter and maps to memory, and getOutliningRangesFromLineSlices takes the slices the editor already holds. The public surface is unchanged, so the surface-area baseline and the StructureTests calls return to what they were, and the release note moves out of Breaking Changes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent b937173 commit ac31157

6 files changed

Lines changed: 73 additions & 65 deletions

File tree

‎docs/release-notes/.FSharp.Compiler.Service/11.0.100.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
* Make Entity's adhoc members list lazy ([PR #20286](https://github.com/dotnet/fsharp/pull/20286/changes))
195195
* Constraint solver: `TryD` is now `inline` with `[<InlineIfLambda>]` on its always-run continuation, so the argument closures are no longer allocated at the (very hot) constraint-solver call sites; `IgnoreFailedMemberConstraintResolution` is `inline` so its forwarded continuation stays a literal. ([PR #20367](https://github.com/dotnet/fsharp/pull/20367))
196196
* `DelayedILModuleReader` no longer boxes its cached `ILModuleReader` on every read: the field is typed `ILModuleReader | null` and matched directly. ([PR #20413](https://github.com/dotnet/fsharp/pull/20413))
197+
* `FSharp.Compiler.EditorServices.Structure.getOutliningRanges` scans the source lines without building a trimmed string per comment line, and no longer stores the text of a comment group next to its line numbers. ([PR #20443](https://github.com/dotnet/fsharp/pull/20443))
197198

198199
### Changed
199200
* The `--warnaserror` option now ignores unrecognized diagnostic identifiers in warning lists while still applying recognized F# warning codes. ([PR #20246](https://github.com/dotnet/fsharp/pull/20246))
@@ -219,4 +220,3 @@
219220
* `FSharp.Compiler.Syntax.SynComponentInfo` now holds the type name as `synType: SynType option` instead of the previous `longId: LongIdent` field, so tuple-type extensions such as `type ('T1 * 'T2) with` can be represented. A `member LongIdent` compatibility property returns the long identifier for named types and an empty list for tuple or erroneous type names. AST consumers that pattern-matched on the `longId` field must switch to the `synType` field or the `LongIdent` member. ([PR #19602](https://github.com/dotnet/fsharp/pull/19602))
220221
* Optimizer: don't inline named functions in debug builds ([PR #19548](https://github.com/dotnet/fsharp/pull/19548)
221222
* LexFilter: drop non-strict mode ([PR #20106](https://github.com/dotnet/fsharp/pull/20106))
222-
* `FSharp.Compiler.EditorServices.Structure.getOutliningRanges` now takes the source lines as `ReadOnlyMemory<char>[]` instead of `string[]`, so a caller that already holds the whole text can slice it instead of building a string per line. Callers passing a `string[]` can migrate with `Array.map (fun line -> line.AsMemory())`. ([PR #20443](https://github.com/dotnet/fsharp/pull/20443))

‎src/Compiler/Service/ServiceStructure.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ module Structure =
218218
Lines = ResizeArray [ lineNum ]
219219
}
220220

221-
/// Returns outlining ranges for given parsed input.
222-
let getOutliningRanges (sourceLines: ReadOnlyMemory<char>[]) (parsedInput: ParsedInput) =
221+
let getOutliningRangesFromLineSlices (sourceLines: ReadOnlyMemory<char>[]) (parsedInput: ParsedInput) =
223222
let acc = ResizeArray()
224223

225224
/// Validation function to ensure that ranges yielded for outlining span 2 or more lines
@@ -1109,3 +1108,6 @@ module Structure =
11091108
getCommentRanges file.Trivia.CodeComments sourceLines
11101109

11111110
acc :> seq<_>
1111+
1112+
let getOutliningRanges (sourceLines: string[]) (parsedInput: ParsedInput) =
1113+
getOutliningRangesFromLineSlices (sourceLines |> Array.map _.AsMemory()) parsedInput

‎src/Compiler/Service/ServiceStructure.fsi‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,11 @@ module public Structure =
8080
}
8181

8282
/// Returns outlining ranges for given parsed input.
83-
val getOutliningRanges: sourceLines: ReadOnlyMemory<char>[] -> parsedInput: ParsedInput -> seq<ScopeRange>
83+
val getOutliningRanges: sourceLines: string[] -> parsedInput: ParsedInput -> seq<ScopeRange>
84+
85+
/// <summary>
86+
/// Returns outlining ranges for given parsed input, taking the source lines as slices of text the
87+
/// caller already holds rather than as strings of their own.
88+
/// </summary>
89+
val internal getOutliningRangesFromLineSlices:
90+
sourceLines: ReadOnlyMemory<char>[] -> parsedInput: ParsedInput -> seq<ScopeRange>

‎tests/FSharp.Compiler.Service.Tests/FSharp.Compiler.Service.SurfaceArea.netstandard20.bsl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4744,7 +4744,7 @@ FSharp.Compiler.EditorServices.Structure+ScopeRange: Void .ctor(Scope, Collapse,
47444744
FSharp.Compiler.EditorServices.Structure: FSharp.Compiler.EditorServices.Structure+Collapse
47454745
FSharp.Compiler.EditorServices.Structure: FSharp.Compiler.EditorServices.Structure+Scope
47464746
FSharp.Compiler.EditorServices.Structure: FSharp.Compiler.EditorServices.Structure+ScopeRange
4747-
FSharp.Compiler.EditorServices.Structure: System.Collections.Generic.IEnumerable`1[FSharp.Compiler.EditorServices.Structure+ScopeRange] getOutliningRanges(System.ReadOnlyMemory`1[System.Char][], FSharp.Compiler.Syntax.ParsedInput)
4747+
FSharp.Compiler.EditorServices.Structure: System.Collections.Generic.IEnumerable`1[FSharp.Compiler.EditorServices.Structure+ScopeRange] getOutliningRanges(System.String[], FSharp.Compiler.Syntax.ParsedInput)
47484748
FSharp.Compiler.EditorServices.ToolTipElement+CompositionError: System.String errorText
47494749
FSharp.Compiler.EditorServices.ToolTipElement+CompositionError: System.String get_errorText()
47504750
FSharp.Compiler.EditorServices.ToolTipElement+Group: Microsoft.FSharp.Collections.FSharpList`1[FSharp.Compiler.EditorServices.ToolTipElementData] elements

‎tests/FSharp.Compiler.Service.Tests/StructureTests.fs‎

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module FSharp.Compiler.Service.Tests.StructureTests
22

3-
open System
43
open System.IO
54
open Xunit
65
open FSharp.Compiler.EditorServices.Structure
@@ -36,7 +35,7 @@ let (=>) (source: string) (expectedRanges: (Range * Range) list) =
3635
let ast = parseSourceCode(fileName, source)
3736
try
3837
let actual =
39-
getOutliningRanges (lines |> Array.map _.AsMemory()) ast
38+
getOutliningRanges lines ast
4039
|> Seq.filter (fun sr -> sr.Range.StartLine <> sr.Range.EndLine)
4140
|> Seq.map (fun sr -> getRange sr.Range, getRange sr.CollapseRange)
4241
|> Seq.sort
@@ -152,7 +151,7 @@ module MyModule = // 2
152151
type Color = // 7
153152
{ Red: int
154153
Green: int
155-
Blue: int
154+
Blue: int
156155
}
157156
158157
interface IDisposable with // 13
@@ -164,7 +163,7 @@ module MyModule = // 2
164163
type RecordColor = // 19
165164
{ Red: int
166165
Green: int
167-
Blue: int
166+
Blue: int
168167
}
169168
170169
interface IDisposable with // 25
@@ -190,31 +189,31 @@ module MyModule = // 2
190189
[<Fact>]
191190
let ``open statements``() =
192191
"""
193-
open M
194-
open N
195-
196-
module M =
197-
let x = 1
198-
199-
open M
200-
open N
201-
202-
module M =
203-
open M
204-
205-
let x = 1
206-
207-
module M =
208-
open M
209-
open N
210-
let x = 1
211-
212-
open M
213-
open N
214-
open H
215-
216-
open G
217-
open H
192+
open M
193+
open N
194+
195+
module M =
196+
let x = 1
197+
198+
open M
199+
open N
200+
201+
module M =
202+
open M
203+
204+
let x = 1
205+
206+
module M =
207+
open M
208+
open N
209+
let x = 1
210+
211+
open M
212+
open N
213+
open H
214+
215+
open G
216+
open H
218217
"""
219218
=> [ (2, 0, 3, 6), (2, 0, 3, 6)
220219
(5, 0, 19, 17), (5, 8, 19, 17)
@@ -227,28 +226,28 @@ open H
227226
[<Fact>]
228227
let ``hash directives``() =
229228
"""
230-
#r @"a"
231-
#r "b"
232-
233-
#r "c"
234-
235-
#r "d"
236-
#r "e"
237-
let x = 1
238-
239-
#r "f"
240-
#r "g"
241-
#load "x"
242-
#r "y"
243-
244-
#load "a"
245-
"b"
246-
"c"
247-
248-
#load "a"
249-
"b"
250-
"c"
251-
#r "d"
229+
#r @"a"
230+
#r "b"
231+
232+
#r "c"
233+
234+
#r "d"
235+
#r "e"
236+
let x = 1
237+
238+
#r "f"
239+
#r "g"
240+
#load "x"
241+
#r "y"
242+
243+
#load "a"
244+
"b"
245+
"c"
246+
247+
#load "a"
248+
"b"
249+
"c"
250+
#r "d"
252251
"""
253252
=> [ (2, 3, 8, 6), (2, 3, 8, 6)
254253
(11, 3, 23, 6), (11, 3, 23, 6) ]
@@ -326,7 +325,7 @@ seq { // 2
326325
[<Fact>]
327326
let ``list``() =
328327
"""
329-
let _ =
328+
let _ =
330329
[ 1; 2
331330
3 ]
332331
"""
@@ -383,7 +382,7 @@ finally // 5
383382
let ``if - then - else``() =
384383
"""
385384
if true then
386-
let f x =
385+
let f x =
387386
()
388387
()
389388
else
@@ -449,7 +448,7 @@ for x = 100 downto 10 do
449448
[<Fact>]
450449
let ``for each``() =
451450
"""
452-
for x in 0 .. 100 ->
451+
for x in 0 .. 100 ->
453452
()
454453
()
455454
"""
@@ -468,7 +467,7 @@ let ``tuple``() =
468467
[<Fact>]
469468
let ``do!``() =
470469
"""
471-
do!
470+
do!
472471
printfn "allo"
473472
printfn "allo"
474473
"""
@@ -478,10 +477,10 @@ do!
478477
let ``cexpr yield yield!``() =
479478
"""
480479
cexpr{
481-
yield!
480+
yield!
482481
cexpr{
483-
yield
484-
482+
yield
483+
485484
10
486485
}
487486
}
@@ -660,7 +659,7 @@ let ``Abstract members`` () =
660659
type T() =
661660
abstract Foo:
662661
int
663-
662+
664663
[<Foo>]
665664
abstract Foo:
666665
int

‎vsintegration/src/FSharp.Editor/Structure/BlockStructureService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module internal BlockStructure =
121121
let createBlockSpans isBlockStructureEnabled (sourceText: SourceText) (parsedInput: ParsedInput) =
122122
let linetext = sourceText.GetLinesAsMemory()
123123

124-
Structure.getOutliningRanges linetext parsedInput
124+
Structure.getOutliningRangesFromLineSlices linetext parsedInput
125125
|> Seq.distinctBy (fun x -> x.Range.StartLine)
126126
|> Seq.chooseV (fun scopeRange ->
127127
// the range of text to collapse

0 commit comments

Comments
 (0)