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

VS checkbox for controlling the "Remove parens" diag+fix #16211

Merged
merged 4 commits into from
Nov 1, 2023
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
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.

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

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