예제 #1
0
        private void HandleParseComplete(object sender, ParseResultEventArgs e)
        {
            AntlrParseResultEventArgs antlrEventArgs = (AntlrParseResultEventArgs)e;
            IList <IAnchor>           result         = _referenceAnchors.GetValue(e.Snapshot, snapshot => CreateReferenceAnchorPoints(snapshot, (GrammarParser.GrammarSpecContext)antlrEventArgs.Result));

            _newestResult = Tuple.Create(e.Snapshot, result);
        }
예제 #2
0
        private bool TryHandleParseCompleteV4(object sender, ParseResultEventArgs e)
        {
            if (!object.ReferenceEquals(sender, BackgroundParser))
            {
                return(false);
            }

            AntlrParseResultEventArgs antlrArgs = e as AntlrParseResultEventArgs;

            if (antlrArgs == null)
            {
                this.Tokens4 = null;
                return(false);
            }

            var result = antlrArgs.Result;

            this.Snapshot = e.Snapshot;
            this.Tokens4  = antlrArgs.Tokens;

            Tree.Dispatcher.Invoke(
                (Action)(() =>
            {
                try
                {
                    this.Tree.Items.Clear();
                    this.Tree.Items.Add(new ParseTreeWrapper(result));
                }
                catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex))
                {
                }
            }));

            return(true);
        }
        protected override void ReParseImpl()
        {
            var snapshot = TextBuffer.CurrentSnapshot;
            AntlrParseResultEventArgs result = ParseSnapshot(snapshot);

            OnParseComplete(result);
        }
예제 #4
0
        private void UpdateTags([NotNull] AntlrParseResultEventArgs antlrParseResultArgs)
        {
            Requires.NotNull(antlrParseResultArgs, nameof(antlrParseResultArgs));

            OutliningRegionListener listener = new OutliningRegionListener(antlrParseResultArgs.Snapshot, antlrParseResultArgs.Tokens);

            ParseTreeWalker.Default.Walk(listener, antlrParseResultArgs.Result);
            _outliningRegions = listener.OutliningRegions;
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(0, antlrParseResultArgs.Snapshot.Length))));
        }
예제 #5
0
        private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            Contract.Requires <ArgumentNullException>(antlrParseResultArgs != null, "antlrParseResultArgs");

            OutliningRegionListener listener = new OutliningRegionListener(antlrParseResultArgs.Snapshot, antlrParseResultArgs.Tokens);

            ParseTreeWalker.Default.Walk(listener, antlrParseResultArgs.Result);
            _outliningRegions = listener.OutliningRegions;
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(0, antlrParseResultArgs.Snapshot.Length))));
        }
예제 #6
0
        private void UpdateNavigationTargets([NotNull] AntlrParseResultEventArgs antlrParseResultArgs)
        {
            Requires.NotNull(antlrParseResultArgs, nameof(antlrParseResultArgs));

            NavigationTargetListener listener = new NavigationTargetListener(this, antlrParseResultArgs.Snapshot, antlrParseResultArgs.Tokens);

            ParseTreeWalker.Default.Walk(listener, antlrParseResultArgs.Result);
            _navigationTargets = listener.NavigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
        private void UpdateNavigationTargets(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            Contract.Requires <ArgumentNullException>(antlrParseResultArgs != null, "antlrParseResultArgs");

            NavigationTargetListener listener = new NavigationTargetListener(this, antlrParseResultArgs.Snapshot, antlrParseResultArgs.Tokens);

            ParseTreeWalker.Default.Walk(listener, antlrParseResultArgs.Result);
            _navigationTargets = listener.NavigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
예제 #8
0
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            AntlrParseResultEventArgs antlrParseResultArgs = e as AntlrParseResultEventArgs;

            if (antlrParseResultArgs == null)
            {
                return;
            }

            UpdateNavigationTargets(antlrParseResultArgs);
        }
        private bool TryHandleParseCompleteV3(object sender, ParseResultEventArgs e)
        {
            if (!object.ReferenceEquals(sender, BackgroundParser))
            {
                return(false);
            }

            AntlrParseResultEventArgs antlrArgs = e as AntlrParseResultEventArgs;

            if (antlrArgs == null)
            {
                this.Tokens3 = null;
                return(false);
            }

            var result = antlrArgs.Result;

            this.Snapshot = e.Snapshot;
            this.Tokens3  = antlrArgs.Tokens;

            Tree.Dispatcher.Invoke(
                (Action)(() =>
            {
                try
                {
                    this.Tree.Items.Clear();
                    IAstRuleReturnScope resultArgs = result as IAstRuleReturnScope;
                    ITree tree = resultArgs != null ? resultArgs.Tree as ITree : null;
                    if (tree != null)
                    {
                        if (!tree.IsNil)
                        {
                            this.Tree.Items.Add(resultArgs.Tree);
                        }
                        else if (tree.ChildCount > 0)
                        {
                            for (int i = 0; i < tree.ChildCount; i++)
                            {
                                this.Tree.Items.Add(tree.GetChild(i));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ErrorHandler.IsCriticalException(ex))
                    {
                        throw;
                    }
                }
            }));

            return(true);
        }
예제 #10
0
            public Listener([NotNull] PhpEditorNavigationSourceProvider provider, [NotNull] ITextSnapshot snapshot, [NotNull] AntlrParseResultEventArgs antlrParseResultArgs, [NotNull] ICollection <IEditorNavigationTarget> navigationTargets)
            {
                Requires.NotNull(provider, nameof(provider));
                Requires.NotNull(snapshot, nameof(snapshot));
                Requires.NotNull(antlrParseResultArgs, nameof(antlrParseResultArgs));
                Requires.NotNull(navigationTargets, nameof(navigationTargets));

                _provider             = provider;
                _snapshot             = snapshot;
                _antlrParseResultArgs = antlrParseResultArgs;
                _navigationTargets    = navigationTargets;
            }
            public Listener(PhpEditorNavigationSourceProvider provider, ITextSnapshot snapshot, AntlrParseResultEventArgs antlrParseResultArgs, ICollection <IEditorNavigationTarget> navigationTargets)
            {
                Contract.Requires <ArgumentNullException>(provider != null, "provider");
                Contract.Requires <ArgumentNullException>(snapshot != null, "snapshot");
                Contract.Requires <ArgumentNullException>(antlrParseResultArgs != null, "antlrParseResultArgs");
                Contract.Requires <ArgumentNullException>(navigationTargets != null, "navigationTargets");

                _provider             = provider;
                _snapshot             = snapshot;
                _antlrParseResultArgs = antlrParseResultArgs;
                _navigationTargets    = navigationTargets;
            }
예제 #12
0
        private IList <IAnchor> CreateReferenceAnchorPoints(ITextSnapshot snapshot, GrammarParser.GrammarSpecContext parseResult)
        {
            if (parseResult == null)
            {
                AntlrParseResultEventArgs resultEventArgs = Antlr4BackgroundParser.ParseSnapshot(snapshot);
                parseResult = (GrammarParser.GrammarSpecContext)resultEventArgs.Result;
            }

            AnchorListener listener = new AnchorListener(snapshot);

            ParseTreeWalker.Default.Walk(listener, parseResult);
            return(listener.Anchors);
        }
예제 #13
0
        private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            List <ITagSpan <IOutliningRegionTag> > outliningRegions = null;
            IAstRuleReturnScope parseResult = antlrParseResultArgs.Result as IAstRuleReturnScope;

            if (parseResult != null)
            {
                outliningRegions = AlloyOutliningTaggerWalker.ExtractOutliningRegions(parseResult, antlrParseResultArgs.Tokens, _provider, antlrParseResultArgs.Snapshot);
            }

            this._outliningRegions = outliningRegions ?? new List <ITagSpan <IOutliningRegionTag> >();
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(0, antlrParseResultArgs.Snapshot.Length))));
        }
예제 #14
0
        private void UpdateNavigationTargets(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            Contract.Requires(antlrParseResultArgs != null);

            List <IEditorNavigationTarget> navigationTargets = null;

            if (antlrParseResultArgs != null)
            {
                IAstRuleReturnScope parseResult = antlrParseResultArgs.Result as IAstRuleReturnScope;
                if (parseResult != null)
                {
                    navigationTargets = AlloyEditorNavigationSourceWalker.ExtractNavigationTargets(parseResult, antlrParseResultArgs.Tokens, _provider, antlrParseResultArgs.Snapshot);
                }
            }

            this._navigationTargets = navigationTargets ?? new List <IEditorNavigationTarget>();
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
예제 #15
0
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            AntlrParseResultEventArgs antlrParseResultArgs          = e as AntlrParseResultEventArgs;
            List <ITagSpan <IOutliningRegionTag> > outliningRegions = new List <ITagSpan <IOutliningRegionTag> >();

            if (antlrParseResultArgs != null)
            {
                IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
                CommonTree          result     = resultArgs != null ? resultArgs.Tree as CommonTree : null;
                if (result != null && result.Children != null)
                {
                    foreach (CommonTree child in result.Children)
                    {
                        if (child == null || string.IsNullOrEmpty(child.Text))
                        {
                            continue;
                        }

                        switch (child.Type)
                        {
                        case GoLexer.KW_IMPORT:
                        case GoLexer.KW_TYPE:
                        case GoLexer.KW_CONST:
                        case GoLexer.KW_FUNC:
                            var                           startToken   = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var                           stopToken    = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            Span                          span         = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            SnapshotSpan                  snapshotSpan = new SnapshotSpan(e.Snapshot, span);
                            IOutliningRegionTag           tag          = new OutliningRegionTag();
                            TagSpan <IOutliningRegionTag> tagSpan      = new TagSpan <IOutliningRegionTag>(snapshotSpan, tag);
                            outliningRegions.Add(tagSpan);
                            break;

                        default:
                            continue;
                        }
                    }
                }
            }

            this._outliningRegions = outliningRegions;
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(e.Snapshot, new Span(0, e.Snapshot.Length))));
        }
예제 #16
0
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            List <ITagSpan <IOutliningRegionTag> > outliningRegions = new List <ITagSpan <IOutliningRegionTag> >();
            AntlrParseResultEventArgs antlrParseResultArgs          = e as AntlrParseResultEventArgs;

            if (antlrParseResultArgs != null)
            {
                var result = antlrParseResultArgs.Result as StringTemplateBackgroundParser.TemplateGroupRuleReturnScope;
                if (result != null)
                {
                    foreach (var templateInfo in result.Group.GetTemplateInformation())
                    {
                        var template = templateInfo.Template;

                        if (template.IsAnonSubtemplate)
                        {
                            continue;
                        }

                        if (template.IsRegion && template.RegionDefType != Antlr4.StringTemplate.Template.RegionType.Explicit)
                        {
                            continue;
                        }

                        Interval     sourceInterval = templateInfo.GroupInterval;
                        SnapshotSpan span           = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length));
                        if (e.Snapshot.GetLineNumberFromPosition(span.Start) == e.Snapshot.GetLineNumberFromPosition(span.End))
                        {
                            continue;
                        }

                        IOutliningRegionTag tag = new OutliningRegionTag();
                        outliningRegions.Add(new TagSpan <IOutliningRegionTag>(span, tag));
                    }
                }
            }

            this._outliningRegions = outliningRegions;
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(e.Snapshot, new Span(0, e.Snapshot.Length))));
        }
예제 #17
0
        private void UpdateNavigationTargets([NotNull] AntlrParseResultEventArgs antlrParseResultArgs)
        {
            Debug.Assert(antlrParseResultArgs != null);

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

            if (antlrParseResultArgs != null)
            {
                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));
                                }
                            }
                        }
                    }
                }
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
예제 #18
0
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            AntlrParseResultEventArgs      antlrParseResultArgs = e as AntlrParseResultEventArgs;
            List <IEditorNavigationTarget> navigationTargets    = new List <IEditorNavigationTarget>();

            if (antlrParseResultArgs != null)
            {
                //// add the Global Scope type
                //{
                //    var name = "Global Scope";
                //    var navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                //    var span = new SnapshotSpan(e.Snapshot, new Span(0, e.Snapshot.Length));
                //    var seek = new SnapshotSpan(e.Snapshot, new Span(0, 0));
                //    var glyph = GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic);
                //    var target = new EditorNavigationTarget(name, navigationType, span, seek, glyph);
                //    navigationTargets.Add(target);
                //}

                IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
                var    result      = resultArgs != null ? resultArgs.Tree as CommonTree : null;
                string packageName = string.Empty;

                if (result != null && result.Children != null)
                {
                    foreach (CommonTree child in result.Children)
                    {
                        if (child == null || string.IsNullOrEmpty(child.Text))
                        {
                            continue;
                        }

                        switch (child.Type)
                        {
                        case GoLexer.KW_PACKAGE:
                        {
                            packageName = ((CommonTree)child.Children[0]).Token.Text;
                            if (string.IsNullOrWhiteSpace(packageName))
                            {
                                continue;
                            }

                            var navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                            var startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            //Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            //SnapshotSpan ruleSpan = new SnapshotSpan(e.Snapshot, span);
                            // applies to the whole file
                            var          span     = new SnapshotSpan(e.Snapshot, new Span(0, e.Snapshot.Length));
                            SnapshotSpan ruleSeek = new SnapshotSpan(e.Snapshot, new Span(((CommonTree)child.Children[0]).Token.StartIndex, 0));
                            var          glyph    = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupModule, StandardGlyphItem.GlyphItemPublic);
                            navigationTargets.Add(new EditorNavigationTarget(packageName, navigationType, span, ruleSeek, glyph));
                        }
                        break;

                        case GoLexer.KW_TYPE:
                            // each child tree is a typeSpec, the root of which is an identifier that names the type
                            foreach (CommonTree typeSpec in child.Children)
                            {
                                var typeName = typeSpec.Token.Text;
                                if (string.IsNullOrWhiteSpace(typeName))
                                {
                                    continue;
                                }

                                for (ITree parent = typeSpec.Parent; parent != null; parent = parent.Parent)
                                {
                                    if (parent.Type == GoParser.TYPE_IDENTIFIER)
                                    {
                                        typeName = parent.Text + "." + typeName;
                                    }
                                }

                                if (!string.IsNullOrWhiteSpace(packageName))
                                {
                                    typeName = packageName + "." + typeName;
                                }

                                var          navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                                var          startToken     = antlrParseResultArgs.Tokens[typeSpec.TokenStartIndex];
                                var          stopToken      = antlrParseResultArgs.Tokens[typeSpec.TokenStopIndex];
                                Span         span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                SnapshotSpan ruleSpan       = new SnapshotSpan(e.Snapshot, span);
                                SnapshotSpan ruleSeek       = new SnapshotSpan(e.Snapshot, new Span(typeSpec.Token.StartIndex, 0));
                                var          glyph          = _provider.GlyphService.GetGlyph(GetGlyphGroupForType(typeSpec), char.IsUpper(typeName[0]) ? StandardGlyphItem.GlyphItemPublic : StandardGlyphItem.GlyphItemPrivate);
                                navigationTargets.Add(new EditorNavigationTarget(typeName, navigationType, ruleSpan, ruleSeek, glyph));

                                if (typeSpec.ChildCount > 0 && typeSpec.Children[0].Type == GoLexer.KW_STRUCT && typeSpec.Children[0].ChildCount > 0)
                                {
                                    foreach (CommonTree fieldSpec in ((CommonTree)typeSpec.Children[0]).Children)
                                    {
                                        if (fieldSpec.Type != GoParser.FIELD_DECLARATION)
                                        {
                                            continue;
                                        }

                                        foreach (CommonTree fieldNameIdentifier in ((CommonTree)fieldSpec.GetFirstChildWithType(GoParser.AST_VARS)).Children)
                                        {
                                            string fieldName = fieldNameIdentifier.Text;
                                            navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                                            startToken     = antlrParseResultArgs.Tokens[fieldNameIdentifier.TokenStartIndex];
                                            stopToken      = antlrParseResultArgs.Tokens[fieldSpec.TokenStopIndex];
                                            span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                            ruleSpan       = new SnapshotSpan(e.Snapshot, span);
                                            ruleSeek       = new SnapshotSpan(e.Snapshot, new Span(fieldNameIdentifier.Token.StartIndex, 0));
                                            glyph          = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupField, char.IsUpper(fieldName[0]) ? StandardGlyphItem.GlyphItemPublic : StandardGlyphItem.GlyphItemPrivate);
                                            navigationTargets.Add(new EditorNavigationTarget(fieldName, navigationType, ruleSpan, ruleSeek, glyph));
                                        }
                                    }
                                }
                            }

                            break;

                        case GoLexer.KW_CONST:
                        case GoLexer.KW_VAR:
                            foreach (CommonTree spec in child.Children)
                            {
                                CommonTree decl = (CommonTree)spec.Children[0];
                                foreach (CommonTree nameToken in decl.Children)
                                {
                                    var name = nameToken.Token.Text;
                                    if (string.IsNullOrWhiteSpace(name))
                                    {
                                        continue;
                                    }

                                    var          navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                                    var          startToken     = antlrParseResultArgs.Tokens[nameToken.TokenStartIndex];
                                    var          stopToken      = antlrParseResultArgs.Tokens[nameToken.TokenStopIndex];
                                    Span         span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                                    SnapshotSpan ruleSpan       = new SnapshotSpan(e.Snapshot, span);
                                    SnapshotSpan ruleSeek       = new SnapshotSpan(e.Snapshot, new Span(nameToken.Token.StartIndex, 0));
                                    var          group          = (child.Type == GoLexer.KW_CONST) ? StandardGlyphGroup.GlyphGroupConstant : StandardGlyphGroup.GlyphGroupVariable;
                                    var          item           = char.IsUpper(name[0]) ? StandardGlyphItem.GlyphItemPublic : StandardGlyphItem.GlyphItemPrivate;
                                    var          glyph          = _provider.GlyphService.GetGlyph(group, item);
                                    navigationTargets.Add(new EditorNavigationTarget(name, navigationType, ruleSpan, ruleSeek, glyph));
                                }
                            }
                            break;

                        case GoLexer.KW_FUNC:
                        {
                            // the first child is either a receiver (method) or an identifier with the name of the function
                            var token = ((CommonTree)child.Children[0]).Token;
                            if (token.Type == GoLexer.METHOD_RECEIVER)
                            {
                                token = ((CommonTree)child.Children[1]).Token;
                            }

                            var functionName = token.Text;
                            if (string.IsNullOrWhiteSpace(functionName))
                            {
                                continue;
                            }

                            ITree receiver = child.GetFirstChildWithType(GoParser.METHOD_RECEIVER);
                            if (receiver != null)
                            {
                                string receiverName;
                                if (receiver.ChildCount >= 2)
                                {
                                    receiverName = receiver.GetChild(receiver.ChildCount - 2).Text;
                                }
                                else
                                {
                                    receiverName = "?";
                                }

                                functionName = receiverName + "." + functionName;
                            }

                            IEnumerable <string> args   = ProcessFunctionParameters(child);
                            string       sig            = string.Format("{0}({1})", functionName, string.Join(", ", args));
                            var          navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                            var          startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var          stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            Span         span           = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            SnapshotSpan ruleSpan       = new SnapshotSpan(e.Snapshot, span);
                            SnapshotSpan ruleSeek       = new SnapshotSpan(e.Snapshot, new Span(child.Token.StartIndex, 0));
                            var          glyph          = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupMethod, char.IsUpper(functionName[0]) ? StandardGlyphItem.GlyphItemPublic : StandardGlyphItem.GlyphItemPrivate);
                            navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, ruleSpan, ruleSeek, glyph));
                        }

                        break;

                        default:
                            continue;
                        }
                    }
                }
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
예제 #19
0
        private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            List <ITagSpan <IOutliningRegionTag> > outliningRegions = new List <ITagSpan <IOutliningRegionTag> >();

            IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
            var result = resultArgs != null ? resultArgs.Tree as CommonTree : null;

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

                // outline all the imports
                IList <ITree> children = result.Children ?? new ITree[0];
                for (int i = 0; i < children.Count; i++)
                {
                    /*
                     *  ^('import' 'static'? IDENTIFIER+ '*'?)
                     *
                     *  ^('import' 'static'? IDENTIFIER+ '*'? ';')
                     *
                     *  ^('import' 'static'? IDENTIFIER+ '*'? ';') ^('import' 'static'? IDENTIFIER+ '*'? ';')+
                     *
                     *  ^('import' .* ';') ^('import' .* ';')+
                     */
                    if (children[i].Type != Java2Lexer.IMPORT)
                    {
                        continue;
                    }

                    int firstImport = i;
                    while (i < children.Count - 1 && children[i + 1].Type == Java2Lexer.IMPORT)
                    {
                        i++;
                    }

                    int lastImport = i;

                    // start 1 token after the first 'import' token
                    var  startToken = antlrParseResultArgs.Tokens[children[firstImport].TokenStartIndex + 1];
                    var  stopToken  = antlrParseResultArgs.Tokens[children[lastImport].TokenStopIndex];
                    Span span       = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                    if (snapshot.GetLineNumberFromPosition(span.Start) == snapshot.GetLineNumberFromPosition(span.End))
                    {
                        continue;
                    }

                    SnapshotSpan                  snapshotSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                    IOutliningRegionTag           tag          = new OutliningRegionTag("...", snapshotSpan.GetText());
                    TagSpan <IOutliningRegionTag> tagSpan      = new TagSpan <IOutliningRegionTag>(snapshotSpan, tag);
                    outliningRegions.Add(tagSpan);
                }

                /*
                 * ^(TYPE_BODY .* '}')
                 *
                 * ^(METHOD_BODY .* '}')
                 */

                // outline the type and method bodies
                for (CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream(result);
                     treeNodeStream.LA(1) != CharStreamConstants.EndOfFile;
                     treeNodeStream.Consume())
                {
                    switch (treeNodeStream.LA(1))
                    {
                    case Java2Lexer.TYPE_BODY:
                    case Java2Lexer.METHOD_BODY:
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null)
                        {
                            var  startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var  stopToken  = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            Span span       = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            if (snapshot.GetLineNumberFromPosition(span.Start) == snapshot.GetLineNumberFromPosition(span.End))
                            {
                                continue;
                            }

                            SnapshotSpan                  snapshotSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                            IOutliningRegionTag           tag          = new OutliningRegionTag("...", snapshotSpan.GetText());
                            TagSpan <IOutliningRegionTag> tagSpan      = new TagSpan <IOutliningRegionTag>(snapshotSpan, tag);
                            outliningRegions.Add(tagSpan);
                        }

                        break;

                    default:
                        continue;
                    }
                }
            }

            this._outliningRegions = outliningRegions;
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(0, antlrParseResultArgs.Snapshot.Length))));
        }
        private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            List <IEditorNavigationTarget> navigationTargets = new List <IEditorNavigationTarget>();

            IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
            var result = resultArgs != null ? resultArgs.Tree as CommonTree : null;

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

                string package = string.Empty;

                /* ^('package' qualifiedName)
                 *
                 * ^(CLASS_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}'))
                 *
                 * ^(INTERFACE_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}'))
                 *
                 * ^(ANNOTATION_TYPE_IDENTIFIER modifiers .* ^(TYPE_BODY .* '}'))
                 *
                 * ^(FIELD_DECLARATION modifiers (.* ^(VARIABLE_IDENTIFIER .*))*)
                 *
                 * ^(METHOD_IDENTIFIER modifiers .* ^(FORMAL_PARAMETERS .* ')') .* ^(METHOD_BODY .* '}'))
                 */

                /* STATEMENT COMPLETION (description unrelated to this file)
                 *
                 * IDENTIFIER ('.' IDENTIFIER)*
                 *
                 * ^(CALL IDENTIFIER .*)
                 *
                 * ^('(' ^('==' .*) ')')
                 *
                 */

                for (CommonTreeNodeStream treeNodeStream = new CommonTreeNodeStream(result);
                     treeNodeStream.LA(1) != CharStreamConstants.EndOfFile;
                     treeNodeStream.Consume())
                {
                    switch (treeNodeStream.LA(1))
                    {
                    case Java2Lexer.PACKAGE:
                        // ^('package' qualifiedName)
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null && child.ChildCount > 0)
                        {
                            package = GetQualifiedIdentifier(child.GetChild(0));
                        }
                    }

                    break;

                    case Java2Lexer.VARIABLE_IDENTIFIER:
                        // ^(FIELD_DECLARATION (.* ^(VARIABLE_IDENTIFIER))*)
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null && child.HasAncestor(Java2Lexer.FIELD_DECLARATION))
                        {
                            string name = child.Token.Text;
                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                            var                   startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var                   stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            SnapshotSpan          span           = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1));
                            SnapshotSpan          seek           = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0));
                            StandardGlyphGroup    glyphGroup     = StandardGlyphGroup.GlyphGroupJSharpField;
                            StandardGlyphItem     glyphItem      = GetGlyphItemFromChildModifier((CommonTree)child.GetAncestor(Java2Lexer.FIELD_DECLARATION));
                            ImageSource           glyph          = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem);
                            NavigationTargetStyle style          = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style));
                        }
                    }

                    break;

                    case Java2Lexer.METHOD_IDENTIFIER:
                        // ^(METHOD_IDENTIFIER ^(FORMAL_PARAMETERS formalParameterDecls?) ^(METHOD_BODY .* END_METHOD_BODY))
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null)
                        {
                            string name = child.Token.Text;
                            IEnumerable <string> args = ProcessArguments((CommonTree)child.GetFirstChildWithType(Java2Lexer.FORMAL_PARAMETERS));
                            string sig = string.Format("{0}({1})", name, string.Join(", ", args));
                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                            var                   startToken     = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var                   stopToken      = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            SnapshotSpan          span           = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1));
                            SnapshotSpan          seek           = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0));
                            StandardGlyphGroup    glyphGroup     = StandardGlyphGroup.GlyphGroupJSharpMethod;
                            StandardGlyphItem     glyphItem      = GetGlyphItemFromChildModifier(child);
                            ImageSource           glyph          = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem);
                            NavigationTargetStyle style          = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style));
                        }
                    }

                    break;

                    case Java2Lexer.ENUM_TYPE_IDENTIFIER:
                    case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER:
                    case Java2Lexer.INTERFACE_TYPE_IDENTIFIER:
                    case Java2Lexer.CLASS_TYPE_IDENTIFIER:
                    {
                        CommonTree child = treeNodeStream.LT(1) as CommonTree;
                        if (child != null)
                        {
                            string name = child.Token.Text;
                            for (ITree parent = child.Parent; parent != null; parent = parent.Parent)
                            {
                                switch (parent.Type)
                                {
                                case Java2Lexer.ENUM_TYPE_IDENTIFIER:
                                case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER:
                                case Java2Lexer.INTERFACE_TYPE_IDENTIFIER:
                                case Java2Lexer.CLASS_TYPE_IDENTIFIER:
                                    name = parent.Text + "." + name;
                                    continue;

                                default:
                                    continue;
                                }
                            }

                            if (!string.IsNullOrEmpty(package))
                            {
                                name = package + "." + name;
                            }

                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Types);
                            var          startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var          stopToken  = antlrParseResultArgs.Tokens[child.TokenStopIndex];
                            SnapshotSpan span       = new SnapshotSpan(snapshot, new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1));
                            SnapshotSpan seek       = new SnapshotSpan(snapshot, new Span(child.Token.StartIndex, 0));

                            StandardGlyphGroup glyphGroup;
                            switch (child.Type)
                            {
                            case Java2Lexer.ENUM_TYPE_IDENTIFIER:
                                glyphGroup = StandardGlyphGroup.GlyphGroupEnum;
                                break;

                            case Java2Lexer.ANNOTATION_TYPE_IDENTIFIER:
                            case Java2Lexer.INTERFACE_TYPE_IDENTIFIER:
                                glyphGroup = StandardGlyphGroup.GlyphGroupJSharpInterface;
                                break;

                            case Java2Lexer.CLASS_TYPE_IDENTIFIER:
                            default:
                                glyphGroup = StandardGlyphGroup.GlyphGroupJSharpClass;
                                break;
                            }

                            StandardGlyphItem     glyphItem = GetGlyphItemFromChildModifier(child);
                            ImageSource           glyph     = _provider.GlyphService.GetGlyph(glyphGroup, glyphItem);
                            NavigationTargetStyle style     = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(name, navigationType, span, seek, glyph, style));
                        }
                    }

                    break;

                    default:
                        continue;
                    }
                }
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
예제 #21
0
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            List <IEditorNavigationTarget> navigationTargets    = new List <IEditorNavigationTarget>();
            AntlrParseResultEventArgs      antlrParseResultArgs = e as AntlrParseResultEventArgs;

            if (antlrParseResultArgs != null)
            {
                var result = antlrParseResultArgs.Result as StringTemplateBackgroundParser.TemplateGroupRuleReturnScope;
                if (result != null)
                {
                    foreach (var templateInfo in result.Group.GetTemplateInformation())
                    {
                        Antlr4.StringTemplate.Compiler.CompiledTemplate template = templateInfo.Template;

                        if (template.IsAnonSubtemplate)
                        {
                            continue;
                        }

                        bool isRegion = !string.IsNullOrEmpty(templateInfo.EnclosingTemplateName);
                        if (isRegion)
                        {
                            string sig = string.Format("{0}.{1}()", templateInfo.EnclosingTemplateName, templateInfo.NameToken.Text);
                            //string sig = string.Format("{0}({1})", name, string.Join(", ", args));
                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(StringTemplateEditorNavigationTypes.Templates);
                            Interval              sourceInterval = templateInfo.GroupInterval;
                            SnapshotSpan          span           = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length));
                            SnapshotSpan          seek           = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, 0));
                            ImageSource           glyph          = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupNamespace, StandardGlyphItem.GlyphItemPublic);
                            NavigationTargetStyle style          = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style));
                        }
                        else
                        {
                            // always pull the name from the templateInfo because the template itself could be an aliased template
                            string name = templateInfo.NameToken.Text;
                            IEnumerable <string> args = template.FormalArguments != null?template.FormalArguments.Select(i => i.Name) : Enumerable.Empty <string>();

                            string sig = string.Format("{0}({1})", name, string.Join(", ", args));
                            IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(StringTemplateEditorNavigationTypes.Templates);
                            Interval              sourceInterval = templateInfo.GroupInterval;
                            SnapshotSpan          span           = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length));
                            SnapshotSpan          seek           = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, 0));
                            bool                  isAlias        = false;
                            StandardGlyphGroup    glyphGroup     = isAlias ? StandardGlyphGroup.GlyphGroupTypedef : StandardGlyphGroup.GlyphGroupTemplate;
                            ImageSource           glyph          = _provider.GlyphService.GetGlyph(StandardGlyphGroup.GlyphGroupTemplate, StandardGlyphItem.GlyphItemPublic);
                            NavigationTargetStyle style          = NavigationTargetStyle.None;
                            navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style));
                        }
                    }

                    //foreach (var dictionaryInfo in result.Group.GetDictionaryInformation())
                    //{
                    //    string name = dictionaryInfo.Name;
                    //    IEditorNavigationType navigationType = EditorNavigationTypeRegistryService.GetEditorNavigationType(PredefinedEditorNavigationTypes.Members);
                    //    Interval sourceInterval = dictionaryInfo.GroupInterval;
                    //    SnapshotSpan span = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, sourceInterval.Length));
                    //    SnapshotSpan seek = new SnapshotSpan(e.Snapshot, new Span(sourceInterval.Start, 0));
                    //    ImageSource glyph = _provider.GetGlyph(StandardGlyphGroup.GlyphGroupModule, StandardGlyphItem.GlyphItemPublic);
                    //    NavigationTargetStyle style = NavigationTargetStyle.None;
                    //    navigationTargets.Add(new EditorNavigationTarget(sig, navigationType, span, seek, glyph, style));
                    //}
                }
            }

            this._navigationTargets = navigationTargets;
            OnNavigationTargetsChanged(EventArgs.Empty);
        }
예제 #22
0
 protected override void OnParseComplete(ParseResultEventArgs e)
 {
     PreviousParseResult = e as AntlrParseResultEventArgs;
     base.OnParseComplete(e);
 }
예제 #23
0
        private void UpdateTags(AntlrParseResultEventArgs antlrParseResultArgs)
        {
            List <ITagSpan <IOutliningRegionTag> > outliningRegions = new List <ITagSpan <IOutliningRegionTag> >();

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

#if false
                IAstRuleReturnScope resultArgs = antlrParseResultArgs.Result as IAstRuleReturnScope;
                var result = resultArgs.Tree as CommonTree;
                if (result != null)
                {
                    foreach (CommonTree child in result.Children)
                    {
                        if (child == null || string.IsNullOrEmpty(child.Text))
                        {
                            continue;
                        }

                        if (child.Text == "rule" && child.ChildCount > 0 || child.Text.StartsWith("tokens") || child.Text.StartsWith("options"))
                        {
                            string blockHint = "...";
                            if (child.Text == "rule")
                            {
                                string ruleName = child.Children[0].Text;
                                // don't try to outline the artificial tokens rule
                                if (ruleName == "Tokens")
                                {
                                    continue;
                                }

                                blockHint = child.Children[0].Text + "...";
                            }
                            else if (child.Text.StartsWith("tokens"))
                            {
                                // this is the special tokens{} block of a combined grammar
                                blockHint = "tokens {...}";
                            }
                            else if (child.Text.StartsWith("options"))
                            {
                                // this is the special options{} block of a grammar
                                blockHint = "options {...}";
                            }

                            var startToken = antlrParseResultArgs.Tokens[child.TokenStartIndex];
                            var stopToken  = antlrParseResultArgs.Tokens[child.TokenStopIndex];

                            if (startToken.Type == ANTLRParser.DOC_COMMENT)
                            {
                                for (int index = child.TokenStartIndex; index <= child.TokenStopIndex; index++)
                                {
                                    startToken = antlrParseResultArgs.Tokens[index];
                                    if (startToken.Type != ANTLRParser.DOC_COMMENT && startToken.Channel != TokenChannels.Hidden)
                                    {
                                        break;
                                    }
                                }
                            }

                            Span span = new Span(startToken.StartIndex, stopToken.StopIndex - startToken.StartIndex + 1);
                            if (snapshot.GetLineNumberFromPosition(span.Start) == snapshot.GetLineNumberFromPosition(span.End))
                            {
                                continue;
                            }

                            SnapshotSpan                  snapshotSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, span);
                            IOutliningRegionTag           tag          = new OutliningRegionTag(blockHint, snapshotSpan.GetText());
                            TagSpan <IOutliningRegionTag> tagSpan      = new TagSpan <IOutliningRegionTag>(snapshotSpan, tag);
                            outliningRegions.Add(tagSpan);
                        }
                    }
                }

                foreach (var token in antlrParseResultArgs.Tokens)
                {
                    switch (token.Type)
                    {
                    case ANTLRParser.DOC_COMMENT:
                    case ANTLRParser.ML_COMMENT:
                        Span commentSpan = Span.FromBounds(token.StartIndex, token.StopIndex + 1);
                        if (snapshot.GetLineNumberFromPosition(commentSpan.Start) != snapshot.GetLineNumberFromPosition(commentSpan.End))
                        {
                            SnapshotSpan                  commentSnapshotSpan = new SnapshotSpan(antlrParseResultArgs.Snapshot, commentSpan);
                            IOutliningRegionTag           commentTag          = new OutliningRegionTag(string.Format("/*{0} ... */", token.Type == ANTLRParser.DOC_COMMENT ? "*" : string.Empty), commentSnapshotSpan.GetText());
                            TagSpan <IOutliningRegionTag> commentTagSpan      = new TagSpan <IOutliningRegionTag>(commentSnapshotSpan, commentTag);
                            outliningRegions.Add(commentTagSpan);
                        }
                        break;

                    default:
                        continue;
                    }
                }
#endif
            }

            this._outliningRegions = outliningRegions;
            OnTagsChanged(new SnapshotSpanEventArgs(new SnapshotSpan(antlrParseResultArgs.Snapshot, new Span(0, antlrParseResultArgs.Snapshot.Length))));
        }