Skip to content

Commit

Permalink
Convert HideAdvancedMembers global option to editorconfig option
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Jul 12, 2024
1 parent e231014 commit 12dc70c
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Tags;
using Microsoft.CodeAnalysis.Test.Utilities;
Expand Down Expand Up @@ -6365,7 +6365,7 @@ static void Main(string[] args)
</Workspace>";

await TestMissingAsync(initialWorkspace, new TestParameters(
globalOptions: Option(CompletionOptionsStorage.HideAdvancedMembers, true),
globalOptions: Option(MemberDisplayOptionsStorage.HideAdvancedMembers, true),
testHost: testHost));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Microsoft.CodeAnalysis.AddImportOnPaste;
using Microsoft.CodeAnalysis.AddMissingImports;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editor.BackgroundWorkIndicator;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
Expand Down Expand Up @@ -157,7 +156,7 @@ private async Task ExecuteAsync(Document document, SnapshotSpan snapshotSpan, IT

var options = new AddMissingImportsOptions(
CleanupOptions: cleanupOptions,
HideAdvancedMembers: _globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, document.Project.Language));
HideAdvancedMembers: _globalOptions.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, document.Project.Language));

var textSpan = snapshotSpan.Span.ToTextSpan();
var updatedDocument = await addMissingImportsService.AddMissingImportsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.AddMissingImports;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Extensions;
Expand Down Expand Up @@ -57,7 +56,7 @@ private async Task<AddMissingImportsOptions> GetOptionsAsync(Document document,

var options = new AddMissingImportsOptions(
CleanupOptions: cleanupOptions,
HideAdvancedMembers: _globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, document.Project.Language));
HideAdvancedMembers: _globalOptions.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, document.Project.Language));

return options;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Features/CSharpTest/FullyQualify/FullyQualifyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp.CodeFixes.FullyQualify;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Remote.Testing;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
Expand Down Expand Up @@ -1656,7 +1656,7 @@ static void Main(string[] args)
</Workspace>";

await TestMissingAsync(initialWorkspace, new TestParameters(
globalOptions: Option(CompletionOptionsStorage.HideAdvancedMembers, true),
globalOptions: Option(MemberDisplayOptionsStorage.HideAdvancedMembers, true),
testHost: testHost));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.CodeStyle;
using Microsoft.CodeAnalysis.CSharp.ImplementAbstractClass;
Expand All @@ -14,6 +13,7 @@
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -1880,7 +1880,7 @@ public async Task TestAutoProperties()
var options = new OptionsCollection(GetLanguage())
{
Option(ImplementTypeOptionsStorage.PropertyGenerationBehavior, ImplementTypePropertyGenerationBehavior.PreferAutoProperties),
Option(CompletionOptionsStorage.HideAdvancedMembers, true),
Option(MemberDisplayOptionsStorage.HideAdvancedMembers, true),
};

await TestInRegularAndScript1Async(
Expand Down
4 changes: 3 additions & 1 deletion src/Features/Core/Portable/Completion/CompletionOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// 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.Collections.Immutable;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Recommendations;
using Microsoft.CodeAnalysis.Shared;

Expand All @@ -16,7 +18,7 @@ internal sealed record class CompletionOptions
public bool TriggerInArgumentLists { get; init; } = true;
public EnterKeyRule EnterKeyBehavior { get; init; } = EnterKeyRule.Default;
public SnippetsRule SnippetsBehavior { get; init; } = SnippetsRule.Default;
public bool HideAdvancedMembers { get; init; } = false;
public bool HideAdvancedMembers { get; init; } = MemberDisplayOptionsStorage.HideAdvancedMembers.DefaultValue;
public bool ShowNameSuggestions { get; init; } = true;
public bool? ShowItemsFromUnimportedNamespaces { get; init; } = true;
public bool UnnamedSymbolCompletionDisabled { get; init; } = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Composition;
using System.Linq;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Features.EmbeddedLanguages.Json.LanguageServices;
using Microsoft.CodeAnalysis.Features.EmbeddedLanguages.RegularExpressions.LanguageServices;
Expand All @@ -31,7 +32,11 @@ internal sealed class EditorConfigOptionsEnumerator(

internal static IEnumerable<(string feature, ImmutableArray<IOption2> options)> GetLanguageAgnosticEditorConfigOptions(bool includeUnsupported)
{
yield return (WorkspacesResources.Core_EditorConfig_Options, FormattingOptions2.EditorConfigOptions);
yield return (WorkspacesResources.Core_EditorConfig_Options,
[
.. FormattingOptions2.EditorConfigOptions,
.. MemberDisplayOptionsStorage.EditorConfigOptions
]);

if (includeUnsupported)
{
Expand All @@ -42,6 +47,10 @@ internal sealed class EditorConfigOptionsEnumerator(
yield return ("unsupported", RegexOptionsStorage.UnsupportedOptions);
}

yield return (WorkspacesResources.dot_NET_Coding_Conventions, GenerationOptions.EditorConfigOptions.AddRange(CodeStyleOptions2.EditorConfigOptions));
yield return (WorkspacesResources.dot_NET_Coding_Conventions,
[
.. GenerationOptions.EditorConfigOptions,
.. CodeStyleOptions2.EditorConfigOptions
]);
}
}
26 changes: 26 additions & 0 deletions src/Features/Core/Portable/Options/MemberDisplayOptionsStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 System.Collections.Immutable;

namespace Microsoft.CodeAnalysis.Options;

/// <summary>
/// Options customizing member display. Used by multiple features.
/// </summary>
internal static class MemberDisplayOptionsStorage
{
public static readonly OptionGroup Group = new(name: "member_display", description: "");

public static readonly PerLanguageOption2<bool> HideAdvancedMembers = new(
"dotnet_hide_advanced_members",
defaultValue: false,
isEditorConfigOption: true,
group: Group);

/// <summary>
/// Options that we expect the user to set in editorconfig.
/// </summary>
public static readonly ImmutableArray<IOption2> EditorConfigOptions = [HideAdvancedMembers];
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Immutable;
using Microsoft.CodeAnalysis.CodeCleanup;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.ImplementType;
using Microsoft.CodeAnalysis.Options;
Expand All @@ -22,7 +21,7 @@ public static CodeActionOptions GetCodeActionOptions(this IGlobalOptionService g
CodeGenerationOptions = globalOptions.GetCodeGenerationOptions(languageServices),
SearchOptions = globalOptions.GetSymbolSearchOptions(languageServices.Language),
ImplementTypeOptions = globalOptions.GetImplementTypeOptions(languageServices.Language),
HideAdvancedMembers = globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, languageServices.Language),
HideAdvancedMembers = globalOptions.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, languageServices.Language),
};

internal static CodeActionOptionsProvider GetCodeActionOptionsProvider(this IGlobalOptionService globalOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static CompletionOptions GetCompletionOptions(this IGlobalOptionService o
TriggerInArgumentLists = options.GetOption(TriggerInArgumentLists, language),
EnterKeyBehavior = options.GetOption(EnterKeyBehavior, language),
SnippetsBehavior = options.GetOption(SnippetsBehavior, language),
HideAdvancedMembers = options.GetOption(HideAdvancedMembers, language),
HideAdvancedMembers = options.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, language),
ShowNameSuggestions = options.GetOption(ShowNameSuggestions, language),
ShowItemsFromUnimportedNamespaces = options.GetOption(ShowItemsFromUnimportedNamespaces, language),
UnnamedSymbolCompletionDisabled = options.GetOption(UnnamedSymbolCompletionDisabledFeatureFlag),
Expand All @@ -43,7 +43,6 @@ public static CompletionOptions GetCompletionOptions(this IGlobalOptionService o

public static readonly Option2<bool> UnnamedSymbolCompletionDisabledFeatureFlag = new("dotnet_disable_unnamed_symbol_completion", CompletionOptions.Default.UnnamedSymbolCompletionDisabled, group: s_completionOptionGroup);
public static readonly Option2<bool> ShowNewSnippetExperienceFeatureFlag = new("dotnet_show_new_snippet_experience_feature_flag", CompletionOptions.Default.ShowNewSnippetExperienceFeatureFlag, group: s_completionOptionGroup);
public static readonly PerLanguageOption2<bool> HideAdvancedMembers = new("dotnet_hide_advanced_members_in_completion", CompletionOptions.Default.HideAdvancedMembers, group: s_completionOptionGroup);
public static readonly PerLanguageOption2<bool> TriggerOnTyping = new("dotnet_trigger_completion_on_typing", CompletionOptions.Default.TriggerOnTyping, group: s_completionOptionGroup);
public static readonly PerLanguageOption2<bool> TriggerOnTypingLetters = new("dotnet_trigger_completion_on_typing_letters", CompletionOptions.Default.TriggerOnTypingLetters, group: s_completionOptionGroup);
public static readonly PerLanguageOption2<bool?> TriggerOnDeletion = new("dotnet_trigger_completion_on_deletion", CompletionOptions.Default.TriggerOnDeletion, group: s_completionOptionGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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.

using Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.SignatureHelp;
Expand All @@ -12,6 +11,6 @@ internal static class SignatureHelpOptionsStorage
public static SignatureHelpOptions GetSignatureHelpOptions(this IGlobalOptionService globalOptions, string language)
=> new()
{
HideAdvancedMembers = globalOptions.GetOption(CompletionOptionsStorage.HideAdvancedMembers, language)
HideAdvancedMembers = globalOptions.GetOption(MemberDisplayOptionsStorage.HideAdvancedMembers, language)
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public bool TryFetch(LocalUserRegistryOptionPersister persister, OptionKey2 opti
{"dotnet_enable_argument_completion_snippets", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.EnableArgumentCompletionSnippets")},
{"dotnet_return_key_completion_behavior", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.EnterKeyBehavior")},
#pragma warning disable CS0612 // Type or member is obsolete
{"dotnet_hide_advanced_members_in_completion", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Hide Advanced Auto List Members", vbKey: "TextEditor.Basic.Hide Advanced Auto List Members")},
{"dotnet_hide_advanced_members", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Hide Advanced Auto List Members", vbKey: "TextEditor.Basic.Hide Advanced Auto List Members")},
#pragma warning restore
{"dotnet_highlight_matching_portions_of_completion_list_items", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.HighlightMatchingPortionsOfCompletionListItems")},
{"dotnet_show_completion_item_filters", new RoamingProfileStorage("TextEditor.%LANGUAGE%.Specific.ShowCompletionItemFilters")},
Expand Down

0 comments on commit 12dc70c

Please sign in to comment.