Skip to content

await completion inserts using directive for System.Threading.Tasks even if is already imported globally #81880

@jhinder

Description

@jhinder

Version Used: VS 18.1.1

Steps to Reproduce:
Type await and hit space in the method body.

global using System.Threading.Tasks;

class C
{
    void M()
    {
        $$
    }
}

Expected Behavior: The using directive for System.Threading.Tasks is not added when the namespace is already imported globally, either explicitly (like here, for demonstration purposes) or implicitly (like in many projects using recent .NET SDK versions).

Actual Behavior: using System.Threading.Tasks; is always added.

Image

It's easy enough to clean up (by hand or by codefix), but since the provider has the semantic model of the document to change, it should be able to determine whether that namespace is already imported, and skip that change.
https://github.com/dotnet/roslyn/blob/main/src/Features/Core/Portable/Completion/Providers/AbstractAwaitCompletionProvider.cs#L197-L200

Side note: if you run the "Make method async" fixer on the code via the context menu, it does not add the using directive, so it seems to be aware of that.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions