VS2010拡張内のテキストを表示するための言語
-
26-09-2019 - |
質問
私は、Visual Studioのアドインを構築するための新たなんだけど、現在アクティブなコードウィンドウに小さなテキスト操作を行いVS2010ためsimpeツールを構築するために管理しています。私は、現在のテキストビューの言語を(VB.Net、C#または何でも)知っている必要がポイントに持っています。
私は、次のコードを使用して(私は言語を決定するために拡張機能を見ることができるようにする)のファイル名を取得しようとしています:
IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager));
int mustHaveFocus = 1;//means true
txtMgr.GetActiveView(mustHaveFocus, null, out currentTextView);
userData = currentTextView as IVsUserData;
if (userData == null)// no text view
{
Console.WriteLine("No text view is currently open");
return;
}
object pathAsObject;
Guid monikerGuid = typeof(IVsUserData).GUID;
userData.GetData(ref monikerGuid, out pathAsObject);
string docPath = (string)pathAsObject;
残念ながらpathAsObjectは常にnullを返します。ファイル名/言語を取得する他の方法はありますか?
解決
この作品のように見えます:
// Get the current text view.
IVsTextManager txtMgr = (IVsTextManager)GetService(typeof(SVsTextManager));
int mustHaveFocus = 1;//means true
txtMgr.GetActiveView(mustHaveFocus, null, out currentTextView);
userData = currentTextView as IVsUserData;
if (userData == null)// no text view
{
Console.WriteLine("No text view is currently open");
return;
}
// In the next 4 statments, I am trying to get access to the editor's view
object holder;
Guid guidViewHost = DefGuidList.guidIWpfTextViewHost;
userData.GetData(ref guidViewHost, out holder);
viewHost = (IWpfTextViewHost)holder;
// Get a snapshot of the current editor's text.
allText = viewHost.TextView.TextSnapshot.GetText();
// Get the language for the current editor.
string language = viewHost.TextViewtextView.TextDataModel.ContentType.TypeName;
この戻り、私が知っている必要があります正確に何であるVB.Netのための「基本」、。
所属していません StackOverflow