-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roslyn implementation of ISourceText (#1123)
- Loading branch information
1 parent
c784751
commit 87a2e9f
Showing
30 changed files
with
1,083 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,10 +27,10 @@ | |
] | ||
}, | ||
"fantomas": { | ||
"version": "6.0.0", | ||
"version": "6.1.0", | ||
"commands": [ | ||
"fantomas" | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ coverage | |
test/FsAutoComplete.Tests.Lsp/TestResults/ | ||
|
||
.tool-versions | ||
BenchmarkDotNet.Artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Benchmarks | ||
open System | ||
open BenchmarkDotNet | ||
open BenchmarkDotNet.Attributes | ||
open BenchmarkDotNet.Running | ||
open System.Security.Cryptography | ||
|
||
|
||
|
||
|
||
module EntryPoint = | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let summary = BenchmarkRunner.Run<SourceText_LineChanges_Benchmarks>(); | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
namespace Benchmarks | ||
|
||
open System | ||
open FSharp.Data.Adaptive | ||
open Microsoft.CodeAnalysis.Text | ||
type FileVersion = int | ||
|
||
|
||
module Helpers = | ||
open FsAutoComplete.LspHelpers | ||
open FSharp.UMX | ||
open System.Collections.Generic | ||
|
||
let fileContents = IO.File.ReadAllText(@"C:\Users\jimmy\Repositories\public\TheAngryByrd\span-playground\Romeo and Juliet by William Shakespeare.txt") | ||
|
||
let initNamedText () = | ||
FsAutoComplete.NamedText(UMX.tag "lol", fileContents) | ||
|
||
let initRoslynSourceText () = | ||
SourceText.From(fileContents) | ||
|
||
|
||
let convertToTextSpan (sourceText : SourceText, range : Ionide.LanguageServerProtocol.Types.Range) = | ||
let start = sourceText.Lines.[max 0 (range.Start.Line)].Start + range.Start.Character | ||
let endPosition = | ||
sourceText.Lines.[min (range.End.Line) (sourceText.Lines.Count - 1)].Start | ||
+ range.End.Character | ||
TextSpan(start, endPosition - start) | ||
|
||
let addToSourceText (sourceText : SourceText, range : Ionide.LanguageServerProtocol.Types.Range, text : string) = | ||
let textSpan = convertToTextSpan(sourceText, range) | ||
let newText = sourceText.WithChanges([| TextChange(textSpan, text) |]) | ||
newText | ||
|
||
let addToSourceTextMany (sourceText : SourceText, spans : IEnumerable<Ionide.LanguageServerProtocol.Types.Range * string>) = | ||
let textSpans = spans |> Seq.map (fun (range, text) -> TextChange(convertToTextSpan(sourceText, range), text)) |> Seq.toArray | ||
let newText = sourceText.WithChanges(textSpans) | ||
newText | ||
|
||
let addToNamedText (namedText : FsAutoComplete.NamedText, range : Ionide.LanguageServerProtocol.Types.Range, text : string) = | ||
let range = protocolRangeToRange (UMX.untag namedText.FileName) range | ||
match namedText.ModifyText(range, text) with | Ok x -> x | Error e -> failwith e | ||
|
||
open BenchmarkDotNet | ||
open BenchmarkDotNet.Attributes | ||
open Helpers | ||
open BenchmarkDotNet.Jobs | ||
[<MemoryDiagnoser>] | ||
[<SimpleJob(RuntimeMoniker.Net70)>] | ||
type SourceText_LineChanges_Benchmarks ()= | ||
|
||
[<Params(1, 15, 50, 100, 1000)>] | ||
member val public N = 0 with get, set | ||
|
||
[<Benchmark(Baseline = true)>] | ||
member this.Named_Text_changeText_everyUpdate () = | ||
let mutable file = initNamedText () | ||
file <- addToNamedText(file, { Start = { Line = 0; Character = 5 }; End = { Line = 0; Character = 5 } }, "World") | ||
for i in 1..this.N do | ||
file <- addToNamedText(file, { Start = { Line = 0; Character = 10 }; End = { Line = 0; Character = 10 } }, "\nLOL") | ||
file.Lines |> Seq.toArray |> ignore | ||
|
||
[<Benchmark>] | ||
member this.Roslyn_Text_changeText_everyUpdate () = | ||
let mutable file = initRoslynSourceText () | ||
file <- addToSourceText(file, { Start = { Line = 0; Character = 5 }; End = { Line = 0; Character = 5 } }, "World") | ||
for i in 1..this.N do | ||
file <- addToSourceText(file, { Start = { Line = 0; Character = 10 }; End = { Line = 0; Character = 10 } }, "\nLOL") | ||
file.Lines |> Seq.toArray |> ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="SourceTextBenchmarks.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\src\FsAutoComplete\FsAutoComplete.fsproj" /> | ||
</ItemGroup> | ||
<Import Project="..\.paket\Paket.Restore.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FSharp.Core | ||
BenchmarkDotNet | ||
Microsoft.CodeAnalysis | ||
FSharp.Data.Adaptive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.