Esempio n. 1
0
        private MoveStartRuleToTop(AntlrLanguageClient package)
        {
            _package = package ?? throw new ArgumentNullException("package");
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                throw new ArgumentNullException("OleMenuCommandService");
            }

            //{
            //    // Set up hook for context menu.
            //    CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidVSPackageCommandCodeWindowContextMenuCmdSet), 0x7002);
            //    _menu_item1 = new MenuCommand(MenuItemCallbackFor, menuCommandID)
            //    {
            //        Enabled = true,
            //        Visible = true
            //    };
            //    commandService.AddCommand(_menu_item1);
            //}
            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7013);
                _menu_item1 = new MenuCommand(MenuItemCallbackFor, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
        }
Esempio n. 2
0
        private void OnTextChanged(object sender, TextContentChangedEventArgs args)
        {
            AntlrLanguageClient alc = AntlrLanguageClient.Instance;

            if (alc == null)
            {
                return;
            }

            string ffn = _buffer.GetFFN();

            if (ffn == null)
            {
                return;
            }

            Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
            if (document == null)
            {
                return;
            }

            LanguageServer.IParserDescription _grammar_description = LanguageServer.ParserDescriptionFactory.Create(document);
            if (_grammar_description == null)
            {
                return;
            }

            if (_buffer.CurrentSnapshot == null)
            {
                return;
            }

            document.Code = _buffer.CurrentSnapshot.GetText();
        }
Esempio n. 3
0
        private SplitCombineGrammars(AntlrLanguageClient package)
        {
            _package = package ?? throw new ArgumentNullException(nameof(package));
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService ?? throw new Exception("Command service not found.");

            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7017);
                _menu_item1 = new MenuCommand(MenuItemCallbackSplit, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7018);
                _menu_item2 = new MenuCommand(MenuItemCallbackCombine, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item2);
            }
        }
Esempio n. 4
0
        private Reorder(AntlrLanguageClient package)
        {
            _package = package ?? throw new ArgumentNullException(nameof(package));
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService ?? throw new Exception("Command service not found.");

            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7014);
                _menu_item1 = new MenuCommand(MenuItemCallbackAlphabetically, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7015);
                _menu_item2 = new MenuCommand(MenuItemCallbackBFS, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item2);
            }
            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7016);
                _menu_item3 = new MenuCommand(MenuItemCallbackDFS, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item3);
            }
        }
Esempio n. 5
0
        private ReplaceLiteral(AntlrLanguageClient package)
        {
            _package = package ?? throw new ArgumentNullException(nameof(package));
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService ?? throw new Exception("Command service not found.");

            //{
            //    // Set up hook for context menu.
            //    CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidVSPackageCommandCodeWindowContextMenuCmdSet), 0x7002);
            //    _menu_item1 = new MenuCommand(MenuItemCallbackFor, menuCommandID)
            //    {
            //        Enabled = true,
            //        Visible = true
            //    };
            //    commandService.AddCommand(_menu_item1);
            //}
            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7011);
                _menu_item1 = new MenuCommand(MenuItemCallback, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
        }
Esempio n. 6
0
        private GoToVisitorCommand(AntlrLanguageClient package)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }
            _package = package;
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService;

            if (commandService == null)
            {
                throw new ArgumentNullException("OleMenuCommandService");
            }

            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidVSPackageCommandCodeWindowContextMenuCmdSet), 0x7005);
                _menu_item1 = new MenuCommand(MenuItemCallbackListener, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidVSPackageCommandCodeWindowContextMenuCmdSet), 0x7006);
                _menu_item2 = new MenuCommand(MenuItemCallbackVisitor, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item2);
            }
            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7005);
                _menu_item3 = new MenuCommand(MenuItemCallbackListener, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item3);
            }
            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7006);
                _menu_item4 = new MenuCommand(MenuItemCallbackVisitor, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item4);
            }
        }
Esempio n. 7
0
        private void MenuItemCallback(object sender, EventArgs e, bool split)
        {
            try
            {
                ////////////////////////
                /// Reorder parser productions.
                ////////////////////////

                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       ffn    = buffer.GetFFN().Result;
                if (ffn == null)
                {
                    return;
                }
                current_grammar_ffn = ffn;

                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }

                int pos = LanguageServer.Module.GetIndex(l, c, document);
                AntlrLanguageClient alc = AntlrLanguageClient.Instance;
                if (alc == null)
                {
                    return;
                }
                Dictionary <string, string> changes = alc.CMSplitCombineGrammarsServer(ffn, pos, split);
                EnterChanges(changes);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 8
0
        private EliminateDirectLeftRecursion(AntlrLanguageClient package)
        {
            _package = package ?? throw new ArgumentNullException(nameof(package));
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService ?? throw new Exception("Command service not found.");

            {
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7020);
                _menu_item1 = new MenuCommand(MenuItemCallback, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
        }
Esempio n. 9
0
        private NextSymCommand(AntlrLanguageClient package)
        {
            _package = package ?? throw new ArgumentNullException(nameof(package));
            OleMenuCommandService commandService = ((IServiceProvider)ServiceProvider).GetService(
                typeof(IMenuCommandService)) as OleMenuCommandService ?? throw new Exception("Command service not found.");

            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidVSPackageCommandCodeWindowContextMenuCmdSet), 0x7002);
                _menu_item1 = new MenuCommand(MenuItemCallbackFor, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item1);
            }
            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidVSPackageCommandCodeWindowContextMenuCmdSet), 0x7003);
                _menu_item2 = new MenuCommand(MenuItemCallbackRev, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item2);
            }
            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7002);
                _menu_item3 = new MenuCommand(MenuItemCallbackFor, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item3);
            }
            {
                // Set up hook for context menu.
                CommandID menuCommandID = new CommandID(new Guid(LspAntlr.Constants.guidMenuAndCommandsCmdSet), 0x7003);
                _menu_item4 = new MenuCommand(MenuItemCallbackRev, menuCommandID)
                {
                    Enabled = true,
                    Visible = true
                };
                commandService.AddCommand(_menu_item4);
            }
        }
Esempio n. 10
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                ////////////////////////
                /// Eliminate left recursion.
                ////////////////////////

                if (!(((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) is IVsTextManager manager))
                {
                    return;
                }
                manager.GetActiveView(1, null, out IVsTextView view);
                if (view == null)
                {
                    return;
                }
                view.GetCaretPos(out int l, out int c);
                view.GetSelection(out int ls, out int cs, out int le, out int ce);
                view.GetBuffer(out IVsTextLines buf);
                if (buf == null)
                {
                    return;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer?.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int start = new LanguageServer.Module().GetIndex(ls, cs, document);
                int end   = new LanguageServer.Module().GetIndex(le, ce, document);
                AntlrLanguageClient.CMEliminateIndirectLeftRecursion(ffn, start, end);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 11
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                ////////////////////////
                /// Replace multiple rules that priorize operators with one rule and multiple ordered alts.
                ////////////////////////

                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.GetSelection(out int ls, out int cs, out int le, out int ce);
                view.GetBuffer(out IVsTextLines buf);
                if (buf == null)
                {
                    return;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int start = new LanguageServer.Module().GetIndex(ls, cs, document);
                int end   = new LanguageServer.Module().GetIndex(le, ce, document);
                AntlrLanguageClient.CMReplacePriorization(ffn, start, end);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 12
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                ////////////////////////
                /// Unfold (substitute RHS of a rule into uses of the LHS symbol).
                ////////////////////////

                if (!(((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) is IVsTextManager manager))
                {
                    return;
                }
                manager.GetActiveView(1, null, out IVsTextView view);
                if (view == null)
                {
                    return;
                }
                view.GetCaretPos(out int l, out int c);
                view.GetSelection(out int ls, out int cs, out int le, out int ce);
                view.GetBuffer(out IVsTextLines buf);
                if (buf == null)
                {
                    return;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view).TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int start = new LanguageServer.Module().GetIndex(ls, cs, document);
                int end   = new LanguageServer.Module().GetIndex(le, ce, document);
                AntlrLanguageClient.CMUnfold(ffn, start, end);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 13
0
        public AboutBox()
        {
            InitializeComponent();
            _info.Text = "Author: Ken Domino";
            _info.AppendText(Environment.NewLine);
            _info.AppendText("AntlrVSIX version: " + LspAntlr.Constants.Version);
            _info.AppendText(Environment.NewLine);
            _info.AppendText("NET Runtime version: " + typeof(string).Assembly.ImageRuntimeVersion);
            _info.AppendText(Environment.NewLine);
            _info.AppendText("Visual Studio version: " + GetVSVersion.GetVisualStudioVersion());
            _info.AppendText(Environment.NewLine);
            var version = AntlrLanguageClient.CMVersion();

            if (version == null)
            {
                version = "LSP server dependent -- requires a server to be started.";
            }
            _info.AppendText("Antlr parser version: " + version);
        }
Esempio n. 14
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                ////////////////////////
                /// Remove useless parser productions.
                ////////////////////////

                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;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int pos = new LanguageServer.Module().GetIndex(l, c, document);
                AntlrLanguageClient.CMMoveStartRuleToTop(ffn);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 15
0
        private void MenuItemCallback(object sender, EventArgs e)
        {
            try
            {
                ////////////////////////
                /// Eliminate Antlr keywords mistakenly used as non-terminal names!
                ////////////////////////

                if (!(((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) is IVsTextManager manager))
                {
                    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;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer?.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int pos = new LanguageServer.Module().GetIndex(l, c, document);
                AntlrLanguageClient.CMEliminateAntlrKeywordsInRules(ffn);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 16
0
        private void MenuItemCallback(ReorderType type)
        {
            try
            {
                ////////////////////////
                /// Reorder parser productions.
                ////////////////////////

                if (!(((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) is IVsTextManager manager))
                {
                    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;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                AntlrLanguageClient.CMReorderParserRules(ffn, type);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 17
0
 private void MenuItemCallback(object sender, EventArgs e)
 {
     try
     {
         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;
         }
         ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
         string      ffn    = buffer.GetFFN();
         if (ffn == null)
         {
             return;
         }
         Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
         if (document == null)
         {
             return;
         }
         AntlrLanguageClient.CMPerformAnalysis(ffn);
     }
     catch (Exception exception)
     {
         Logger.Log.Notify(exception.StackTrace);
     }
 }
Esempio n. 18
0
        private async void OnTextChanged(object sender, TextContentChangedEventArgs args)
        {
            AntlrLanguageClient alc = AntlrLanguageClient.Instance;

            if (alc == null)
            {
                return;
            }

            string ffn = _buffer.GetFFN().Result;

            Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
            if (document == null)
            {
                return;
            }

            if (_buffer.CurrentSnapshot == null)
            {
                return;
            }

            document.Code = _buffer.CurrentSnapshot.GetText();
        }
Esempio n. 19
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new NextSymCommand(package);
 }
Esempio n. 20
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new MoveStartRuleToTop(package);
 }
Esempio n. 21
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new ReplacePriorization(package);
 }
Esempio n. 22
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new Unfold(package);
 }
Esempio n. 23
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            AntlrLanguageClient alc = AntlrLanguageClient.Instance;

            if (alc == null)
            {
                yield break;
            }
            string ffn = _buffer.GetFFN().Result;

            if (ffn == null)
            {
                yield break;
            }
            Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
            IVsTextView         vstv     = IVsTextViewExtensions.FindTextViewFor(ffn);

            foreach (SnapshotSpan curSpan in spans)
            {
                SnapshotPoint       start                  = curSpan.Start;
                SnapshotPoint       end                    = curSpan.End;
                string              text                   = curSpan.GetText();
                int                 curLocStart            = start.Position;
                int                 curLocEnd              = end.Position;
                SymbolInformation[] sorted_combined_tokens = alc.CMGetClassifiersSendServer(curLocStart, curLocEnd - 1, ffn);
                if (sorted_combined_tokens == null)
                {
                    continue;
                }

                foreach (SymbolInformation r in sorted_combined_tokens)
                {
                    int l  = r.Location.Range.Start.Line;
                    int c  = r.Location.Range.Start.Character;
                    int i  = LanguageServer.Module.GetIndex(l, c, document);
                    int l2 = r.Location.Range.End.Line;
                    int c2 = r.Location.Range.End.Character;
                    int i2 = LanguageServer.Module.GetIndex(l2, c2, document);
                    int start_token_start = i;
                    int end_token_end     = i2;
                    int type   = (int)r.Kind;
                    int length = end_token_end - start_token_start + 1;
                    if (length < 0)
                    {
                        continue;
                    }
                    TagSpan <ClassificationTag> result = null;
                    try
                    {
                        if (type >= 0)
                        {
                            // Make sure the length doesn't go past the end of the current span.
                            if (start_token_start + length > curLocEnd)
                            {
                                var new_length = curLocEnd - start_token_start;
                                if (new_length >= 0)
                                {
                                    length = new_length;
                                }
                            }

                            ITextSnapshot a = curSpan.Snapshot.TextBuffer.CurrentSnapshot;
                            ITextSnapshot b = curSpan.Snapshot;

                            SnapshotSpan tokenSpan = new SnapshotSpan(
                                curSpan.Snapshot.TextBuffer.CurrentSnapshot,
                                //curSpan.Snapshot,
                                new Span(start_token_start, length));

                            result = new TagSpan <ClassificationTag>(tokenSpan,
                                                                     new ClassificationTag(_lsptype_to_classifiertype[type]));
                        }
                    }
                    catch (Exception)
                    {
                        //Logger.Log.Notify(exception.StackTrace);
                    }
                    if (result != null)
                    {
                        yield return(result);
                    }
                }
            }
        }
Esempio n. 24
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new EliminateDirectLeftRecursion(package);
 }
Esempio n. 25
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new SplitCombineGrammars(package);
 }
Esempio n. 26
0
        private void MenuItemCallback(bool split)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            try
            {
                ////////////////////////
                /// Reorder parser productions.
                ////////////////////////

                if (!(((IServiceProvider)ServiceProvider).GetService(typeof(VsTextManagerClass)) is IVsTextManager manager))
                {
                    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;
                }
                ITextBuffer buffer = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(view)?.TextBuffer;
                string      ffn    = buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }
                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }
                int pos = new LanguageServer.Module().GetIndex(l, c, document);
                Dictionary <string, string> changes = AntlrLanguageClient.CMSplitCombineGrammars(ffn, split);
                EnvDTE.Project project       = null;
                string         the_namespace = "";
                for (; ;)
                {
                    string current_grammar_ffn = ffn;
                    (EnvDTE.Project, EnvDTE.ProjectItem)p_f_original_grammar = LspAntlr.MakeChanges.FindProjectAndItem(current_grammar_ffn);
                    project = p_f_original_grammar.Item1;
                    try
                    {
                        object prop = p_f_original_grammar.Item2.Properties.Item("CustomToolNamespace").Value;
                        the_namespace = prop.ToString();
                    }
                    catch (Exception)
                    {
                    }
                    break;
                }
                if (project == null)
                {
                    EnvDTE.DTE      dte      = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
                    EnvDTE.Projects projects = dte.Solution.Projects;
                    project = projects.Item(EnvDTE.Constants.vsMiscFilesProjectUniqueName);
                }
                if (changes == null)
                {
                    return;
                }
                MakeChanges.EnterChanges(changes, project, the_namespace);
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 27
0
        public IEnumerable <ITagSpan <ClassificationTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (!Options.Option.GetBoolean("SemanticHighlighting"))
            {
                yield break;
            }
            // Checks to partially fix https://github.com/kaby76/AntlrVSIX/issues/31#.
            string ffn = _buffer.GetFFN();

            if (ffn == null)
            {
                yield break;
            }
            var doc = Workspaces.Workspace.Instance.FindDocument(ffn);

            LanguageServer.IParserDescription _grammar_description = LanguageServer.ParserDescriptionFactory.Create(doc);
            if (_grammar_description == null)
            {
                yield break;
            }
            _ = IVsTextViewExtensions.FindTextViewFor(ffn);
            foreach (SnapshotSpan curSpan in spans)
            {
                SnapshotPoint start       = curSpan.Start;
                SnapshotPoint end         = curSpan.End;
                string        text        = curSpan.GetText();
                int           curLocStart = start.Position;
                int           curLocEnd   = end.Position;
                LanguageServer.CMClassifierInformation[] sorted_combined_tokens = AntlrLanguageClient.CMGetClassifiers(curLocStart, curLocEnd - 1, ffn);
                if (sorted_combined_tokens == null)
                {
                    continue;
                }

                foreach (LanguageServer.CMClassifierInformation r in sorted_combined_tokens)
                {
                    int type = (int)r.Kind;
                    if (type < 0)
                    {
                        continue;
                    }
                    int i      = r.start;
                    int i2     = r.end;
                    int length = i2 - i;
                    if (length < 0)
                    {
                        continue;
                    }
                    TagSpan <ClassificationTag> result = null;
                    try
                    {
                        ITextSnapshot a = curSpan.Snapshot.TextBuffer.CurrentSnapshot;
                        ITextSnapshot b = curSpan.Snapshot;

                        SnapshotSpan tokenSpan = new SnapshotSpan(
                            curSpan.Snapshot.TextBuffer.CurrentSnapshot,
                            //curSpan.Snapshot,
                            new Span(i, length));
                        result = new TagSpan <ClassificationTag>(tokenSpan,
                                                                 new ClassificationTag(_to_classifiertype[type]));
                    }
                    catch (Exception)
                    {
                        //Logger.Log.Notify(exception.StackTrace);
                    }
                    if (result != null)
                    {
                        yield return(result);
                    }
                }
            }
        }
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new RemoveUselessParentheses(package);
 }
Esempio n. 29
0
        private void MenuItemCallback(object sender, EventArgs e, bool forward)
        {
            try
            {
                ////////////////////////
                /// Next rule.
                ////////////////////////

                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       ffn    = buffer.GetFFN().Result;
                if (ffn == null)
                {
                    return;
                }

                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                if (document == null)
                {
                    return;
                }

                int pos = LanguageServer.Module.GetIndex(l, c, document);
                AntlrLanguageClient alc = AntlrLanguageClient.Instance;
                if (alc == null)
                {
                    return;
                }

                int new_pos = alc.CMNextSymbolSendServer(ffn, pos, forward);
                if (new_pos < 0)
                {
                    return;
                }

                List <IToken> where = new List <IToken>();
                List <ParserDetails> where_details = new List <ParserDetails>();
                IVsTextView          vstv          = IVsTextViewExtensions.FindTextViewFor(ffn);
                if (vstv == null)
                {
                    return;
                }

                IWpfTextView wpftv = AntlrLanguageClient.AdaptersFactory.GetWpfTextView(vstv);
                if (wpftv == null)
                {
                    return;
                }

                vstv.GetLineAndColumn(new_pos, out int line_number, out int colum_number);
                ITextSnapshot cc = wpftv.TextBuffer.CurrentSnapshot;
                SnapshotSpan  ss = new SnapshotSpan(cc, new_pos, 1);
                SnapshotPoint sp = ss.Start;
                // Put cursor on symbol.
                wpftv.Caret.MoveTo(sp);
                if (line_number > 0)
                {
                    vstv.CenterLines(line_number - 1, 2);
                }
                else
                {
                    vstv.CenterLines(line_number, 1);
                }
            }
            catch (Exception exception)
            {
                Logger.Log.Notify(exception.StackTrace);
            }
        }
Esempio n. 30
0
 public static void Initialize(AntlrLanguageClient package)
 {
     Instance = new ReplaceLiteral(package);
 }