我试图在Visual Studio扩展包中的VSSDK和Roslyn SDK之间架起桥梁,并且一直很难用.Visual Studio提供的ActivePoint.AbsoluteCharOffset与使用FindToken(offset)时从Roslyn获取的元素不匹配.我很确定这与我的当前工作黑客的每一方如何计算EOL字符有关,但我不是100%,我的黑客将长期坚持.
我的黑客就是这条线: charOffset += point.Line;
我在char偏移量上添加行数,这似乎有效,所以我猜我正在添加所有被activepoint计数忽略的换行符.
助手
private VisualStudioWorkspace workspace = null;
public RoslynUtilities(VisualStudioWorkspace workspace)
{
this.workspace = workspace;
}
public Solution Solution { get { return workspace.CurrentSolution; } }
public Document GetDocumentFromPath(string fullPath)
{
foreach (Project proj in this.Solution.Projects)
{
foreach (Document doc in proj.Documents)
{
if (doc.FilePath == fullPath)
return doc;
}
}
return null;
}
public SyntaxTree GetSyntaxTreeFromDocumentPath(string fullPath)
{
Document doc = GetDocumentFromPath(fullPath);
if (doc != null)
return doc.GetSyntaxTreeAsync().Result;
else
return null;
} …Run Code Online (Sandbox Code Playgroud) c# visual-studio visual-studio-extensions roslyn visual-studio-2015
我正在编写一个Roslyn诊断分析器,它应该适用于VS2015及更高版本.我想知道Microsoft.CodeAnalysis我可以使用我的项目的最新版本,仍然支持VS2015.我需要使用在Roslyn 1.2.0(AnalysisContext.EnableConcurrentExecution)中添加的API ,但我认为该版本的Roslyn不包含在VS2015中(IIRC,只有VS2017支持C#7).这是否意味着我无法在我的分析仪中使用此API?