Skip to content

Commit

Permalink
Update logic and models to use Ionide.LanguageServerProtocol types ge…
Browse files Browse the repository at this point in the history
…nerated from LSP metamodel (#1301)

Co-authored-by: Jimmy Byrd <[email protected]>
  • Loading branch information
baronfel and TheAngryByrd authored Jun 14, 2024
1 parent edca0ec commit e0bbe10
Show file tree
Hide file tree
Showing 60 changed files with 2,916 additions and 2,590 deletions.
14 changes: 7 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"args": [
"--debug",
"--filter",
"FSAC.lsp.${input:loader}.${input:lsp-server}.${input:testName}"
"FSAC.lsp.${input:loader}.${input:compiler}.${input:testName}"
]
},
{
Expand Down Expand Up @@ -103,13 +103,13 @@
"type": "pickString"
},
{
"id": "lsp-server",
"description": "The lsp serrver",
"id": "compiler",
"description": "The compiler to use",
"options": [
"FSharpLspServer",
"AdaptiveLspServer"
"BackgroundCompiler",
"TransparentCompiler"
],
"default": "AdaptiveLspServer",
"default": "BackgroundCompiler",
"type": "pickString",
},
{
Expand All @@ -118,4 +118,4 @@
"type": "promptString"
}
]
}
}
63 changes: 46 additions & 17 deletions benchmarks/SourceTextBenchmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Benchmarks
open System
open FSharp.Data.Adaptive
open Microsoft.CodeAnalysis.Text

type FileVersion = int


Expand All @@ -11,46 +12,74 @@ module Helpers =
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 fileContents =
IO.File.ReadAllText(
@"C:\Users\jimmy\Repositories\public\TheAngryByrd\span-playground\Romeo and Juliet by William Shakespeare.txt"
)



let initRoslynSourceText () = SourceText.From(fileContents)

let initRoslynSourceText () =
SourceText.From(fileContents)

let convertToTextSpan (sourceText: SourceText, range: Ionide.LanguageServerProtocol.Types.Range) =
let start =
uint32 sourceText.Lines.[int (max 0u range.Start.Line)].Start
+ range.Start.Character

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)
uint32 sourceText.Lines.[int32 (min range.End.Line (uint32 (sourceText.Lines.Count - 1)))].Start
+ range.End.Character

let addToSourceText (sourceText : SourceText, range : Ionide.LanguageServerProtocol.Types.Range, text : string) =
let textSpan = convertToTextSpan(sourceText, range)
TextSpan(int start, int endPosition - int 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 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

open BenchmarkDotNet
open BenchmarkDotNet.Attributes
open Helpers
open BenchmarkDotNet.Jobs

[<MemoryDiagnoser>]
[<SimpleJob(RuntimeMoniker.Net70)>]
type SourceText_LineChanges_Benchmarks ()=
type SourceText_LineChanges_Benchmarks() =

[<Params(1, 15, 50, 100, 1000)>]
member val public N = 0 with get, set

[<Benchmark>]
member this.Roslyn_Text_changeText_everyUpdate () =
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 <-
addToSourceText (
file,
{ Start = { Line = 0u; Character = 5u }
End = { Line = 0u; Character = 5u } },
"World"
)

for i in 1 .. this.N do
file <-
addToSourceText (
file,
{ Start = { Line = 0u; Character = 10u }
End = { Line = 0u; Character = 10u } },
"\nLOL"
)

file.Lines |> Seq.toArray |> ignore
9 changes: 9 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<!-- <add key="local" value="./libs" /> -->
</packageSources>
</configuration>
4 changes: 2 additions & 2 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ framework: netstandard2.0, netstandard2.1, net6.0, net7.0, net8.0
source https://api.nuget.org/v3/index.json
# this is the FCS nightly feed, re-enable at your own risk!
# source: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json
#source: ./libs
# source: ./libs
storage: none
strategy: min
lowest_matching: true
Expand Down Expand Up @@ -52,7 +52,7 @@ nuget Expecto.Diff
nuget YoloDev.Expecto.TestSdk
nuget AltCover
nuget GitHubActionsTestLogger
nuget Ionide.LanguageServerProtocol >= 0.4.23
nuget Ionide.LanguageServerProtocol 0.6.0
nuget Microsoft.Extensions.Caching.Memory
nuget OpenTelemetry.Api >= 1.3.2
nuget OpenTelemetry.Exporter.OpenTelemetryProtocol >= 1.3.2 # 1.4 bumps to 7.0 versions of System.Diagnostics libs, so can't use it
Expand Down
2 changes: 1 addition & 1 deletion paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ NUGET
System.Reflection.Metadata (>= 5.0)
Ionide.Analyzers (0.11)
Ionide.KeepAChangelog.Tasks (0.1.8) - copy_local: true
Ionide.LanguageServerProtocol (0.4.23)
Ionide.LanguageServerProtocol (0.6.0)
FSharp.Core (>= 6.0)
Newtonsoft.Json (>= 13.0.1)
StreamJsonRpc (>= 2.16.36)
Expand Down
9 changes: 8 additions & 1 deletion src/FsAutoComplete.Core/AbstractClassStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ let writeAbstractClassStub
let getMemberByLocation (_: string, range: Range, _: Range) =
match doc.GetLine range.Start with
| Some lineText ->
match Lexer.getSymbol range.Start.Line range.Start.Column lineText SymbolLookupKind.ByLongIdent [||] with
match
Lexer.getSymbol
(uint32 range.Start.Line)
(uint32 range.Start.Column)
lineText
SymbolLookupKind.ByLongIdent
[||]
with
| Some sym ->
checkResultForFile.GetCheckResults.GetSymbolUseAtLocation(
range.StartLine,
Expand Down
5 changes: 3 additions & 2 deletions src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ module Commands =

let getNamespaceSuggestions (tyRes: ParseAndCheckResults) (pos: Position) (line: LineStr) =
async {
match Lexer.findLongIdents (pos.Column, line) with
match Lexer.findLongIdents (uint32 pos.Column, line) with
| None -> return CoreResponse.InfoRes "Ident not found"
| Some(_, idents) ->
match ParsedInput.GetEntityKind(pos, tyRes.GetParseResults.ParseTree) with
| None -> return CoreResponse.InfoRes "EntityKind not found"
| Some entityKind ->

let symbol = Lexer.getSymbol pos.Line pos.Column line SymbolLookupKind.Fuzzy [||]
let symbol =
Lexer.getSymbol (uint32 pos.Line) (uint32 pos.Column) line SymbolLookupKind.Fuzzy [||]

match symbol with
| None -> return CoreResponse.InfoRes "Symbol at position not found"
Expand Down
8 changes: 4 additions & 4 deletions src/FsAutoComplete.Core/FileSystem.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ type IFSACSourceText =
/// Provides safe access to a line of the file via FCS-provided Position
abstract member GetLine: position: Position -> option<string>
/// Provide safe access to the length of a line of the file via FCS-provided Position
abstract member GetLineLength: position: Position -> option<int>
abstract member GetLineLength: position: Position -> option<uint32>
abstract member GetCharUnsafe: position: Position -> char
/// <summary>Provides safe access to a character of the file via FCS-provided Position.
/// Also available in indexer form: <code lang="fsharp">x[pos]</code></summary>
Expand Down Expand Up @@ -262,11 +262,11 @@ module RoslynSourceText =
else
Some((x :> ISourceText).GetLineString(pos.Line - 1))

member x.GetLineLength(pos: Position) : int option =
member x.GetLineLength(pos: Position) : uint32 option =
if pos.Line > totalLinesLength () then
None
else
Some((x :> ISourceText).GetLineString(pos.Line - 1).Length)
Some(uint32 ((x :> ISourceText).GetLineString(pos.Line - 1).Length))

member x.GetCharUnsafe(pos: Position) : char = (x :> IFSACSourceText).GetLine(pos).Value[pos.Column - 1]

Expand Down Expand Up @@ -331,7 +331,7 @@ module RoslynSourceText =
let! np = (x :> IFSACSourceText).PrevPos pos
let! prevLineLength = (x :> IFSACSourceText).GetLineLength(np)

if np.Column < 1 || prevLineLength < np.Column then
if np.Column < 1 || prevLineLength < uint32 np.Column then
return! (x :> IFSACSourceText).TryGetPrevChar(np)
else
return np, (x :> IFSACSourceText).GetCharUnsafe np
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/FileSystem.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type IFSACSourceText =
/// Provides safe access to a line of the file via FCS-provided Position
abstract member GetLine: position: Position -> option<string>
/// Provide safe access to the length of a line of the file via FCS-provided Position
abstract member GetLineLength: position: Position -> option<int>
abstract member GetLineLength: position: Position -> option<uint32>
abstract member GetCharUnsafe: position: Position -> char
/// <summary>Provides safe access to a character of the file via FCS-provided Position.
/// Also available in indexer form: <code lang="fsharp">x[pos]</code></summary>
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/KeywordList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module KeywordList =
InsertText = Some kv.Key
FilterText = Some kv.Key
SortText = Some kv.Key
Documentation = Some(Documentation.String kv.Value)
Documentation = Some(U2.C1 kv.Value)
Label = label })
|> Seq.toArray

Expand Down
Loading

0 comments on commit e0bbe10

Please sign in to comment.