qsharp-compiler: Code completion doesn't recognize attributes

Describe the bug

After typing @, typing a letter or pressing Ctrl+Space shows completions for all identifiers and keywords, not just attribute names.

To Reproduce

Steps to reproduce the behavior:

  1. Open a Q# file in Visual Studio Code.

  2. Type @r in a namespace:

    namespace Example {
        @r
    }
    
  3. Code completion shows identifiers that aren’t valid as attributes, like the repeat keyword.

Expected behavior

Code completion should only valid attribute names. It is probably easier to show all user-defined types instead of only user-defined types with the @Attribute() attribute, since I don’t think code completion is capable of filtering by attributes right now.

Screenshots

grafik

System information

  • QDK extension v0.12.20092803
  • Windows 10, .NET Core 3.1.401
  • Visual Studio Code version 1.49.2

Additional context

CodeCompletion\FragmentParsing.fs is probably a good place to start. The modifiers parser can parse things that appear before a declaration, like the internal keyword. It should be possible to also parse the @ symbol here followed by a user-defined type name.

https://github.com/microsoft/qsharp-compiler/blob/edc3d1557d62dc3cf1175caf6386e78aee91eb03/src/QsCompiler/TextProcessor/CodeCompletion/FragmentParsing.fs#L25-L27

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I think this screenshot might be a better example:

grafik

I think the only things that should be shown are:

  • EntryPoint
  • Example (which is a namespace, because the namespace could contain attributes)
  • ExampleType

Although ExampleType is technically not an attribute, code completion only supports filtering based on categories like “callable” and “user-defined type” currently. So I think it’s OK if we show all user-defined types, even if they aren’t necessarily attributes - it would still be a big improvement over the current behavior, and we can possibly add more specific filtering later.

There are also two of each for EntryPoint and ExampleType because one of them is the type itself and the other is the type constructor (which is a callable). If code completion shows only user-defined types, then only the ones with the gray rectangle and two squares should be shown, not the purple cube ones.