public JSONItemValidationResult ValidateItem(JSONParseItem item, IJSONValidationContext context)
        {
            JSONMember member = item as JSONMember;

            if (member != null && member.Name != null && member.Name.Text == "\"$ref\"")
            {
                var parent = member.FindType <JSONBlockItem>();

                // Only show error when $ref is not the only property in the object
                if (parent == null || parent.BlockItemChildren.Count() == 1)
                {
                    return(JSONItemValidationResult.Continue);
                }

                JsonErrorTag error = new JsonErrorTag
                {
                    Flags    = JSONErrorFlags.UnderlineBlue | JSONErrorFlags.ErrorListMessage,
                    Item     = member.Name,
                    Start    = member.Name.Start,
                    AfterEnd = member.Name.AfterEnd,
                    Length   = member.Name.Length,
                    Text     = "When $ref is present, all other attributes are ignored"
                };

                context.AddError(error);
            }

            return(JSONItemValidationResult.Continue);
        }
Exemplo n.º 2
0
        protected override IEnumerable <JSONCompletionEntry> GetEntries(JSONCompletionContext context)
        {
            JSONMember member = context.ContextItem.FindType <JSONMember>();

            if (member == null || (member.UnquotedNameText != ManifestConstants.Destination && member.UnquotedNameText != ManifestConstants.DefaultDestination))
            {
                yield break;
            }

            JSONMember parent = member.FindType <JSONObject>()?.FindType <JSONMember>();

            if (member.UnquotedNameText == ManifestConstants.Destination && (parent == null || parent.UnquotedNameText != ManifestConstants.Libraries))
            {
                yield break;
            }

            if (member.UnquotedNameText == ManifestConstants.DefaultDestination && parent != null)
            {
                yield break;
            }

            int caretPosition = context.Session.TextView.Caret.Position.BufferPosition - member.Value.Start - 1;

            if (caretPosition > member.UnquotedValueText.Length)
            {
                yield break;
            }

            var    dependencies = Dependencies.FromConfigFile(ConfigFilePath);
            string cwd          = dependencies?.GetHostInteractions().WorkingDirectory;

            if (string.IsNullOrEmpty(cwd))
            {
                yield break;
            }

            IEnumerable <Tuple <string, string> > completions = GetCompletions(cwd, member.UnquotedValueText, caretPosition, out Span span);
            int           start        = member.Value.Start;
            ITrackingSpan trackingSpan = context.Snapshot.CreateTrackingSpan(start + 1 + span.Start, span.Length, SpanTrackingMode.EdgeInclusive);

            foreach (Tuple <string, string> item in completions)
            {
                yield return(new SimpleCompletionEntry(item.Item1, item.Item2, KnownMonikers.FolderClosed, trackingSpan, context.Session));
            }
        }
Exemplo n.º 3
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));
                }
            }
        }