Skip to content

Commit

Permalink
* refactor(FSharpParseFileResults.fs, FSharpParseFileResults.fsi, Ref…
Browse files Browse the repository at this point in the history
…actorTestFramework.fs): remove unused RangeOfReturnTypeDefinition method
  • Loading branch information
SebastianAtWork committed Nov 13, 2023
1 parent 8ea39e3 commit 38a479a
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 109 deletions.
32 changes: 0 additions & 32 deletions src/Compiler/Service/FSharpParseFileResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,35 +1064,3 @@ type FSharpParseFileResults(diagnostics: FSharpDiagnostic[], input: ParsedInput,
member scope.ValidateBreakpointLocation pos =
// This does not need to be run on the background thread
scope.ValidateBreakpointLocationImpl pos

member _.RangeOfReturnTypeDefinition(symbolUseStart: pos, ?skipLambdas) =
let skipLambdas = defaultArg skipLambdas true

SyntaxTraversal.Traverse(
symbolUseStart,
input,
{ new SyntaxVisitorBase<_>() with
member _.VisitExpr(_path, _traverseSynExpr, defaultTraverse, expr) = defaultTraverse expr

override _.VisitBinding(_path, defaultTraverse, binding) =
match binding with
| SynBinding(expr = SynExpr.Lambda _) when skipLambdas -> defaultTraverse binding
| SynBinding(expr = SynExpr.DotLambda _) when skipLambdas -> defaultTraverse binding
////I need the : before the Return Info
//| SynBinding(expr = SynExpr.Typed _) -> defaultTraverse binding

// Dont skip manually type-annotated bindings
| SynBinding(returnInfo = Some (SynBindingReturnInfo (_, r, _, _))) -> Some r

// Let binding
| SynBinding (trivia = { EqualsRange = Some equalsRange }; range = range) when range.Start = symbolUseStart ->
Some equalsRange.StartRange

// Member binding
| SynBinding (headPat = SynPat.LongIdent(longDotId = SynLongIdent(id = _ :: ident :: _))
trivia = { EqualsRange = Some equalsRange }) when ident.idRange.Start = symbolUseStart ->
Some equalsRange.StartRange

| _ -> defaultTraverse binding
}
)
2 changes: 0 additions & 2 deletions src/Compiler/Service/FSharpParseFileResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ type public FSharpParseFileResults =
/// Indicates if any errors occurred during the parse
member ParseHadErrors: bool

member RangeOfReturnTypeDefinition: symbolUseStart: pos * ?skipLambdas: bool -> range option

internal new:
diagnostics: FSharpDiagnostic[] * input: ParsedInput * parseHadErrors: bool * dependencyFiles: string[] ->
FSharpParseFileResults
Original file line number Diff line number Diff line change
Expand Up @@ -13,85 +13,10 @@ open FSharp.Editor.Tests.Helpers
open Microsoft.CodeAnalysis.CodeRefactorings
open Microsoft.CodeAnalysis.CodeActions
open System.Threading
open FSharp.Compiler.Symbols
open FSharp.Compiler.Text
open NUnit.Framework

let GetTaskResult (task: Tasks.Task<'T>) = task.GetAwaiter().GetResult()

let GetSymbol (symbolName: string) (document: Document) ct =
task {
let! (_, checkFileResults) = document.GetFSharpParseAndCheckResultsAsync "" |> CancellableTask.start ct

let symbols = checkFileResults.GetAllUsesOfAllSymbolsInFile ct
let symbolUse = symbols |> Seq.find (fun s -> s.Symbol.DisplayName = symbolName)

return
match symbolUse.Symbol with
| :? FSharpMemberOrFunctionOrValue as v -> Some(v)
| _ -> None

}

let GetReturnTypeOfSymbol (symbolName: string) (document: Document) ct =
let (_, checkFileResults) =
document.GetFSharpParseAndCheckResultsAsync ""
|> CancellableTask.start ct
|> GetTaskResult

let symbols = checkFileResults.GetAllUsesOfAllSymbolsInFile ct |> List.ofSeq
let symbolUse = symbols |> Seq.find (fun s -> s.Symbol.DisplayName = symbolName)

match symbolUse.Symbol with
| :? FSharpMemberOrFunctionOrValue as v -> Some(v.ReturnParameter.Type.TypeDefinition.CompiledName)
| _ -> None

let TryGetRangeOfExplicitReturnType (symbolName: string) (document: Document) ct =
task {
let! parseFileResults = document.GetFSharpParseResultsAsync symbolName ct
let! symbol = GetSymbol symbolName document ct

let range =
symbol
|> Option.bind (fun sym -> parseFileResults.RangeOfReturnTypeDefinition(sym.DeclarationLocation.Start, false))

return range
}

let AssertCodeHasNotChanged (code: string) (document: Document) ct =
task {
let! newText = document.GetTextAsync ct
Assert.AreEqual(code, newText.ToString())
}

let AssertHasAnyExplicitReturnType (symbolName: string) (document: Document) ct =
task {
let! range = TryGetRangeOfExplicitReturnType symbolName document ct
Assert.IsTrue(range.IsSome)
}

let AssertHasSpecificExplicitReturnType (symbolName: string) (expectedTypeName: string) (document: Document) ct =

let returnType = GetReturnTypeOfSymbol symbolName document ct

match returnType with
| Some t -> Assert.AreEqual(expectedTypeName, t)
| None -> Assert.Fail($"Unexpected type. Expected {expectedTypeName} but was t")

()

let AssertHasNoExplicitReturnType (symbolName: string) (document: Document) ct =
task {
let! parseFileResults = document.GetFSharpParseResultsAsync symbolName ct
let! symbol = GetSymbol symbolName document ct

let range =
symbol
|> Option.bind (fun sym -> parseFileResults.TryRangeOfReturnTypeHint(sym.DeclarationLocation.Start, false))

Assert.IsTrue(range.IsSome)
}

type TestCodeFix = { Message: string; FixedCode: string }

type TestContext(Solution: Solution, CT) =
Expand Down

0 comments on commit 38a479a

Please sign in to comment.