Skip to content

Commit

Permalink
Merge pull request #39518 from dotnet/merges/release/dev16.4-to-relea…
Browse files Browse the repository at this point in the history
…se/dev16.4-vs-deps

Merge release/dev16.4 to release/dev16.4-vs-deps
  • Loading branch information
msftbot[bot] committed Oct 25, 2019
2 parents e4396c0 + 23885cd commit b8a5611
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 88 deletions.
34 changes: 20 additions & 14 deletions src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.CodeAnalysis.ErrorLogger;
using Microsoft.CodeAnalysis.Extensions;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Shared.Utilities;
Expand Down Expand Up @@ -303,15 +304,17 @@ await AppendFixesOrConfigurationsAsync(
hasFix: d => this.GetFixableDiagnosticIds(fixer, extensionManager).Contains(d.Id),
getFixes: dxs =>
{
if (fixAllForInSpan)
using (RoslynEventSource.LogInformationalBlock(FunctionId.CodeFixes_GetCodeFixesAsync, fixer, cancellationToken))
{
var primaryDiagnostic = dxs.First();
return GetCodeFixesAsync(document, primaryDiagnostic.Location.SourceSpan, fixer, isBlocking, ImmutableArray.Create(primaryDiagnostic), cancellationToken);
}
else
{
return GetCodeFixesAsync(document, span, fixer, isBlocking, dxs, cancellationToken);
if (fixAllForInSpan)
{
var primaryDiagnostic = dxs.First();
return GetCodeFixesAsync(document, primaryDiagnostic.Location.SourceSpan, fixer, isBlocking, ImmutableArray.Create(primaryDiagnostic), cancellationToken);
}
else
{
return GetCodeFixesAsync(document, span, fixer, isBlocking, dxs, cancellationToken);
}
}
},
cancellationToken: cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -357,12 +360,15 @@ private async Task AppendConfigurationsAsync(
// append CodeFixCollection for each CodeFixProvider
foreach (var provider in lazyConfigurationProviders.Value)
{
await AppendFixesOrConfigurationsAsync(
document, diagnosticsSpan, diagnostics, fixAllForInSpan: false, result, provider,
hasFix: d => provider.IsFixableDiagnostic(d),
getFixes: dxs => provider.GetFixesAsync(
document, diagnosticsSpan, dxs, cancellationToken),
cancellationToken: cancellationToken).ConfigureAwait(false);
using (RoslynEventSource.LogInformationalBlock(FunctionId.CodeFixes_GetCodeFixesAsync, provider, cancellationToken))
{
await AppendFixesOrConfigurationsAsync(
document, diagnosticsSpan, diagnostics, fixAllForInSpan: false, result, provider,
hasFix: d => provider.IsFixableDiagnostic(d),
getFixes: dxs => provider.GetFixesAsync(
document, diagnosticsSpan, dxs, cancellationToken),
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ namespace Microsoft.CodeAnalysis.Editor.Implementation.IntelliSense.AsyncComplet
internal sealed class FilterSet
{
// Cache all the VS completion filters which essentially make them singletons.
// Because all items that should be filtered using the same filter button must
// use the same reference to the instance of CompletionFilter.
// Need to map item tags such as Class, Interface, Local, Enum to filter buttons.
// There can be tags mapping to the same button:
// Local -> Locals and Parameters, Parameter -> Locals and Parameters.
private static readonly ImmutableDictionary<string, FilterWithMask> s_filterMap;

// Distinct list of all filters.
// Need to iterate over a distinct list of filters
// to create a filter list covering a completion session.
private static readonly ImmutableArray<FilterWithMask> s_filters;

private BitVector32 _vector;
private static readonly int s_expanderMask;

Expand All @@ -54,7 +60,9 @@ internal sealed class FilterSet

static FilterSet()
{
var builder = ImmutableDictionary.CreateBuilder<string, FilterWithMask>();
var mapBuilder = ImmutableDictionary.CreateBuilder<string, FilterWithMask>();
var arrayBuilder = ImmutableArray.CreateBuilder<FilterWithMask>();

var previousMask = 0;

NamespaceFilter = CreateCompletionFilterAndAddToBuilder(FeaturesResources.Namespaces, 'n', WellKnownTags.Namespace);
Expand All @@ -75,7 +83,8 @@ static FilterSet()
SnippetFilter = CreateCompletionFilterAndAddToBuilder(FeaturesResources.Snippets, 't', WellKnownTags.Snippet);
TargetTypedFilter = CreateCompletionFilterAndAddToBuilder(FeaturesResources.Target_type_matches, 'j', WellKnownTags.TargetTypeMatch);

s_filterMap = builder.ToImmutable();
s_filterMap = mapBuilder.ToImmutable();
s_filters = arrayBuilder.ToImmutable();

s_expanderMask = BitVector32.CreateMask(previousMask);

Expand All @@ -91,9 +100,12 @@ CompletionFilter CreateCompletionFilterAndAddToBuilder(string displayText, char
var filter = CreateCompletionFilter(displayText, tags, accessKey);
previousMask = BitVector32.CreateMask(previousMask);

var filterWithMask = new FilterWithMask(filter, previousMask);
arrayBuilder.Add(filterWithMask);

foreach (var tag in tags)
{
builder.Add(tag, new FilterWithMask(filter, previousMask));
mapBuilder.Add(tag, filterWithMask);
}

return filter;
Expand Down Expand Up @@ -173,7 +185,7 @@ public ImmutableArray<CompletionFilterWithState> GetFilterStatesInSet(bool addUn
builder.Add(new CompletionFilterWithState(Expander, isAvailable: true, isSelected: false));
}

foreach (var filterWithMask in s_filterMap.Values)
foreach (var filterWithMask in s_filters)
{
if (_vector[filterWithMask.Mask])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ protected void SetExperimentOption(string experimentName, bool enabled)
private bool FiltersMatch(List<CompletionFilter> expectedMatchingFilters, RoslynCompletion.CompletionItem item)
{
var matchingFilters = FilterSet.GetFilters(item);

// Check that the list has no duplicates.
Assert.Equal(matchingFilters.Count, matchingFilters.Distinct().Count());
return expectedMatchingFilters.SetEquals(matchingFilters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ async Task<ImmutableArray<CodeRefactoring>> ICodeRefactoringService.GetRefactori
foreach (var provider in GetProviders(document))
{
tasks.Add(Task.Run(
() => GetRefactoringFromProviderAsync(document, state, provider, extensionManager, isBlocking, cancellationToken), cancellationToken));
() =>
{
using (RoslynEventSource.LogInformationalBlock(FunctionId.Refactoring_CodeRefactoringService_GetRefactoringsAsync, provider, cancellationToken))
{
return GetRefactoringFromProviderAsync(document, state, provider, extensionManager, isBlocking, cancellationToken);
}
},
cancellationToken));
}

var results = await Task.WhenAll(tasks).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Internal.Log;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
Expand Down Expand Up @@ -111,32 +113,35 @@ public async Task<bool> TryGetAsync(List<DiagnosticData> list, CancellationToken
var containsFullResult = true;
foreach (var stateSet in _stateSets)
{
cancellationToken.ThrowIfCancellationRequested();

containsFullResult &= await TryGetSyntaxAndSemanticDiagnosticsAsync(stateSet, list, cancellationToken).ConfigureAwait(false);

// check whether compilation end code fix is enabled
if (!_document.Project.Solution.Workspace.Options.GetOption(InternalDiagnosticsOptions.CompilationEndCodeFix))
using (RoslynEventSource.LogInformationalBlock(FunctionId.DiagnosticAnalyzerService_GetDiagnosticsForSpanAsync, stateSet.Analyzer, cancellationToken))
{
continue;
}
cancellationToken.ThrowIfCancellationRequested();

// check whether heuristic is enabled
if (_blockForData && _document.Project.Solution.Workspace.Options.GetOption(InternalDiagnosticsOptions.UseCompilationEndCodeFixHeuristic))
{
var avoidLoadingData = true;
var state = stateSet.GetProjectState(_project.Id);
var result = await state.GetAnalysisDataAsync(_document, avoidLoadingData, cancellationToken).ConfigureAwait(false);
containsFullResult &= await TryGetSyntaxAndSemanticDiagnosticsAsync(stateSet, list, cancellationToken).ConfigureAwait(false);

// no previous compilation end diagnostics in this file.
var version = await GetDiagnosticVersionAsync(_project, cancellationToken).ConfigureAwait(false);
if (state.IsEmpty(_document.Id) || result.Version != version)
// check whether compilation end code fix is enabled
if (!_document.Project.Solution.Workspace.Options.GetOption(InternalDiagnosticsOptions.CompilationEndCodeFix))
{
continue;
}
}

containsFullResult &= await TryGetProjectDiagnosticsAsync(stateSet, GetProjectDiagnosticsAsync, list, cancellationToken).ConfigureAwait(false);
// check whether heuristic is enabled
if (_blockForData && _document.Project.Solution.Workspace.Options.GetOption(InternalDiagnosticsOptions.UseCompilationEndCodeFixHeuristic))
{
var avoidLoadingData = true;
var state = stateSet.GetProjectState(_project.Id);
var result = await state.GetAnalysisDataAsync(_document, avoidLoadingData, cancellationToken).ConfigureAwait(false);

// no previous compilation end diagnostics in this file.
var version = await GetDiagnosticVersionAsync(_project, cancellationToken).ConfigureAwait(false);
if (state.IsEmpty(_document.Id) || result.Version != version)
{
continue;
}
}

containsFullResult &= await TryGetProjectDiagnosticsAsync(stateSet, GetProjectDiagnosticsAsync, list, cancellationToken).ConfigureAwait(false);
}
}

// if we are blocked for data, then we should always have full result.
Expand Down
6 changes: 3 additions & 3 deletions src/Workspaces/Core/Portable/Log/EtwLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ public void Log(FunctionId functionId, LogMessage logMessage)

public void LogBlockStart(FunctionId functionId, LogMessage logMessage, int uniquePairId, CancellationToken cancellationToken)
{
RoslynEventSource.Instance.BlockStart(GetMessage(logMessage), functionId, uniquePairId);
_source.BlockStart(GetMessage(logMessage), functionId, uniquePairId);
}

public void LogBlockEnd(FunctionId functionId, LogMessage logMessage, int uniquePairId, int delta, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
RoslynEventSource.Instance.BlockCanceled(functionId, delta, uniquePairId);
_source.BlockCanceled(functionId, delta, uniquePairId);
}
else
{
RoslynEventSource.Instance.BlockStop(functionId, delta, uniquePairId);
_source.BlockStop(functionId, delta, uniquePairId);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Workspaces/Core/Portable/Log/FunctionId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,8 @@ internal enum FunctionId
Liveshare_SyntacticTagger,

CommandHandler_GoToBase,

DiagnosticAnalyzerService_GetDiagnosticsForSpanAsync,
CodeFixes_GetCodeFixesAsync,
}
}
Loading

0 comments on commit b8a5611

Please sign in to comment.