没有找到我需要的所有符号,如何使用 Roslyn API 找到更多符号 [英] Not finding all of the symbols I need,How to find more symbols using the Roslyn API

查看:33
本文介绍了没有找到我需要的所有符号,如何使用 Roslyn API 找到更多符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 roslyn API 和 ace 文本编辑器来创建 Web IDE.

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

当我将鼠标悬停在数据上时,我需要它在给定位置找到符号.这在某些情况下通过调用 roslyn 方法起作用:

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);

在下面的示例中,当我将鼠标悬停在单词table"上时,这种情况有效.

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;

但是,当我将鼠标悬停在 Schema 或 Name SymbolFinder.FindSymbolAtPosition 一词上时,将返回 null.

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

然而:如果我转到单词表的末尾并要求提供自动完成信息,我会在推荐符号列表中获得 Schema

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);

如何让 roslyn 找到作为对象的属性、方法或字段的符号?

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

推荐答案

所以 FindSymbolAtPosition 应该可以正常工作——毕竟它与我们用于定义或任何其他核心的 API 相同语言功能.我会猜测这里是您的编译或语义模型不完整,因此当我们出于某种原因尝试绑定 Schema 或 Name 时.推荐 API 可能能够确定父级的类型并知道它有成员,但由于某种原因,这些成员没有正确绑定.

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.

我建议您尝试的是在您的语义模型或​​编译中,调用 GetDiagnostics 并验证那里没有任何意外错误.您可能会遗漏一个导致一切横盘整理的参考,清除它会使这项工作正常进行.

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.

这篇关于没有找到我需要的所有符号,如何使用 Roslyn API 找到更多符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆