Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FadingOptionsProvider #53873

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/VisualStudio/CSharp/Impl/Options/AutomationObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Editor.Shared.Options;
using Microsoft.CodeAnalysis.ExtractMethod;
using Microsoft.CodeAnalysis.Fading;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.SymbolSearch;
Expand Down Expand Up @@ -769,6 +770,18 @@ public int Wrapping_PreserveSingleLine
set { SetBooleanOption(CSharpFormattingOptions2.WrappingPreserveSingleLine, value); }
}

public int Fading_FadeOutUnreachableCode
{
get { return GetBooleanOption(FadingOptions.FadeOutUnreachableCode); }
set { SetBooleanOption(FadingOptions.FadeOutUnreachableCode, value); }
}

public int Fading_FadeOutUnusedImports
{
get { return GetBooleanOption(FadingOptions.FadeOutUnusedImports); }
set { SetBooleanOption(FadingOptions.FadeOutUnusedImports, value); }
}

private int GetBooleanOption(Option2<bool> key)
=> _workspace.Options.GetOption(key) ? 1 : 0;

Expand Down
19 changes: 19 additions & 0 deletions src/VisualStudio/VisualBasic/Impl/Options/AutomationObject.vb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.DocumentationComments
Imports Microsoft.CodeAnalysis.Editing
Imports Microsoft.CodeAnalysis.Editor.Shared.Options
Imports Microsoft.CodeAnalysis.ExtractMethod
Imports Microsoft.CodeAnalysis.Fading
Imports Microsoft.CodeAnalysis.Options
Imports Microsoft.CodeAnalysis.Shared.Options
Imports Microsoft.CodeAnalysis.Simplification
Expand Down Expand Up @@ -295,6 +296,24 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Options
End Set
End Property

Public Property Fading_FadeOutUnreachableCode As Boolean
Get
Return GetBooleanOption(FadingOptions.FadeOutUnreachableCode)
End Get
Set(value As Boolean)
SetBooleanOption(FadingOptions.FadeOutUnreachableCode, value)
End Set
End Property

Public Property Fading_FadeOutUnusedImports As Boolean
Get
Return GetBooleanOption(FadingOptions.FadeOutUnusedImports)
End Get
Set(value As Boolean)
SetBooleanOption(FadingOptions.FadeOutUnusedImports, value)
End Set
End Property

Private Function GetBooleanOption(key As [PerLanguageOption2](Of Boolean)) As Boolean
Return _workspace.Options.GetOption(key, LanguageNames.VisualBasic)
End Function
Expand Down
25 changes: 25 additions & 0 deletions src/Workspaces/Core/Portable/Fading/FadingOptionsProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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;
using System.Collections.Immutable;
using System.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Options.Providers;

namespace Microsoft.CodeAnalysis.Fading
{
[ExportOptionProvider, Shared]
internal class FadingOptionsProvider : IOptionProvider
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public FadingOptionsProvider()
{
}

public ImmutableArray<IOption> Options { get; } = FadingOptions.AllOptions.As<IOption>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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.Options;

namespace Microsoft.CodeAnalysis.Fading
Expand All @@ -15,5 +16,9 @@ internal static class FadingOptions
public static readonly PerLanguageOption2<bool> FadeOutUnreachableCode = new(
nameof(FadingOptions), nameof(FadeOutUnreachableCode), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation($"TextEditor.%LANGUAGE%.Specific.{nameof(FadeOutUnreachableCode)}"));

public static readonly ImmutableArray<IOption2> AllOptions = ImmutableArray.Create<IOption2>(
FadeOutUnusedImports,
FadeOutUnreachableCode);
}
}