dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.07k stars 4.04k forks source link

IntelliSense should filter attributes to only those that apply #7640

Open davkean opened 8 years ago

davkean commented 8 years ago

There are two behaviors that I think should change with IntelliSense when in attribute context

1) We should open IntelliSense immediately:

[assembly: $

Above I need to CTRL+SPACE to open IntelliSense window, what else is valid in that case?

2) We should filter it to just the attributes that are applied in that case:

[assembly: $

namespace ConsoleApplication53
{
    class Program
    {
        static void Main(string[] args)
        {            
        }
    }
}

[System.AttributeUsage(System.AttributeTargets.Assembly)]
public class AttributeOnlyValidInAssembly : System.Attribute
{
}

[System.AttributeUsage(System.AttributeTargets.Class)]
public class AttributeOnlyValidInClass : System.Attribute
{
}

At $, we should only be showing AttributeOnlyValidInAssembly, instead we show both attributes.

SergeyZhurikhin commented 8 years ago

@davkean I agree with you, only be showing AttributeOnlyValidInAssembly.

pawchen commented 8 years ago

For the first point, yes, and wouldn't it be even better to give a list when you typed [?

For the second point, I would argue that if the attribute is from source instead of metadata, one could always change it's usage, rather than not seeing it in the completion list and scratch the head wondering why, squiggle with error message after inserting is better IMHO.

pawchen commented 8 years ago

I think I can create a PR for the first request later, then we can discuss.

pawchen commented 8 years ago

Having tried this locally, I was able to get the behavior I want, but the change introduce redundant work:

Main reason of those redundant work needed is that, [ can be indexer context, currently no completion list will be triggered when you type someArray[. If I simply add [ to the trigger character to KeywordCompletionProvider and SymbolCompletionProvider, they WILL recommend something in indexer context, like nameof, local variables, or namespace symbols. To keep the current behavior, separate completion providers are necessary.

So, what do you think? Add [ as trigger character in all case, or add separate completion providers that introduce redundant work?

pawchen commented 8 years ago

Pausing, because I notice some huge changes are in review #10666