我有一个 Rider 插件,可以获取 Rider 中打开文件的本地路径。它是一个上下文菜单按钮。现在只能获取某些项目文件的路径,例如 C# 文件。
无法获取txt等其他文件类型的路径。
下面是我的代码
public void Execute(IDataContext context, DelegateExecute nextExecute)
{
var solution = context.GetData(JetBrains.ProjectModel.DataContext.ProjectModelDataConstants.SOLUTION);
if (solution == null)
return;
var textControl = context.GetData(TextControlDataConstants.TEXT_CONTROL);
if (textControl == null)
return;
var document = textControl.Document;
var Offset = textControl.Caret.Offset();
var lineNumber = document.GetCoordsByOffset(Offset).Line.Plus1();
var sourceFile = document.GetPsiSourceFile(solution);
if (sourceFile == null)
return;
var fullPath = $"{sourceFile.GetLocation().FullPath}?line={lineNumber}";
var file = solution.SolutionDirectory / "file.txt";
}
如何让它能够获取所有文件类型的路径?
请提前帮忙并致谢。
看看这个扩展方法
IDocument
JetBrains.DocumentManagers.DocumentManagerExtensions.TryGetFilePath