Resharper は、独自のドッグフードを食べると主張しています。具体的には、Resharper の多くの機能が R# (OpenAPI) の上に書かれていると主張しています。選択した現在のドキュメントのコメントを修正するための簡単なプラグインを作成しています。このプラグインを実行すると、次のように例外がスローされます。
ドキュメントはコマンド スコープ内でのみ変更できます
エラーを調査しましたが、これに役立つものは何も見つかりませんでした。おそらく、これを達成するためのプラグインを作成したことを願っています。そうでない場合は、スニペットが他の人が独自のプラグインを開始するのに十分であることを願っています.
using System;
using System.IO;
using System.Windows.Forms;
using JetBrains.ActionManagement;
using JetBrains.DocumentModel;
using JetBrains.IDE;
using JetBrains.TextControl;
using JetBrains.Util;
namespace TinkerToys.Actions
{
[ActionHandler("TinkerToys.RewriteComment")]
public class RewriteCommentAction : IActionHandler
{
#region Implementation of IActionHandler
/// <summary>
/// Updates action visual presentation. If presentation.Enabled is set to false, Execute
/// will not be called.
/// </summary>
/// <param name="context">DataContext</param>
/// <param name="presentation">presentation to update</param>
/// <param name="nextUpdate">delegate to call</param>
public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate)
{
ITextControl textControl = context.GetData(DataConstants.TEXT_CONTROL);
return textControl != null;
}
/// <summary>
/// Executes action. Called after Update, that set ActionPresentation.Enabled to true.
/// </summary>
/// <param name="context">DataContext</param>
/// <param name="nextExecute">delegate to call</param>
public void Execute(IDataContext context, DelegateExecute nextExecute)
{
ITextControl textControl = context.GetData(DataConstants.TEXT_CONTROL);
if (textControl != null) {
TextRange textSelectRange;
ISelectionModel textSelectionModel = textControl.SelectionModel;
if ((textSelectionModel != null) && textSelectionModel.HasSelection()) {
textSelectRange = textSelectionModel.Range;
} else {
textSelectRange = new TextRange(0, textControl.Document.GetTextLength());
}
IDocument textDocument = textControl.Document;
String textSelection = textDocument.GetText(textSelectRange);
if (textSelection != null) {
StringReader sReader = new StringReader(textSelection);
StringWriter sWriter = new StringWriter();
Converter.Convert(sReader, sWriter);
textSelection = sWriter.ToString();
textDocument.ReplaceText(textSelectRange, textSelection);
}
}
}
#endregion
}
}
それで、それがひどく望んでいるこのコマンドスコープは何ですか? 投稿する前にこれに追加のログを記録したので、範囲とテキストの両方が有効であることは間違いありません。さらに、エラーは、まだ見つけられていないスコープが欠落していることを示しているようです。
ええ、マクロを使用して同じタスクを達成できると思います。振り返ってみると、同じことを行う単純な vs アドインを作成しました。私が R# を見ている/見ている理由は、生のテキストに加えて提供できる言語固有の要素の解析があるためです。しかし、この問題については、マクロまたは標準のアドインでも問題なく機能すると思います。