Example #1
0
        public async System.Threading.Tasks.Task <CMGotoResult> CMGotoListener(JToken arg)
        {
            CMGotoParams request  = arg.ToObject <CMGotoParams>();
            Document     document = CheckDoc(request.TextDocument);
            int          pos      = request.Pos;

            if (trace)
            {
                System.Console.Error.WriteLine("<-- CMGotoListener");
                System.Console.Error.WriteLine(arg.ToString());
                (int, int)bs = LanguageServer.Module.GetLineColumn(pos, document);
                System.Console.Error.WriteLine("");
            }
            var          is_enter = request.IsEnter;
            CMGotoResult s        = Goto.main(false, is_enter, document, pos);

            return(s);
        }
Example #2
0
        public CMGotoResult CMGotoVisitorSendServer(string ffn, int pos)
        {
            try
            {
                if (_rpc == null)
                {
                    return(null);
                }

                CMGotoParams p   = new CMGotoParams();
                Uri          uri = new Uri(ffn);
                p.TextDocument = uri;
                p.Pos          = pos;
                CMGotoResult result = _rpc.InvokeAsync <CMGotoResult>("CMGotoVisitor", p).Result;
                return(result);
            }
            catch (Exception)
            {
            }
            return(null);
        }
Example #3
0
        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);
            }
        }