Skip to content

Trigger add open for FS0043 #2474

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

Merged
merged 4 commits into from
Feb 23, 2017
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
6 changes: 4 additions & 2 deletions src/fsharp/vs/ServiceAssemblyContent.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>]
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("_", "__")
Expand Down Expand Up @@ -131,15 +131,16 @@ type internal FSharpAddOpenCodeFixProvider
openNamespaceFix context ctx name ns multipleNames)
|> Seq.toList

let quilifySymbolFixes =
let qualifiedSymbolFixes =
candidates
|> 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
|> 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()
Expand Down Expand Up @@ -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
}
Expand Down