Skip to content

Commit

Permalink
VS checkbox for controlling the "Remove parens" diag+fix (#16211)
Browse files Browse the repository at this point in the history
* Editor option around the remove parens codefix
  • Loading branch information
T-Gro authored Nov 1, 2023
1 parent f42bdae commit f47a471
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ type internal FSharpDocumentDiagnosticAnalyzer [<ImportingConstructor>] () =

let! unnecessaryParentheses =
match diagnosticType with
| DiagnosticsType.Semantic -> CancellableTask.singleton ImmutableArray.Empty
| DiagnosticsType.Syntax -> UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document
| DiagnosticsType.Syntax when document.Project.IsFsharpRemoveParensEnabled ->
UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document
| _ -> CancellableTask.singleton ImmutableArray.Empty

if errors.Count = 0 && unnecessaryParentheses.IsEmpty then
return ImmutableArray.Empty
Expand Down
4 changes: 4 additions & 0 deletions vsintegration/src/FSharp.Editor/Options/EditorOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type CodeFixesOptions =
UnusedOpens: bool
UnusedDeclarations: bool
SuggestNamesForErrors: bool
RemoveParens: bool
}

static member Default =
Expand All @@ -73,6 +74,7 @@ type CodeFixesOptions =
UnusedOpens = true
UnusedDeclarations = true
SuggestNamesForErrors = true
RemoveParens = false
}

[<CLIMutable>]
Expand Down Expand Up @@ -250,6 +252,8 @@ module EditorOptionsExtensions =
member this.IsFSharpCodeFixesUnusedOpensEnabled =
this.EditorOptions.CodeFixes.UnusedOpens

member this.IsFsharpRemoveParensEnabled = this.EditorOptions.CodeFixes.RemoveParens

member this.IsFSharpCodeFixesSuggestNamesForErrorsEnabled =
this.EditorOptions.CodeFixes.SuggestNamesForErrors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

<CheckBox x:Name="suggestNamesForErrors" IsChecked="{Binding SuggestNamesForErrors}"
Content="{x:Static local:Strings.Suggest_names_for_errors_code_fix}"/>
<CheckBox x:Name="removeParens" IsChecked="{Binding RemoveParens}"
Content="{x:Static local:Strings.Remove_parens_code_fix}"/>
</StackPanel>
</GroupBox>
</StackPanel>
Expand Down
9 changes: 9 additions & 0 deletions 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 @@ -285,4 +285,7 @@
<data name="Background_analysis" xml:space="preserve">
<value>Background analysis</value>
</data>
<data name="Remove_parens_code_fix" xml:space="preserve">
<value>Remove unnecessary parentheses (experimental, might affect typing performance)</value>
</data>
</root>
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf

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

5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf

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

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ module private TopLevel =

let private tryFix (code: string) =
cancellableTask {
let document = Document.create Auto code
let mode =
WithSettings
{ CodeFixesOptions.Default with
RemoveParens = true
}

let document = Document.create mode code
let sourceText = SourceText.From code

let! diagnostics = FSharpDocumentDiagnosticAnalyzer.GetDiagnostics(document, DiagnosticsType.Syntax)
Expand Down

0 comments on commit f47a471

Please sign in to comment.