Roslyn: Signature help in collection inializers

Created on 25 Sep 2019  Â·  13Comments  Â·  Source: dotnet/roslyn

Collection initializers are just a syntactic sugar for calling an Add() method. When calling the Add() method explicitly, I get signature help:

ci1

However, when using the collection initializer syntax, I don't:

ci2

Version Used:

Microsoft Visual Studio Enterprise 2019 Int Preview
Version 16.4.0 Preview 2.0 [29322.22.master]
VisualStudio.16.IntPreview/16.4.0-pre.2.0+29322.22.master

4 - In Review Area-IDE Concept-Continuous Improvement

Most helpful comment

Oh... fyi, i heard about this last night and already started a PR on hte matter :-/

All 13 comments

I'd like to try and give this a shot
Where would I need to start?

I'd like to try and give this a shot
Where would I need to start?

@jasonmalinowski can probably point you somewhere. I suspect you can start by looking at the types derived from AbstractCSharpSignatureHelpProvider.

Indeed, a few steps for this:

  1. Make a new type in https://github.com/dotnet/roslyn/tree/master/src/Features/CSharp/Portable/SignatureHelp that derives from AbstractCSharpSignatureHelpProvider. There are some methods to override, you may find looking at the other implementations helpful to see what they do (there's a certain number of utility functions that make it easier.)
  2. When you recognize you're in this context you'll have to go up, call SemanticModel.GetTypeInfo() on the overall initializer which will give you the type of the underlying thing (the "JObject" in the case of @terrajobst's screenshot).
  3. This API exists which will let you know which Add method is being used. I'm not sure if there's a good way to get all of the methods, since you would need them all at once to list overloads. You'd have to mess with that, I don't actually remember any of the details...

Oh... fyi, i heard about this last night and already started a PR on hte matter :-/

Oh... fyi, i heard about this last night and already started a PR on hte matter :-/

Of course you did :-)

@CyrusNajmabadi for what it's worth, I'd rather see the feature get in than be the one to do it ☺

+1 if only for consistency and completeness.

Would it make sense to do any of the following:

  • include element initializers in Find All References results for Add methods
  • go to the appropriate Add method on F12 of the curly brace for the element initializer

@RikkiGibson sure. it's just a question of motivation.

  • include element initializers in Find All References results for Add methods

Yes.

  • go to the appropriate Add method on F12 of the curly brace for the element initializer

Maybe? I think this would never occur to me.

Here's the location we would need to update for find-refs: https://github.com/dotnet/roslyn/blob/6dab121ff512e2bcc5028149d7705d3ba2d51a72/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/OrdinaryMethodReferenceFinder.cs#L94-L105

We already have the concept of being able to find special methods. It would just be a matter of adding support for this additional special method and putting the right information in our indices to determine which documents to search.

The index to update would be: https://github.com/dotnet/roslyn/blob/master/src/Workspaces/Core/Portable/FindSymbols/SyntaxTree/SyntaxTreeIndex_Forwarders.cs

@RikkiGibson, would you mind filing suggestions for your comments?

One issue already existed, and I filed another issue to follow up on these.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vbcodec picture vbcodec  Â·  3Comments

marler8997 picture marler8997  Â·  3Comments

OndrejPetrzilka picture OndrejPetrzilka  Â·  3Comments

AceHack picture AceHack  Â·  3Comments

NikChao picture NikChao  Â·  3Comments