From 20eb9df88356637dc171b121484e06e1cf9bd63e Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Wed, 22 Feb 2017 17:42:20 -0800 Subject: [PATCH 1/3] Trigger add open for FS0043 --- .../src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs index 71dd1ed5c7b..8d55df35c53 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs @@ -85,7 +85,7 @@ type internal FSharpAddOpenCodeFixProvider assemblyContentProvider: AssemblyContentProvider ) = inherit CodeFixProvider() - let fixableDiagnosticIds = ["FS0039"] + let fixableDiagnosticIds = ["FS0039"; "FS0043"] let checker = checkerProvider.Checker let fixUnderscoresInMenuText (text: string) = text.Replace("_", "__") @@ -133,6 +133,7 @@ type internal FSharpAddOpenCodeFixProvider let quilifySymbolFixes = candidates + |> Seq.filter (fun (entity,_) -> not(entity.FullRelativeName.Contains("op_"))) // Don't include fully-qualified operator names. The resultant suggestion makes the code not compile. |> Seq.map (fun (entity, _) -> entity.FullRelativeName, entity.Qualifier) |> Seq.distinct |> Seq.sort @@ -181,9 +182,9 @@ type internal FSharpAddOpenCodeFixProvider longIdent |> List.map (fun ident -> { Ident = ident.idText - Resolved = not (ident.idRange = unresolvedIdentRange) }) + Resolved = not (ident.idRange = unresolvedIdentRange)}) |> List.toArray) - + let createEntity = ParsedInput.tryFindInsertionContext unresolvedIdentRange.StartLine parsedInput maybeUnresolvedIdents return entities |> Seq.map createEntity |> Seq.concat |> Seq.toList |> getSuggestions context } From a0135b532742725e649849ad97f2745ddfebb6ef Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Wed, 22 Feb 2017 17:58:19 -0800 Subject: [PATCH 2/3] Contains -> StartsWith --- .../src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs index 8d55df35c53..0b22c4aa390 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs @@ -131,16 +131,16 @@ type internal FSharpAddOpenCodeFixProvider openNamespaceFix context ctx name ns multipleNames) |> Seq.toList - let quilifySymbolFixes = + let qualifiedSymbolFixes = candidates - |> Seq.filter (fun (entity,_) -> not(entity.FullRelativeName.Contains("op_"))) // Don't include fully-qualified operator names. The resultant suggestion makes the code not compile. + |> Seq.filter (fun (entity,_) -> not(entity.FullRelativeName.StartsWith("op_"))) // Don't include qualified operator names. The resultant codefix won't compile because it won't be an infix operator anymore. |> Seq.map (fun (entity, _) -> entity.FullRelativeName, entity.Qualifier) |> Seq.distinct |> Seq.sort |> Seq.map (qualifySymbolFix context) |> Seq.toList - for codeFix in openNamespaceFixes @ quilifySymbolFixes do + for codeFix in openNamespaceFixes @ qualifiedSymbolFixes do context.RegisterCodeFix(codeFix, (context.Diagnostics |> Seq.filter (fun x -> fixableDiagnosticIds |> List.contains x.Id)).ToImmutableArray()) override __.FixableDiagnosticIds = fixableDiagnosticIds.ToImmutableArray() From 4fdfea3e4e152c5d5c026995501515d40adbebfa Mon Sep 17 00:00:00 2001 From: Vasily Kirichenko Date: Thu, 23 Feb 2017 10:57:45 +0300 Subject: [PATCH 3/3] fixed: AddOpenCodeFixProvider may suggest name qualifying for operators --- src/fsharp/vs/ServiceAssemblyContent.fs | 6 ++++-- .../src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/fsharp/vs/ServiceAssemblyContent.fs b/src/fsharp/vs/ServiceAssemblyContent.fs index 7aa5c61532f..2c21d4d31ed 100644 --- a/src/fsharp/vs/ServiceAssemblyContent.fs +++ b/src/fsharp/vs/ServiceAssemblyContent.fs @@ -437,7 +437,8 @@ type internal Entity = { FullRelativeName: LongIdent Qualifier: LongIdent Namespace: LongIdent option - Name: LongIdent } + Name: LongIdent + LastIdent: string } override x.ToString() = sprintf "%A" x [] @@ -512,7 +513,8 @@ module internal Entity = { FullRelativeName = String.concat "." fullRelativeName //.[0..fullRelativeName.Length - identCount - 1] Qualifier = String.concat "." qualifier Namespace = ns - Name = match restIdents with [|_|] -> "" | _ -> String.concat "." restIdents }) + Name = match restIdents with [|_|] -> "" | _ -> String.concat "." restIdents + LastIdent = Array.tryLast restIdents |> Option.defaultValue "" }) type internal ScopeKind = | Namespace diff --git a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs index 0b22c4aa390..5085293f7a6 100644 --- a/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs +++ b/vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs @@ -133,7 +133,7 @@ type internal FSharpAddOpenCodeFixProvider let qualifiedSymbolFixes = candidates - |> Seq.filter (fun (entity,_) -> not(entity.FullRelativeName.StartsWith("op_"))) // Don't include qualified operator names. The resultant codefix won't compile because it won't be an infix operator anymore. + |> Seq.filter (fun (entity,_) -> not(entity.LastIdent.StartsWith "op_")) // Don't include qualified operator names. The resultant codefix won't compile because it won't be an infix operator anymore. |> Seq.map (fun (entity, _) -> entity.FullRelativeName, entity.Qualifier) |> Seq.distinct |> Seq.sort