提交 803ec0c3 编写于 作者: D Dustin Campbell

Replace 'usePreviewTab' parameter with OptionSet in navigation services

上级 cf7ca280
......@@ -333,8 +333,8 @@ Global
src\ExpressionEvaluator\CSharp\Source\ResultProvider\CSharpResultProvider.projitems*{bf9dac1e-3a5e-4dc3-bb44-9a64e0d4e9d3}*SharedItemsImports = 4
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{afde6bea-5038-4a4a-a88e-dbd2e4088eed}*SharedItemsImports = 4
src\ExpressionEvaluator\Core\Source\ResultProvider\ResultProvider.projitems*{fa0e905d-ec46-466d-b7b2-3b5557f9428c}*SharedItemsImports = 4
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
src\Compilers\Core\AnalyzerDriver\AnalyzerDriver.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
src\Compilers\Core\SharedCollections\SharedCollections.projitems*{1ee8cad3-55f9-4d91-96b2-084641da9a6c}*SharedItemsImports = 4
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems*{3973b09a-4fbf-44a5-8359-3d22ceb71f71}*SharedItemsImports = 4
src\ExpressionEvaluator\Core\Source\ResultProvider\ResultProvider.projitems*{bedc5a4a-809e-4017-9cfd-6c8d4e1847f0}*SharedItemsImports = 4
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems*{b501a547-c911-4a05-ac6e-274a50dff30e}*SharedItemsImports = 4
......
......@@ -102,7 +102,8 @@ public void NavigateTo()
if (document != null)
{
var navigator = _workspace.Services.GetService<IDocumentNavigationService>();
navigator.TryNavigateToSpan(_workspace, document.Id, _span, usePreviewTab: true);
var options = _workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, true);
navigator.TryNavigateToSpan(_workspace, document.Id, _span, options);
}
}
}
......
......@@ -132,7 +132,11 @@ public void NavigateTo(SymbolKey id, Project project, CancellationToken cancella
{
var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var resolution = id.Resolve(compilation, cancellationToken: cancellationToken);
project.Solution.Workspace.Services.GetService<ISymbolNavigationService>().TryNavigateToSymbol(resolution.Symbol, project, usePreviewTab: true, cancellationToken: cancellationToken);
var workspace = project.Solution.Workspace;
var options = workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, true);
var symbolNavigationService = workspace.Services.GetService<ISymbolNavigationService>();
symbolNavigationService.TryNavigateToSymbol(resolution.Symbol, project, options, cancellationToken);
}
}
}
......@@ -9,7 +9,6 @@
using Microsoft.CodeAnalysis.Editor.Navigation;
using Microsoft.CodeAnalysis.FindSymbols;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.Implementation.GoToDefinition
......@@ -61,6 +60,8 @@ internal static class GoToDefinitionHelpers
symbol = ((IMethodSymbol)symbol).PartialImplementationPart ?? symbol;
}
var options = project.Solution.Workspace.Options;
var preferredSourceLocations = NavigableItemFactory.GetPreferredSourceLocations(solution, symbol).ToArray();
if (!preferredSourceLocations.Any())
{
......@@ -70,7 +71,10 @@ internal static class GoToDefinitionHelpers
// to a metadata-as-source view.
var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>();
return symbolNavigationService.TryNavigateToSymbol(symbol, project, cancellationToken: cancellationToken, usePreviewTab: true);
return symbolNavigationService.TryNavigateToSymbol(
symbol, project,
options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true),
cancellationToken: cancellationToken);
}
// If we have a single location, then just navigate to it.
......@@ -82,7 +86,11 @@ internal static class GoToDefinitionHelpers
if (navigationService.CanNavigateToSpan(workspace, solution.GetDocument(firstItem.SourceTree).Id, firstItem.SourceSpan))
{
return navigationService.TryNavigateToSpan(workspace, solution.GetDocument(firstItem.SourceTree).Id, firstItem.SourceSpan, usePreviewTab: true);
return navigationService.TryNavigateToSpan(
workspace,
documentId: solution.GetDocument(firstItem.SourceTree).Id,
textSpan: firstItem.SourceSpan,
options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true));
}
else
{
......
' 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 Microsoft.CodeAnalysis.Navigation
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.Options
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Friend Class MockDocumentNavigationService
......@@ -17,7 +17,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Public _triedNavigationToSpan As Boolean = False
Public _documentId As DocumentId = Nothing
Public _usePreviewTab As Boolean = False
Public _options As OptionSet = Nothing
Public _line As Integer = -1
Public _offset As Integer = -1
Public _span As TextSpan = Nothing
......@@ -36,30 +36,30 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities.GoToHelpers
Return _canNavigateToSpan
End Function
Public Function TryNavigateToLineAndOffset(workspace As Workspace, documentId As DocumentId, lineNumber As Integer, offset As Integer, Optional usePreviewTab As Boolean = False) As Boolean Implements IDocumentNavigationService.TryNavigateToLineAndOffset
Public Function TryNavigateToLineAndOffset(workspace As Workspace, documentId As DocumentId, lineNumber As Integer, offset As Integer, Optional options As OptionSet = Nothing) As Boolean Implements IDocumentNavigationService.TryNavigateToLineAndOffset
_triedNavigationToLineAndOffset = True
_documentId = documentId
_usePreviewTab = usePreviewTab
_options = options
_line = lineNumber
_offset = offset
Return _canNavigateToLineAndOffset
End Function
Public Function TryNavigateToPosition(workspace As Workspace, documentId As DocumentId, position As Integer, Optional virtualSpace As Integer = 0, Optional usePreviewTab As Boolean = False) As Boolean Implements IDocumentNavigationService.TryNavigateToPosition
Public Function TryNavigateToPosition(workspace As Workspace, documentId As DocumentId, position As Integer, Optional virtualSpace As Integer = 0, Optional options As OptionSet = Nothing) As Boolean Implements IDocumentNavigationService.TryNavigateToPosition
_triedNavigationToPosition = True
_documentId = documentId
_usePreviewTab = usePreviewTab
_options = options
_position = position
_positionVirtualSpace = virtualSpace
Return _canNavigateToPosition
End Function
Public Function TryNavigateToSpan(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, Optional usePreviewTab As Boolean = False) As Boolean Implements IDocumentNavigationService.TryNavigateToSpan
Public Function TryNavigateToSpan(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, Optional options As OptionSet = Nothing) As Boolean Implements IDocumentNavigationService.TryNavigateToSpan
_triedNavigationToSpan = True
_documentId = documentId
_usePreviewTab = usePreviewTab
_options = options
_span = textSpan
Return _canNavigateToSpan
......
......@@ -4,6 +4,7 @@ Imports System.Composition
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.Navigation
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Text
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
......@@ -28,7 +29,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
Public ProvidedOffset As Integer
Public ProvidedPosition As Integer
Public ProvidedVirtualSpace As Integer
Public ProvidedUsePreviewTab As Boolean
Public ProvidedOptions As OptionSet
Public CanNavigateToLineAndOffsetReturnValue As Boolean = True
Public CanNavigateToPositionReturnValue As Boolean = True
......@@ -60,28 +61,28 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
Return CanNavigateToSpanReturnValue
End Function
Public Function TryNavigateToLineAndOffset(workspace As Workspace, documentId As DocumentId, lineNumber As Integer, offset As Integer, Optional usePreviewTab As Boolean = False) As Boolean Implements IDocumentNavigationService.TryNavigateToLineAndOffset
Public Function TryNavigateToLineAndOffset(workspace As Workspace, documentId As DocumentId, lineNumber As Integer, offset As Integer, Optional options As OptionSet = Nothing) As Boolean Implements IDocumentNavigationService.TryNavigateToLineAndOffset
Me.ProvidedDocumentId = documentId
Me.ProvidedLineNumber = lineNumber
Me.ProvidedOffset = offset
Me.ProvidedUsePreviewTab = usePreviewTab
Me.ProvidedOptions = options
Return TryNavigateToLineAndOffsetReturnValue
End Function
Public Function TryNavigateToPosition(workspace As Workspace, documentId As DocumentId, position As Integer, Optional virtualSpace As Integer = 0, Optional usePreviewTab As Boolean = False) As Boolean Implements IDocumentNavigationService.TryNavigateToPosition
Public Function TryNavigateToPosition(workspace As Workspace, documentId As DocumentId, position As Integer, Optional virtualSpace As Integer = 0, Optional options As OptionSet = Nothing) As Boolean Implements IDocumentNavigationService.TryNavigateToPosition
Me.ProvidedDocumentId = documentId
Me.ProvidedPosition = position
Me.ProvidedVirtualSpace = virtualSpace
Me.ProvidedUsePreviewTab = usePreviewTab
Me.ProvidedOptions = options
Return TryNavigateToPositionReturnValue
End Function
Public Function TryNavigateToSpan(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, Optional usePreviewTab As Boolean = False) As Boolean Implements IDocumentNavigationService.TryNavigateToSpan
Public Function TryNavigateToSpan(workspace As Workspace, documentId As DocumentId, textSpan As TextSpan, Optional options As OptionSet = Nothing) As Boolean Implements IDocumentNavigationService.TryNavigateToSpan
Me.ProvidedDocumentId = documentId
Me.ProvidedTextSpan = textSpan
Me.ProvidedUsePreviewTab = usePreviewTab
Me.ProvidedOptions = options
Return TryNavigateToSpanReturnValue
End Function
......
......@@ -5,6 +5,7 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.Host
Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.Navigation
Imports Microsoft.CodeAnalysis.Options
Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
' Note: by default, TestWorkspace produces a composition from all assemblies except EditorServicesTest2.
......@@ -24,7 +25,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
Public TryNavigateToSymbolProvidedSymbol As ISymbol
Public TryNavigateToSymbolProvidedProject As Project
Public TryNavigateToSymbolProvidedUsePreviewTab As Boolean
Public TryNavigateToSymbolProvidedOptions As OptionSet
Public TrySymbolNavigationNotifyProvidedSymbol As ISymbol
Public TrySymbolNavigationNotifyProvidedSolution As Solution
......@@ -37,10 +38,10 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Utilities
Public NavigationLineNumberReturnValue As Integer = 0
Public NavigationCharOffsetReturnValue As Integer = 0
Public Function TryNavigateToSymbol(symbol As ISymbol, project As Project, cancellationToken As CancellationToken, Optional usePreviewTab As Boolean = False) As Boolean Implements ISymbolNavigationService.TryNavigateToSymbol
Public Function TryNavigateToSymbol(symbol As ISymbol, project As Project, Optional options As OptionSet = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Boolean Implements ISymbolNavigationService.TryNavigateToSymbol
Me.TryNavigateToSymbolProvidedSymbol = symbol
Me.TryNavigateToSymbolProvidedProject = project
Me.TryNavigateToSymbolProvidedUsePreviewTab = usePreviewTab
Me.TryNavigateToSymbolProvidedOptions = options
Return True
End Function
......
using System.Collections.Generic;
// 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.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.Options;
......
......@@ -237,6 +237,8 @@
<Compile Include="IntroduceVariable\AbstractIntroduceVariableService.AbstractIntroduceVariableCodeAction.cs" />
<Compile Include="IntroduceVariable\AbstractIntroduceVariableService.IntroduceVariableAllOccurrenceCodeAction.cs" />
<Compile Include="LanguageServices\ProjectInfoService\IProjectInfoService.cs" />
<Compile Include="Navigation\NavigationOptions.cs" />
<Compile Include="Navigation\NavigationOptionsProvider.cs" />
<Compile Include="QuickInfo\QuickInfoUtilities.cs" />
<Compile Include="RemoveUnnecessaryImports\AbstractRemoveUnnecessaryImportsService.cs" />
<Compile Include="ReplaceMethodWithProperty\ReplaceMethodWithPropertyCodeRefactoringProvider.cs" />
......@@ -555,4 +557,4 @@
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
</Project>
\ 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.
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Navigation
......@@ -16,22 +17,22 @@ public bool CanNavigateToLineAndOffset(Workspace workspace, DocumentId documentI
return false;
}
public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace = 0)
public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace)
{
return false;
}
public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool usePreviewTab = false)
public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options)
{
return false;
}
public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, bool usePreviewTab = false)
public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options)
{
return false;
}
public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, bool usePreviewTab = false)
public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, OptionSet options)
{
return 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.Threading;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Navigation
{
internal class DefaultSymbolNavigationService : ISymbolNavigationService
{
public bool TryNavigateToSymbol(ISymbol symbol, Project project, CancellationToken cancellationToken = default(CancellationToken), bool usePreviewTab = false)
public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet options = null, CancellationToken cancellationToken = default(CancellationToken))
{
return 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 Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis.Navigation
......@@ -25,16 +26,16 @@ internal interface IDocumentNavigationService : IWorkspaceService
/// <summary>
/// Navigates to the given position in the specified document, opening it if necessary.
/// </summary>
bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool usePreviewTab = false);
bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options = null);
/// <summary>
/// Navigates to the given line/offset in the specified document, opening it if necessary.
/// </summary>
bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, bool usePreviewTab = false);
bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options = null);
/// <summary>
/// Navigates to the given virtual position in the specified document, opening it if necessary.
/// </summary>
bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace = 0, bool usePreviewTab = false);
bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace = 0, OptionSet options = null);
}
}
......@@ -2,6 +2,7 @@
using Microsoft.CodeAnalysis.Host;
using System.Threading;
using Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Navigation
{
......@@ -13,10 +14,10 @@ internal interface ISymbolNavigationService : IWorkspaceService
/// <param name="project">A project context with which to generate source for symbol
/// if it has no source locations</param>
/// <param name="symbol">The symbol to navigate to</param>
/// <param name="options">An set of options. If these options are not supplied the
/// current set of options from the project's workspace will be used.</param>
/// <param name="cancellationToken">The token to check for cancellation</param>
/// <param name="usePreviewTab">Indicates whether a preview tab should be used if the
/// containing document is opened in a new tab. Defaults to false.</param>
bool TryNavigateToSymbol(ISymbol symbol, Project project, CancellationToken cancellationToken, bool usePreviewTab = false);
bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet options = null, CancellationToken cancellationToken = default(CancellationToken));
/// <returns>True if the navigation was handled, indicating that the caller should not
/// perform the navigation.</returns>
......
// 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 Microsoft.CodeAnalysis.Options;
namespace Microsoft.CodeAnalysis.Navigation
{
internal static class NavigationOptions
{
public const string FeatureName = "Navigation";
public static readonly Option<bool> UsePreviewTab = new Option<bool>(FeatureName, "UsePreviewTab", defaultValue: 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.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Options.Providers;
namespace Microsoft.CodeAnalysis.Navigation
{
[ExportOptionProvider, Shared]
internal class NavigationOptionsProvider : IOptionProvider
{
private readonly IEnumerable<IOption> _options = new List<IOption>
{
NavigationOptions.UsePreviewTab
}.ToImmutableArray();
public IEnumerable<IOption> GetOptions()
{
return _options;
}
}
}
......@@ -5,6 +5,7 @@
using System.Threading;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
......@@ -29,7 +30,7 @@ public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, in
return false;
}
public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool usePreviewTab = false)
public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options)
{
var interactiveWorkspace = workspace as InteractiveWorkspace;
if (interactiveWorkspace == null)
......@@ -70,12 +71,12 @@ public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSp
return true;
}
public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, bool usePreviewTab = false)
public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options)
{
throw new NotSupportedException();
}
public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, bool usePreviewTab = false)
public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, OptionSet options)
{
throw new NotSupportedException();
}
......
......@@ -40,7 +40,7 @@ public override int GoToSource()
if (symbol != null && referencingProject != null)
{
var navigationService = _workspace.Services.GetService<ISymbolNavigationService>();
return navigationService.TryNavigateToSymbol(symbol, referencingProject, CancellationToken.None)
return navigationService.TryNavigateToSymbol(symbol, referencingProject, cancellationToken: CancellationToken.None)
? VSConstants.S_OK
: VSConstants.E_FAIL;
}
......
......@@ -2,12 +2,10 @@
using System;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.Shell.TableManager;
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;
......@@ -190,7 +188,8 @@ protected bool TryNavigateTo(Workspace workspace, DocumentId documentId, int lin
return false;
}
if (navigationService.TryNavigateToLineAndOffset(workspace, documentId, line, column, usePreviewTab: previewTab))
var options = workspace.Options.WithChangedOption(NavigationOptions.UsePreviewTab, previewTab);
if (navigationService.TryNavigateToLineAndOffset(workspace, documentId, line, column, options))
{
return true;
}
......
......@@ -2,12 +2,12 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.LanguageServices.Implementation.Extensions;
......@@ -87,7 +87,7 @@ public bool CanNavigateToPosition(Workspace workspace, DocumentId documentId, in
return CanMapFromSecondaryBufferToPrimaryBuffer(workspace, documentId, vsTextSpan);
}
public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool usePreviewTab = false)
public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSpan textSpan, OptionSet options)
{
// Navigation should not change the context of linked files and Shared Projects.
documentId = workspace.GetDocumentIdInCurrentContext(documentId);
......@@ -97,7 +97,7 @@ public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSp
throw new InvalidOperationException(ServicesVSResources.NavigationMustBePerformedOnTheForegroundThread);
}
var document = OpenDocument(workspace, documentId, usePreviewTab);
var document = OpenDocument(workspace, documentId, options);
if (document == null)
{
return false;
......@@ -116,7 +116,7 @@ public bool TryNavigateToSpan(Workspace workspace, DocumentId documentId, TextSp
return NavigateTo(textBuffer, vsTextSpan);
}
public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, bool usePreviewTab = false)
public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentId, int lineNumber, int offset, OptionSet options)
{
// Navigation should not change the context of linked files and Shared Projects.
documentId = workspace.GetDocumentIdInCurrentContext(documentId);
......@@ -126,7 +126,7 @@ public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentI
throw new InvalidOperationException(ServicesVSResources.NavigationMustBePerformedOnTheForegroundThread);
}
var document = OpenDocument(workspace, documentId, usePreviewTab);
var document = OpenDocument(workspace, documentId, options);
if (document == null)
{
return false;
......@@ -146,7 +146,7 @@ public bool TryNavigateToLineAndOffset(Workspace workspace, DocumentId documentI
return NavigateTo(textBuffer, vsTextSpan);
}
public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, bool usePreviewTab = false)
public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, int position, int virtualSpace, OptionSet options)
{
// Navigation should not change the context of linked files and Shared Projects.
documentId = workspace.GetDocumentIdInCurrentContext(documentId);
......@@ -156,7 +156,7 @@ public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, in
throw new InvalidOperationException(ServicesVSResources.NavigationMustBePerformedOnTheForegroundThread);
}
var document = OpenDocument(workspace, documentId, usePreviewTab);
var document = OpenDocument(workspace, documentId, options);
if (document == null)
{
return false;
......@@ -176,14 +176,14 @@ public bool TryNavigateToPosition(Workspace workspace, DocumentId documentId, in
return NavigateTo(textBuffer, vsTextSpan);
}
private static Document OpenDocument(Workspace workspace, DocumentId documentId, bool usePreviewTab)
private static Document OpenDocument(Workspace workspace, DocumentId documentId, OptionSet options)
{
// Always open the document again, even if the document is already open in the
// workspace. If a document is already open in a preview tab and it is opened again
// in a permanent tab, this allows the document to transition to the new state.
if (workspace.CanOpenDocuments)
{
if (usePreviewTab)
if (options.GetOption(NavigationOptions.UsePreviewTab))
{
using (NewDocumentStateScope ndss = new NewDocumentStateScope(__VSNEWDOCUMENTSTATE.NDS_Provisional, VSConstants.NewDocumentStateReason.Navigation))
{
......
......@@ -11,6 +11,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.GeneratedCodeRecognition;
using Microsoft.CodeAnalysis.Navigation;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.ComponentModelHost;
......@@ -49,13 +50,14 @@ internal partial class VisualStudioSymbolNavigationService : ForegroundThreadAff
_metadataAsSourceFileService = componentModel.GetService<IMetadataAsSourceFileService>();
}
public bool TryNavigateToSymbol(ISymbol symbol, Project project, CancellationToken cancellationToken, bool usePreviewTab = false)
public bool TryNavigateToSymbol(ISymbol symbol, Project project, OptionSet options, CancellationToken cancellationToken)
{
if (project == null || symbol == null)
{
return false;
}
options = options ?? project.Solution.Workspace.Options;
symbol = symbol.OriginalDefinition;
// Prefer visible source locations if possible.
......@@ -70,7 +72,7 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, CancellationTok
{
var editorWorkspace = targetDocument.Project.Solution.Workspace;
var navigationService = editorWorkspace.Services.GetService<IDocumentNavigationService>();
return navigationService.TryNavigateToSpan(editorWorkspace, targetDocument.Id, sourceLocation.SourceSpan, usePreviewTab);
return navigationService.TryNavigateToSpan(editorWorkspace, targetDocument.Id, sourceLocation.SourceSpan, options);
}
}
......@@ -115,7 +117,12 @@ public bool TryNavigateToSymbol(ISymbol symbol, Project project, CancellationTok
{
var editorWorkspace = openedDocument.Project.Solution.Workspace;
var navigationService = editorWorkspace.Services.GetService<IDocumentNavigationService>();
return navigationService.TryNavigateToSpan(editorWorkspace, openedDocument.Id, result.IdentifierLocation.SourceSpan, usePreviewTab: true);
return navigationService.TryNavigateToSpan(
workspace: editorWorkspace,
documentId: openedDocument.Id,
textSpan: result.IdentifierLocation.SourceSpan,
options: options.WithChangedOption(NavigationOptions.UsePreviewTab, true));
}
return true;
......
......@@ -56,13 +56,13 @@ public override EnvDTE.FileCodeModel GetFileCodeModel(DocumentId documentId)
var project = ProjectTracker.GetProject(documentId.ProjectId);
if (project == null)
{
throw new ArgumentException(ServicesVSResources.DocumentIdNotFromWorkspace, "documentId");
throw new ArgumentException(ServicesVSResources.DocumentIdNotFromWorkspace, nameof(documentId));
}
var document = project.GetDocumentOrAdditionalDocument(documentId);
if (document == null)
{
throw new ArgumentException(ServicesVSResources.DocumentIdNotFromWorkspace, "documentId");
throw new ArgumentException(ServicesVSResources.DocumentIdNotFromWorkspace, nameof(documentId));
}
var provider = project as IProjectCodeModelProvider;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册