private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            AntlrParseResultEventArgs antlrParseResultArgs = e as AntlrParseResultEventArgs;
            if (antlrParseResultArgs == null)
                return;

            UpdateTags(antlrParseResultArgs);
        }
        protected virtual void OnParseComplete(ParseResultEventArgs e)
        {
            Contract.Requires <ArgumentNullException>(e != null, "e");

            var t = ParseComplete;

            if (t != null)
            {
                t(this, e);
            }
        }
Exemplo n.º 3
0
        protected virtual void OnParseComplete(ParseResultEventArgs e)
        {
            Requires.NotNull(e, nameof(e));

            var t = ParseComplete;

            if (t != null)
            {
                t(this, e);
            }
        }
        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;
        }
 protected override void OnParseComplete(ParseResultEventArgs e)
 {
     PreviousParseResult = e as AntlrParseResultEventArgs;
     base.OnParseComplete(e);
 }
        private void HandleBackgroundParseComplete(object sender, ParseResultEventArgs e)
        {
            if (!object.ReferenceEquals(sender, BackgroundParser))
                return;

            MarkdownParseResultEventArgs markdownArgs = e as MarkdownParseResultEventArgs;
            if (e == null)
                return;

            var html = markdownArgs.HtmlText;
            BrowserDispatch(SaveScrollTop);
            NavigateToString(html);
        }
        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);
        }
        protected virtual void OnParseComplete(ParseResultEventArgs e)
        {
            Contract.Requires<ArgumentNullException>(e != null, "e");

            var t = ParseComplete;
            if (t != null)
                t(this, e);
        }
        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);
        }
Exemplo n.º 10
0
 private void HandleParseComplete(object sender, ParseResultEventArgs e)
 {
     TryHandleParseCompleteV3(sender, e);
     TryHandleParseCompleteV4(sender, e);
 }