Skip to content

Commit

Permalink
2
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Feb 4, 2022
1 parent 798045e commit 0387a9f
Show file tree
Hide file tree
Showing 23 changed files with 172 additions and 177 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.Classification
{
internal static class ClassificationOptionsStorage
{
public static ClassificationOptions GetClassificationOptions(this IGlobalOptionService globalOptions, string language)
=> new(
ClassifyReassignedVariables: globalOptions.GetOption(ClassifyReassignedVariables, language),
ColorizeRegexPatterns: globalOptions.GetOption(ColorizeRegexPatterns, language),
ColorizeJsonPatterns: globalOptions.GetOption(ColorizeJsonPatterns, language));

public static PerLanguageOption2<bool> ClassifyReassignedVariables =
new("ClassificationOptions", "ClassifyReassignedVariables", ClassificationOptions.Default.ClassifyReassignedVariables,
storageLocation: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.ClassificationOptions.ClassifyReassignedVariables"));

public static PerLanguageOption2<bool> ColorizeRegexPatterns =
new("RegularExpressionsOptions", "ColorizeRegexPatterns", ClassificationOptions.Default.ColorizeRegexPatterns,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorizeRegexPatterns"));

public static PerLanguageOption2<bool> ColorizeJsonPatterns =
new("JsonFeatureOptions", "ColorizeJsonPatterns", ClassificationOptions.Default.ColorizeJsonPatterns,
storageLocation: new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ColorizeJsonPatterns"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ protected override ITaggerEventSource CreateEventSource(ITextView textViewOpt, I
TaggerEventSources.OnViewSpanChanged(ThreadingContext, textViewOpt),
TaggerEventSources.OnWorkspaceChanged(subjectBuffer, _listener),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsGlobalStateOption.DisplayAllOverride),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.EnabledForParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForLiteralParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForIndexerParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForObjectCreationParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForOtherParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.SuppressForParametersThatMatchMethodIntent),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.SuppressForParametersThatDifferOnlyBySuffix),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.SuppressForParametersThatMatchArgumentName),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.EnabledForTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForImplicitVariableTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForLambdaParameterTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsMetadata.ForImplicitObjectCreation));
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.EnabledForParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForLiteralParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForIndexerParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForObjectCreationParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForOtherParameters),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.SuppressForParametersThatMatchMethodIntent),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.SuppressForParametersThatDifferOnlyBySuffix),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.SuppressForParametersThatMatchArgumentName),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.EnabledForTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForImplicitVariableTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForLambdaParameterTypes),
TaggerEventSources.OnOptionChanged(subjectBuffer, InlineHintsOptionsStorage.ForImplicitObjectCreation));
}

protected override IEnumerable<SnapshotSpan> GetSpansToTag(ITextView textView, ITextBuffer subjectBuffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.CodeAnalysis.InlineHints
{
internal static class InlineHintsOptionsMetadata
internal static class InlineHintsOptionsStorage
{
public static InlineHintsOptions GetInlineHintsOptions(this IGlobalOptionService globalOptions, string language)
=> new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.CodeAnalysis.QuickInfo
{
internal static class QuickInfoOptionsMetadata
internal static class QuickInfoOptionsStorage
{
public static QuickInfoOptions GetQuickInfoOptions(this IGlobalOptionService globalOptions, string? language)
=> new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private async Task<ImmutableArray<DocumentHighlights>> GetTagsForReferencedSymbo
{
var progress = new StreamingProgressCollector();

var options = FindSymbols.FindReferencesSearchOptions.GetFeatureOptionsForStartingSymbol(symbol);
var options = FindReferencesSearchOptions.GetFeatureOptionsForStartingSymbol(symbol);
await SymbolFinder.FindReferencesAsync(
symbol, document.Project.Solution, progress,
documentsToSearch, options, cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private class FindReferencesProgressAdapter : IStreamingFindReferencesProgress
{
private readonly Solution _solution;
private readonly IFindUsagesContext _context;
private readonly FindReferencesSearchOptions _options;
private readonly FindReferencesSearchOptions Options;

/// <summary>
/// We will hear about definition symbols many times while performing FAR. We'll
Expand All @@ -80,7 +80,7 @@ public FindReferencesProgressAdapter(
{
_solution = solution;
_context = context;
_options = options;
Options = options;
}

// Do nothing functions. The streaming far service doesn't care about
Expand All @@ -104,7 +104,7 @@ private async ValueTask<DefinitionItem> GetDefinitionItemAsync(SymbolGroup group
_solution,
isPrimary: _definitionToItem.Count == 0,
includeHiddenLocations: false,
_options,
Options,
cancellationToken).ConfigureAwait(false);

_definitionToItem[group] = definitionItem;
Expand All @@ -120,11 +120,11 @@ public async ValueTask OnDefinitionFoundAsync(SymbolGroup group, CancellationTok
await _context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false);
}

public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, CancellationToken cancellationToken)
public async ValueTask OnReferenceFoundAsync(SymbolGroup group, ISymbol definition, ReferenceLocation location, ClassificationOptions classificationOptions, CancellationToken cancellationToken)
{
var definitionItem = await GetDefinitionItemAsync(group, cancellationToken).ConfigureAwait(false);
var referenceItem = await location.TryCreateSourceReferenceItemAsync(
definitionItem, includeHiddenLocations: false,
definitionItem, classificationOptions, includeHiddenLocations: false,
cancellationToken).ConfigureAwait(false);

if (referenceItem != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ namespace Microsoft.CodeAnalysis.FindUsages
internal abstract partial class AbstractFindUsagesService
{
async Task IFindUsagesService.FindReferencesAsync(
Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken)
Document document, int position, IFindUsagesContext context, FindUsagesOptions options, CancellationToken cancellationToken)
{
var definitionTrackingContext = new DefinitionTrackingContext(context);

await FindLiteralOrSymbolReferencesAsync(
document, position, definitionTrackingContext, cancellationToken).ConfigureAwait(false);
document, position, definitionTrackingContext, options, cancellationToken).ConfigureAwait(false);

// After the FAR engine is done call into any third party extensions to see
// if they want to add results.
Expand All @@ -38,23 +38,23 @@ await FindLiteralOrSymbolReferencesAsync(
}

Task IFindUsagesLSPService.FindReferencesAsync(
Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken)
Document document, int position, IFindUsagesContext context, FindUsagesOptions options, CancellationToken cancellationToken)
{
// We don't need to get third party definitions when finding references in LSP.
// Currently, 3rd party definitions = XAML definitions, and XAML will provide
// references via LSP instead of hooking into Roslyn.
// This also means that we don't need to be on the UI thread.
return FindLiteralOrSymbolReferencesAsync(
document, position, new DefinitionTrackingContext(context), cancellationToken);
document, position, new DefinitionTrackingContext(context), options, cancellationToken);
}

private static async Task FindLiteralOrSymbolReferencesAsync(
Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken)
Document document, int position, IFindUsagesContext context, FindUsagesOptions options, CancellationToken cancellationToken)
{
// First, see if we're on a literal. If so search for literals in the solution with
// the same value.
var found = await TryFindLiteralReferencesAsync(
document, position, context, cancellationToken).ConfigureAwait(false);
document, position, context, options, cancellationToken).ConfigureAwait(false);
if (found)
{
return;
Expand Down Expand Up @@ -165,7 +165,7 @@ private static Task FindReferencesInCurrentProcessAsync(
}

private static async Task<bool> TryFindLiteralReferencesAsync(
Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken)
Document document, int position, IFindUsagesContext context, FindUsagesOptions options, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -225,8 +225,7 @@ private static async Task<bool> TryFindLiteralReferencesAsync(

await context.OnDefinitionFoundAsync(definition, cancellationToken).ConfigureAwait(false);

var classificationOptions = ClassificationOptions.From(document.Project);
var progressAdapter = new FindLiteralsProgressAdapter(context, definition, classificationOptions);
var progressAdapter = new FindLiteralsProgressAdapter(context, definition, options.ClassificationOptions);

// Now call into the underlying FAR engine to find reference. The FAR
// engine will push results into the 'progress' instance passed into it.
Expand Down
11 changes: 11 additions & 0 deletions src/Features/Core/Portable/FindUsages/FindUsagesOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.CodeAnalysis.Classification;

namespace Microsoft.CodeAnalysis.FindUsages
{
internal readonly record struct FindUsagesOptions(
ClassificationOptions ClassificationOptions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ private static ImmutableDictionary<string, string> GetProperties(ISymbol definit
public static async Task<SourceReferenceItem?> TryCreateSourceReferenceItemAsync(
this ReferenceLocation referenceLocation,
DefinitionItem definitionItem,
ClassificationOptions classificationOptions,
bool includeHiddenLocations,
CancellationToken cancellationToken)
{
Expand All @@ -240,10 +241,9 @@ private static ImmutableDictionary<string, string> GetProperties(ISymbol definit

var document = referenceLocation.Document;
var sourceSpan = location.SourceSpan;
var options = ClassificationOptions.From(document.Project);

var documentSpan = await ClassifiedSpansAndHighlightSpanFactory.GetClassifiedDocumentSpanAsync(
document, sourceSpan, options, cancellationToken).ConfigureAwait(false);
document, sourceSpan, classificationOptions, cancellationToken).ConfigureAwait(false);

return new SourceReferenceItem(definitionItem, documentSpan, referenceLocation.SymbolUsageInfo, referenceLocation.AdditionalProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host;

namespace Microsoft.CodeAnalysis.FindUsages
Expand All @@ -15,7 +14,7 @@ internal interface IFindUsagesLSPService : ILanguageService
/// Finds the references for the symbol at the specific position in the document,
/// pushing the results into the context instance.
/// </summary>
Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken);
Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, FindUsagesOptions options, CancellationToken cancellationToken);

/// <summary>
/// Finds the implementations for the symbol at the specific position in the document,
Expand Down
3 changes: 1 addition & 2 deletions src/Features/Core/Portable/FindUsages/IFindUsagesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.FindUsages;
using Microsoft.CodeAnalysis.Host;

namespace Microsoft.CodeAnalysis.FindUsages
Expand All @@ -15,7 +14,7 @@ internal interface IFindUsagesService : ILanguageService
/// Finds the references for the symbol at the specific position in the document,
/// pushing the results into the context instance.
/// </summary>
Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, CancellationToken cancellationToken);
Task FindReferencesAsync(Document document, int position, IFindUsagesContext context, FindUsagesOptions options, CancellationToken cancellationToken);

/// <summary>
/// Finds the implementations for the symbol at the specific position in the document,
Expand Down
9 changes: 5 additions & 4 deletions src/Features/Core/Portable/InlineHints/InlineHintsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Serialization;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.InlineHints
{
[DataContract]
internal readonly record struct InlineHintsOptions(
InlineParameterHintsOptions ParameterOptions,
InlineTypeHintsOptions TypeOptions,
SymbolDescriptionOptions DisplayOptions);
[property: DataMember(Order = 0)] InlineParameterHintsOptions ParameterOptions,
[property: DataMember(Order = 1)] InlineTypeHintsOptions TypeOptions,
[property: DataMember(Order = 2)] SymbolDescriptionOptions DisplayOptions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ internal readonly record struct InlineParameterHintsOptions(
[property: DataMember(Order = 6)] bool SuppressForParametersThatMatchMethodIntent = true,
[property: DataMember(Order = 7)] bool SuppressForParametersThatMatchArgumentName = true)
{
// note: must pass at least one parameter to avoid calling default ctor:
public static readonly InlineParameterHintsOptions Default = new(EnabledForParameters: false);
public InlineParameterHintsOptions()
: this(EnabledForParameters: false)
{
}

public static readonly InlineParameterHintsOptions Default = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ internal readonly record struct InlineTypeHintsOptions(
[property: DataMember(Order = 2)] bool ForLambdaParameterTypes = true,
[property: DataMember(Order = 3)] bool ForImplicitObjectCreation = true)
{
// note: must pass at least one parameter to avoid calling default ctor:
public static readonly InlineTypeHintsOptions Default = new(EnabledForTypes: false);
public InlineTypeHintsOptions()
: this(EnabledForTypes: false)
{
}

public static readonly InlineTypeHintsOptions Default = new();
}
}
8 changes: 6 additions & 2 deletions src/Features/Core/Portable/QuickInfo/QuickInfoOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ internal readonly record struct QuickInfoOptions(
[property: DataMember(Order = 0)] bool ShowRemarksInQuickInfo = true,
[property: DataMember(Order = 1)] bool IncludeNavigationHintsInQuickInfo = true)
{
// note: must pass at least one parameter to avoid calling default ctor:
public static readonly QuickInfoOptions Default = new(ShowRemarksInQuickInfo: true);
public QuickInfoOptions()
: this(ShowRemarksInQuickInfo: true)
{
}

public static readonly QuickInfoOptions Default = new();
}
}
Loading

0 comments on commit 0387a9f

Please sign in to comment.