From 657a06290735e991ab2fe121605690bbed071592 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 1 Nov 2023 12:20:49 +0100 Subject: [PATCH 1/3] Editor option around the remove parens codefix --- .../Diagnostics/DocumentDiagnosticAnalyzer.fs | 7 ++++--- vsintegration/src/FSharp.Editor/Options/EditorOptions.fs | 5 +++++ .../src/FSharp.UIResources/CodeFixesOptionControl.xaml | 2 ++ vsintegration/src/FSharp.UIResources/Strings.Designer.cs | 9 +++++++++ vsintegration/src/FSharp.UIResources/Strings.resx | 3 +++ vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf | 5 +++++ .../src/FSharp.UIResources/xlf/Strings.pt-BR.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf | 5 +++++ vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf | 5 +++++ .../src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf | 5 +++++ .../src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf | 5 +++++ 18 files changed, 88 insertions(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs b/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs index aee56efed4..36865c44cb 100644 --- a/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs +++ b/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs @@ -109,9 +109,10 @@ type internal FSharpDocumentDiagnosticAnalyzer [] () = errors.Add(diagnostic) |> ignore let! unnecessaryParentheses = - match diagnosticType with - | DiagnosticsType.Semantic -> CancellableTask.singleton ImmutableArray.Empty - | DiagnosticsType.Syntax -> UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document + match diagnosticType with + | DiagnosticsType.Syntax when document.Project.IsFsharpRemoveParensEnabled -> + UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document + | _ -> CancellableTask.singleton ImmutableArray.Empty if errors.Count = 0 && unnecessaryParentheses.IsEmpty then return ImmutableArray.Empty diff --git a/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs b/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs index 04e37fa863..7dfc9d75fb 100644 --- a/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs +++ b/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs @@ -63,6 +63,7 @@ type CodeFixesOptions = UnusedOpens: bool UnusedDeclarations: bool SuggestNamesForErrors: bool + RemoveParens: bool } static member Default = @@ -73,6 +74,7 @@ type CodeFixesOptions = UnusedOpens = true UnusedDeclarations = true SuggestNamesForErrors = true + RemoveParens = false } [] @@ -250,6 +252,9 @@ module EditorOptionsExtensions = member this.IsFSharpCodeFixesUnusedOpensEnabled = this.EditorOptions.CodeFixes.UnusedOpens + member this.IsFsharpRemoveParensEnabled = + this.EditorOptions.CodeFixes.RemoveParens + member this.IsFSharpCodeFixesSuggestNamesForErrorsEnabled = this.EditorOptions.CodeFixes.SuggestNamesForErrors diff --git a/vsintegration/src/FSharp.UIResources/CodeFixesOptionControl.xaml b/vsintegration/src/FSharp.UIResources/CodeFixesOptionControl.xaml index c9111067b4..211e17fd3c 100644 --- a/vsintegration/src/FSharp.UIResources/CodeFixesOptionControl.xaml +++ b/vsintegration/src/FSharp.UIResources/CodeFixesOptionControl.xaml @@ -31,6 +31,8 @@ + diff --git a/vsintegration/src/FSharp.UIResources/Strings.Designer.cs b/vsintegration/src/FSharp.UIResources/Strings.Designer.cs index a723eb86cb..a7bcaa0841 100644 --- a/vsintegration/src/FSharp.UIResources/Strings.Designer.cs +++ b/vsintegration/src/FSharp.UIResources/Strings.Designer.cs @@ -384,6 +384,15 @@ public static string Project_Performance { } } + /// + /// Looks up a localized string similar to Remove unnecessary parentheses (experimental, might affect typing performance). + /// + public static string Remove_parens_code_fix { + get { + return ResourceManager.GetString("Remove_parens_code_fix", resourceCulture); + } + } + /// /// Looks up a localized string similar to Send additional performance telemetry. /// diff --git a/vsintegration/src/FSharp.UIResources/Strings.resx b/vsintegration/src/FSharp.UIResources/Strings.resx index 45341e046d..b1362651cb 100644 --- a/vsintegration/src/FSharp.UIResources/Strings.resx +++ b/vsintegration/src/FSharp.UIResources/Strings.resx @@ -285,4 +285,7 @@ Background analysis + + Remove unnecessary parentheses (experimental, might affect typing performance) + \ No newline at end of file diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf index 466ed87ec6..4c1afb7bca 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.cs.xlf @@ -127,6 +127,11 @@ Upřednostňovaná šířka popisu ve znacích + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Odeslat další telemetrii výkonu diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf index 1f517d8e4c..f93c85b0af 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.de.xlf @@ -127,6 +127,11 @@ Bevorzugte Beschreibungsbreite in Zeichen + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Zusätzliche Leistungstelemetriedaten senden diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf index 644581f92b..3b65a70284 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.es.xlf @@ -127,6 +127,11 @@ Anchura preferida de la descripción en caracteres + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Enviar telemetría de rendimiento adicional diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf index 68499f2c4d..1fcb58d38a 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.fr.xlf @@ -127,6 +127,11 @@ Largeur de description préférée en caractères + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Envoyer une télémétrie de performances supplémentaire diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf index 484e7d17f8..ac84a49ac0 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.it.xlf @@ -127,6 +127,11 @@ Larghezza descrizione preferita in caratteri + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Invia dati di telemetria aggiuntivi per le prestazioni diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf index 9d86054985..76036894dc 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.ja.xlf @@ -127,6 +127,11 @@ 優先する説明の文字幅 + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry 追加のパフォーマンス テレメトリを送信する diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf index 554d0f3a6f..f166bba08f 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.ko.xlf @@ -127,6 +127,11 @@ 기본 설정 설명 너비(문자) + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry 추가 성능 원격 분석 보내기 diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf index f8a16928d8..c4d70ab3a1 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.pl.xlf @@ -127,6 +127,11 @@ Preferowana szerokość opisu w znakach + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Wysyłanie dodatkowych danych telemetrycznych dotyczących wydajności diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf index 46c9407d0a..f1ef03e827 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.pt-BR.xlf @@ -127,6 +127,11 @@ Largura de descrição preferencial em caracteres + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Enviar telemetria de desempenho adicional diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf index 3d1d2fbeec..4db5610e9b 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.ru.xlf @@ -127,6 +127,11 @@ Предпочитаемая ширина описания в символах + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Отправить дополнительные диагностические данные о производительности diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf index 020981e851..95fa383de7 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.tr.xlf @@ -127,6 +127,11 @@ Karakter olarak tercih edilen açıklama genişliği + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry Ek performans telemetrisi gönder diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf index 51078539ab..3b45fdaf52 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hans.xlf @@ -127,6 +127,11 @@ 以字符为单位的首选说明宽度 + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry 发送其他性能遥测 diff --git a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf index 1b0cec83a5..50aede6ee9 100644 --- a/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf +++ b/vsintegration/src/FSharp.UIResources/xlf/Strings.zh-Hant.xlf @@ -127,6 +127,11 @@ 慣用説明寬度 (以字元為單位) + + Remove unnecessary parentheses (experimental, might affect typing performance) + Remove unnecessary parentheses (experimental, might affect typing performance) + + Send additional performance telemetry 傳送其他效能遙測 From a9fea55c8562e6e0891ce7f25d8a86b6298b3966 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 1 Nov 2023 13:16:34 +0100 Subject: [PATCH 2/3] fatomas'd --- .../FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs | 4 ++-- vsintegration/src/FSharp.Editor/Options/EditorOptions.fs | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs b/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs index 36865c44cb..36eb5bc7a0 100644 --- a/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs +++ b/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs @@ -109,8 +109,8 @@ type internal FSharpDocumentDiagnosticAnalyzer [] () = errors.Add(diagnostic) |> ignore let! unnecessaryParentheses = - match diagnosticType with - | DiagnosticsType.Syntax when document.Project.IsFsharpRemoveParensEnabled -> + match diagnosticType with + | DiagnosticsType.Syntax when document.Project.IsFsharpRemoveParensEnabled -> UnnecessaryParenthesesDiagnosticAnalyzer.GetDiagnostics document | _ -> CancellableTask.singleton ImmutableArray.Empty diff --git a/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs b/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs index 7dfc9d75fb..c531d386af 100644 --- a/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs +++ b/vsintegration/src/FSharp.Editor/Options/EditorOptions.fs @@ -252,8 +252,7 @@ module EditorOptionsExtensions = member this.IsFSharpCodeFixesUnusedOpensEnabled = this.EditorOptions.CodeFixes.UnusedOpens - member this.IsFsharpRemoveParensEnabled = - this.EditorOptions.CodeFixes.RemoveParens + member this.IsFsharpRemoveParensEnabled = this.EditorOptions.CodeFixes.RemoveParens member this.IsFSharpCodeFixesSuggestNamesForErrorsEnabled = this.EditorOptions.CodeFixes.SuggestNamesForErrors From e6cf44061bf123910fbbc625ee1a7223c4cc8985 Mon Sep 17 00:00:00 2001 From: Tomas Grosup Date: Wed, 1 Nov 2023 14:36:29 +0100 Subject: [PATCH 3/3] Enable the setting for tests --- .../CodeFixes/RemoveUnnecessaryParenthesesTests.fs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs index c1caae8ab6..d0d1dd9bf5 100644 --- a/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs +++ b/vsintegration/tests/FSharp.Editor.Tests/CodeFixes/RemoveUnnecessaryParenthesesTests.fs @@ -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)