public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null || member.Name.Text != "\"$ref\"" || member.JSONDocument.Children.Count == 0)
            {
                yield break;
            }

            var visitor = new JSONItemCollector <JSONMember>(false);

            member.JSONDocument.Children[0].Accept(visitor);

            var definition = visitor.Items.FirstOrDefault(prop => prop.Name != null && prop.Name.Text == "\"definitions\"");

            if (definition == null || definition.Children.Count < 3)
            {
                yield break;
            }

            var block = definition.Children[2] as JSONBlockItem;

            var visitor2 = new JSONItemCollector <JSONMember>(false);

            block.Accept(visitor2);

            foreach (var prop in visitor2.Items)
            {
                string text = "#/definitions/" + prop.Name.Text.Trim('"');

                yield return(new SimpleCompletionEntry(text, StandardGlyphGroup.GlyphReference, context.Session));
            }
        }
예제 #2
0
        protected override bool Execute(VSConstants.VSStd2KCmdID commandId, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            var selection = TextView.GetSelection("JSON");

            if (selection == null)
            {
                return(false);
            }

            var doc = JSONEditorDocument.FromTextBuffer(selection.Value.Snapshot.TextBuffer);

            if (doc == null)
            {
                return(false);
            }

            var visitor = new JSONItemCollector <JSONMember>(true);

            doc.JSONDocument.Accept(visitor);

            var properties = visitor.Items.Where(i => !i.IsValid && i.Name != null).Reverse();

            if (properties.Count() == 0)
            {
                return(false);
            }

            try
            {
                InsertMissingQuotes(properties);
            }
            catch
            {
                // Do nothing
            }

            return(false);
        }
예제 #3
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember req = context.ContextItem.FindType <JSONMember>();

            if (req == null || req.Name == null || req.Name.Text != "\"required\"")
            {
                yield break;
            }

            var propVisitor = new JSONItemCollector <JSONMember>();

            req.Parent.Accept(propVisitor);

            var props = propVisitor.Items.FirstOrDefault(i => i.Name.Text == "\"properties\"");

            if (props == null)
            {
                yield break;
            }

            var child = props.Children[2] as JSONBlockItem;

            if (child == null)
            {
                yield break;
            }

            var visitor = new JSONItemCollector <JSONMember>();

            child.Accept(visitor);

            foreach (var item in visitor.Items)
            {
                yield return(new SimpleCompletionEntry(item.Name.Text.Trim('"'), context.Session));
            }
        }