提交 a60a3567 编写于 作者: C CyrusNajmabadi

Remove the synchronous GoToImplementation path for C#/VB.

上级 dab6e14f
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. #if false
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
...@@ -19,4 +20,5 @@ internal sealed class CSharpGoToImplementationService : AbstractGoToImplementati ...@@ -19,4 +20,5 @@ internal sealed class CSharpGoToImplementationService : AbstractGoToImplementati
{ {
} }
} }
} }
\ No newline at end of file #endif
\ No newline at end of file
#if false
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
...@@ -96,4 +97,5 @@ private static IEnumerable<INavigableItem> CreateItemsForImplementation(ISymbol ...@@ -96,4 +97,5 @@ private static IEnumerable<INavigableItem> CreateItemsForImplementation(ISymbol
displayTaggedParts: symbolDisplayService.ToDisplayParts(implementation).ToTaggedText()); displayTaggedParts: symbolDisplayService.ToDisplayParts(implementation).ToTaggedText());
} }
} }
} }
\ No newline at end of file #endif
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Threading Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition Imports Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
Imports Microsoft.CodeAnalysis.Editor.Host Imports Microsoft.CodeAnalysis.Editor.Host
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Imports System.Threading.Tasks Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition
Imports Microsoft.CodeAnalysis.Navigation
Imports Microsoft.VisualStudio.Composition
Imports Microsoft.VisualStudio.Text
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition
Public Class GoToDefinitionTests Public Class GoToDefinitionTests
Friend Async Function TestAsync(workspaceDefinition As XElement,
expectedResult As Boolean,
executeOnDocument As Func(Of Document, Integer, IEnumerable(Of Lazy(Of INavigableItemsPresenter)), Boolean)) As System.Threading.Tasks.Task
Using workspace = Await TestWorkspace.CreateAsync(
workspaceDefinition, exportProvider:=GoToTestHelpers.ExportProvider)
Dim solution = workspace.CurrentSolution
Dim cursorDocument = workspace.Documents.First(Function(d) d.CursorPosition.HasValue)
Dim cursorPosition = cursorDocument.CursorPosition.Value
Dim items As IList(Of INavigableItem) = Nothing
' Set up mocks. The IDocumentNavigationService should be called if there is one,
' location and the INavigableItemsPresenter should be called if there are
' multiple locations.
' prepare a notification listener
Dim textView = cursorDocument.GetTextView()
Dim textBuffer = textView.TextBuffer
textView.Caret.MoveTo(New SnapshotPoint(textBuffer.CurrentSnapshot, cursorPosition))
Dim cursorBuffer = cursorDocument.TextBuffer
Dim document = workspace.CurrentSolution.GetDocument(cursorDocument.Id)
Dim mockDocumentNavigationService = DirectCast(workspace.Services.GetService(Of IDocumentNavigationService)(), MockDocumentNavigationService)
Dim presenter = New MockNavigableItemsPresenter(Sub(i) items = i)
Dim presenters = {New Lazy(Of INavigableItemsPresenter)(Function() presenter)}
Dim actualResult = executeOnDocument(document, cursorPosition, presenters)
Assert.Equal(expectedResult, actualResult)
Dim expectedLocations As New List(Of FilePathAndSpan)
For Each testDocument In workspace.Documents
For Each selectedSpan In testDocument.SelectedSpans
expectedLocations.Add(New FilePathAndSpan(testDocument.FilePath, selectedSpan))
Next
Next
expectedLocations.Sort()
If expectedResult Then
If mockDocumentNavigationService._triedNavigationToSpan Then
Dim definitionDocument = workspace.GetTestDocument(mockDocumentNavigationService._documentId)
Assert.Single(definitionDocument.SelectedSpans)
Assert.Equal(definitionDocument.SelectedSpans.Single(), mockDocumentNavigationService._span)
' The INavigableItemsPresenter should not have been called
Assert.Null(items)
Else
Assert.False(mockDocumentNavigationService._triedNavigationToPosition)
Assert.False(mockDocumentNavigationService._triedNavigationToLineAndOffset)
Assert.NotEmpty(items)
Dim actualLocations As New List(Of FilePathAndSpan)
For Each location In items
actualLocations.Add(New FilePathAndSpan(location.Document.FilePath, location.SourceSpan))
Next
actualLocations.Sort()
Assert.Equal(expectedLocations, actualLocations)
' The IDocumentNavigationService should not have been called
Assert.Null(mockDocumentNavigationService._documentId)
End If
Else
Assert.Null(mockDocumentNavigationService._documentId)
Assert.True(items Is Nothing OrElse items.Count = 0)
End If
End Using
End Function
Private Function TestAsync(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) As Tasks.Task Private Function TestAsync(workspaceDefinition As XElement, Optional expectedResult As Boolean = True) As Tasks.Task
Return GoToTestHelpers.TestAsync(workspaceDefinition, expectedResult, Return TestAsync(workspaceDefinition, expectedResult,
Function(document As Document, cursorPosition As Integer, presenters As IEnumerable(Of Lazy(Of INavigableItemsPresenter))) Function(document As Document, cursorPosition As Integer, presenters As IEnumerable(Of Lazy(Of INavigableItemsPresenter)))
Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp, Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp,
DirectCast(New CSharpGoToDefinitionService(presenters, {}), IGoToDefinitionService), DirectCast(New CSharpGoToDefinitionService(presenters, {}), IGoToDefinitionService),
......
...@@ -2,23 +2,49 @@ ...@@ -2,23 +2,49 @@
Imports System.Threading Imports System.Threading
Imports System.Threading.Tasks Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.Editor.CSharp.GoToImplementation Imports Microsoft.CodeAnalysis.Editor.FindUsages
Imports Microsoft.CodeAnalysis.Editor.Host Imports Microsoft.CodeAnalysis.Editor.Host
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Imports Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.GoToImplementation Imports Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToImplementation Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToImplementation
Public Class GoToImplementationTests Public Class GoToImplementationTests
Private Function TestAsync(workspaceDefinition As XElement, Optional shouldSucceed As Boolean = True) As Tasks.Task Private Async Function TestAsync(workspaceDefinition As XElement, Optional shouldSucceed As Boolean = True) As Tasks.Task
Return GoToTestHelpers.TestAsync(workspaceDefinition, shouldSucceed, Using workspace = Await TestWorkspace.CreateAsync(workspaceDefinition)
Function(document As Document, cursorPosition As Integer, presenters As IEnumerable(Of Lazy(Of INavigableItemsPresenter))) Dim documentWithCursor = workspace.DocumentWithCursor
Dim service = If(document.Project.Language = LanguageNames.CSharp, Dim position = documentWithCursor.CursorPosition.Value
DirectCast(New CSharpGoToImplementationService(presenters), IGoToImplementationService),
New VisualBasicGoToImplementationService(presenters)) Dim document = workspace.CurrentSolution.GetDocument(documentWithCursor.Id)
Dim findUsagesService = document.GetLanguageService(Of IFindUsagesService)
Dim message As String = Nothing
Return service.TryGoToImplementation(document, cursorPosition, CancellationToken.None, message) Dim context = New SimpleFindUsagesContext(CancellationToken.None)
End Function) Await findUsagesService.FindImplementationsAsync(document, position, context)
If Not shouldSucceed Then
Assert.NotNull(context.Message)
Else
Dim actualDefinitions = context.GetDefinitions().
SelectMany(Function(d) d.SourceSpans).
Select(Function(ss) New FilePathAndSpan(ss.Document.FilePath, ss.SourceSpan)).
ToList()
actualDefinitions.Sort()
Dim expectedDefinitions = workspace.Documents.SelectMany(
Function(d) d.SelectedSpans.Select(Function(ss) New FilePathAndSpan(d.FilePath, ss))).ToList()
expectedDefinitions.Sort()
Assert.Equal(actualDefinitions.Count, expectedDefinitions.Count)
For i = 0 To actualDefinitions.Count - 1
Dim actual = actualDefinitions(i)
Dim expected = expectedDefinitions(i)
Assert.True(actual.CompareTo(expected) = 0,
$"Expected: ({expected}) but got: ({actual})")
Next
End If
End Using
End Function End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)> <WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)>
......
...@@ -93,7 +93,8 @@ protected internal override bool PartialSemanticsEnabled ...@@ -93,7 +93,8 @@ protected internal override bool PartialSemanticsEnabled
get { return _backgroundCompiler != null; } get { return _backgroundCompiler != null; }
} }
public TestHostDocument DocumentWithCursor { get { return Documents.Single(d => d.CursorPosition.HasValue && !d.IsLinkFile); } } public TestHostDocument DocumentWithCursor
=> Documents.Single(d => d.CursorPosition.HasValue && !d.IsLinkFile);
protected override void OnDocumentTextChanged(Document document) protected override void OnDocumentTextChanged(Document document)
{ {
......
...@@ -17,100 +17,32 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers ...@@ -17,100 +17,32 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Public ReadOnly ExportProvider As ExportProvider = MinimalTestExportProvider.CreateExportProvider(Catalog) Public ReadOnly ExportProvider As ExportProvider = MinimalTestExportProvider.CreateExportProvider(Catalog)
Public Async Function TestAsync(workspaceDefinition As XElement, expectedResult As Boolean, executeOnDocument As Func(Of Document, Integer, IEnumerable(Of Lazy(Of INavigableItemsPresenter)), Boolean)) As System.Threading.Tasks.Task End Module
Using workspace = Await TestWorkspace.CreateAsync(workspaceDefinition, exportProvider:=ExportProvider)
Dim solution = workspace.CurrentSolution
Dim cursorDocument = workspace.Documents.First(Function(d) d.CursorPosition.HasValue)
Dim cursorPosition = cursorDocument.CursorPosition.Value
Dim items As IList(Of INavigableItem) = Nothing
' Set up mocks. The IDocumentNavigationService should be called if there is one,
' location and the INavigableItemsPresenter should be called if there are
' multiple locations.
' prepare a notification listener
Dim textView = cursorDocument.GetTextView()
Dim textBuffer = textView.TextBuffer
textView.Caret.MoveTo(New SnapshotPoint(textBuffer.CurrentSnapshot, cursorPosition))
Dim cursorBuffer = cursorDocument.TextBuffer
Dim document = workspace.CurrentSolution.GetDocument(cursorDocument.Id)
Dim mockDocumentNavigationService = DirectCast(workspace.Services.GetService(Of IDocumentNavigationService)(), MockDocumentNavigationService)
Dim presenter = New MockNavigableItemsPresenter(Sub(i) items = i)
Dim presenters = {New Lazy(Of INavigableItemsPresenter)(Function() presenter)}
Dim actualResult = executeOnDocument(document, cursorPosition, presenters)
Assert.Equal(expectedResult, actualResult)
Dim expectedLocations As New List(Of FilePathAndSpan)
For Each testDocument In workspace.Documents
For Each selectedSpan In testDocument.SelectedSpans
expectedLocations.Add(New FilePathAndSpan(testDocument.FilePath, selectedSpan))
Next
Next
expectedLocations.Sort()
If expectedResult Then Friend Structure FilePathAndSpan
If mockDocumentNavigationService._triedNavigationToSpan Then Implements IComparable(Of FilePathAndSpan)
Dim definitionDocument = workspace.GetTestDocument(mockDocumentNavigationService._documentId)
Assert.Single(definitionDocument.SelectedSpans)
Assert.Equal(definitionDocument.SelectedSpans.Single(), mockDocumentNavigationService._span)
' The INavigableItemsPresenter should not have been called Public ReadOnly Property FilePath As String
Assert.Null(items) Public ReadOnly Property Span As TextSpan
Else
Assert.False(mockDocumentNavigationService._triedNavigationToPosition)
Assert.False(mockDocumentNavigationService._triedNavigationToLineAndOffset)
Assert.NotEmpty(items)
Dim actualLocations As New List(Of FilePathAndSpan) Public Sub New(filePath As String, span As TextSpan)
Me.FilePath = filePath
Me.Span = span
End Sub
For Each location In items Public Function CompareTo(other As FilePathAndSpan) As Integer Implements IComparable(Of FilePathAndSpan).CompareTo
actualLocations.Add(New FilePathAndSpan(location.Document.FilePath, location.SourceSpan)) Dim result = String.CompareOrdinal(FilePath, other.FilePath)
Next
actualLocations.Sort() If result <> 0 Then
Assert.Equal(expectedLocations, actualLocations) Return result
End If
' The IDocumentNavigationService should not have been called Return Span.CompareTo(other.Span)
Assert.Null(mockDocumentNavigationService._documentId)
End If
Else
Assert.Null(mockDocumentNavigationService._documentId)
Assert.True(items Is Nothing OrElse items.Count = 0)
End If
End Using
End Function End Function
Private Structure FilePathAndSpan Public Overrides Function ToString() As String
Implements IComparable(Of FilePathAndSpan) Return $"{FilePath}, {Span}"
End Function
Public ReadOnly Property FilePath As String End Structure
Public ReadOnly Property Span As TextSpan
Public Sub New(filePath As String, span As TextSpan)
Me.FilePath = filePath
Me.Span = span
End Sub
Public Function CompareTo(other As FilePathAndSpan) As Integer Implements IComparable(Of FilePathAndSpan).CompareTo
Dim result = String.CompareOrdinal(FilePath, other.FilePath)
If result <> 0 Then
Return result
End If
Return Span.CompareTo(other.Span)
End Function
Public Overrides Function ToString() As String
Return $"{FilePath}, {Span}"
End Function
End Structure
End Module
End Namespace End Namespace
\ No newline at end of file
#If False Then
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. ' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Composition Imports System.Composition
...@@ -15,4 +16,5 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToImplementation ...@@ -15,4 +16,5 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToImplementation
MyBase.New(presenters) MyBase.New(presenters)
End Sub End Sub
End Class End Class
End Namespace End Namespace
\ No newline at end of file #end if
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册