示例#1
0
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            PhpEditorNavigationParseResultEventArgs antlrParseResultArgs = e as PhpEditorNavigationParseResultEventArgs;

            if (antlrParseResultArgs == null)
            {
                return;
            }

            UpdateNavigationTargets(antlrParseResultArgs);
        }
示例#2
0
        private void UpdateNavigationTargets([NotNull] PhpEditorNavigationParseResultEventArgs antlrParseResultArgs)
        {
            Debug.Assert(antlrParseResultArgs != null);

            List <IEditorNavigationTarget> navigationTargets = new List <IEditorNavigationTarget>();

            // always add the "global scope" element
            {
                string name = "Global Scope";
                IEditorNavigationType editorNavigationType = Provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                SnapshotSpan          span  = new SnapshotSpan(antlrParseResultArgs.Snapshot, 0, antlrParseResultArgs.Snapshot.Length);
                SnapshotSpan          seek  = new SnapshotSpan(span.Start, 0);
                ImageSource           glyph = Provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic);
                NavigationTargetStyle style = NavigationTargetStyle.None;
                navigationTargets.Add(new EditorNavigationTarget(name, editorNavigationType, span, seek, glyph, style));
            }

            if (antlrParseResultArgs != null)
            {
                ITextSnapshot snapshot = antlrParseResultArgs.Snapshot;

                Listener listener = new Listener(Provider, snapshot, antlrParseResultArgs, navigationTargets);

                foreach (var tree in antlrParseResultArgs.NavigationTrees)
                {
                    ParseTreeWalkers.SingleTree.Walk(listener, tree);
                }
#if false
                IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
                var result = resultArgs != null ? resultArgs.Tree as CommonTree : null;
                if (result != null)
                {
                    foreach (CommonTree child in result.Children)
                    {
                        if (child == null || string.IsNullOrEmpty(child.Text))
                        {
                            continue;
                        }

                        if (child.Text == "rule" && child.ChildCount > 0)
                        {
                            var ruleName = child.GetChild(0).Text;
                            if (string.IsNullOrEmpty(ruleName))
                            {
                                continue;
                            }

                            if (ruleName == "Tokens")
                            {
                                continue;
                            }

                            var          navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType;
                            IToken       startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            IToken       stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            Span         span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            SnapshotSpan ruleSpan       = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                            SnapshotSpan ruleSeek       = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)child.GetChild(0)).Token.StartIndex, 0));
                            var          glyph          = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph;
                            navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph));
                        }
                        else if (child.Text.StartsWith("tokens"))
                        {
                            foreach (CommonTree tokenChild in child.Children)
                            {
                                if (tokenChild.Text == "=" && tokenChild.ChildCount == 2)
                                {
                                    var ruleName = tokenChild.GetChild(0).Text;
                                    if (string.IsNullOrEmpty(ruleName))
                                    {
                                        continue;
                                    }

                                    var          navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType;
                                    IToken       startToken     = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex];
                                    IToken       stopToken      = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex];
                                    Span         span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                    SnapshotSpan ruleSpan       = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                                    SnapshotSpan ruleSeek       = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)tokenChild.GetChild(0)).Token.StartIndex, 0));
                                    var          glyph          = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph;
                                    navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph));
                                }
                                else if (tokenChild.ChildCount == 0)
                                {
                                    var ruleName = tokenChild.Text;
                                    if (string.IsNullOrEmpty(ruleName))
                                    {
                                        continue;
                                    }

                                    var          navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType;
                                    IToken       startToken     = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex];
                                    IToken       stopToken      = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex];
                                    Span         span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                    SnapshotSpan ruleSpan       = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                                    SnapshotSpan ruleSeek       = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(tokenChild.Token.StartIndex, 0));
                                    var          glyph          = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph;
                                    navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph));
                                }
                            }
                        }
                    }
                }
#endif
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
        private void UpdateNavigationTargets(PhpEditorNavigationParseResultEventArgs antlrParseResultArgs)
        {
            Contract.Requires(antlrParseResultArgs != null);

            List<IEditorNavigationTarget> navigationTargets = new List<IEditorNavigationTarget>();

            // always add the "global scope" element
            {
                string name = "Global Scope";
                IEditorNavigationType editorNavigationType = Provider.EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                SnapshotSpan span = new SnapshotSpan(antlrParseResultArgs.Snapshot, 0, antlrParseResultArgs.Snapshot.Length);
                SnapshotSpan seek = new SnapshotSpan(span.Start, 0);
                ImageSource glyph = Provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic);
                NavigationTargetStyle style = NavigationTargetStyle.None;
                navigationTargets.Add(new EditorNavigationTarget(name, editorNavigationType, span, seek, glyph, style));
            }

            if (antlrParseResultArgs != null)
            {
                ITextSnapshot snapshot = antlrParseResultArgs.Snapshot;

                Listener listener = new Listener(Provider, snapshot, antlrParseResultArgs, navigationTargets);

                foreach (var tree in antlrParseResultArgs.NavigationTrees)
                {
                    ParseTreeWalkers.SingleTree.Walk(listener, tree);
                }
#if false
                IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
                var result = resultArgs != null ? resultArgs.Tree as CommonTree : null;
                if (result != null)
                {
                    foreach (CommonTree child in result.Children)
                    {
                        if (child == null || string.IsNullOrEmpty(child.Text))
                            continue;

                        if (child.Text == "rule" && child.ChildCount > 0)
                        {
                            var ruleName = child.GetChild(0).Text;
                            if (string.IsNullOrEmpty(ruleName))
                                continue;

                            if (ruleName == "Tokens")
                                continue;

                            var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType;
                            IToken startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            IToken stopToken = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                            SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)child.GetChild(0)).Token.StartIndex, 0));
                            var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph;
                            navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph));
                        }
                        else if (child.Text.StartsWith("tokens"))
                        {
                            foreach (CommonTree tokenChild in child.Children)
                            {
                                if (tokenChild.Text == "=" && tokenChild.ChildCount == 2)
                                {
                                    var ruleName = tokenChild.GetChild(0).Text;
                                    if (string.IsNullOrEmpty(ruleName))
                                        continue;

                                    var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType;
                                    IToken startToken = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex];
                                    IToken stopToken = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex];
                                    Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                    SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                                    SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(((CommonTree)tokenChild.GetChild(0)).Token.StartIndex, 0));
                                    var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph;
                                    navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph));
                                }
                                else if (tokenChild.ChildCount == 0)
                                {
                                    var ruleName = tokenChild.Text;
                                    if (string.IsNullOrEmpty(ruleName))
                                        continue;

                                    var navigationType = char.IsUpper(ruleName[0]) ? _lexerRuleNavigationType : _parserRuleNavigationType;
                                    IToken startToken = antlrParseResultArgs.Tokens[tokenChild.TokenStartIndex];
                                    IToken stopToken = antlrParseResultArgs.Tokens[tokenChild.TokenStopIndex];
                                    Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                    SnapshotSpan ruleSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                                    SnapshotSpan ruleSeek = new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(tokenChild.Token.StartIndex, 0));
                                    var glyph = char.IsUpper(ruleName[0]) ? _lexerRuleGlyph : _parserRuleGlyph;
                                    navigationTargets.Add(new EditorNavigationTarget(ruleName, navigationType, ruleSpan, ruleSeek, glyph));
                                }
                            }
                        }

                    }
                }
#endif
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }