Skip to content

Commit f47a471

Browse files
authored
VS checkbox for controlling the "Remove parens" diag+fix (#16211)
* Editor option around the remove parens codefix
1 parent f42bdae commit f47a471

19 files changed

+93
-3
lines changed

vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =
110110

111111
let! unnecessaryParentheses =
112112
match diagnosticType with
113-
| DiagnosticsType.Semantic -> CancellableTask.singleton ImmutableArray.Empty
114-
| DiagnosticsType.Syntax -> UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document
113+
| DiagnosticsType.Syntax when document.Project.IsFsharpRemoveParensEnabled ->
114+
UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document
115+
| _ -> CancellableTask.singleton ImmutableArray.Empty
115116

116117
if errors.Count = 0 && unnecessaryParentheses.IsEmpty then
117118
return ImmutableArray.Empty

vsintegration/src/FSharp.Editor/Options/EditorOptions.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type CodeFixesOptions =
6363
UnusedOpens: bool
6464
UnusedDeclarations: bool
6565
SuggestNamesForErrors: bool
66+
RemoveParens: bool
6667
}
6768

6869
static member Default =
@@ -73,6 +74,7 @@ type CodeFixesOptions =
7374
UnusedOpens = true
7475
UnusedDeclarations = true
7576
SuggestNamesForErrors = true
77+
RemoveParens = false
7678
}
7779

7880
[<CLIMutable>]
@@ -250,6 +252,8 @@ module EditorOptionsExtensions =
250252
member this.IsFSharpCodeFixesUnusedOpensEnabled =
251253
this.EditorOptions.CodeFixes.UnusedOpens
252254

255+
member this.IsFsharpRemoveParensEnabled = this.EditorOptions.CodeFixes.RemoveParens
256+
253257
member this.IsFSharpCodeFixesSuggestNamesForErrorsEnabled =
254258
this.EditorOptions.CodeFixes.SuggestNamesForErrors
255259

vsintegration/src/FSharp.UIResources/CodeFixesOptionControl.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
<CheckBox x:Name="suggestNamesForErrors" IsChecked="{Binding SuggestNamesForErrors}"
3333
Content="{x:Static local:Strings.Suggest_names_for_errors_code_fix}"/>
34+
<CheckBox x:Name="removeParens" IsChecked="{Binding RemoveParens}"
35+
Content="{x:Static local:Strings.Remove_parens_code_fix}"/>
3436
</StackPanel>
3537
</GroupBox>
3638
</StackPanel>

vsintegration/src/FSharp.UIResources/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vsintegration/src/FSharp.UIResources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,7 @@
285285
<data name="Background_analysis" xml:space="preserve">
286286
<value>Background analysis</value>
287287
</data>
288+
<data name="Remove_parens_code_fix" xml:space="preserve">
289+
<value>Remove unnecessary parentheses (experimental, might affect typing performance)</value>
290+
</data>
288291
</root>

vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)