Skip to content

Commit

Permalink
Remove older impls (#1174)
Browse files Browse the repository at this point in the history
* Remove NamedText implementation

* 🫡  Remove FsAutoComplete.Lsp

* Fix codefix scaffolding

* formatting

* Remove unused State/Commands

* Cleanup RoslynSourceText

* Remove SourceText CLI option
  • Loading branch information
TheAngryByrd authored Oct 12, 2023
1 parent 131d8cb commit 2e2593a
Show file tree
Hide file tree
Showing 25 changed files with 205 additions and 5,202 deletions.
15 changes: 1 addition & 14 deletions benchmarks/SourceTextBenchmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ module Helpers =

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)
Expand All @@ -37,10 +36,6 @@ module Helpers =
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
Expand All @@ -52,14 +47,6 @@ 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 ()
Expand Down
66 changes: 0 additions & 66 deletions build/ScaffoldCodeFix.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ let AdaptiveFSharpLspServerPath =
</> "LspServers"
</> "AdaptiveFSharpLspServer.fs"

let FsAutoCompleteLspPath =
repositoryRoot
</> "src"
</> "FsAutoComplete"
</> "LspServers"
</> "FsAutoComplete.Lsp.fs"

let TestsPath =
repositoryRoot
Expand Down Expand Up @@ -312,64 +306,6 @@ let wireCodeFixInAdaptiveFSharpLspServer codeFixName =
Trace.traceError
$"Unable to find array of codefixes in %s{AdaptiveFSharpLspServerPath}.\nDid the code structure change?"

let findArrayInFsAutoCompleteLsp () =
let oak = getOakFor FsAutoCompleteLspPath
// namespace FsAutoComplete.Lsp
let ns =
oak.ModulesOrNamespaces
|> List.exactlyOneOrFail "Expected a single namespace in Oak."

// type AdaptiveFSharpLspServer
let t = findTypeWithNameOfFail "FSharpLspServer" ns

// interface IFSharpLspServer with
let iFSharpLspServer =
t.Members
|> List.pick (function
| MemberDefn.Interface i -> Some i
| _ -> None)

// override _.Initialize(p: InitializeParams) =
let overrideMember =
iFSharpLspServer.Members
|> List.pick (function
| MemberDefn.Member mb ->
match mb.FunctionName with
| Choice1Of2 iln ->
match iln.Content with
| [ _; _; IdentifierOrDot.Ident ident ] when ident.Text = "Initialize" -> Some mb
| _ -> None
| Choice2Of2 _ -> None
| _ -> None)

let asyncComp =
match overrideMember.Expr with
| Expr.NamedComputation namedComputation -> namedComputation
| e -> failwithf $"Expected Expr.NamedComputation, got %A{e}"

let compBody =
match asyncComp.Body with
| Expr.CompExprBody body -> body
| e -> failwithf $"Expected Expr.CompExprBody, got %A{e}"

compBody.Statements
|> List.pickOrFail "Expected to find ComputationExpressionStatement.OtherStatement" (function
| ComputationExpressionStatement.OtherStatement(Expr.LongIdentSet longIdentSet) ->
match longIdentSet.Identifier with
| IdentName "codefixes" ->
match longIdentSet.Expr with
| Expr.ArrayOrList array -> Some array
| _ -> None
| _ -> None
| _ -> None)

let wireCodeFixInFsAutoCompleteLsp codeFixName =
try
let array = findArrayInFsAutoCompleteLsp ()
appendItemToArrayOrList $"%s{codeFixName}.fix tryGetParseResultsForFile" FsAutoCompleteLspPath array
with ex ->
Trace.traceException ex
Trace.traceError $"Unable to find array of codefixes in %s{FsAutoCompleteLspPath}.\nDid the code structure change?"

let mkCodeFixTests codeFixName =
let path =
Expand Down Expand Up @@ -444,7 +380,6 @@ let scaffold (codeFixName: string) : unit =

// Wire up codefix to LSP servers
wireCodeFixInAdaptiveFSharpLspServer codeFixName
wireCodeFixInFsAutoCompleteLsp codeFixName

// Add test file
mkCodeFixTests codeFixName
Expand All @@ -457,5 +392,4 @@ let scaffold (codeFixName: string) : unit =

let ensureScaffoldStillWorks () =
findArrayInAdaptiveFSharpLspServer () |> ignore
findArrayInFsAutoCompleteLsp () |> ignore
findListInTests () |> ignore
2 changes: 1 addition & 1 deletion build/ScaffoldCodeFix.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ScaffoldCodeFix

/// Scaffold a new CodeFix by:
/// - Generating the implementation and signature files.
/// - Wire up the codefix AdaptiveFSharpLspServer.fs and FsAutoComplete.Lsp.fs.
/// - Wire up the codefix AdaptiveFSharpLspServer.fs
/// - Generate a tests file with a focused test.
/// - Wire up the tests file.
/// - Update the last write time the project files.
Expand Down
3 changes: 1 addition & 2 deletions docs/Creating a new code fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To introduce a new code fix within the context of FSAutocomplete, there are seve

1. **Code Fix File**: This pertains to the actual implementation of the code fix.

2. **Registration in LSP Servers**: Registration of the code fix is required in both of the associated LSP servers.
2. **Registration in LSP Server**: Registration of the code fix is required in the associated LSP server.

3. **Unit Test Setup**: Proper unit tests need to be established to ensure the correctness and effectiveness of the new code fix.

Expand All @@ -28,7 +28,6 @@ The above command accomplishes the following tasks:
Furthermore, this command updates the following files to properly register the new code fix:

- `src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs`
- `src/FsAutoComplete/LspServers/FsAutoComplete.Lsp.fs`
- `test/FsAutoComplete.Tests.Lsp/CodeFixTests/Tests.fs`

The unit test file contains a [single focused test](https://github.com/haf/expecto#focusing-tests), allowing you to promptly verify the functionality. To run this initial test, you have two options:
Expand Down
52 changes: 0 additions & 52 deletions src/FsAutoComplete.Core/CodeGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,6 @@ type ICodeGenerationService =

abstract ParseFileInProject: string<LocalPath> -> Async<option<FSharpParseFileResults>>

type CodeGenerationService(checker: FSharpCompilerServiceChecker, state: State) =
interface ICodeGenerationService with
override x.TokenizeLine(fileName, i) =
asyncOption {
let! text = state.TryGetFileSource fileName |> Option.ofResult

try
let! line = text.GetLine(Position.mkPos i 0)
return Lexer.tokenizeLine [||] line
with _ ->
return! None
}

override x.GetSymbolAtPosition(fileName, pos: Position) =
asyncOption {
return!
match state.TryGetFileCheckerOptionsWithLinesAndLineStr(fileName, pos) with
| ResultOrString.Error _ -> None
| ResultOrString.Ok(opts, lines, line) ->
try
Lexer.getSymbol pos.Line pos.Column line SymbolLookupKind.Fuzzy [||]
with _ ->
None
}

override x.GetSymbolAndUseAtPositionOfKind(fileName, pos: Position, kind) =
asyncOption {
let! symbol = (x :> ICodeGenerationService).GetSymbolAtPosition(fileName, pos)

if symbol.Kind = kind then
match state.TryGetFileCheckerOptionsWithLinesAndLineStr(fileName, pos) with
| ResultOrString.Error _ -> return! None
| ResultOrString.Ok(opts, text, line) ->
let! result = checker.TryGetRecentCheckResultsForFile(fileName, opts, text)
let symbolUse = result.TryGetSymbolUse pos line
return! Some(symbol, symbolUse)
else
return! None
}

override x.ParseFileInProject(fileName) =
async {
match state.TryGetFileCheckerOptionsWithLines fileName with
| ResultOrString.Error _ -> return None
| ResultOrString.Ok(opts, text) ->
try
return
checker.TryGetRecentCheckResultsForFile(fileName, opts, text)
|> Option.map (fun n -> n.GetParseResults)
with _ ->
return None
}

module CodeGenerationUtils =
open FSharp.Compiler.Syntax.PrettyNaming
Expand Down
3 changes: 0 additions & 3 deletions src/FsAutoComplete.Core/CodeGeneration.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ type ICodeGenerationService =

abstract ParseFileInProject: string<LocalPath> -> Async<option<FSharpParseFileResults>>

type CodeGenerationService =
new: checker: FSharpCompilerServiceChecker * state: State -> CodeGenerationService
interface ICodeGenerationService

module CodeGenerationUtils =
open FSharp.Compiler.Syntax.PrettyNaming
Expand Down
Loading

0 comments on commit 2e2593a

Please sign in to comment.