Do not find all the characters I need. How to find more characters using the Roslyn API

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

When I hang over the data, I need to find the symbol in this place. This works in some situations by invoking the roslyn method:

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

Example situations where this works when I hover over the word β€œtable” in the example below.

 var SchemaName = table.Schema.Name; 

However, when I hover over the word Schema or Name SymbolFinder.FindSymbolAtPosition, it returns null.

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

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

How to get roslyn to search for characters that are properties, methods or fields of objects?

+1
source share
1 answer

So, FindSymbolAtPosition should work very well - it's the same API that we use for such things as switching to a definition or any other function of the main language. I would suggest that your compilation or semantic model is not complete, and therefore, when we try to bind Schema or Name, we are for some reason. The recommendation API may be able to determine the type of parent and know that it has members, but for some reason these members do not have the proper binding.

What I would recommend you try in your semantic model or compilation, call GetDiagnostics and make sure there are no unexpected errors. Perhaps you are missing a link that makes everything go sideways and clean, which will make this work great.

+4
source

All Articles