From fc50bd7ad151a9af9ad243d72f6c759edd919331 Mon Sep 17 00:00:00 2001 From: isc30 Date: Sat, 17 Feb 2018 05:24:18 +0100 Subject: [PATCH 1/9] [#23030] Disable literal Ctrl+Click navigation --- .../AbstractGoToDefinitionService.cs | 4 +- .../AbstractGoToDefinitionSymbolService.cs | 30 ++++++--- .../AbstractGoToSymbolService.cs | 2 +- .../IGoToDefinitionSymbolService.cs | 2 +- .../GoToDefinition/GoToDefinitionTests.vb | 56 ++++++++++++++++ .../NavigableSymbols/NavigableSymbolsTest.vb | 66 ++++++++++++++++++- 6 files changed, 146 insertions(+), 14 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index a4280ca647aba..f798083e81dc9 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -27,7 +27,7 @@ public async Task> FindDefinitionsAsync( Document document, int position, CancellationToken cancellationToken) { var symbolService = document.GetLanguageService(); - var (symbol, span) = await symbolService.GetSymbolAndBoundSpanAsync(document, position, cancellationToken).ConfigureAwait(false); + var (symbol, span) = await symbolService.GetSymbolAndBoundSpanAsync(document, position, includeLiterals: true, cancellationToken).ConfigureAwait(false); // Try to compute source definitions from symbol. var items = symbol != null @@ -43,7 +43,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken { // Try to compute the referenced symbol and attempt to go to definition for the symbol. var symbolService = document.GetLanguageService(); - var (symbol, _) = symbolService.GetSymbolAndBoundSpanAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken); + var (symbol, _) = symbolService.GetSymbolAndBoundSpanAsync(document, position, includeLiterals: true, cancellationToken).WaitAndGetResult(cancellationToken); if (symbol is null) { return false; diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs index f6c7eece0f552..714b7fe1247e7 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.FindSymbols; +using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.Editor.GoToDefinition @@ -12,23 +13,36 @@ internal abstract class AbstractGoToDefinitionSymbolService : IGoToDefinitionSym { protected abstract ISymbol FindRelatedExplicitlyDeclaredSymbol(ISymbol symbol, Compilation compilation); - public async Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, CancellationToken cancellationToken) + public async Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, bool includeLiterals, CancellationToken cancellationToken) { var workspace = document.Project.Solution.Workspace; var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var semanticInfo = await SymbolFinder.GetSemanticInfoAtPositionAsync(semanticModel, position, workspace, cancellationToken).ConfigureAwait(false); + var symbol = GetSymbol(semanticInfo, includeLiterals); - // prefer references to declarations. It's more likely that the user is attempting to - // go to a definition at some other location, rather than the definition they're on. + if (symbol is null) + { + return (null, semanticInfo.Span); + } + + return (FindRelatedExplicitlyDeclaredSymbol(symbol, semanticModel.Compilation), semanticInfo.Span); + } + + private ISymbol GetSymbol(TokenSemanticInfo semanticInfo, bool includeLiterals) + { + // Prefer references to declarations. It's more likely that the user is attempting to + // go to a definition at some other location, rather than the definition they're on. // This can happen when a token is at a location that is both a reference and a definition. // For example, on an anonymous type member declaration. - var symbol = semanticInfo.AliasSymbol ?? - semanticInfo.ReferencedSymbols.FirstOrDefault() ?? - semanticInfo.DeclaredSymbol ?? - semanticInfo.Type; - return (FindRelatedExplicitlyDeclaredSymbol(symbol, semanticModel.Compilation), semanticInfo.Span); + var symbol = semanticInfo.AliasSymbol + ?? semanticInfo.ReferencedSymbols.FirstOrDefault() + ?? semanticInfo.DeclaredSymbol; + + return includeLiterals + ? (symbol ?? semanticInfo.Type) + : symbol; } } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index 4e0488a7485bc..fba7948bc61a5 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -15,7 +15,7 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) var cancellationToken = context.CancellationToken; var service = document.GetLanguageService(); - var (symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, cancellationToken).ConfigureAwait(false); + var (symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, includeLiterals: false, cancellationToken).ConfigureAwait(false); if (symbol == null) { diff --git a/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs index 99a30194235f7..95c4da51c572b 100644 --- a/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs @@ -9,6 +9,6 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { internal interface IGoToDefinitionSymbolService : ILanguageService { - Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, CancellationToken cancellationToken); + Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, bool includeLiterals, CancellationToken cancellationToken); } } diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb index d0c0670850b3e..bcb405533bb6e 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb @@ -150,6 +150,34 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Test(workspace) End Sub + + Public Sub TestCSharpLiteralGoToDefinition() + Dim workspace = + + + + int x = 1$$23; + + + + + Test(workspace) + End Sub + + + Public Sub TestCSharpStringLiteralGoToDefinition() + Dim workspace = + + + + string x = "wo$$ow"; + + + + + Test(workspace) + End Sub + Public Sub TestCSharpGoToDefinitionOnAnonymousMember() @@ -1457,6 +1485,34 @@ class D Test(workspace) End Sub + + Public Sub TestVisualBasicLiteralGoToDefinition() + Dim workspace = + + + + Dim x as Integer = 12$$3 + + + + + Test(workspace) + End Sub + + + Public Sub TestVisualBasicStringLiteralGoToDefinition() + Dim workspace = + + + + Dim x as String = "wo$$ow" + + + + + Test(workspace) + End Sub + Public Sub TestVisualBasicPropertyBackingField() diff --git a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb index 38414782967c9..b8c8ed984f756 100644 --- a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb +++ b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb @@ -18,6 +18,7 @@ Imports Microsoft.VisualStudio.Composition Imports Microsoft.VisualStudio.Text Imports Roslyn.Test.Utilities Imports Xunit +Imports Microsoft.VisualStudio.Language.Intellisense Namespace Microsoft.CodeAnalysis.Editor.UnitTests.NavigableSymbols @@ -45,6 +46,32 @@ class {|target:C|} End Using End Function + + Public Async Function TestCharpLiteral() As Task + Dim markup = "var x = {|literal:1$$23|};" + Dim text As String = Nothing + Dim position As Integer? = Nothing + Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing + MarkupTestFile.GetPositionAndSpans(markup, text, position, spans) + + Using workspace = TestWorkspace.CreateCSharp(text, exportProvider:=s_exportProvider) + Await TestNotNavigated(workspace, position.Value, spans) + End Using + End Function + + + Public Async Function TestCharpStringLiteral() As Task + Dim markup = "var x = ""{|literal:w$$ow|}"";" + Dim text As String = Nothing + Dim position As Integer? = Nothing + Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing + MarkupTestFile.GetPositionAndSpans(markup, text, position, spans) + + Using workspace = TestWorkspace.CreateCSharp(text, exportProvider:=s_exportProvider) + Await TestNotNavigated(workspace, position.Value, spans) + End Using + End Function + Public Async Function TestVB() As Task Dim markup = " @@ -61,14 +88,44 @@ End Class" End Using End Function - Private Async Function TestNavigated(workspace As TestWorkspace, position As Integer, spans As IDictionary(Of String, ImmutableArray(Of TextSpan))) As Task + + Public Async Function TestVBLiteral() As Task + Dim markup = "Dim x as Integer = {|literal:1$$23|}" + Dim text As String = Nothing + Dim position As Integer? = Nothing + Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing + MarkupTestFile.GetPositionAndSpans(markup, text, position, spans) + + Using workspace = TestWorkspace.CreateVisualBasic(text, exportProvider:=s_exportProvider) + Await TestNotNavigated(workspace, position.Value, spans) + End Using + End Function + + + Public Async Function TestVBStringLiteral() As Task + Dim markup = "Dim x as String = ""{|literal:w$$ow|}""" + Dim text As String = Nothing + Dim position As Integer? = Nothing + Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing + MarkupTestFile.GetPositionAndSpans(markup, text, position, spans) + + Using workspace = TestWorkspace.CreateVisualBasic(text, exportProvider:=s_exportProvider) + Await TestNotNavigated(workspace, position.Value, spans) + End Using + End Function + + Private Function ExtractSymbol(workspace As TestWorkspace, position As Integer, spans As IDictionary(Of String, ImmutableArray(Of TextSpan))) As Task(Of INavigableSymbol) Dim presenter = {New Lazy(Of IStreamingFindUsagesPresenter)(Function() New MockStreamingFindUsagesPresenter(Sub() Return))} Dim service = New NavigableSymbolService(TestWaitIndicator.Default, presenter) Dim view = workspace.Documents.First().GetTextView() Dim buffer = workspace.Documents.First().GetTextBuffer() Dim triggerSpan = New SnapshotSpan(buffer.CurrentSnapshot, New Span(position, 0)) Dim source = service.TryCreateNavigableSymbolSource(view, buffer) - Dim symbol = Await source.GetNavigableSymbolAsync(triggerSpan, CancellationToken.None) + Return source.GetNavigableSymbolAsync(triggerSpan, CancellationToken.None) + End Function + + Private Async Function TestNavigated(workspace As TestWorkspace, position As Integer, spans As IDictionary(Of String, ImmutableArray(Of TextSpan))) As Task + Dim symbol = Await ExtractSymbol(workspace, position, spans) Dim highlightedSpan = spans("highlighted").First() Dim navigationTarget = spans("target").First() @@ -84,5 +141,10 @@ End Class" Assert.Equal(True, navigationService.TryNavigateToSpanReturnValue) Assert.Equal(navigationTarget, navigationService.ProvidedTextSpan) End Function + + Private Async Function TestNotNavigated(workspace As TestWorkspace, position As Integer, spans As IDictionary(Of String, ImmutableArray(Of TextSpan))) As Task + Dim symbol = Await ExtractSymbol(workspace, position, spans) + Assert.Null(symbol) + End Function End Class End Namespace From bd4aa1e9d9587b6c558dc5f1894fa761af1b152f Mon Sep 17 00:00:00 2001 From: isc30 Date: Sun, 18 Feb 2018 15:08:18 +0100 Subject: [PATCH 2/9] Move literal information to TokenSemanticInfo using SyntaxFactsService --- .../AbstractGoToDefinitionSymbolService.cs | 14 ++++++++------ .../Core/Portable/FindSymbols/SymbolFinder.cs | 17 ++++++++++++++--- .../Extensions/SemanticModelExtensions.cs | 11 ++++++++--- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs index 714b7fe1247e7..601fc23528b2e 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs @@ -31,18 +31,20 @@ internal abstract class AbstractGoToDefinitionSymbolService : IGoToDefinitionSym private ISymbol GetSymbol(TokenSemanticInfo semanticInfo, bool includeLiterals) { + if (!includeLiterals && semanticInfo.IsLiteral) + { + return null; + } + // Prefer references to declarations. It's more likely that the user is attempting to // go to a definition at some other location, rather than the definition they're on. // This can happen when a token is at a location that is both a reference and a definition. // For example, on an anonymous type member declaration. - var symbol = semanticInfo.AliasSymbol + return semanticInfo.AliasSymbol ?? semanticInfo.ReferencedSymbols.FirstOrDefault() - ?? semanticInfo.DeclaredSymbol; - - return includeLiterals - ? (symbol ?? semanticInfo.Type) - : symbol; + ?? semanticInfo.DeclaredSymbol + ?? semanticInfo.Type; } } } diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs index 6e0a045340fef..81023b007088e 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs @@ -51,9 +51,7 @@ internal static async Task GetSemanticInfoAtPositionAsync( Workspace workspace, CancellationToken cancellationToken) { - var syntaxTree = semanticModel.SyntaxTree; - var syntaxFacts = workspace.Services.GetLanguageServices(semanticModel.Language).GetService(); - var token = await syntaxTree.GetTouchingTokenAsync(position, syntaxFacts.IsBindableToken, cancellationToken, findInsideTrivia: true).ConfigureAwait(false); + var token = await GetTokenAtPositionAsync(semanticModel, position, workspace, cancellationToken).ConfigureAwait(false); if (token != default && token.Span.IntersectsWith(position)) @@ -64,6 +62,19 @@ internal static async Task GetSemanticInfoAtPositionAsync( return TokenSemanticInfo.Empty; } + internal static async Task GetTokenAtPositionAsync( + SemanticModel semanticModel, + int position, + Workspace workspace, + CancellationToken cancellationToken) + { + var syntaxTree = semanticModel.SyntaxTree; + var syntaxFacts = workspace.Services.GetLanguageServices(semanticModel.Language).GetService(); + var token = await syntaxTree.GetTouchingTokenAsync(position, syntaxFacts.IsBindableToken, cancellationToken, findInsideTrivia: true).ConfigureAwait(false); + + return token; + } + public static async Task FindSymbolAtPositionAsync( Document document, int position, diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs index 17e919315150b..2b7c5a544afca 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs @@ -15,26 +15,29 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions internal struct TokenSemanticInfo { public static readonly TokenSemanticInfo Empty = new TokenSemanticInfo( - null, null, ImmutableArray.Empty, null, default(TextSpan)); + null, null, ImmutableArray.Empty, null, default, default); public readonly ISymbol DeclaredSymbol; public readonly IAliasSymbol AliasSymbol; public readonly ImmutableArray ReferencedSymbols; public readonly ITypeSymbol Type; public readonly TextSpan Span; + public readonly bool IsLiteral; public TokenSemanticInfo( ISymbol declaredSymbol, IAliasSymbol aliasSymbol, ImmutableArray referencedSymbols, ITypeSymbol type, - TextSpan span) + TextSpan span, + bool isLiteral) { DeclaredSymbol = declaredSymbol; AliasSymbol = aliasSymbol; ReferencedSymbols = referencedSymbols; Type = type; Span = span; + IsLiteral = isLiteral; } public ImmutableArray GetSymbols(bool includeType) @@ -231,7 +234,9 @@ private static TokenSemanticInfo GetSemanticInfo( } } - return new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type, token.Span); + var isLiteral = syntaxFacts.IsLiteral(token); + + return new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type, token.Span, isLiteral); } public static SemanticModel GetOriginalSemanticModel(this SemanticModel semanticModel) From 0ea1d9588acd01792b74955c3c63c7e8bc4bec25 Mon Sep 17 00:00:00 2001 From: isc30 Date: Wed, 21 Feb 2018 01:15:24 +0100 Subject: [PATCH 3/9] tests: specify target symbol --- .../Test2/GoToDefinition/GoToDefinitionTests.vb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb index bcb405533bb6e..530db17109b47 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb @@ -156,7 +156,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - int x = 1$$23; + [|int|] x = 1$$23; @@ -170,7 +170,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition - string x = "wo$$ow"; + [|string|] x = "wo$$ow"; @@ -1491,7 +1491,7 @@ class D - Dim x as Integer = 12$$3 + Dim x as [|Integer|] = 12$$3 @@ -1505,7 +1505,7 @@ class D - Dim x as String = "wo$$ow" + Dim x as [|String|] = "wo$$ow" From cbb443003e5b742388192aa899704049a0de06a1 Mon Sep 17 00:00:00 2001 From: isc30 Date: Fri, 23 Feb 2018 22:45:25 +0100 Subject: [PATCH 4/9] PR comments --- .../AbstractGoToDefinitionService.cs | 5 +++-- .../AbstractGoToDefinitionSymbolService.cs | 20 +++++++++---------- .../AbstractGoToSymbolService.cs | 6 ++++-- .../IGoToDefinitionSymbolService.cs | 2 +- .../GoToDefinition/GoToDefinitionTests.vb | 12 +++++++---- .../NavigableSymbols/NavigableSymbolsTest.vb | 6 ++++-- .../Core/Portable/FindSymbols/SymbolFinder.cs | 5 ++--- .../Extensions/SemanticModelExtensions.cs | 11 +++------- 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs index f798083e81dc9..578dc110a0e71 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionService.cs @@ -13,6 +13,7 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { + // GoToDefinition internal abstract class AbstractGoToDefinitionService : IGoToDefinitionService { private readonly IEnumerable> _streamingPresenters; @@ -27,7 +28,7 @@ public async Task> FindDefinitionsAsync( Document document, int position, CancellationToken cancellationToken) { var symbolService = document.GetLanguageService(); - var (symbol, span) = await symbolService.GetSymbolAndBoundSpanAsync(document, position, includeLiterals: true, cancellationToken).ConfigureAwait(false); + var (symbol, span) = await symbolService.GetSymbolAndBoundSpanAsync(document, position, includeType: true, cancellationToken).ConfigureAwait(false); // Try to compute source definitions from symbol. var items = symbol != null @@ -43,7 +44,7 @@ public bool TryGoToDefinition(Document document, int position, CancellationToken { // Try to compute the referenced symbol and attempt to go to definition for the symbol. var symbolService = document.GetLanguageService(); - var (symbol, _) = symbolService.GetSymbolAndBoundSpanAsync(document, position, includeLiterals: true, cancellationToken).WaitAndGetResult(cancellationToken); + var (symbol, _) = symbolService.GetSymbolAndBoundSpanAsync(document, position, includeType: true, cancellationToken).WaitAndGetResult(cancellationToken); if (symbol is null) { return false; diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs index 601fc23528b2e..2afadf4126743 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs @@ -13,13 +13,13 @@ internal abstract class AbstractGoToDefinitionSymbolService : IGoToDefinitionSym { protected abstract ISymbol FindRelatedExplicitlyDeclaredSymbol(ISymbol symbol, Compilation compilation); - public async Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, bool includeLiterals, CancellationToken cancellationToken) + public async Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, bool includeType, CancellationToken cancellationToken) { var workspace = document.Project.Solution.Workspace; var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var semanticInfo = await SymbolFinder.GetSemanticInfoAtPositionAsync(semanticModel, position, workspace, cancellationToken).ConfigureAwait(false); - var symbol = GetSymbol(semanticInfo, includeLiterals); + var symbol = GetSymbol(semanticInfo, includeType); if (symbol is null) { @@ -29,22 +29,20 @@ internal abstract class AbstractGoToDefinitionSymbolService : IGoToDefinitionSym return (FindRelatedExplicitlyDeclaredSymbol(symbol, semanticModel.Compilation), semanticInfo.Span); } - private ISymbol GetSymbol(TokenSemanticInfo semanticInfo, bool includeLiterals) + private ISymbol GetSymbol(TokenSemanticInfo semanticInfo, bool includeType) { - if (!includeLiterals && semanticInfo.IsLiteral) - { - return null; - } - // Prefer references to declarations. It's more likely that the user is attempting to // go to a definition at some other location, rather than the definition they're on. // This can happen when a token is at a location that is both a reference and a definition. // For example, on an anonymous type member declaration. - return semanticInfo.AliasSymbol + var symbol = semanticInfo.AliasSymbol ?? semanticInfo.ReferencedSymbols.FirstOrDefault() - ?? semanticInfo.DeclaredSymbol - ?? semanticInfo.Type; + ?? semanticInfo.DeclaredSymbol; + + return includeType + ? (symbol ?? semanticInfo.Type) + : symbol; } } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index fba7948bc61a5..da43e953db162 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -6,6 +6,7 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { + // Ctrl+Click (GoToSymbol) internal abstract class AbstractGoToSymbolService : ForegroundThreadAffinitizedObject, IGoToSymbolService { public async Task GetSymbolsAsync(GoToSymbolContext context) @@ -13,9 +14,10 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) var document = context.Document; var position = context.Position; var cancellationToken = context.CancellationToken; - var service = document.GetLanguageService(); - var (symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, includeLiterals: false, cancellationToken).ConfigureAwait(false); + + // includeType: if the token has no aliased, referenced or declared symbols (mostly literals) we want to disable Ctrl+Click on them + var (symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, includeType: false, cancellationToken).ConfigureAwait(false); if (symbol == null) { diff --git a/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs index 95c4da51c572b..5c9c98f167cdc 100644 --- a/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/IGoToDefinitionSymbolService.cs @@ -9,6 +9,6 @@ namespace Microsoft.CodeAnalysis.Editor.GoToDefinition { internal interface IGoToDefinitionSymbolService : ILanguageService { - Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, bool includeLiterals, CancellationToken cancellationToken); + Task<(ISymbol, TextSpan)> GetSymbolAndBoundSpanAsync(Document document, int position, bool includeType, CancellationToken cancellationToken); } } diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb index 530db17109b47..5fbd236f4d369 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb @@ -151,12 +151,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition End Sub + Public Sub TestCSharpLiteralGoToDefinition() Dim workspace = - [|int|] x = 1$$23; + int x = 1$$23; @@ -165,12 +166,13 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition End Sub + Public Sub TestCSharpStringLiteralGoToDefinition() Dim workspace = - [|string|] x = "wo$$ow"; + string x = "wo$$ow"; @@ -1486,12 +1488,13 @@ class D End Sub + Public Sub TestVisualBasicLiteralGoToDefinition() Dim workspace = - Dim x as [|Integer|] = 12$$3 + Dim x as Integer = 12$$3 @@ -1500,12 +1503,13 @@ class D End Sub + Public Sub TestVisualBasicStringLiteralGoToDefinition() Dim workspace = - Dim x as [|String|] = "wo$$ow" + Dim x as String = "wo$$ow" diff --git a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb index b8c8ed984f756..35de77b301ec1 100644 --- a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb +++ b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb @@ -89,8 +89,9 @@ End Class" End Function + Public Async Function TestVBLiteral() As Task - Dim markup = "Dim x as Integer = {|literal:1$$23|}" + Dim markup = "Dim x as Integer = 1$$23" Dim text As String = Nothing Dim position As Integer? = Nothing Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing @@ -102,8 +103,9 @@ End Class" End Function + Public Async Function TestVBStringLiteral() As Task - Dim markup = "Dim x as String = ""{|literal:w$$ow|}""" + Dim markup = "Dim x as String = ""w$$ow"";" Dim text As String = Nothing Dim position As Integer? = Nothing Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing diff --git a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs index 81023b007088e..c8ebb0553d6d6 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs @@ -62,7 +62,7 @@ internal static async Task GetSemanticInfoAtPositionAsync( return TokenSemanticInfo.Empty; } - internal static async Task GetTokenAtPositionAsync( + private static Task GetTokenAtPositionAsync( SemanticModel semanticModel, int position, Workspace workspace, @@ -70,9 +70,8 @@ internal static async Task GetTokenAtPositionAsync( { var syntaxTree = semanticModel.SyntaxTree; var syntaxFacts = workspace.Services.GetLanguageServices(semanticModel.Language).GetService(); - var token = await syntaxTree.GetTouchingTokenAsync(position, syntaxFacts.IsBindableToken, cancellationToken, findInsideTrivia: true).ConfigureAwait(false); - return token; + return syntaxTree.GetTouchingTokenAsync(position, syntaxFacts.IsBindableToken, cancellationToken, findInsideTrivia: true); } public static async Task FindSymbolAtPositionAsync( diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs index 2b7c5a544afca..17e919315150b 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/SemanticModelExtensions.cs @@ -15,29 +15,26 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions internal struct TokenSemanticInfo { public static readonly TokenSemanticInfo Empty = new TokenSemanticInfo( - null, null, ImmutableArray.Empty, null, default, default); + null, null, ImmutableArray.Empty, null, default(TextSpan)); public readonly ISymbol DeclaredSymbol; public readonly IAliasSymbol AliasSymbol; public readonly ImmutableArray ReferencedSymbols; public readonly ITypeSymbol Type; public readonly TextSpan Span; - public readonly bool IsLiteral; public TokenSemanticInfo( ISymbol declaredSymbol, IAliasSymbol aliasSymbol, ImmutableArray referencedSymbols, ITypeSymbol type, - TextSpan span, - bool isLiteral) + TextSpan span) { DeclaredSymbol = declaredSymbol; AliasSymbol = aliasSymbol; ReferencedSymbols = referencedSymbols; Type = type; Span = span; - IsLiteral = isLiteral; } public ImmutableArray GetSymbols(bool includeType) @@ -234,9 +231,7 @@ private static TokenSemanticInfo GetSemanticInfo( } } - var isLiteral = syntaxFacts.IsLiteral(token); - - return new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type, token.Span, isLiteral); + return new TokenSemanticInfo(declaredSymbol, aliasSymbol, allSymbols, type, token.Span); } public static SemanticModel GetOriginalSemanticModel(this SemanticModel semanticModel) From 01c18e0fd8a60cbefc75e73bf5336af20014617c Mon Sep 17 00:00:00 2001 From: isc30 Date: Fri, 23 Feb 2018 22:48:49 +0100 Subject: [PATCH 5/9] remove literal --- .../Test2/NavigableSymbols/NavigableSymbolsTest.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb index 35de77b301ec1..f5950bbbe570b 100644 --- a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb +++ b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb @@ -48,7 +48,7 @@ class {|target:C|} Public Async Function TestCharpLiteral() As Task - Dim markup = "var x = {|literal:1$$23|};" + Dim markup = "int x = 1$$23;" Dim text As String = Nothing Dim position As Integer? = Nothing Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing @@ -61,7 +61,7 @@ class {|target:C|} Public Async Function TestCharpStringLiteral() As Task - Dim markup = "var x = ""{|literal:w$$ow|}"";" + Dim markup = "string x = ""w$$ow"";" Dim text As String = Nothing Dim position As Integer? = Nothing Dim spans As IDictionary(Of String, ImmutableArray(Of TextSpan)) = Nothing From b89c0849aa1b2a69a7fddd84d3a119d0d6dab4f2 Mon Sep 17 00:00:00 2001 From: isc30 Date: Fri, 23 Feb 2018 23:34:48 +0100 Subject: [PATCH 6/9] better comment + simpler logic --- .../AbstractGoToDefinitionSymbolService.cs | 9 +++------ .../Core/GoToDefinition/AbstractGoToSymbolService.cs | 4 +++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs index 2afadf4126743..2fbc4ba164be2 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToDefinitionSymbolService.cs @@ -36,13 +36,10 @@ private ISymbol GetSymbol(TokenSemanticInfo semanticInfo, bool includeType) // This can happen when a token is at a location that is both a reference and a definition. // For example, on an anonymous type member declaration. - var symbol = semanticInfo.AliasSymbol + return semanticInfo.AliasSymbol ?? semanticInfo.ReferencedSymbols.FirstOrDefault() - ?? semanticInfo.DeclaredSymbol; - - return includeType - ? (symbol ?? semanticInfo.Type) - : symbol; + ?? semanticInfo.DeclaredSymbol + ?? (includeType ? semanticInfo.Type : null); } } } diff --git a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs index da43e953db162..c66ca6a464a78 100644 --- a/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs +++ b/src/EditorFeatures/Core/GoToDefinition/AbstractGoToSymbolService.cs @@ -16,7 +16,9 @@ public async Task GetSymbolsAsync(GoToSymbolContext context) var cancellationToken = context.CancellationToken; var service = document.GetLanguageService(); - // includeType: if the token has no aliased, referenced or declared symbols (mostly literals) we want to disable Ctrl+Click on them + // [includeType: false] + // Enable Ctrl+Click on tokens with aliased, referenced or declared symbol. + // If the token has none of those but does have a type (mostly literals), we're not interested var (symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, includeType: false, cancellationToken).ConfigureAwait(false); if (symbol == null) From 85fc0807c17502fa21df726b630c4d8d2e05c15d Mon Sep 17 00:00:00 2001 From: JieCarolHu Date: Wed, 11 Apr 2018 10:45:55 -0700 Subject: [PATCH 7/9] use MockSymbolNavigationService for literal go to definition tests --- .../GoToDefinition/GoToDefinitionTests.vb | 127 ++++++++++-------- .../Utilities/GoToHelpers/GoToTestHelpers.vb | 1 + .../MockSymbolNavigationService.vb | 31 +++++ .../MockSymbolNavigationServiceFactory.vb | 17 +++ 4 files changed, 119 insertions(+), 57 deletions(-) create mode 100644 src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb create mode 100644 src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb diff --git a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb index abfff579aee1c..304de51fe3c59 100644 --- a/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb +++ b/src/EditorFeatures/Test2/GoToDefinition/GoToDefinitionTests.vb @@ -22,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Dim cursorPosition = cursorDocument.CursorPosition.Value ' Set up mocks. The IDocumentNavigationService should be called if there is one, - ' location and the INavigableItemsPresenter should be called if there are + ' location and the INavigableItemsPresenter should be called if there are ' multiple locations. ' prepare a notification listener @@ -34,6 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Dim document = workspace.CurrentSolution.GetDocument(cursorDocument.Id) Dim mockDocumentNavigationService = DirectCast(workspace.Services.GetService(Of IDocumentNavigationService)(), MockDocumentNavigationService) + Dim mockSymbolNavigationService = DirectCast(workspace.Services.GetService(Of ISymbolNavigationService)(), MockSymbolNavigationService) Dim presenterCalled As Boolean = False Dim presenter = New MockStreamingFindUsagesPresenter(Sub() presenterCalled = True) @@ -54,38 +55,50 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.GoToDefinition Dim context = presenter.Context 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 + If expectedLocations.Count = 0 Then + ' if there is not expected locations, it means symbol navigation is used + Assert.True(mockSymbolNavigationService._triedNavigationToSymbol) + Assert.Null(mockDocumentNavigationService._documentId) Assert.False(presenterCalled) Else - Assert.False(mockDocumentNavigationService._triedNavigationToPosition) - Assert.False(mockDocumentNavigationService._triedNavigationToLineAndOffset) - Assert.True(presenterCalled) + Assert.False(mockSymbolNavigationService._triedNavigationToSymbol) + + If mockDocumentNavigationService._triedNavigationToSpan Then + Dim definitionDocument = workspace.GetTestDocument(mockDocumentNavigationService._documentId) + Assert.Single(definitionDocument.SelectedSpans) + Assert.Equal(definitionDocument.SelectedSpans.Single(), mockDocumentNavigationService._span) - Dim actualLocations As New List(Of FilePathAndSpan) + ' The INavigableItemsPresenter should not have been called + Assert.False(presenterCalled) + Else + Assert.False(mockDocumentNavigationService._triedNavigationToPosition) + Assert.False(mockDocumentNavigationService._triedNavigationToLineAndOffset) + Assert.True(presenterCalled) - Dim items = context.GetDefinitions() + Dim actualLocations As New List(Of FilePathAndSpan) - For Each location In items - For Each docSpan In location.SourceSpans - actualLocations.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) + Dim items = context.GetDefinitions() + + For Each location In items + For Each docSpan In location.SourceSpans + actualLocations.Add(New FilePathAndSpan(docSpan.Document.FilePath, docSpan.SourceSpan)) + Next Next - Next - actualLocations.Sort() - Assert.Equal(expectedLocations, actualLocations) + actualLocations.Sort() + Assert.Equal(expectedLocations, actualLocations) - ' The IDocumentNavigationService should not have been called - Assert.Null(mockDocumentNavigationService._documentId) + ' The IDocumentNavigationService should not have been called + Assert.Null(mockDocumentNavigationService._documentId) + End If End If Else + Assert.False(mockSymbolNavigationService._triedNavigationToSymbol) Assert.Null(mockDocumentNavigationService._documentId) Assert.False(presenterCalled) End If + + End Using End Sub @@ -785,8 +798,8 @@ class C - class [|SomeClass|] - { + class [|SomeClass|] + { }]]> @@ -1528,8 +1541,8 @@ namespace System partial class [|C|] { - void M() - { + void M() + { $$C c; } } @@ -1633,7 +1646,7 @@ Class C Sub M() Me.$$_P = 10 End Sub -End Class +End Class @@ -1682,7 +1695,7 @@ End Class Class OtherClass - Dim obj As SomeClass + Dim obj As SomeClass End Class @@ -1691,7 +1704,7 @@ End Class End Class - Class [|SomeClass|] + Class [|SomeClass|] End Class @@ -1706,22 +1719,22 @@ End Class - DummyClass + DummyClass End Class Partial Class [|OtherClass|] - Dim a As Integer + Dim a As Integer End Class Partial Class [|OtherClass|] - Dim b As Integer + Dim b As Integer End Class Class ConsumingClass - Dim obj As Other$$Class + Dim obj As Other$$Class End Class @@ -1737,7 +1750,7 @@ End Class Class [|SomeClass|] - Dim x As Integer + Dim x As Integer End Class @@ -1790,7 +1803,7 @@ End Class Class [|SomeClass|] - Dim x As Integer + Dim x As Integer End Class @@ -1813,7 +1826,7 @@ End Class Class [|SomeClass|] - Dim x As Integer + Dim x As Integer End Class @@ -1840,19 +1853,19 @@ Class B Sub New() End Sub End Class - + Class [|C|] Inherits B - + Sub New() MyBase.New() MyClass.Goo() $$Me.Bar() End Sub - + Private Sub Bar() End Sub - + Private Sub Goo() End Sub End Class @@ -1874,19 +1887,19 @@ Class B Sub New() End Sub End Class - + Class [|C|] Inherits B - + Sub New() MyBase.New() $$MyClass.Goo() Me.Bar() End Sub - + Private Sub Bar() End Sub - + Private Sub Goo() End Sub End Class @@ -1908,19 +1921,19 @@ Class [|B|] Sub New() End Sub End Class - + Class C Inherits B - + Sub New() $$MyBase.New() MyClass.Goo() Me.Bar() End Sub - + Private Sub Bar() End Sub - + Private Sub Goo() End Sub End Class @@ -2074,7 +2087,7 @@ End Class Class [|SomeClass|] - Dim x As Integer + Dim x As Integer End Class @@ -2127,12 +2140,12 @@ End Module]]>] using [|AliasedSomething|] = X.Something; - + namespace X { class Something { public Something() { } } } - + class Program { static void Main(string[] args) @@ -2156,12 +2169,12 @@ class Program using [|AliasedSomething|] = X.Something; - + namespace X { class Something { public Something() { } } } - + class Program { static void Main(string[] args) @@ -2185,12 +2198,12 @@ class Program using AliasedSomething = X.Something; - + namespace X { class [|Something|] { public Something() { } } } - + class Program { static void Main(string[] args) @@ -2214,12 +2227,12 @@ class Program using AliasedSomething = X.Something; - + namespace X { class Something { public [|Something|]() { } } } - + class Program { static void Main(string[] args) @@ -2245,7 +2258,7 @@ class Program Imports System Imports System.Collections.Generic Imports System.Linq - + Module Program Sub Main(args As String()) Dim arr = New Integer() {4, 5} @@ -2409,7 +2422,7 @@ Public Class Class2 Sub Test() Dim var1 = New With {Key .var2 = "Bob", Class2.va$$r3} End Sub - + Shared Property [|var3|]() As Integer Get End Get diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/GoToTestHelpers.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/GoToTestHelpers.vb index e26a72794fdce..1103c4baeaefe 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/GoToTestHelpers.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/GoToTestHelpers.vb @@ -13,6 +13,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers Friend Module GoToTestHelpers Public ReadOnly Catalog As ComposableCatalog = TestExportProvider.MinimumCatalogWithCSharpAndVisualBasic.WithParts( GetType(MockDocumentNavigationServiceFactory), + GetType(MockSymbolNavigationServiceFactory), GetType(DefaultSymbolNavigationServiceFactory), GetType(CSharpGoToDefinitionSymbolService), GetType(VisualBasicGoToDefinitionSymbolService), diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb new file mode 100644 index 0000000000000..87cdc861fe5c1 --- /dev/null +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationService.vb @@ -0,0 +1,31 @@ +' 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 Microsoft.CodeAnalysis.FindUsages +Imports Microsoft.CodeAnalysis.Navigation +Imports Microsoft.CodeAnalysis.Options + +Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers + Friend Class MockSymbolNavigationService + Implements ISymbolNavigationService + + Public _triedNavigationToSymbol As Boolean = False + Public _triedSymbolNavigationNotify As Boolean = False + Public _wouldNavigateToSymbol As Boolean = False + + Public Function TryNavigateToSymbol(symbol As ISymbol, project As Project, Optional options As OptionSet = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Boolean Implements ISymbolNavigationService.TryNavigateToSymbol + _triedNavigationToSymbol = True + Return True + End Function + + Public Function TrySymbolNavigationNotify(symbol As ISymbol, project As Project, cancellationToken As CancellationToken) As Boolean Implements ISymbolNavigationService.TrySymbolNavigationNotify + _triedSymbolNavigationNotify = True + Return True + End Function + + Public Function WouldNavigateToSymbol(definitionItem As DefinitionItem, solution As Solution, cancellationToken As CancellationToken, ByRef filePath As String, ByRef lineNumber As Integer, ByRef charOffset As Integer) As Boolean Implements ISymbolNavigationService.WouldNavigateToSymbol + _wouldNavigateToSymbol = True + Return True + End Function + End Class +End Namespace diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb new file mode 100644 index 0000000000000..3fbf54f18d4d3 --- /dev/null +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb @@ -0,0 +1,17 @@ +' 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 Microsoft.CodeAnalysis.Host +Imports Microsoft.CodeAnalysis.Host.Mef +Imports Microsoft.CodeAnalysis.Navigation + +Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers + + Friend Class MockSymbolNavigationServiceFactory + Implements IWorkspaceServiceFactory + + Public Function CreateService(workspaceServices As HostWorkspaceServices) As IWorkspaceService Implements IWorkspaceServiceFactory.CreateService + Return New MockSymbolNavigationService() + End Function + End Class +End Namespace From 99da5c3c8c3d749371ebd2fea0b08012515b5af1 Mon Sep 17 00:00:00 2001 From: Ivan Sanz Carasa Date: Sun, 22 Apr 2018 12:12:56 +0200 Subject: [PATCH 8/9] Update NavigableSymbolsTest.vb --- .../Test2/NavigableSymbols/NavigableSymbolsTest.vb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb index 106919684ee5b..155d4f2480384 100644 --- a/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb +++ b/src/EditorFeatures/Test2/NavigableSymbols/NavigableSymbolsTest.vb @@ -43,6 +43,7 @@ class {|target:C|} End Using End Function + Public Async Function TestCharpLiteral() As Task Dim markup = "int x = 1$$23;" @@ -56,6 +57,7 @@ class {|target:C|} End Using End Function + Public Async Function TestCharpStringLiteral() As Task Dim markup = "string x = ""w$$ow"";" From 8529918f5de511e6338e6fc8345da9ba77501a79 Mon Sep 17 00:00:00 2001 From: JieCarolHu Date: Tue, 1 May 2018 15:33:41 -0700 Subject: [PATCH 9/9] Use ServiceLayer.Host and Add --- .../GoToHelpers/MockDocumentNavigationServiceFactory.vb | 3 ++- .../GoToHelpers/MockSymbolNavigationServiceFactory.vb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationServiceFactory.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationServiceFactory.vb index f3c16cedad4d9..6fe50c3a97839 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationServiceFactory.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockDocumentNavigationServiceFactory.vb @@ -6,7 +6,8 @@ Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.Navigation Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers - + + Friend Class MockDocumentNavigationServiceFactory Implements IWorkspaceServiceFactory diff --git a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb index 3fbf54f18d4d3..f49f6f8a73e2d 100644 --- a/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb +++ b/src/EditorFeatures/TestUtilities2/Utilities/GoToHelpers/MockSymbolNavigationServiceFactory.vb @@ -6,7 +6,8 @@ Imports Microsoft.CodeAnalysis.Host.Mef Imports Microsoft.CodeAnalysis.Navigation Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers - + + Friend Class MockSymbolNavigationServiceFactory Implements IWorkspaceServiceFactory