提交 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.Collections.Generic;
......@@ -20,3 +21,4 @@ internal sealed class CSharpGoToImplementationService : AbstractGoToImplementati
}
}
}
#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.
using System;
......@@ -97,3 +98,4 @@ private static IEnumerable<INavigableItem> CreateItemsForImplementation(ISymbol
}
}
}
#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.
Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.Editor.CSharp.GoToDefinition
Imports Microsoft.CodeAnalysis.Editor.Host
Imports Microsoft.CodeAnalysis.Editor.VisualBasic.GoToDefinition
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
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
Return GoToTestHelpers.TestAsync(workspaceDefinition, expectedResult,
Return TestAsync(workspaceDefinition, expectedResult,
Function(document As Document, cursorPosition As Integer, presenters As IEnumerable(Of Lazy(Of INavigableItemsPresenter)))
Dim goToDefService = If(document.Project.Language = LanguageNames.CSharp,
DirectCast(New CSharpGoToDefinitionService(presenters, {}), IGoToDefinitionService),
......
......@@ -2,23 +2,49 @@
Imports System.Threading
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.Editor.CSharp.GoToImplementation
Imports Microsoft.CodeAnalysis.Editor.FindUsages
Imports Microsoft.CodeAnalysis.Editor.Host
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
Public Class GoToImplementationTests
Private Function TestAsync(workspaceDefinition As XElement, Optional shouldSucceed As Boolean = True) As Tasks.Task
Return GoToTestHelpers.TestAsync(workspaceDefinition, shouldSucceed,
Function(document As Document, cursorPosition As Integer, presenters As IEnumerable(Of Lazy(Of INavigableItemsPresenter)))
Dim service = If(document.Project.Language = LanguageNames.CSharp,
DirectCast(New CSharpGoToImplementationService(presenters), IGoToImplementationService),
New VisualBasicGoToImplementationService(presenters))
Dim message As String = Nothing
Return service.TryGoToImplementation(document, cursorPosition, CancellationToken.None, message)
End Function)
Private Async Function TestAsync(workspaceDefinition As XElement, Optional shouldSucceed As Boolean = True) As Tasks.Task
Using workspace = Await TestWorkspace.CreateAsync(workspaceDefinition)
Dim documentWithCursor = workspace.DocumentWithCursor
Dim position = documentWithCursor.CursorPosition.Value
Dim document = workspace.CurrentSolution.GetDocument(documentWithCursor.Id)
Dim findUsagesService = document.GetLanguageService(Of IFindUsagesService)
Dim context = New SimpleFindUsagesContext(CancellationToken.None)
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
<WpfFact, Trait(Traits.Feature, Traits.Features.GoToImplementation)>
......
......@@ -93,7 +93,8 @@ protected internal override bool PartialSemanticsEnabled
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)
{
......
......@@ -17,77 +17,9 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
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
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
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
End Module
Private Structure FilePathAndSpan
Friend Structure FilePathAndSpan
Implements IComparable(Of FilePathAndSpan)
Public ReadOnly Property FilePath As String
......@@ -112,5 +44,5 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Return $"{FilePath}, {Span}"
End Function
End Structure
End Module
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.
Imports System.Composition
......@@ -16,3 +17,4 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.GoToImplementation
End Sub
End Class
End Namespace
#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.
先完成此消息的编辑!
想要评论请 注册