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);
            }
        }
        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);
            }            
        }
        public IEnumerable<JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null)
                yield break;

            var vocabularies = VocabularyFactory.GetVocabularies(member);

            if (!vocabularies.Any())
                yield break;

            JSONBlockItem block = member.FindType<JSONBlockItem>();

            var visitor = new JSONItemCollector<JSONMember>();
            block.Accept(visitor);

            JSONMember ldType = visitor.Items.FirstOrDefault(m => m.Name != null && m.Value != null && m.Name.Text == "\"@type\"");

            if (ldType == null)
                yield break;

            string value = ldType.Value.Text.Trim('"');

            foreach (IVocabulary vocab in vocabularies.Where(v => v.Cache.ContainsKey(value)))
                foreach (Entry entry in vocab.Cache[value])
                    yield return new JSONCompletionEntry(entry.Name, "\"" + entry.Name + "\"", null,
                        entry.Glyph, "iconAutomationText", true, context.Session as ICompletionSession);
        }
        public static IEnumerable<Tuple<string, string>> GetTasks(JSONParseItem item)
        {
            var visitor = new JSONItemCollector<JSONMember>(true);
            item.JSONDocument.Accept(visitor);

            var scripts = visitor.Items.FirstOrDefault(member => member.UnquotedNameText == "scripts");

            if (scripts == null)
                yield break;

            foreach (JSONObject child in scripts.Children.Where(c => c is JSONObject))
                foreach (JSONMember taskItem in child.Children.Where(c => c is JSONMember))
                {
                    yield return Tuple.Create(taskItem.UnquotedNameText, taskItem.Value.Text);
                }
        }
Ejemplo n.º 5
0
        private static IEnumerable<IVocabulary> FindApplicableVocabularies(JSONParseItem member, IEnumerable<IVocabulary> vocabularies)
        {
            var parent = member.FindType<JSONBlockItem>();

            while (parent != null)
            {
                var visitor = new JSONItemCollector<JSONMember>();
                parent.Accept(visitor);

                var context = visitor.Items.FirstOrDefault(c => c.Name != null && c.Name.Text == "\"@context\"");

                foreach (IVocabulary vocab in vocabularies)
                {
                    if (vocab.AppliesToContext(context))
                        yield return vocab;
                }

                parent = parent.Parent.FindType<JSONBlockItem>();
            }
        }
Ejemplo n.º 6
0
        public IEnumerable <JSONCompletionEntry> GetListEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem as JSONMember;

            if (member == null || member.Name == null)
            {
                yield break;
            }

            var vocabularies = VocabularyFactory.GetVocabularies(member);

            if (!vocabularies.Any())
            {
                yield break;
            }

            JSONBlockItem block = member.FindType <JSONBlockItem>();

            var visitor = new JSONItemCollector <JSONMember>();

            block.Accept(visitor);

            JSONMember ldType = visitor.Items.FirstOrDefault(m => m.Name != null && m.Value != null && m.Name.Text == "\"@type\"");

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

            string value = ldType.Value.Text.Trim('"');

            foreach (IVocabulary vocab in vocabularies.Where(v => v.Cache.ContainsKey(value)))
            {
                foreach (Entry entry in vocab.Cache[value])
                {
                    yield return(new JSONCompletionEntry(entry.Name, "\"" + entry.Name + "\"", null,
                                                         entry.Glyph, "iconAutomationText", true, context.Session as ICompletionSession));
                }
            }
        }
Ejemplo n.º 7
0
        private static IEnumerable <IVocabulary> FindApplicableVocabularies(JSONParseItem member, IEnumerable <IVocabulary> vocabularies)
        {
            var parent = member.FindType <JSONBlockItem>();

            while (parent != null)
            {
                var visitor = new JSONItemCollector <JSONMember>();
                parent.Accept(visitor);

                var context = visitor.Items.FirstOrDefault(c => c.Name != null && c.Name.Text == "\"@context\"");

                foreach (IVocabulary vocab in vocabularies)
                {
                    if (vocab.AppliesToContext(context))
                    {
                        yield return(vocab);
                    }
                }

                parent = parent.Parent.FindType <JSONBlockItem>();
            }
        }
        public static IDictionary<string, string> GetIcons(JSONParseItem item)
        {
            var visitor = new JSONItemCollector<JSONMember>(true);
            var dic = new Dictionary<string, string>();

            if (!item.JSONDocument.Accept(visitor))
                return dic;

            var icons = visitor.Items.FirstOrDefault(m => m.UnquotedNameText == "icons");
            var value = icons?.Value as JSONObject;

            if (value == null)
                return dic;

            string folder = Path.GetDirectoryName(item.JSONDocument.DocumentLocation);

            foreach (JSONMember icon in value.Children.OfType<JSONMember>())
            {
                dic.Add(icon.UnquotedNameText, icon.UnquotedValueText);
            }

            return dic;
        }
        public static IEnumerable<string> GetVariables(JSONParseItem item)
        {
            var visitor = new JSONItemCollector<JSONMember>(true);

            if (!item.JSONDocument.Accept(visitor))
                return null;

            var contents = visitor.Items.Where(m => m.UnquotedNameText == "content" && m.IsValid);
            List<string> list = new List<string>();

            foreach (JSONMember content in contents)
            {
                var value = content?.Value as JSONObject;

                if (value == null)
                    continue;

                var names = value.Children.OfType<JSONMember>().Select(s => s.UnquotedNameText);

                list.AddRange(names.Where(n => !list.Contains(n)));
            }

            return list;
        }