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.11k stars 4.04k forks source link

IntelliSense surfacing unrelated extension methods #68720

Open stephentoub opened 1 year ago

stephentoub commented 1 year ago

Version Used: Version 17.7.0 Preview 3.0 [33819.433.main]

Steps to Reproduce:

  1. Create a new console application
  2. Add a nuget reference to Azure.AI.OpenAI
  3. Type object o = new object();
  4. Start typing o.A to trigger IntelliSense to come up. It shows this:
image

That method is defined as:

public static IAzureClientBuilder<OpenAIClient, OpenAIClientOptions> AddOpenAIClient<TBuilder, TConfiguration>(this TBuilder builder, TConfiguration configuration)
        where TBuilder : IAzureClientFactoryBuilderWithConfiguration<TConfiguration>

and obviously System.Object does not implement IAzureClientFactoryBuilderWithConfiguration<TConfiguration>.

Interestingly, if I add a using Microsoft.Extensions.Azure;, then IntelliSense correctly won't show this extension. If I remove the using, then it starts showing it again.

CyrusNajmabadi commented 1 year ago

The problem here as I remember it is that we don't actually have the symbols here. We just have an index that says this is an extension method on T (no ability for constraints to encode anything we could test for viability efficiently).

@genlu for thoughts since he built the index

genlu commented 1 year ago

The index is used for quick filtering, but at the end we still get down to symbols to provide more accurate results (here is how it's done) I will investigatge