SymbolFinder.FindReferencesAsync is missing a reference to a type used in a document with implicit declaration only #49387
-
Hi everyone. Version Used:
The issue can be reproduced in Visual Studio. I'm using Visual Studio Professional 16.7.7 Steps to Reproduce:
public class Input
{
}
public class InputReader
{
public Input ReadInput(string[] input) => new Input();
}
class Program
{
static void Main(string[] args)
{
var reader = new InputReader();
var input = reader.ReadInput(args);
Console.WriteLine(input.ToString());
}
}
using (MSBuildWorkspace workspace = MSBuildWorkspace.Create())
{
string solutionPath = @"<path to solution>";
var solution = await workspace.OpenSolutionAsync(solutionPath);
var proj = solution.Projects.First();
var compilation = await proj.GetCompilationAsync();
var symbol = compilation.GetTypeByMetadataName("SomeNamespace.Input");
var references = await SymbolFinder.FindReferencesAsync(symbol, solution); //Examine references to "Input" type
} Expected Behavior: Actual Behavior: I wrote my own custom IFindReferencesProgress reporter and found out that Program.cs file is completely not searched. Internally it is not included to a set of documents which should be searched. return FindDocumentsAsync(project, documents, async (d, c) =>
{
var info = await SyntaxTreeIndex.GetIndexAsync(d, c).ConfigureAwait(false);
//This parts in my opinion adds AssemblyInfo and some other compiler generated Documents to the search
if (findInGlobalSuppressions && info.ContainsGlobalAttributes)
{
return true;
}
foreach (var value in values) //Here 'value' is the string name of a type, in my case it is "Input"
{
// Here if I understand correctly is a check which internally use BloomFilter to see if the document
// definitely should not be searched.
// I'm not sure but I think it works on strings and does not consider implicit declarations
if (!info.ProbablyContainsIdentifier(value))
{
return false;
}
}
return true;
}, cancellationToken); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 12 replies
-
This is out of scope for find-references. It finds direct literal references, not inferred references. You hit the nail on hte head with that observation. Another way to think about this is that it would be the set of things that would need to be updated if the name of the entity changed. That doesn't happen with 'var', so it's not given in the result. While the request is understandable, it's also not feasible. Find-References depends heavily on being able to examine a massively smaller subset of possibilities in the system. If we had to examine all 'var' references, we would effectively have to search every single file (and hundreds to thousands of possibilities per document). This would be far too expensive and would make FindReferences take ages. -- Note: you can do this search yourself. It will be expensive as you will have to check all the 'var's yourself. But that's no worse than what we would be doing. Good luck! |
Beta Was this translation helpful? Give feedback.
-
Totally agree with @SENya1990. This is far from a useless scenario. I just spent more time than I should have trying to figure out why |
Beta Was this translation helpful? Give feedback.
Correct. It's just generally an intuition. I don't think we'd strongly define it either as that would lock us into a particular implementatino/result strategy. We may absolutely change this in the future if we replaced our existing system with an entirely new system based on different concepts.
Sure. As i mentioned, your intuition is fine and understandable. It's just not what we provide (for many reasons). The intuition here is more like "if i changed this name, what …