Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release/dev16.11 to release/dev16.11-vs-deps #53989

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public CSharpEditorNavigationBarItemService(IThreadingContext threadingContext)
return new VirtualTreePoint(tree, tree.GetText(cancellationToken), location.SourceSpan.Start);
}

protected override Task NavigateToItemAsync(Document document, WrappedNavigationBarItem item, ITextView textView, CancellationToken cancellationToken)
=> NavigateToSymbolItemAsync(document, (RoslynNavigationBarItem.SymbolItem)item.UnderlyingItem, cancellationToken);
protected override async Task<bool> TryNavigateToItemAsync(Document document, WrappedNavigationBarItem item, ITextView textView, CancellationToken cancellationToken)
{
await NavigateToSymbolItemAsync(document, (RoslynNavigationBarItem.SymbolItem)item.UnderlyingItem, cancellationToken).ConfigureAwait(false);
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ protected AbstractEditorNavigationBarItemService(IThreadingContext threadingCont
}

protected abstract Task<VirtualTreePoint?> GetSymbolNavigationPointAsync(Document document, ISymbol symbol, CancellationToken cancellationToken);
protected abstract Task NavigateToItemAsync(Document document, WrappedNavigationBarItem item, ITextView textView, CancellationToken cancellationToken);
protected abstract Task<bool> TryNavigateToItemAsync(Document document, WrappedNavigationBarItem item, ITextView textView, CancellationToken cancellationToken);

[Obsolete("Caller should call NavigateToItemAsync instead", error: true)]
public void NavigateToItem(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
=> throw new NotSupportedException($"Caller should call {nameof(NavigateToItemAsync)} instead");
=> throw new NotSupportedException($"Caller should call {nameof(TryNavigateToItemAsync)} instead");

public async Task<IList<NavigationBarItem>?> GetItemsAsync(Document document, CancellationToken cancellationToken)
{
Expand All @@ -38,8 +38,8 @@ public void NavigateToItem(Document document, NavigationBarItem item, ITextView
return items.SelectAsArray(v => (NavigationBarItem)new WrappedNavigationBarItem(v));
}

public Task NavigateToItemAsync(Document document, NavigationBarItem item, ITextView textView, CancellationToken cancellationToken)
=> NavigateToItemAsync(document, (WrappedNavigationBarItem)item, textView, cancellationToken);
public Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView textView, CancellationToken cancellationToken)
=> TryNavigateToItemAsync(document, (WrappedNavigationBarItem)item, textView, cancellationToken);

protected async Task NavigateToSymbolItemAsync(
Document document, RoslynNavigationBarItem.SymbolItem item, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.VisualStudio.Text.Editor;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Editor
{
Expand All @@ -23,7 +24,10 @@ internal interface INavigationBarItemServiceRenameOnceTypeScriptMovesToExternalA
{
Task<IList<NavigationBarItem>?> GetItemsAsync(Document document, CancellationToken cancellationToken);
bool ShowItemGrayedIfNear(NavigationBarItem item);
Task NavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken);
/// <summary>
/// Returns <see langword="true"/> if navigation (or generation) happened. <see langword="false"/> otherwise.
/// </summary>
Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken);
}

internal class NavigationBarItemServiceWrapper : INavigationBarItemServiceRenameOnceTypeScriptMovesToExternalAccess
Expand All @@ -41,10 +45,10 @@ public NavigationBarItemServiceWrapper(INavigationBarItemService service)
public bool ShowItemGrayedIfNear(NavigationBarItem item)
=> _service.ShowItemGrayedIfNear(item);

public Task NavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
public Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
{
_service.NavigateToItem(document, item, view, cancellationToken);
return Task.CompletedTask;
return SpecializedTasks.True;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ public VSTypeScriptNavigationBarItemService(
return items.Select(x => ConvertToNavigationBarItem(x)).ToList();
}

public async Task NavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
public async Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
{
if (item.Spans.Length <= 0)
return;
if (item.Spans.Length > 0)
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var workspace = document.Project.Solution.Workspace;
var navigationService = VSTypeScriptDocumentNavigationServiceWrapper.Create(workspace);
navigationService.TryNavigateToPosition(workspace, document.Id, item.Spans[0].Start, virtualSpace: 0, options: null, cancellationToken: cancellationToken);
}

var workspace = document.Project.Solution.Workspace;
var navigationService = VSTypeScriptDocumentNavigationServiceWrapper.Create(workspace);
navigationService.TryNavigateToPosition(workspace, document.Id, item.Spans[0].Start, virtualSpace: 0, options: null, cancellationToken: cancellationToken);
return true;
}

public bool ShowItemGrayedIfNear(NavigationBarItem item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,14 @@ private async Task ProcessItemSelectionAsync(NavigationBarItem item, Cancellatio
item.Spans = item.TrackingSpans.SelectAsArray(ts => ts.GetSpan(snapshot).Span.ToTextSpan());
var view = _presenter.TryGetCurrentView();

// ConfigureAwait(true) as we have to come back to UI thread in order to kick of the refresh task below.
await navBarService.NavigateToItemAsync(document, item, view, cancellationToken).ConfigureAwait(true);
// ConfigureAwait(true) as we have to come back to UI thread in order to kick of the refresh task
// below. Note that we only want to refresh if selecting the item had an effect (either navigating
// or generating). If nothing happened to don't want to refresh. This is important as some items
// exist in the type list that are only there to show a set a particular set of items in the member
// list. So selecting such an item should only update the member list, and we do not want a refresh
// to wipe that out.
if (!await navBarService.TryNavigateToItemAsync(document, item, view, cancellationToken).ConfigureAwait(true))
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,21 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.NavigationBar
Return location
End Function

Protected Overrides Async Function NavigateToItemAsync(document As Document, item As WrappedNavigationBarItem, textView As ITextView, cancellationToken As CancellationToken) As Task
Protected Overrides Async Function TryNavigateToItemAsync(
document As Document, item As WrappedNavigationBarItem, textView As ITextView, cancellationToken As CancellationToken) As Task(Of Boolean)
Dim underlying = item.UnderlyingItem

Dim generateCodeItem = TryCast(underlying, AbstractGenerateCodeItem)
Dim symbolItem = TryCast(underlying, SymbolItem)
If generateCodeItem IsNot Nothing Then
Await GenerateCodeForItemAsync(document, generateCodeItem, textView, cancellationToken).ConfigureAwait(False)
Return True
ElseIf symbolItem IsNot Nothing Then
Await NavigateToSymbolItemAsync(document, symbolItem, cancellationToken).ConfigureAwait(False)
Return True
End If

Return False
End Function
End Class
End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public FSharpNavigationBarItemService(
return items?.Select(x => ConvertToNavigationBarItem(x)).ToList();
}

public async Task NavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
public async Task<bool> TryNavigateToItemAsync(Document document, NavigationBarItem item, ITextView view, CancellationToken cancellationToken)
{
// The logic here was ported from FSharp's implementation. The main reason was to avoid shimming INotificationService.
if (!item.Spans.IsEmpty)
Expand All @@ -65,6 +65,8 @@ public async Task NavigateToItemAsync(Document document, NavigationBarItem item,
notificationService.SendNotification(EditorFeaturesResources.The_definition_of_the_object_is_hidden, severity: NotificationSeverity.Error);
}
}

return true;
}

public bool ShowItemGrayedIfNear(NavigationBarItem item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public static async Task<CPSProject> CreateCSharpCPSProjectAsync(TestEnvironment
projectGuid,
hierarchy,
binOutputPath,
assemblyName: null,
CancellationToken.None);

cpsProject.SetOptions(ImmutableArray.Create(commandLineArguments));
Expand All @@ -105,6 +106,7 @@ public static async Task<CPSProject> CreateNonCompilableProjectAsync(TestEnviron
Guid.NewGuid(),
hierarchy,
binOutputPath: null,
assemblyName: null,
CancellationToken.None);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -17,7 +15,11 @@ internal interface IWorkspaceProjectContextFactory
{
/// <inheritdoc cref="CreateProjectContextAsync"/>
[Obsolete("Use CreateProjectContextAsync instead")]
IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath);
IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath);

/// <inheritdoc cref="CreateProjectContextAsync"/>
[Obsolete("Use CreateProjectContextAsync instead")]
IWorkspaceProjectContext CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath, string? assemblyName);

/// <summary>
/// Creates and initializes a new Workspace project and returns a <see
Expand All @@ -29,8 +31,16 @@ internal interface IWorkspaceProjectContextFactory
/// <param name="projectUniqueName">Unique name for the project.</param>
/// <param name="projectFilePath">Full path to the project file for the project.</param>
/// <param name="projectGuid">Project guid.</param>
/// <param name="hierarchy">Obsolete. The argument is ignored.</param>
/// <param name="hierarchy">The IVsHierarchy for the project; this is used to track linked files across multiple projects when determining contexts.</param>
/// <param name="binOutputPath">Initial project binary output path.</param>
Task<IWorkspaceProjectContext> CreateProjectContextAsync(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath, CancellationToken cancellationToken);
Task<IWorkspaceProjectContext> CreateProjectContextAsync(
string languageName,
string projectUniqueName,
string projectFilePath,
Guid projectGuid,
object? hierarchy,
string? binOutputPath,
string? assemblyName,
CancellationToken cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.ComponentModel.Composition;
using System.Threading;
Expand Down Expand Up @@ -43,25 +41,33 @@ public CPSProjectFactory(
_serviceProvider = (Shell.IAsyncServiceProvider)serviceProvider;
}

IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object hierarchy, string binOutputPath)
IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath)
{
return _threadingContext.JoinableTaskFactory.Run(() =>
this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, assemblyName: null, CancellationToken.None));
}

IWorkspaceProjectContext IWorkspaceProjectContextFactory.CreateProjectContext(string languageName, string projectUniqueName, string projectFilePath, Guid projectGuid, object? hierarchy, string? binOutputPath, string? assemblyName)
{
return _threadingContext.JoinableTaskFactory.Run(() =>
this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, CancellationToken.None));
this.CreateProjectContextAsync(languageName, projectUniqueName, projectFilePath, projectGuid, hierarchy, binOutputPath, assemblyName, CancellationToken.None));
}

public async Task<IWorkspaceProjectContext> CreateProjectContextAsync(
string languageName,
string projectUniqueName,
string projectFilePath,
string? projectFilePath,
Guid projectGuid,
object hierarchy,
string binOutputPath,
object? hierarchy,
string? binOutputPath,
string? assemblyName,
CancellationToken cancellationToken)
{
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

var creationInfo = new VisualStudioProjectCreationInfo
{
AssemblyName = assemblyName,
FilePath = projectFilePath,
Hierarchy = hierarchy as IVsHierarchy,
ProjectGuid = projectGuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public bool LastDesignTimeBuildSucceeded
set => _visualStudioProject.HasAllInformation = value;
}

public CPSProject(VisualStudioProject visualStudioProject, VisualStudioWorkspaceImpl visualStudioWorkspace, IProjectCodeModelFactory projectCodeModelFactory, Guid projectGuid, string binOutputPath)
public CPSProject(VisualStudioProject visualStudioProject, VisualStudioWorkspaceImpl visualStudioWorkspace, IProjectCodeModelFactory projectCodeModelFactory, Guid projectGuid, string? binOutputPath)
{
_visualStudioProject = visualStudioProject;
_visualStudioWorkspace = visualStudioWorkspace;
Expand Down