public static IEnumerable <BaseInfo> GetElementCompletions(this MSBuildResolveResult rr, IEnumerable <IMSBuildSchema> schemas)
        {
            if (rr?.LanguageElement == null)
            {
                yield return(MSBuildLanguageElement.Get("Project"));

                yield break;
            }

            if (rr.LanguageElement.Children == null)
            {
                yield break;
            }

            foreach (var c in rr.LanguageElement.Children)
            {
                if (c.IsAbstract)
                {
                    var abstractChildren = GetAbstractChildren(schemas, rr.LanguageElement.AbstractChild.SyntaxKind, rr.ElementName);
                    if (abstractChildren != null)
                    {
                        foreach (var child in abstractChildren)
                        {
                            yield return(child);
                        }
                    }
                }
                else
                {
                    yield return(c);
                }
            }
        }
예제 #2
0
        static MSBuildLanguageElement AddBuiltin(string name, string description, MSBuildSyntaxKind kind, MSBuildValueKind valueKind = MSBuildValueKind.Nothing, bool isAbstract = false)
        {
            var el = new MSBuildLanguageElement(name, description, kind, valueKind, isAbstract);

            builtin.Add(el.Name, el);
            return(el);
        }
 public MSBuildLanguageAttribute(
     MSBuildLanguageElement element,
     string name, DisplayText description, MSBuildSyntaxKind syntaxKind, MSBuildValueKind valueKind,
     bool required = false, MSBuildSyntaxKind?abstractKind = null)
     : base(name, description, valueKind)
 {
     SyntaxKind   = syntaxKind;
     Element      = element;
     Required     = required;
     AbstractKind = abstractKind;
 }
예제 #4
0
        public static MSBuildLanguageElement Get(string name, MSBuildLanguageElement parent = null)
        {
            if (parent != null)
            {
                foreach (var child in parent.children)
                {
                    if (string.Equals(child.Name, name, StringComparison.OrdinalIgnoreCase))
                    {
                        return(child);
                    }
                }
                return(parent.AbstractChild);
            }

            builtin.TryGetValue(name, out MSBuildLanguageElement result);
            return(result);
        }
        public static bool IsInTarget(this MSBuildLanguageElement resolvedElement, Xml.Dom.XElement element)
        {
            switch (resolvedElement.SyntaxKind)
            {
            case MSBuildSyntaxKind.Metadata:
                element = element?.ParentElement;
                goto case MSBuildSyntaxKind.Item;

            case MSBuildSyntaxKind.Property:
            case MSBuildSyntaxKind.Item:
                element = element?.ParentElement;
                goto case MSBuildSyntaxKind.ItemGroup;

            case MSBuildSyntaxKind.ItemGroup:
            case MSBuildSyntaxKind.PropertyGroup:
                var name = element?.ParentElement?.Name.Name;
                return(string.Equals(name, "Target", StringComparison.OrdinalIgnoreCase));
            }
            return(false);
        }
예제 #6
0
        public static ValueInfo GetElementInfo(this IEnumerable <IMSBuildSchema> schemas, MSBuildLanguageElement element, string parentName, string elementName, bool omitEmpty = false)
        {
            if (element.IsAbstract)
            {
                switch (element.SyntaxKind)
                {
                case MSBuildSyntaxKind.Item:
                case MSBuildSyntaxKind.ItemDefinition:
                    if (omitEmpty)
                    {
                        return(null);
                    }
                    return(schemas.GetItem(elementName));

                case MSBuildSyntaxKind.Metadata:
                    return(schemas.GetMetadata(parentName, elementName, false));

                case MSBuildSyntaxKind.Property:
                    return(schemas.GetProperty(elementName));

                case MSBuildSyntaxKind.Task:
                    return(null);

                case MSBuildSyntaxKind.Parameter:
                    if (omitEmpty)
                    {
                        return(null);
                    }
                    return(new TaskParameterInfo(elementName, null, false, false, MSBuildValueKind.Unknown));

                default:
                    throw new InvalidOperationException($"Unsupported abstract element kind {element.SyntaxKind}");
                }
            }

            if (omitEmpty && (element.ValueKind == MSBuildValueKind.Nothing || element.ValueKind == MSBuildValueKind.Data))
            {
                return(null);
            }
            return(element);
        }