Skip to content

Commit

Permalink
Merge pull request #21598 from dotnet/dev15.3.x
Browse files Browse the repository at this point in the history
merge dev15.3.x to dev15.4.x
  • Loading branch information
Pilchie authored Aug 18, 2017
2 parents c143577 + aca31f6 commit 80db2d9
Show file tree
Hide file tree
Showing 42 changed files with 244 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis;

namespace Roslyn.Utilities
{
Expand Down Expand Up @@ -242,6 +244,19 @@ public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T> source)
return source.Where((Func<T, bool>)s_notNullTest);
}

public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
{
if (source == null)
{
return ImmutableArray<TResult>.Empty;
}

var builder = ArrayBuilder<TResult>.GetInstance();
builder.AddRange(source.Select(selector));

return builder.ToImmutableAndFree();
}

public static bool All(this IEnumerable<bool> source)
{
if (source == null)
Expand Down
6 changes: 3 additions & 3 deletions src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests_NuGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,16 @@ await TestInRegularAndScriptAsync(
installerServiceMock.Verify();
}

private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(
private Task<IList<PackageWithTypeResult>> CreateSearchResult(
string packageName, string typeName, ImmutableArray<string> containingNamespaceNames)
{
return CreateSearchResult(new PackageWithTypeResult(
packageName: packageName, typeName: typeName, version: null,
rank: 0, containingNamespaceNames: containingNamespaceNames));
}

private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
=> Task.FromResult(ImmutableArray.Create(results));
private Task<IList<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
=> Task.FromResult<IList<PackageWithTypeResult>>(ImmutableArray.Create(results));

private ImmutableArray<string> CreateNameParts(params string[] parts) => parts.ToImmutableArray();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// 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.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp.Completion.Providers;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.VisualStudio.Text;
using Roslyn.Test.Utilities;
using Xunit;

Expand Down Expand Up @@ -320,5 +322,38 @@ class C { void M() { B.$$ } }
await VerifyItemExistsAsync(code, "X");
await VerifyItemExistsAsync(code, "Y");
}

[WorkItem(209299, "https://devdiv.visualstudio.com/DevDiv/_workitems?id=209299")]
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
public async Task TestDescriptionWhenDocumentLengthChanges()
{
var code = @"using System;
class C
{
string Property
{
get
{
Console.$$";//, @"Beep"

using (var workspace = TestWorkspace.CreateCSharp(code))
{
var testDocument = workspace.Documents.Single();
var position = testDocument.CursorPosition.Value;

var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
var service = CompletionService.GetService(document);
var completions = await service.GetCompletionsAsync(document, position);

var item = completions.Items.First(i => i.DisplayText == "Beep");
var edit = testDocument.GetTextBuffer().CreateEdit();
edit.Delete(Span.FromBounds(position - 10, position));
edit.Apply();

document = workspace.CurrentSolution.GetDocument(testDocument.Id);
var description = service.GetDescriptionAsync(document, item);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reason
}
}

private async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, ImmutableArray<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
private async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, IList<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
{
var service = document.GetLanguageService<ITodoCommentService>();
if (service == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Linq;
using System.Threading;
Expand Down Expand Up @@ -122,11 +123,11 @@ public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsy
return ImmutableArray<PackageWithTypeResult>.Empty;
}

var results = await session.InvokeAsync<ImmutableArray<PackageWithTypeResult>>(
var results = await session.InvokeAsync<IList<PackageWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithTypeAsync),
source, name, arity).ConfigureAwait(false);

return results;
return results.ToImmutableArrayOrEmpty();
}

public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
Expand All @@ -139,11 +140,11 @@ public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAss
return ImmutableArray<PackageWithAssemblyResult>.Empty;
}

var results = await session.InvokeAsync<ImmutableArray<PackageWithAssemblyResult>>(
var results = await session.InvokeAsync<IList<PackageWithAssemblyResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithAssemblyAsync),
source, assemblyName).ConfigureAwait(false);

return results;
return results.ToImmutableArrayOrEmpty();
}

public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
Expand All @@ -156,11 +157,11 @@ public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReference
return ImmutableArray<ReferenceAssemblyWithTypeResult>.Empty;
}

var results = await session.InvokeAsync<ImmutableArray<ReferenceAssemblyWithTypeResult>>(
var results = await session.InvokeAsync<IList<ReferenceAssemblyWithTypeResult>>(
nameof(IRemoteSymbolSearchUpdateEngine.FindReferenceAssembliesWithTypeAsync),
name, arity).ConfigureAwait(false);

return results;
return results.ToImmutableArrayOrEmpty();
}

public async Task UpdateContinuouslyAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
installerServiceMock.Verify()
End Function

Private Function CreateSearchResult(packageName As String, typeName As String, nameParts As ImmutableArray(Of String)) As Task(Of ImmutableArray(Of PackageWithTypeResult))
Private Function CreateSearchResult(packageName As String, typeName As String, nameParts As ImmutableArray(Of String)) As Task(Of IList(Of PackageWithTypeResult))
Return CreateSearchResult(New PackageWithTypeResult(
packageName:=packageName,
typeName:=typeName,
Expand All @@ -248,8 +248,8 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
containingNamespaceNames:=nameParts))
End Function

Private Function CreateSearchResult(ParamArray results As PackageWithTypeResult()) As Task(Of ImmutableArray(Of PackageWithTypeResult))
Return Task.FromResult(ImmutableArray.Create(results))
Private Function CreateSearchResult(ParamArray results As PackageWithTypeResult()) As Task(Of IList(Of PackageWithTypeResult))
Return Task.FromResult(Of IList(Of PackageWithTypeResult))(ImmutableArray.Create(results))
End Function

Private Function CreateNameParts(ParamArray parts As String()) As ImmutableArray(Of String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class CSharpTodoCommentService : AbstractTodoCommentService
private static readonly int s_multilineCommentPostfixLength = "*/".Length;
private const string SingleLineCommentPrefix = "//";

protected override void AppendTodoComments(ImmutableArray<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
protected override void AppendTodoComments(IList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
{
if (PreprocessorHasComment(trivia))
{
Expand Down
5 changes: 3 additions & 2 deletions src/Features/Core/Portable/AddImport/AddImportFixData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis.CodeActions;
Expand All @@ -19,7 +20,7 @@ internal class AddImportFixData
/// May be empty for fixes that don't need to add an import and only do something like
/// add a project/metadata reference.
/// </summary>
public ImmutableArray<TextChange> TextChanges { get; }
public IList<TextChange> TextChanges { get; }

/// <summary>
/// String to display in the lightbulb menu.
Expand All @@ -29,7 +30,7 @@ internal class AddImportFixData
/// <summary>
/// Tags that control what glyph is displayed in the lightbulb menu.
/// </summary>
public ImmutableArray<string> Tags { get; private set; }
public IList<string> Tags { get; private set; }

/// <summary>
/// The priority this item should have in the lightbulb list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.AddImport
{
Expand Down Expand Up @@ -44,9 +45,9 @@ protected AddImportCodeAction(
FixData = fixData;

Title = fixData.Title;
Tags = fixData.Tags;
Tags = fixData.Tags.ToImmutableArrayOrEmpty();
Priority = fixData.Priority;
_textChanges = fixData.TextChanges;
_textChanges = fixData.TextChanges.ToImmutableArrayOrEmpty();
}

protected async Task<Document> GetUpdatedDocumentAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
Expand All @@ -19,12 +20,12 @@ private async Task<ImmutableArray<AddImportFixData>> GetFixesInRemoteProcessAsyn
string diagnosticId, bool placeSystemNamespaceFirst,
bool searchReferenceAssemblies, ImmutableArray<PackageSource> packageSources)
{
var result = await session.InvokeAsync<ImmutableArray<AddImportFixData>>(
var result = await session.InvokeAsync<IList<AddImportFixData>>(
nameof(IRemoteAddImportFeatureService.GetFixesAsync),
document.Id, span, diagnosticId, placeSystemNamespaceFirst,
searchReferenceAssemblies, packageSources).ConfigureAwait(false);

return result;
return result.AsImmutableOrEmpty();
}

/// <summary>
Expand Down Expand Up @@ -56,7 +57,7 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
throw new NotImplementedException();
}

public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(
public async Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
string source, string name, int arity)
{
var result = await _symbolSearchService.FindPackagesWithTypeAsync(
Expand All @@ -65,7 +66,7 @@ public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsy
return result;
}

public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
public async Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
string source, string name)
{
var result = await _symbolSearchService.FindPackagesWithAssemblyAsync(
Expand All @@ -74,7 +75,7 @@ public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAss
return result;
}

public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
public async Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
string name, int arity)
{
var result = await _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// 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.Threading.Tasks;
using Microsoft.CodeAnalysis.Packaging;
Expand All @@ -9,8 +10,8 @@ namespace Microsoft.CodeAnalysis.AddImport
{
internal interface IRemoteAddImportFeatureService
{
Task<ImmutableArray<AddImportFixData>> GetFixesAsync(
Task<IList<AddImportFixData>> GetFixesAsync(
DocumentId documentId, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
bool searchReferenceAssemblies, ImmutableArray<PackageSource> packageSources);
bool searchReferenceAssemblies, IList<PackageSource> packageSources);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Packaging;
using Microsoft.CodeAnalysis.SymbolSearch;
using Microsoft.CodeAnalysis.Utilities;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.AddImport
Expand Down Expand Up @@ -87,7 +88,7 @@ private async Task FindReferenceAssemblyTypeReferencesAsync(
cancellationToken.ThrowIfCancellationRequested();
var results = await _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
name, arity, cancellationToken).ConfigureAwait(false);
if (results.IsDefault)
if (results == null)
{
return;
}
Expand Down Expand Up @@ -118,7 +119,7 @@ private async Task FindNugetTypeReferencesAsync(
cancellationToken.ThrowIfCancellationRequested();
var results = await _symbolSearchService.FindPackagesWithTypeAsync(
source.Name, name, arity, cancellationToken).ConfigureAwait(false);
if (results.IsDefault)
if (results == null)
{
return;
}
Expand Down Expand Up @@ -160,7 +161,7 @@ private async Task HandleReferenceAssemblyReferenceAsync(

var desiredName = GetDesiredName(isAttributeSearch, result.TypeName);
allReferences.Add(new AssemblyReference(
_owner, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight), result));
_owner, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames.ToReadOnlyList(), weight), result));
}

private void HandleNugetReference(
Expand All @@ -174,7 +175,7 @@ private void HandleNugetReference(
{
var desiredName = GetDesiredName(isAttributeSearch, result.TypeName);
allReferences.Add(new PackageReference(_owner,
new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight),
new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames.ToReadOnlyList(), weight),
source, result.PackageName, result.Version));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ abstract class AbstractCrefCompletionProvider : CommonCompletionProvider
{
protected const string HideAdvancedMembers = nameof(HideAdvancedMembers);

protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(
Document document, CompletionItem item, CancellationToken cancellationToken)
{
var position = SymbolCompletionItem.GetContextPosition(item);
var position = await SymbolCompletionItem.GetContextPositionAsync(document, item, cancellationToken).ConfigureAwait(false);

// What EditorBrowsable settings were we previously passed in (if it mattered)?
bool hideAdvancedMembers = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private static int ComputeSymbolMatchPriority(ISymbol symbol)
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(
Document document, CompletionItem item, CancellationToken cancellationToken)
{
var position = SymbolCompletionItem.GetContextPosition(item);
var position = await SymbolCompletionItem.GetContextPositionAsync(document, item, cancellationToken).ConfigureAwait(false);
var name = SymbolCompletionItem.GetSymbolName(item);
var kind = SymbolCompletionItem.GetKind(item);
var relatedDocumentIds = document.Project.Solution.GetRelatedDocumentIds(document.Id).Concat(document.Id);
Expand Down
Loading

0 comments on commit 80db2d9

Please sign in to comment.