protected override void OnExecute(Microsoft.VisualStudio.Shell.OleMenuCommand command) { int curLineIndex, curColumnIndex; VSTextView textView = new VSTextView(VSTextView.ActiveTextView); if (textView == null) { MessageBox.Show("textView is null"); return; } textView.GetCursorPositon(out curLineIndex, out curColumnIndex); //帮助:http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/c62a70eb-d84c-4410-890d-b41a86b2b55f/ ILangService langService; LangService_GetInstance(out langService); if (langService == null) { MessageBox.Show("langService is null"); return; } IDECompilerHost compilerHost = new IDECompilerHost(); IProject prj; Project currentPro = VSDocument.ActiveDocument.ProjectItem.ContainingProject; LangService_GetDteProject(langService, currentPro, out prj); if (prj == null) { MessageBox.Show("prj is null"); return; } FileName fileName = new Microsoft.RestrictedUsage.CSharp.Core.FileName(VSDocument.ActiveDocument.FullName); CSRPOSDATA data = new CSRPOSDATA() { LineIndex = curLineIndex, ColumnIndex = curColumnIndex }; CSharpMember m = Utilities.GetMemberAtLocation(compilerHost, prj, fileName.Value, data); if (m != null && m.ReturnType != null) { string returnName = m.ReturnType.GetFormattedName(InteropTypeFormatFlags.TypeFormatFlags_BestNameGUI); returnName = FilterReturnName(returnName); if (string.IsNullOrEmpty(returnName)) { return; } int insertCol = GetInsertPosition(textView, curLineIndex, curColumnIndex); textView.InsertText(returnName + " v =", curLineIndex, insertCol); textView.SelectText(curLineIndex, insertCol + returnName.Length + 1, curLineIndex, insertCol + returnName.Length + 2); } }
private static void InsertBlackLineBefore() { int line, col; VSTextView textView = new VSTextView(VSTextView.ActiveTextView); textView.GetCursorPositon(out line, out col); textView.InsertText("\r\n", line, 0); textView.MoveCursorTo(line, textView.GetStartTextIndexOfCurrLine()); }
private static void InsertPair(string pair) { if (BaseUCSetting.SettingModel.AutoBraceModel.OpenAutoBrace) { int currentLineIndex, currentColIndex; VSTextView textview = new VSTextView(VSTextView.ActiveTextView); textview.GetCursorPositon(out currentLineIndex, out currentColIndex); textview.InsertText(pair, currentLineIndex, currentColIndex); textview.MoveCursorTo(currentLineIndex, currentColIndex); } }
private static void SelectCurrentLine() { VSTextView text = new VSTextView(VSTextView.ActiveTextView); if (text != null) { int line = 0; int col = 0; text.GetCursorPositon(out line, out col); text.SelectText(line, 0, line, text.GetOneLineText(line).Length); } }
private void ShowSuggest() { if (VSTextView.ActiveTextView == null) { return; } VSTextView textView = new VSTextView(VSTextView.ActiveTextView); //检测到前面的类型名字 //如果类型后面隔了一个空格这进行提示,否则不提示 int cursorLine; int cursorCol; textView.GetCursorPositon(out cursorLine, out cursorCol); string before = textView.GetText(cursorLine, cursorCol - 1, cursorLine, cursorCol); }
private TextSpan GetCommentTextSpanAtCurrentCaret() { VSTextView textView = new VSTextView(VSTextView.ActiveTextView); if (textView != null) { int line, col; textView.GetCursorPositon(out line, out col); int topIndex = line; int bottomIndex = line; string topLineText = textView.GetOneLineText(topIndex); while (!string.IsNullOrEmpty(topLineText) && topLineText.Trim().StartsWith("///")) { topIndex--; topLineText = textView.GetOneLineText(topIndex); } string bottomLineText = textView.GetOneLineText(bottomIndex); while (!string.IsNullOrEmpty(topLineText) && bottomLineText.Trim().StartsWith("///")) { bottomIndex++; bottomLineText = textView.GetOneLineText(bottomIndex); } return(new TextSpan() { iStartLine = topIndex, iEndLine = bottomIndex }); } return(new TextSpan() { iStartLine = -1, iEndLine = -1 }); }
public IEnumerable <ITagSpan <EasyVSSmartTag> > GetTags(NormalizedSnapshotSpanCollection spans) { ITextSnapshot snapshot = textBuffer.CurrentSnapshot; if (snapshot.Length == 0) { yield break; //don't do anything if the buffer is empty } VSTextView tv = new VSTextView(VSTextView.ActiveTextView); int line, col; tv.GetCursorPositon(out line, out col); if (VSDocument.ActiveDocument != null) { //EditPoint p = tv.GetEditPoint(line, col); //CodeElement c = VSDocument.ActiveDocument.ProjectItem.FileCodeModel.CodeElementFromPoint(p, vsCMElement.vsCMElementProperty); //if (c != null) //{ //} //CodeElements elements = VSDocument.ActiveDocument.ProjectItem.FileCodeModel .CodeElements; //foreach (CodeElement element in elements) //{ // if (element.Kind == vsCMElement.vsCMElementNamespace) // { // CodeNamespace ns = (CodeNamespace)element; // foreach (CodeElement elem in ns.Members) // { // if (elem is CodeClass) // { // CodeClass cls = elem as CodeClass; // foreach (CodeElement member in cls.Members) // if (member is CodeProperty) // { // CodeType memberType = ((member as CodeProperty)).Type.CodeType; // } // } // } // } //} //set up the navigator ITextStructureNavigator navigator = smartTaggerProvider.NavigatorService.GetTextStructureNavigator(textBuffer); foreach (var span in spans) { ITextCaret caret = textView.Caret; SnapshotPoint point; if (caret.Position.BufferPosition > 0) { point = caret.Position.BufferPosition - 1; } else { yield break; } TextExtent extent = navigator.GetExtentOfWord(point); //don't display the tag if the extent has whitespace if (extent.IsSignificant) { yield return(new TagSpan <EasyVSSmartTag>(extent.Span, new EasyVSSmartTag(GetSmartTagActions(extent.Span)))); } else { yield break; } } } }