提交 e8e46ac7 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #15383 from CyrusNajmabadi/findRefsProvisionalTab

Find-refs should open documents in a provisional tab.
......@@ -22,31 +22,21 @@ public DocumentSpan(Document document, TextSpan sourceSpan)
}
public override bool Equals(object obj)
{
return Equals((DocumentSpan)obj);
}
=> Equals((DocumentSpan)obj);
public bool Equals(DocumentSpan obj)
{
return this.Document == obj.Document && this.SourceSpan == obj.SourceSpan;
}
=> this.Document == obj.Document && this.SourceSpan == obj.SourceSpan;
public static bool operator ==(DocumentSpan d1, DocumentSpan d2)
{
return d1.Equals(d2);
}
=> d1.Equals(d2);
public static bool operator !=(DocumentSpan d1, DocumentSpan d2)
{
return !(d1 == d2);
}
=> !(d1 == d2);
public override int GetHashCode()
{
return Hash.Combine(
=> Hash.Combine(
this.Document,
this.SourceSpan.GetHashCode());
}
public bool CanNavigateTo()
{
......@@ -57,9 +47,11 @@ public bool CanNavigateTo()
public bool TryNavigateTo()
{
var workspace = Document.Project.Solution.Workspace;
var solution = Document.Project.Solution;
var workspace = solution.Workspace;
var service = workspace.Services.GetService<IDocumentNavigationService>();
return service.TryNavigateToPosition(workspace, Document.Id, SourceSpan.Start);
return service.TryNavigateToPosition(workspace, Document.Id, SourceSpan.Start,
options: solution.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true));
}
}
}
\ 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 System;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.FindUsages
......
......@@ -43,14 +43,13 @@ private sealed class MetadataDefinitionItem : DefinitionItem
}
public override bool CanNavigateTo()
{
return TryNavigateTo((symbol, project, service) => true);
}
=> TryNavigateTo((symbol, project, service) => true);
public override bool TryNavigateTo()
{
return TryNavigateTo((symbol, project, service) =>
service.TryNavigateToSymbol(symbol, project));
service.TryNavigateToSymbol(
symbol, project, project.Solution.Options.WithChangedOption(NavigationOptions.PreferProvisionalTab, true)));
}
private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool> action)
......@@ -61,8 +60,8 @@ private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool
return false;
}
var project = projectAndSymbol.Value.Item1;
var symbol = projectAndSymbol.Value.Item2;
var project = projectAndSymbol?.project;
var symbol = projectAndSymbol?.symbol;
if (symbol == null || project == null)
{
return false;
......@@ -77,7 +76,7 @@ private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool
return action(symbol, project, navigationService);
}
private ValueTuple<Project, ISymbol>? ResolveSymbolInCurrentSolution()
private (Project project, ISymbol symbol)? ResolveSymbolInCurrentSolution()
{
var project = _workspace.CurrentSolution
.ProjectsWithReferenceToAssembly(_symbolAssemblyIdentity)
......@@ -90,7 +89,7 @@ private bool TryNavigateTo(Func<ISymbol, Project, ISymbolNavigationService, bool
var compilation = project.GetCompilationAsync(CancellationToken.None)
.WaitAndGetResult(CancellationToken.None);
return ValueTuple.Create(project, _symbolKey.Resolve(compilation).Symbol);
return (project, _symbolKey.Resolve(compilation).Symbol);
}
}
}
......
using System;
// 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.Immutable;
using System.Composition;
using System.Runtime.InteropServices;
......@@ -12,7 +14,6 @@
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.TextManager.Interop;
using OLEServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
namespace Microsoft.VisualStudio.LanguageServices.Implementation.FindReferences
{
......@@ -32,9 +33,7 @@ public VisualStudioDefinitionsAndReferencesFactory(SVsServiceProvider servicePro
Solution solution, ISymbol definition)
{
var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>();
string filePath;
int lineNumber, charOffset;
if (!symbolNavigationService.WouldNavigateToSymbol(definition, solution, out filePath, out lineNumber, out charOffset))
if (!symbolNavigationService.WouldNavigateToSymbol(definition, solution, out var filePath, out var lineNumber, out var charOffset))
{
return null;
}
......@@ -64,12 +63,9 @@ private string GetSourceLine(string filePath, int lineNumber)
_serviceProvider, filePath, needsSave: false, needsUndoDisabled: false))
{
var vsTextLines = invisibleEditor.VsTextLines;
int lineLength;
string lineText;
if (vsTextLines != null &&
vsTextLines.GetLengthOfLine(lineNumber, out lineLength) == VSConstants.S_OK &&
vsTextLines.GetLineText(lineNumber, 0, lineNumber, lineLength, out lineText) == VSConstants.S_OK)
vsTextLines.GetLengthOfLine(lineNumber, out var lineLength) == VSConstants.S_OK &&
vsTextLines.GetLineText(lineNumber, 0, lineNumber, lineLength, out var lineText) == VSConstants.S_OK)
{
return lineText;
}
......@@ -113,13 +109,9 @@ private bool TryOpenFile()
{
var shellOpenDocument = (IVsUIShellOpenDocument)_serviceProvider.GetService(typeof(SVsUIShellOpenDocument));
var textViewGuid = VSConstants.LOGVIEWID.TextView_guid;
uint itemid;
IVsUIHierarchy hierarchy;
OLEServiceProvider oleServiceProvider;
IVsWindowFrame frame;
if (shellOpenDocument.OpenDocumentViaProject(
_filePath, ref textViewGuid, out oleServiceProvider, out hierarchy, out itemid, out frame) == VSConstants.S_OK)
_filePath, ref textViewGuid, out var oleServiceProvider,
out var hierarchy, out var itemid, out var frame) == VSConstants.S_OK)
{
frame.Show();
return true;
......@@ -131,13 +123,8 @@ private bool TryOpenFile()
private bool TryNavigateToPosition()
{
IVsRunningDocumentTable docTable = (IVsRunningDocumentTable)_serviceProvider.GetService(typeof(SVsRunningDocumentTable));
IntPtr bufferPtr;
IVsHierarchy hierarchy;
uint cookie;
uint itemid;
if (docTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, _filePath, out hierarchy, out itemid, out bufferPtr, out cookie) != VSConstants.S_OK)
if (docTable.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, _filePath,
out var hierarchy, out var itemid, out var bufferPtr, out var cookie) != VSConstants.S_OK)
{
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册