Search code examples
c#symbolsroslynquickinfo

Not finding all of the symbols I need,How to find more symbols using the Roslyn API


I am using the roslyn API and ace text editor to create a web IDE.

When i hover over data i need it to find the symbol at the given location. This works in some situations by calling the roslyn method:

var symbol = SymbolFinder.FindSymbolAtPosition(semanticModel, offset, dotNetCodeManager.Solution.Workspace, cancellationToken);

An example of the situations where this works is when i hover my mouse over the word "table" in the below example.

var SchemaName = table.Schema.Name;

However when i hover my mouse over the word Schema or Name SymbolFinder.FindSymbolAtPosition returns null.

However: If I go to the end of the word table and ask for autocomplete information I do get Schema in the list of recommended symbols

 var result = Recommender.GetRecommendedSymbolsAtPosition(semanticModel, offset, solution.Workspace);

How do I get roslyn to find symbols that are properties, methods, or fields of objects?


Solution

  • So FindSymbolAtPosition should work just fine -- it's after all the same API we use for things like go to definition or any other core language feature. What I would guess here is your compilation or semantic model isn't complete, and so when we try to bind Schema or Name we for some reason. The recommendation API might be able to figure out the type of the parent and know it has members, but for some reason those members aren't properly binding.

    What I would recommend you try is in your semantic model or compilation, call GetDiagnostics and verify there aren't any unexpected errors there. You might be missing a reference that's causing everything to go sideways, and clearing that will make this work fine.