【问题标题】:ReSharper 6 Plugin: Adding HighlightingInfosReSharper 6 插件:添加 HighlightingInfos
【发布时间】:2011-12-12 10:59:38
【问题描述】:

我目前正在编写一个 ReSharper 6 插件,它应该将 Warnings 添加到我的 IDE。这些是从带有 LineNumber 和其他数据的 XML 文件中读取的。

到目前为止,我已经用ErrorStripeRequest.STRIPE_AND_ERRORSIDaemonStageProcess 创建了一个IDaemonStage。到目前为止,这有效并已执行。

问题是:警告没有添加到我的 IDE。
如何获得正确的 TextRange 和 DocumentRange?

在我的Execute() 我有这个:

var violations = new List<HighlightingInfo>();
foreach (var error in errorsFromXML)
{
    // assignments here
    int lineNumber = 172; // example
    string ruleId;
    string rule;
    string error;
    rule = ruleId + ":" + rule;

    // I guess this is what's wrong
    var lineNumber = 
            JetBrains.Util.dataStructures.TypedIntrinsics.Int32<DocLine>.Parse(
                      linumber.ToString());
    int start = daemonProcess.Document.GetLineStartOffset(lineNumber);
    int end = daemonProcess.Document.GetLineEndOffsetNoLineBreak(lineNumber);
    var textRange = new JetBrains.Util.TextRange(start, end);
    var range = new JetBrains.DocumentModel.DocumentRange(
        daemonProcess.Document, textRange);
    // range.ToString() => (DocumentRange (6.253 - 6.262) on <WrongThread>) // example

    // and this should be fine again
    var highlight = new TqsHighlight(rule, error);
    violations.Add(new HighlightingInfo(range, highlight, Severity.WARNING, rule + id));
}
return violations; // returns various violations

我还有一个自定义高亮类:

internal class TqsHighlight : IHighlighting
{
    private readonly string error;

    private readonly string rule;

    public TqsHighlight(string rule, string error)
    {
        this.rule = rule;
        this.error = error;
    }

    public bool IsValid()
    {
        return true;
    }

    public string ToolTip
    {
        get
        {
            return this.error;
        }
    }

    public string ErrorStripeToolTip
    {
        get
        {
            return this.rule;
        }
    }

    public int NavigationOffsetPatch
    {
        get
        {
            return 0;
        }
    }
}

【问题讨论】:

    标签: plugins resharper resharper-plugins


    【解决方案1】:

    TextRange 构造函数实际上需要一个偏移量,这可能不是您想要的。您需要做的是在daemonProcess.Document 上调用一些方法。即,如果您调用GetLineStartOffset()GetLineEndOffsetNoLineBreak(),这将为您提供行的开始和结束。您可以将普通的int 强制转换为所需的参数类型。然后,您可以使用这些结果创建一个TextRange(使用同时采用startOffsetendOffset 的构造函数),然后创建一个DocumentRange

    希望这能解决问题。如果我能提供进一步的帮助,请告诉我。

    【讨论】:

    • 谢谢!我刚刚编辑了我的问题并更正了我的 TextRange,但我仍然看不到条纹,而且我的 DocumentRange 似乎是错误的(DocumentRange (5.580 - 5.585) on &lt;WrongThread&gt;)
    • 嗨,我已经尝试过这种方法,它在我的机器上运行良好。查看我使用的示例gist.github.com/1474476">this Listing。
    • 我认为缺少的部分是 StaticSeverityHighlighting 属性。现在可以正常使用了,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    • 2011-03-16
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 1970-01-01
    相关资源
    最近更新 更多