Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 2a75d7d

Browse files
cartermpKevinRansom
authored andcommitted
Add option to toggle unused declarations analyzer (dotnet#4074)
* Add option to toggle unused declarations analyzer * Better name and handle registering code fixes. This will ensure that if someone uses warnon:1182, we won't suggest fixes if they've turned off the feature.
1 parent 7b9ed3d commit 2a75d7d

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CodeFix/RenameUnusedValue.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ type internal FSharpRenameUnusedValueCodeFixProvider
4747

4848
override __.RegisterCodeFixesAsync context : Task =
4949
asyncMaybe {
50+
// Don't show code fixes for unused values, even if they are compiler-generated.
51+
do! Option.guard Settings.CodeFixes.UnusedDeclarations
52+
5053
let document = context.Document
5154
let! sourceText = document.GetTextAsync()
5255
let ident = sourceText.ToString(context.Span)

Diagnostics/UnusedDeclarationsAnalyzer.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ type internal UnusedDeclarationsAnalyzer() =
100100

101101
override __.AnalyzeSemanticsAsync(document, cancellationToken) =
102102
asyncMaybe {
103+
do! Option.guard Settings.CodeFixes.UnusedDeclarations
104+
103105
do Trace.TraceInformation("{0:n3} (start) UnusedDeclarationsAnalyzer", DateTime.Now.TimeOfDay.TotalSeconds)
104106
do! Async.Sleep DefaultTuning.UnusedDeclarationsAnalyzerInitialDelay |> liftAsync // be less intrusive, give other work priority most of the time
105107
match getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document) with

Options/EditorOptions.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ type QuickInfoOptions =
3434
type CodeFixesOptions =
3535
{ SimplifyName: bool
3636
AlwaysPlaceOpensAtTopLevel: bool
37-
UnusedOpens: bool }
37+
UnusedOpens: bool
38+
UnusedDeclarations: bool }
3839

3940
[<CLIMutable>]
4041
type LanguageServicePerformanceOptions =
@@ -59,7 +60,8 @@ type internal Settings [<ImportingConstructor>](store: SettingsStore) =
5960
// See https://github.com/Microsoft/visualfsharp/pull/3238#issue-237699595
6061
SimplifyName = false
6162
AlwaysPlaceOpensAtTopLevel = false
62-
UnusedOpens = true }
63+
UnusedOpens = true
64+
UnusedDeclarations = true }
6365

6466
store.RegisterDefault
6567
{ EnableInMemoryCrossProjectReferences = true

0 commit comments

Comments
 (0)