private void MenuItemCallback(object sender, EventArgs e, bool visitor) { try { //////////////////////// /// Go to visitor. //////////////////////// IVsTextManager manager = ((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) as IVsTextManager; if (manager == null) { return; } manager.GetActiveView(1, null, out IVsTextView view); if (view == null) { return; } view.GetCaretPos(out int l, out int c); view.GetBuffer(out IVsTextLines buf); if (buf == null) { return; } IWpfTextView xxx = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view); ITextBuffer buffer = xxx.TextBuffer; string orig_ffn = buffer.GetFFN().Result; if (orig_ffn == null) { return; } Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(orig_ffn); if (document == null) { return; } int pos = LanguageServer.Module.GetIndex(l, c, document); AntlrLanguageClient alc = AntlrLanguageClient.Instance; if (alc == null) { return; } CMGotoResult symbol = null; if (visitor) { symbol = alc.CMGotoVisitorSendServer(orig_ffn, pos); } else { var is_enter = CtrlKeyState.GetStateForView(xxx).Enabled; symbol = alc.CMGotoListenerSendServer(orig_ffn, is_enter, pos); } if (symbol == null) { return; } { string class_file_path = symbol.TextDocument.LocalPath; int index = symbol.Start; // Open to this line in editor. IVsTextView vstv = IVsTextViewExtensions.FindTextViewFor(class_file_path); { IVsTextViewExtensions.ShowFrame(ServiceProvider, class_file_path); vstv = IVsTextViewExtensions.FindTextViewFor(class_file_path); } IWpfTextView wpftv = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(vstv); if (wpftv == null) { return; } // Create new span in the appropriate view. ITextSnapshot cc = wpftv.TextBuffer.CurrentSnapshot; vstv.GetLineAndColumn(index, out int line_number, out int colum_number); // Put cursor on symbol. wpftv.Caret.MoveTo(new SnapshotPoint(cc, index)); // This sets cursor, bot does not center. // Center on cursor. //wpftv.Caret.EnsureVisible(); // This works, sort of. It moves the scroll bar, but it does not CENTER! Does not really work! if (line_number > 0) { vstv.CenterLines(line_number - 1, 2); } else { vstv.CenterLines(line_number, 1); } return; } } catch (Exception exception) { Logger.Log.Notify(exception.StackTrace); } }