2

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

到目前为止,我已经创建了一个IDaemonStagewithErrorStripeRequest.STRIPE_AND_ERRORS和一个IDaemonStageProcess. 到目前为止,这有效并被执行。

问题是:警告没有添加到我的 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;
        }
    }
}
4

1 回答 1

2

构造TextRange函数实际上需要一个偏移量,这可能不是您想要的。相反,您需要做的是在daemonProcess.Document. 即,如果您打电话GetLineStartOffset()GetLineEndOffsetNoLineBreak()这将为您提供线路的开始和结束。您可以将普通int类型转换为所需的参数类型。然后,您可以使用这些结果来创建 a (使用同时采用andTextRange的构造函数),然后创建 a 。startOffsetendOffsetDocumentRange

希望这可以解决问题。让我知道我是否可以提供进一步的帮助。

于 2011-12-12T15:48:18.200 回答