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

Add AddMissingEqualsToTypeDefinition code fixer #10470

Merged
merged 5 commits into from Nov 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,56 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.Composition
open System.Threading.Tasks

open Microsoft.VisualStudio.FSharp.Editor.Logging

open Microsoft.CodeAnalysis.Text
open Microsoft.CodeAnalysis.CodeFixes

[<ExportCodeFixProvider(FSharpConstants.FSharpLanguageName, Name = "AddMissingEqualsToTypeDefinition"); Shared>]
type internal FSharpAddMissingEqualsToTypeDefinitionCodeFixProvider() =
inherit CodeFixProvider()

let fixableDiagnosticIds = set ["FS3360"]

override _.FixableDiagnosticIds = Seq.toImmutableArray fixableDiagnosticIds

override _.RegisterCodeFixesAsync context : Task =
asyncMaybe {
let diagnostics =
context.Diagnostics
|> Seq.filter (fun x -> fixableDiagnosticIds |> Set.contains x.Id)
|> Seq.toImmutableArray

let! sourceText = context.Document.GetTextAsync(context.CancellationToken)

let mutable pos = context.Span.Start - 1

// This won't ever actually happen, but eh why not
do! Option.guard (pos > 0)

let mutable ch = sourceText.GetSubText(TextSpan(pos, 1)).ToString().[0]

while pos > 0 && Char.IsWhiteSpace(ch) do
pos <- pos - 1
let text = sourceText.GetSubText(TextSpan(pos, 1))
ch <- text.ToString().[0]

let title = SR.AddMissingEqualsToTypeDefinition()

let codeFix =
CodeFixHelpers.createTextChangeCodeFix(
title,
context,
// 'pos + 1' is here because 'pos' is now the position of the first non-whitespace character.
// Using just 'pos' will creat uncompilable code.
(fun () -> asyncMaybe.Return [| TextChange(TextSpan(pos + 1, 0), " =") |]))

context.RegisterCodeFix(codeFix, diagnostics)
}
|> Async.Ignore
|> RoslynHelpers.StartAsyncUnitAsTask(context.CancellationToken)
1 change: 1 addition & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Expand Up @@ -89,6 +89,7 @@
<Compile Include="Commands\FsiCommandService.fs" />
<Compile Include="Commands\XmlDocCommandService.fs" />
<Compile Include="CodeFix\CodeFixHelpers.fs" />
<Compile Include="CodeFix\AddMissingEqualsToTypeDefinition.fs" />
<Compile Include="CodeFix\ConvertToSingleEqualsEqualityExpression.fs" />
<Compile Include="CodeFix\ChangeRefCellDerefToNotExpression.fs" />
<Compile Include="CodeFix\WrapExpressionInParentheses.fs" />
Expand Down
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.resx
Expand Up @@ -219,6 +219,9 @@
<data name="FSharpDisposableTopLevelValuesClassificationType" xml:space="preserve">
<value>F# Dispostable Values (top-level)</value>
</data>
<data name="AddMissingEqualsToTypeDefinition" xml:space="preserve">
<value>Add missing '=' to type definition</value>
</data>
<data name="ConvertToSingleEqualsEqualityExpression" xml:space="preserve">
<value>Use '=' for equality check</value>
</data>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.cs.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Přidejte klíčové slovo new.</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.de.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Schlüsselwort "new" hinzufügen</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.es.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Agregar "nueva" palabra clave</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.fr.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Ajouter le mot clé 'new'</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.it.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="it" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Aggiungi la parola chiave 'new'</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ja.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ja" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">'new' キーワードを追加する</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ko.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ko" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">'new' 키워드 추가</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pl.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pl" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Dodaj słowo kluczowe „new”</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.pt-BR.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="pt-BR" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Adicionar a palavra-chave 'new'</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.ru.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="ru" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">Добавить ключевое слово "new"</target>
Expand Down
5 changes: 5 additions & 0 deletions vsintegration/src/FSharp.Editor/xlf/FSharp.Editor.tr.xlf
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="tr" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">'new' anahtar sözcüğünü ekleme</target>
Expand Down
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hans" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">添加“新”关键字</target>
Expand Down
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="zh-Hant" original="../FSharp.Editor.resx">
<body>
<trans-unit id="AddMissingEqualsToTypeDefinition">
<source>Add missing '=' to type definition</source>
<target state="new">Add missing '=' to type definition</target>
<note />
</trans-unit>
<trans-unit id="AddNewKeyword">
<source>Add 'new' keyword</source>
<target state="translated">新增 'new' 關鍵字</target>
Expand Down