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