コード例 #1
0
        public void Update(AmmyFile <Top> file)
        {
            try {
                _currentSpans.Clear();

                var fileSnapshot = (ITextSnapshot)file.Meta.Snapshot;
                var collector    = new AstCollectorVisitor(ast => ast is PropertyValue.String || ast is PropertyValue.ReferenceValue);

                file.Ast.Accept(collector);

                foreach (var item in collector.CollectedItems)
                {
                    if (item is PropertyValue.String)
                    {
                        var pvString = (PropertyValue.String)item;
                        if (pvString.Val.HasValue)
                        {
                            var stringValue = pvString.Val.Value;
                            var match       = Regex.Match(stringValue, @"^#([0-9a-fA-F]{8})$|^#((?:[0-9a-fA-F]{3}){1,2})$");
                            if (match.Success)
                            {
                                var brush = ParseColorValue(match.Value);
                                _currentSpans.Add(new ColorValueSpan(brush, new SnapshotSpan(fileSnapshot, item.Location.StartPos, item.Location.Length)));
                            }
                        }
                    }
                    else if (item is PropertyValue.ReferenceValue)
                    {
                        var rvalue = (PropertyValue.ReferenceValue)item;
                        if (rvalue.IsRefEvaluated && rvalue.Ref.IsSymbolEvaluated)
                        {
                            var symbol = rvalue.Ref.Symbol;

                            if (_brushesType.Namespace == null)
                            {
                                continue;
                            }

                            if (symbol.FullName.StartsWith(_brushesType.Namespace))
                            {
                                foreach (var brushProperty in _brushProperties)
                                {
                                    if (brushProperty.Name == symbol.Name)
                                    {
                                        var brush    = GetPredefinedBrush(brushProperty);
                                        var location = rvalue.Ref.Location;

                                        _currentSpans.Add(new ColorValueSpan(brush, new SnapshotSpan(fileSnapshot, location.StartPos, location.Length)));
                                    }
                                }
                            }
                        }
                    }
                }
            } catch (Exception e) {
                this.LogDebugInfo(e.ToString());
            }
        }
コード例 #2
0
        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());
            }
        }
コード例 #3
0
        public void Update(AmmyFile <Top> file)
        {
            _regionList = new List <ITagSpan <IOutliningRegionTag> >();

            var snapshot      = (ITextSnapshot)file.Meta.Snapshot;
            var nodeCollector = new AstCollectorVisitor(ast => ast is Node || ast is Function || ast is TypeFunctionRef);

            file.Ast.Accept(nodeCollector);

            foreach (var item in nodeCollector.CollectedItems)
            {
                var location = item.Location;

                if (location.StartLineColumn.Line == location.EndLineColumn.Line)
                {
                    continue;
                }

                var start             = location.StartPos;
                var text              = location.GetText();
                var closingBracketPos = text.LastIndexOf('}');
                var openingBraceIndex = text.IndexOf("{", StringComparison.InvariantCultureIgnoreCase);

                var ellipsis = openingBraceIndex > -1
                               ? text.Substring(0, openingBraceIndex)
                               : text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None).FirstOrDefault();

                var snapshotSpan       = new SnapshotSpan(snapshot, start, closingBracketPos + 1);
                var outliningRegionTag = new OutliningRegionTag(false, false, ellipsis, text);
                var span = new TagSpan <IOutliningRegionTag>(snapshotSpan, outliningRegionTag);

                _regionList.Add(span);
            }

            var args = new SnapshotSpanEventArgs(new SnapshotSpan(snapshot, 0, snapshot.Length));

            TagsChanged?.Invoke(this, args);
        }