Skip to content

Commit 80db2d9

Browse files
authored
Merge pull request #21598 from dotnet/dev15.3.x
merge dev15.3.x to dev15.4.x
2 parents c143577 + aca31f6 commit 80db2d9

File tree

42 files changed

+244
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+244
-122
lines changed

src/Compilers/Core/Portable/InternalUtilities/EnumerableExtensions.cs

+15
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System;
44
using System.Collections;
55
using System.Collections.Generic;
6+
using System.Collections.Immutable;
67
using System.Collections.ObjectModel;
78
using System.Diagnostics;
89
using System.Linq;
10+
using Microsoft.CodeAnalysis;
911

1012
namespace Roslyn.Utilities
1113
{
@@ -242,6 +244,19 @@ public static IEnumerable<T> WhereNotNull<T>(this IEnumerable<T> source)
242244
return source.Where((Func<T, bool>)s_notNullTest);
243245
}
244246

247+
public static ImmutableArray<TResult> SelectAsArray<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TResult> selector)
248+
{
249+
if (source == null)
250+
{
251+
return ImmutableArray<TResult>.Empty;
252+
}
253+
254+
var builder = ArrayBuilder<TResult>.GetInstance();
255+
builder.AddRange(source.Select(selector));
256+
257+
return builder.ToImmutableAndFree();
258+
}
259+
245260
public static bool All(this IEnumerable<bool> source)
246261
{
247262
if (source == null)

src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests_NuGet.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,16 @@ await TestInRegularAndScriptAsync(
257257
installerServiceMock.Verify();
258258
}
259259

260-
private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(
260+
private Task<IList<PackageWithTypeResult>> CreateSearchResult(
261261
string packageName, string typeName, ImmutableArray<string> containingNamespaceNames)
262262
{
263263
return CreateSearchResult(new PackageWithTypeResult(
264264
packageName: packageName, typeName: typeName, version: null,
265265
rank: 0, containingNamespaceNames: containingNamespaceNames));
266266
}
267267

268-
private Task<ImmutableArray<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
269-
=> Task.FromResult(ImmutableArray.Create(results));
268+
private Task<IList<PackageWithTypeResult>> CreateSearchResult(params PackageWithTypeResult[] results)
269+
=> Task.FromResult<IList<PackageWithTypeResult>>(ImmutableArray.Create(results));
270270

271271
private ImmutableArray<string> CreateNameParts(params string[] parts) => parts.ToImmutableArray();
272272
}

src/EditorFeatures/CSharpTest/Completion/CompletionProviders/SymbolCompletionProviderTests_NoInteractive.cs

+35
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
using System.Linq;
34
using System.Threading.Tasks;
45
using Microsoft.CodeAnalysis.Completion;
56
using Microsoft.CodeAnalysis.CSharp.Completion.Providers;
67
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders;
78
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
9+
using Microsoft.VisualStudio.Text;
810
using Roslyn.Test.Utilities;
911
using Xunit;
1012

@@ -320,5 +322,38 @@ class C { void M() { B.$$ } }
320322
await VerifyItemExistsAsync(code, "X");
321323
await VerifyItemExistsAsync(code, "Y");
322324
}
325+
326+
[WorkItem(209299, "https://devdiv.visualstudio.com/DevDiv/_workitems?id=209299")]
327+
[Fact, Trait(Traits.Feature, Traits.Features.Completion)]
328+
public async Task TestDescriptionWhenDocumentLengthChanges()
329+
{
330+
var code = @"using System;
331+
332+
class C
333+
{
334+
string Property
335+
{
336+
get
337+
{
338+
Console.$$";//, @"Beep"
339+
340+
using (var workspace = TestWorkspace.CreateCSharp(code))
341+
{
342+
var testDocument = workspace.Documents.Single();
343+
var position = testDocument.CursorPosition.Value;
344+
345+
var document = workspace.CurrentSolution.GetDocument(testDocument.Id);
346+
var service = CompletionService.GetService(document);
347+
var completions = await service.GetCompletionsAsync(document, position);
348+
349+
var item = completions.Items.First(i => i.DisplayText == "Beep");
350+
var edit = testDocument.GetTextBuffer().CreateEdit();
351+
edit.Delete(Span.FromBounds(position - 10, position));
352+
edit.Apply();
353+
354+
document = workspace.CurrentSolution.GetDocument(testDocument.Id);
355+
var description = service.GetDescriptionAsync(document, item);
356+
}
357+
}
323358
}
324359
}

src/EditorFeatures/Core/Implementation/TodoComment/TodoCommentIncrementalAnalyzer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public async Task AnalyzeSyntaxAsync(Document document, InvocationReasons reason
8787
}
8888
}
8989

90-
private async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, ImmutableArray<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
90+
private async Task<IList<TodoComment>> GetTodoCommentsAsync(Document document, IList<TodoCommentDescriptor> tokens, CancellationToken cancellationToken)
9191
{
9292
var service = document.GetLanguageService<ITodoCommentService>();
9393
if (service == null)

src/EditorFeatures/Core/SymbolSearch/SymbolSearchUpdateEngineFactory.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
using System.Collections.Generic;
34
using System.Collections.Immutable;
45
using System.Linq;
56
using System.Threading;
@@ -122,11 +123,11 @@ public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsy
122123
return ImmutableArray<PackageWithTypeResult>.Empty;
123124
}
124125

125-
var results = await session.InvokeAsync<ImmutableArray<PackageWithTypeResult>>(
126+
var results = await session.InvokeAsync<IList<PackageWithTypeResult>>(
126127
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithTypeAsync),
127128
source, name, arity).ConfigureAwait(false);
128129

129-
return results;
130+
return results.ToImmutableArrayOrEmpty();
130131
}
131132

132133
public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
@@ -139,11 +140,11 @@ public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAss
139140
return ImmutableArray<PackageWithAssemblyResult>.Empty;
140141
}
141142

142-
var results = await session.InvokeAsync<ImmutableArray<PackageWithAssemblyResult>>(
143+
var results = await session.InvokeAsync<IList<PackageWithAssemblyResult>>(
143144
nameof(IRemoteSymbolSearchUpdateEngine.FindPackagesWithAssemblyAsync),
144145
source, assemblyName).ConfigureAwait(false);
145146

146-
return results;
147+
return results.ToImmutableArrayOrEmpty();
147148
}
148149

149150
public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
@@ -156,11 +157,11 @@ public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReference
156157
return ImmutableArray<ReferenceAssemblyWithTypeResult>.Empty;
157158
}
158159

159-
var results = await session.InvokeAsync<ImmutableArray<ReferenceAssemblyWithTypeResult>>(
160+
var results = await session.InvokeAsync<IList<ReferenceAssemblyWithTypeResult>>(
160161
nameof(IRemoteSymbolSearchUpdateEngine.FindReferenceAssembliesWithTypeAsync),
161162
name, arity).ConfigureAwait(false);
162163

163-
return results;
164+
return results.ToImmutableArrayOrEmpty();
164165
}
165166

166167
public async Task UpdateContinuouslyAsync(

src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
239239
installerServiceMock.Verify()
240240
End Function
241241

242-
Private Function CreateSearchResult(packageName As String, typeName As String, nameParts As ImmutableArray(Of String)) As Task(Of ImmutableArray(Of PackageWithTypeResult))
242+
Private Function CreateSearchResult(packageName As String, typeName As String, nameParts As ImmutableArray(Of String)) As Task(Of IList(Of PackageWithTypeResult))
243243
Return CreateSearchResult(New PackageWithTypeResult(
244244
packageName:=packageName,
245245
typeName:=typeName,
@@ -248,8 +248,8 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
248248
containingNamespaceNames:=nameParts))
249249
End Function
250250

251-
Private Function CreateSearchResult(ParamArray results As PackageWithTypeResult()) As Task(Of ImmutableArray(Of PackageWithTypeResult))
252-
Return Task.FromResult(ImmutableArray.Create(results))
251+
Private Function CreateSearchResult(ParamArray results As PackageWithTypeResult()) As Task(Of IList(Of PackageWithTypeResult))
252+
Return Task.FromResult(Of IList(Of PackageWithTypeResult))(ImmutableArray.Create(results))
253253
End Function
254254

255255
Private Function CreateNameParts(ParamArray parts As String()) As ImmutableArray(Of String)

src/Features/CSharp/Portable/TodoComments/CSharpTodoCommentIncrementalAnalyzerProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal class CSharpTodoCommentService : AbstractTodoCommentService
1717
private static readonly int s_multilineCommentPostfixLength = "*/".Length;
1818
private const string SingleLineCommentPrefix = "//";
1919

20-
protected override void AppendTodoComments(ImmutableArray<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
20+
protected override void AppendTodoComments(IList<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
2121
{
2222
if (PreprocessorHasComment(trivia))
2323
{

src/Features/Core/Portable/AddImport/AddImportFixData.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

33
using System;
4+
using System.Collections.Generic;
45
using System.Collections.Immutable;
56
using System.Linq;
67
using Microsoft.CodeAnalysis.CodeActions;
@@ -19,7 +20,7 @@ internal class AddImportFixData
1920
/// May be empty for fixes that don't need to add an import and only do something like
2021
/// add a project/metadata reference.
2122
/// </summary>
22-
public ImmutableArray<TextChange> TextChanges { get; }
23+
public IList<TextChange> TextChanges { get; }
2324

2425
/// <summary>
2526
/// String to display in the lightbulb menu.
@@ -29,7 +30,7 @@ internal class AddImportFixData
2930
/// <summary>
3031
/// Tags that control what glyph is displayed in the lightbulb menu.
3132
/// </summary>
32-
public ImmutableArray<string> Tags { get; private set; }
33+
public IList<string> Tags { get; private set; }
3334

3435
/// <summary>
3536
/// The priority this item should have in the lightbulb list.

src/Features/Core/Portable/AddImport/CodeActions/AddImportCodeAction.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Threading.Tasks;
66
using Microsoft.CodeAnalysis.CodeActions;
77
using Microsoft.CodeAnalysis.Text;
8+
using Roslyn.Utilities;
89

910
namespace Microsoft.CodeAnalysis.AddImport
1011
{
@@ -44,9 +45,9 @@ protected AddImportCodeAction(
4445
FixData = fixData;
4546

4647
Title = fixData.Title;
47-
Tags = fixData.Tags;
48+
Tags = fixData.Tags.ToImmutableArrayOrEmpty();
4849
Priority = fixData.Priority;
49-
_textChanges = fixData.TextChanges;
50+
_textChanges = fixData.TextChanges.ToImmutableArrayOrEmpty();
5051
}
5152

5253
protected async Task<Document> GetUpdatedDocumentAsync(CancellationToken cancellationToken)

src/Features/Core/Portable/AddImport/Remote/AbstractAddImportFeatureService_Remote.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

33
using System;
4+
using System.Collections.Generic;
45
using System.Collections.Immutable;
56
using System.Linq;
67
using System.Threading;
@@ -19,12 +20,12 @@ private async Task<ImmutableArray<AddImportFixData>> GetFixesInRemoteProcessAsyn
1920
string diagnosticId, bool placeSystemNamespaceFirst,
2021
bool searchReferenceAssemblies, ImmutableArray<PackageSource> packageSources)
2122
{
22-
var result = await session.InvokeAsync<ImmutableArray<AddImportFixData>>(
23+
var result = await session.InvokeAsync<IList<AddImportFixData>>(
2324
nameof(IRemoteAddImportFeatureService.GetFixesAsync),
2425
document.Id, span, diagnosticId, placeSystemNamespaceFirst,
2526
searchReferenceAssemblies, packageSources).ConfigureAwait(false);
2627

27-
return result;
28+
return result.AsImmutableOrEmpty();
2829
}
2930

3031
/// <summary>
@@ -56,7 +57,7 @@ public Task UpdateContinuouslyAsync(string sourceName, string localSettingsDirec
5657
throw new NotImplementedException();
5758
}
5859

59-
public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsync(
60+
public async Task<IList<PackageWithTypeResult>> FindPackagesWithTypeAsync(
6061
string source, string name, int arity)
6162
{
6263
var result = await _symbolSearchService.FindPackagesWithTypeAsync(
@@ -65,7 +66,7 @@ public async Task<ImmutableArray<PackageWithTypeResult>> FindPackagesWithTypeAsy
6566
return result;
6667
}
6768

68-
public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
69+
public async Task<IList<PackageWithAssemblyResult>> FindPackagesWithAssemblyAsync(
6970
string source, string name)
7071
{
7172
var result = await _symbolSearchService.FindPackagesWithAssemblyAsync(
@@ -74,7 +75,7 @@ public async Task<ImmutableArray<PackageWithAssemblyResult>> FindPackagesWithAss
7475
return result;
7576
}
7677

77-
public async Task<ImmutableArray<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
78+
public async Task<IList<ReferenceAssemblyWithTypeResult>> FindReferenceAssembliesWithTypeAsync(
7879
string name, int arity)
7980
{
8081
var result = await _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

3+
using System.Collections.Generic;
34
using System.Collections.Immutable;
45
using System.Threading.Tasks;
56
using Microsoft.CodeAnalysis.Packaging;
@@ -9,8 +10,8 @@ namespace Microsoft.CodeAnalysis.AddImport
910
{
1011
internal interface IRemoteAddImportFeatureService
1112
{
12-
Task<ImmutableArray<AddImportFixData>> GetFixesAsync(
13+
Task<IList<AddImportFixData>> GetFixesAsync(
1314
DocumentId documentId, TextSpan span, string diagnosticId, bool placeSystemNamespaceFirst,
14-
bool searchReferenceAssemblies, ImmutableArray<PackageSource> packageSources);
15+
bool searchReferenceAssemblies, IList<PackageSource> packageSources);
1516
}
1617
}

src/Features/Core/Portable/AddImport/SymbolReferenceFinder_PackageAssemblySearch.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Microsoft.CodeAnalysis.Packaging;
66
using Microsoft.CodeAnalysis.SymbolSearch;
7+
using Microsoft.CodeAnalysis.Utilities;
78
using Roslyn.Utilities;
89

910
namespace Microsoft.CodeAnalysis.AddImport
@@ -87,7 +88,7 @@ private async Task FindReferenceAssemblyTypeReferencesAsync(
8788
cancellationToken.ThrowIfCancellationRequested();
8889
var results = await _symbolSearchService.FindReferenceAssembliesWithTypeAsync(
8990
name, arity, cancellationToken).ConfigureAwait(false);
90-
if (results.IsDefault)
91+
if (results == null)
9192
{
9293
return;
9394
}
@@ -118,7 +119,7 @@ private async Task FindNugetTypeReferencesAsync(
118119
cancellationToken.ThrowIfCancellationRequested();
119120
var results = await _symbolSearchService.FindPackagesWithTypeAsync(
120121
source.Name, name, arity, cancellationToken).ConfigureAwait(false);
121-
if (results.IsDefault)
122+
if (results == null)
122123
{
123124
return;
124125
}
@@ -160,7 +161,7 @@ private async Task HandleReferenceAssemblyReferenceAsync(
160161

161162
var desiredName = GetDesiredName(isAttributeSearch, result.TypeName);
162163
allReferences.Add(new AssemblyReference(
163-
_owner, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight), result));
164+
_owner, new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames.ToReadOnlyList(), weight), result));
164165
}
165166

166167
private void HandleNugetReference(
@@ -174,7 +175,7 @@ private void HandleNugetReference(
174175
{
175176
var desiredName = GetDesiredName(isAttributeSearch, result.TypeName);
176177
allReferences.Add(new PackageReference(_owner,
177-
new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames, weight),
178+
new SearchResult(desiredName, nameNode, result.ContainingNamespaceNames.ToReadOnlyList(), weight),
178179
source, result.PackageName, result.Version));
179180
}
180181

src/Features/Core/Portable/Completion/Providers/AbstractCrefCompletionProvider.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ abstract class AbstractCrefCompletionProvider : CommonCompletionProvider
1111
{
1212
protected const string HideAdvancedMembers = nameof(HideAdvancedMembers);
1313

14-
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(Document document, CompletionItem item, CancellationToken cancellationToken)
14+
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(
15+
Document document, CompletionItem item, CancellationToken cancellationToken)
1516
{
16-
var position = SymbolCompletionItem.GetContextPosition(item);
17+
var position = await SymbolCompletionItem.GetContextPositionAsync(document, item, cancellationToken).ConfigureAwait(false);
1718

1819
// What EditorBrowsable settings were we previously passed in (if it mattered)?
1920
bool hideAdvancedMembers = false;

src/Features/Core/Portable/Completion/Providers/AbstractRecommendationServiceBasedCompletionProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private static int ComputeSymbolMatchPriority(ISymbol symbol)
108108
protected override async Task<CompletionDescription> GetDescriptionWorkerAsync(
109109
Document document, CompletionItem item, CancellationToken cancellationToken)
110110
{
111-
var position = SymbolCompletionItem.GetContextPosition(item);
111+
var position = await SymbolCompletionItem.GetContextPositionAsync(document, item, cancellationToken).ConfigureAwait(false);
112112
var name = SymbolCompletionItem.GetSymbolName(item);
113113
var kind = SymbolCompletionItem.GetKind(item);
114114
var relatedDocumentIds = document.Project.Solution.GetRelatedDocumentIds(document.Id).Concat(document.Id);

0 commit comments

Comments
 (0)