【发布时间】:2020-01-22 07:53:08
【问题描述】:
我在 this tutorial 之后创建了我的第一个 VS 扩展。
我想获取当前编辑文件的项目,即ITextView textView和ITextBuffer textBuffer的相关项目属性。
经过一番搜索,我发现:
似乎我可以将文件路径与所有项目进行匹配来决定这一点,但这并不理想。
我可以直接在某处获得这些信息吗?
【问题讨论】:
标签: visual-studio-extensions vsx
我在 this tutorial 之后创建了我的第一个 VS 扩展。
我想获取当前编辑文件的项目,即ITextView textView和ITextBuffer textBuffer的相关项目属性。
经过一番搜索,我发现:
似乎我可以将文件路径与所有项目进行匹配来决定这一点,但这并不理想。
我可以直接在某处获得这些信息吗?
【问题讨论】:
标签: visual-studio-extensions vsx
嘿 :) 我上周也有同样的问题。
当前打开的文件名:
DTE dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
string docName = dte.ActiveDocument.Name;
我使用了 ITagger - 每次更改代码时都会调用它,因此您始终是最新的。看看这个tutorial。
IEnumerable<ITagSpan<IssueTag>> ITagger<IssueTag>.GetTags(NormalizedSnapshotSpanCollection spans)
{
DTE dte = Package.GetGlobalService(typeof(SDTE)) as DTE;
string docName = dte.ActiveDocument.Name;
foreach (SnapshotSpan span in spans)
{
//look at each classification span \
foreach (ClassificationSpan classification in m_classifier.GetClassificationSpans(span))
{
//if the classification is a comment
if (classification.ClassificationType.Classification.ToLower().Contains("comment"))
{
//if the word "todo" is in the comment,
//create a new TodoTag TagSpan
int index = classification.Span.GetText().ToLower().IndexOf(m_searchText);
if (index != -1)
{
yield return new TagSpan<IssueTag>(new SnapshotSpan(classification.Span.Start + index, m_searchText.Length), new IssueTag());
}
}
}
}
【讨论】: