public void Update(AmmyFile <Top> file)
        {
            try {
                _currentSpans.Clear();

                var fileSnapshot = (ITextSnapshot)file.Meta.Snapshot;
                var collector    = new AstCollectorVisitor(ast => ast is Node || ast is TypeFunctionRef);

                file.Ast.Accept(collector);

                if (file.GetErrors().Any())
                {
                    return;
                }

                foreach (var item in collector.CollectedItems)
                {
                    if (item.Location.EndLineColumn.Line - item.Location.StartLineColumn.Line < 5)
                    {
                        continue;
                    }

                    if (item is Node)
                    {
                        var node     = (Node)item;
                        var fullName = "end of " + node.Key.FullName();

                        if (node.NodeName.HasValue && node.NodeName.Value.Key.HasValue)
                        {
                            fullName += $" \"{node.NodeName.Value.Key.Value}\"";
                        }

                        var text = node.Location.GetText();
                        var closingBracketPos = text.LastIndexOf('}');
                        var position          = node.Location.StartPos + closingBracketPos;

                        _currentSpans.Add(new ClosingBracketSpan(fullName, new SnapshotSpan(fileSnapshot, position, 1)));
                    }
                    else if (item is TypeFunctionRef)
                    {
                        var tfr               = (TypeFunctionRef)item;
                        var fullName          = "end of @" + tfr.FunctionRef.Name;
                        var text              = tfr.Location.GetText();
                        var closingBracketPos = text.LastIndexOf('}');
                        var position          = tfr.Location.StartPos + closingBracketPos;

                        _currentSpans.Add(new ClosingBracketSpan(fullName, new SnapshotSpan(fileSnapshot, position, 1)));
                    }
                }
            } catch (Exception e) {
                this.LogDebugInfo(e.ToString());
            }
        }
Esempio n. 2
0
        public IEnumerable <ITagSpan <ErrorTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            try {
                var snapshot = _buffer.CurrentSnapshot;

                if (_latestFile == null)
                {
                    return(_emptyTags);
                }

                var localMessages = _latestFile.GetErrors();

                return(localMessages.Where(msg => msg.Location.EndPos <= snapshot.Length)
                       .Select(msg => TagSpanFromMessage(msg, snapshot)));
            } catch (Exception e) {
                this.LogDebugInfo("ErrorTagger.GetTags failed: " + e);
                return(new ITagSpan <ErrorTag> [0]);
            }
        }