Skip to content

Commit

Permalink
Add option to toggle unused declarations analyzer (dotnet#4074)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
cartermp authored and KevinRansom committed Jan 3, 2018
1 parent c6a5a98 commit 939050e
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 3 deletions.
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ type internal FSharpRenameUnusedValueCodeFixProvider

override __.RegisterCodeFixesAsync context : Task =
asyncMaybe {
// Don't show code fixes for unused values, even if they are compiler-generated.
do! Option.guard Settings.CodeFixes.UnusedDeclarations

let document = context.Document
let! sourceText = document.GetTextAsync()
let ident = sourceText.ToString(context.Span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ type internal UnusedDeclarationsAnalyzer() =

override __.AnalyzeSemanticsAsync(document, cancellationToken) =
asyncMaybe {
do! Option.guard Settings.CodeFixes.UnusedDeclarations

do Trace.TraceInformation("{0:n3} (start) UnusedDeclarationsAnalyzer", DateTime.Now.TimeOfDay.TotalSeconds)
do! Async.Sleep DefaultTuning.UnusedDeclarationsAnalyzerInitialDelay |> liftAsync // be less intrusive, give other work priority most of the time
match getProjectInfoManager(document).TryGetOptionsForEditingDocumentOrProject(document) with
Expand Down
6 changes: 4 additions & 2 deletions vsintegration/src/FSharp.Editor/Options/EditorOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ type QuickInfoOptions =
type CodeFixesOptions =
{ SimplifyName: bool
AlwaysPlaceOpensAtTopLevel: bool
UnusedOpens: bool }
UnusedOpens: bool
UnusedDeclarations: bool }

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

store.RegisterDefault
{ EnableInMemoryCrossProjectReferences = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<StackPanel Margin="15 0 0 0"/>
<CheckBox x:Name="unusedOpens" IsChecked="{Binding UnusedOpens}"
Content="{x:Static local:Strings.Unused_opens_code_fix}"/>
<CheckBox x:Name="unusedDeclaration" IsChecked="{Binding UnusedDeclarations}"
Content="{x:Static local:Strings.Unused_declaration_code_fix}"/>
</StackPanel>
</GroupBox>
</StackPanel>
Expand Down
11 changes: 10 additions & 1 deletion vsintegration/src/FSharp.UIResources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.UIResources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,7 @@
<data name="Unused_opens_code_fix" xml:space="preserve">
<value>Remove unused open statements</value>
</data>
<data name="Unused_declaration_code_fix" xml:space="preserve">
<value>Analyze and suggest fixes for unused values</value>
</data>
</root>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Odebrat nepoužívané otevřené výkazy</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Nicht verwendete "open"-Anweisungen entfernen</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="new">Remove unused open statements</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Quitar instrucciones open no usadas</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Supprimer les instructions open inutilisées</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Rimuovi istruzioni OPEN inutilizzate</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">未使用の Open ステートメントを削除する</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">사용되지 않는 open 문 제거</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Usuń nieużywane otwarte instrukcje</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Remover instruções abertas não usadas</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Удалить неиспользуемые открытые операторы</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Kullanılmayan açık deyimleri kaldır</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">删除未使用的 open 语句</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">移除未使用的 open 陳述式</target>
<note />
</trans-unit>
<trans-unit id="Unused_declaration_code_fix">
<source>Analyze and suggest fixes for unused values</source>
<target state="new">Analyze and suggest fixes for unused values</target>
<note />
</trans-unit>
</body>
</file>
</xliff>

0 comments on commit 939050e

Please sign in to comment.