提交 dc6f54ea 编写于 作者: V Vasily Kirichenko 提交者: Kevin Ransom (msft)

Refactor Go to Definition service (#2855)

* cleanup

* refactor GoToDefinitionService

* incorporate @majocha's PR #2856
上级 9a9ea54c
......@@ -23,26 +23,47 @@ namespace Microsoft.VisualStudio.FSharp.Editor.Tests.Roslyn
open System
open System.IO
open System.Threading
open System.Linq
open NUnit.Framework
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Completion
open Microsoft.CodeAnalysis.Classification
open Microsoft.CodeAnalysis.Text
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.VisualStudio.FSharp.Editor
open Microsoft.VisualStudio.FSharp.LanguageService
open Microsoft.FSharp.Compiler.SourceCodeServices
open Microsoft.FSharp.Compiler.Range
[<TestFixture>][<Category "Roslyn Services">]
module GoToDefinitionServiceTests =
let private findDefinition
(
checker: FSharpChecker,
documentKey: DocumentId,
sourceText: SourceText,
filePath: string,
position: int,
defines: string list,
options: FSharpProjectOptions,
textVersionHash: int
) : range option =
maybe {
let textLine = sourceText.Lines.GetLineFromPosition position
let textLinePos = sourceText.Lines.GetLinePosition position
let fcsTextLineNumber = Line.fromZ textLinePos.Line
let! lexerSymbol = Tokenizer.getSymbolAtPosition(documentKey, sourceText, position, filePath, defines, SymbolLookupKind.Greedy, false)
let! _, _, checkFileResults =
checker.ParseAndCheckDocument
(filePath, textVersionHash, sourceText.ToString(), options, allowStaleResults = true) |> Async.RunSynchronously
let declarations =
checkFileResults.GetDeclarationLocationAlternate
(fcsTextLineNumber, lexerSymbol.Ident.idRange.EndColumn, textLine.ToString(), lexerSymbol.FullIsland, false) |> Async.RunSynchronously
match declarations with
| FSharpFindDeclResult.DeclFound range -> return range
| _ -> return! None
}
[<Test>]
let VerifyDefinition() =
......@@ -100,16 +121,12 @@ let _ = Module1.foo 1
let caretPosition = fileContents.IndexOf(caretMarker) + caretMarker.Length - 1 // inside the marker
let documentId = DocumentId.CreateNewId(ProjectId.CreateNewId())
let actual =
FSharpGoToDefinitionService.FindDefinition(FSharpChecker.Instance, documentId, SourceText.From(fileContents), filePath, caretPosition, [], options, 0)
findDefinition(FSharpChecker.Instance, documentId, SourceText.From(fileContents), filePath, caretPosition, [], options, 0)
|> Option.map (fun range -> (range.StartLine, range.EndLine, range.StartColumn, range.EndColumn))
if actual <> expected then
Assert.Fail(sprintf "Incorrect information returned for fileContents=<<<%s>>>, caretMarker=<<<%s>>>, expected =<<<%A>>>, actual = <<<%A>>>" fileContents caretMarker expected actual)
#if EXE
VerifyDefinition()
#endif
#endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册