Ejemplo n.º 1
0
        protected GraphNode CreateParentNode(IGraphContext context, GraphNodeId urlPart, string label, GraphCategory category)
        {
            GraphNodeId idPart = urlPart + GraphNodeId.GetPartial(CssGraphSchema.CssType, label);
            GraphNode   idNode = context.Graph.Nodes.GetOrCreate(idPart, label, category);

            idNode[DgmlNodeProperties.Icon] = Images.Parent;

            return(idNode);
        }
        private static GraphNodeId GetTopLevelGraphNodeId(string projectPath, string modelId)
        {
            string projectFolder = Path.GetDirectoryName(projectPath)?.ToLowerInvariant() ?? string.Empty;
            var    filePath      = new Uri(Path.Combine(projectFolder, modelId.ToLowerInvariant()), UriKind.RelativeOrAbsolute);

            return(GraphNodeId.GetNested(
                       GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, new Uri(projectPath, UriKind.RelativeOrAbsolute)),
                       GraphNodeId.GetPartial(CodeGraphNodeIdName.File, filePath)));
        }
Ejemplo n.º 3
0
        protected virtual void CreateNode(IGraphContext context, GraphNode file, ParseItem item, GraphCategory category)
        {
            GraphNodeId id   = file.Id + GraphNodeId.GetPartial(CssGraphSchema.CssParseItem, item);
            GraphNode   node = context.Graph.Nodes.GetOrCreate(id, GetLabel(item), category);

            node[DgmlNodeProperties.Icon] = Images.Child;

            context.Graph.Links.GetOrCreate(file, node, null, GraphCommonSchema.Contains);
            context.OutputNodes.Add(node);
        }
Ejemplo n.º 4
0
        private static async Task <IEnumerable <GraphNodeId> > GetPartialsForNamespaceAndTypeAsync(ITypeSymbol symbol, bool includeNamespace, Solution solution, CancellationToken cancellationToken, bool isInGenericArguments = false)
        {
            var items = new List <GraphNodeId>();

            Uri assembly = null;

            if (includeNamespace)
            {
                assembly = await GetAssemblyFullPathAsync(symbol, solution, cancellationToken).ConfigureAwait(false);
            }

            var underlyingType = ChaseToUnderlyingType(symbol);

            if (symbol.TypeKind == TypeKind.TypeParameter)
            {
                var typeParameter = (ITypeParameterSymbol)symbol;

                if (typeParameter.TypeParameterKind == TypeParameterKind.Type)
                {
                    if (includeNamespace && !typeParameter.ContainingNamespace.IsGlobalNamespace)
                    {
                        if (assembly != null)
                        {
                            items.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, assembly));
                        }

                        items.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Namespace, typeParameter.ContainingNamespace.ToDisplayString()));
                    }

                    items.Add(await GetPartialForTypeAsync(symbol.ContainingType, CodeGraphNodeIdName.Type, solution, cancellationToken).ConfigureAwait(false));
                }

                items.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Parameter, ((ITypeParameterSymbol)symbol).Ordinal.ToString()));
            }
            else
            {
                if (assembly != null)
                {
                    items.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, assembly));
                }

                if (underlyingType.TypeKind == TypeKind.Dynamic)
                {
                    items.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Namespace, "System"));
                }
                else if (underlyingType.ContainingNamespace != null && !underlyingType.ContainingNamespace.IsGlobalNamespace)
                {
                    items.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Namespace, underlyingType.ContainingNamespace.ToDisplayString()));
                }

                items.Add(await GetPartialForTypeAsync(symbol, CodeGraphNodeIdName.Type, solution, cancellationToken, isInGenericArguments).ConfigureAwait(false));
            }

            return(items);
        }
Ejemplo n.º 5
0
        private GraphNodeId GetGraphNodeId(string projectPath, IDependencyNode nodeInfo)
        {
            var partialValues = new List <GraphNodeId>();

            partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly,
                                                     new Uri(projectPath, UriKind.RelativeOrAbsolute)));
            partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.File,
                                                     new Uri(nodeInfo.Id.ToString().ToLowerInvariant(),
                                                             UriKind.RelativeOrAbsolute)));
            return(GraphNodeId.GetNested(partialValues.ToArray()));
        }
Ejemplo n.º 6
0
 public static GraphNodeId GetIdForDocument(Document document)
 {
     return(GraphNodeId.GetNested(
                GraphNodeId.GetPartial(
                    CodeGraphNodeIdName.Assembly,
                    new Uri(document.Project.FilePath, UriKind.RelativeOrAbsolute)
                    ),
                GraphNodeId.GetPartial(
                    CodeGraphNodeIdName.File,
                    new Uri(document.FilePath, UriKind.RelativeOrAbsolute)
                    )
                ));
 }
Ejemplo n.º 7
0
        private GraphNodeId GetTopLevelGraphNodeId(string projectPath, string modelId)
        {
            var partialValues = new List<GraphNodeId>
            {
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, new Uri(projectPath, UriKind.RelativeOrAbsolute))
            };

            var projectFolder = Path.GetDirectoryName(projectPath)?.ToLowerInvariant() ?? string.Empty;
            var filePath = new Uri(Path.Combine(projectFolder, modelId.ToLowerInvariant()), UriKind.RelativeOrAbsolute);

            partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.File, filePath));

            return GraphNodeId.GetNested(partialValues.ToArray());
        }
Ejemplo n.º 8
0
        private static async Task <GraphNodeId> GetPartialForTypeParameterSymbolAsync(ITypeParameterSymbol typeParameterSymbol, GraphNodeIdName nodeName, Solution solution, CancellationToken cancellationToken)
        {
            if (typeParameterSymbol.TypeParameterKind == TypeParameterKind.Method)
            {
                return(GraphNodeId.GetPartial(nodeName,
                                              new GraphNodeIdCollection(false,
                                                                        GraphNodeId.GetPartial(CodeGraphNodeIdName.Parameter, typeParameterSymbol.Ordinal.ToString()))));
            }
            else
            {
                var nodes = await GetPartialsForNamespaceAndTypeAsync(typeParameterSymbol, false, solution, cancellationToken).ConfigureAwait(false);

                return(GraphNodeId.GetPartial(nodeName,
                                              new GraphNodeIdCollection(false, nodes.ToArray())));
            }
        }
Ejemplo n.º 9
0
        internal static async Task <GraphNodeId> GetIdForParameterAsync(
            IParameterSymbol symbol,
            Solution solution,
            CancellationToken cancellationToken
            )
        {
            if (
                symbol.ContainingSymbol == null ||
                (
                    symbol.ContainingSymbol.Kind != SymbolKind.Method &&
                    symbol.ContainingSymbol.Kind != SymbolKind.Property
                )
                )
            {
                // We are only support parameters inside methods or properties.
                throw new ArgumentException("symbol");
            }

            var containingSymbol = symbol.ContainingSymbol;

            if (
                containingSymbol is IMethodSymbol method &&
                method.AssociatedSymbol != null &&
                method.AssociatedSymbol.Kind == SymbolKind.Property
                )
            {
                var property = (IPropertySymbol)method.AssociatedSymbol;
                if (property.Parameters.Any(p => p.Name == symbol.Name))
                {
                    containingSymbol = property;
                }
            }

            var memberId = await GetIdForMemberAsync(containingSymbol, solution, cancellationToken)
                           .ConfigureAwait(false);

            if (memberId != null)
            {
                return(memberId
                       + GraphNodeId.GetPartial(CodeGraphNodeIdName.Parameter, symbol.Name));
            }

            return(null);
        }
        public static GraphNode CreateNode(string projectPath,
                                           string nodeIdString,
                                           IDependencyNode node = null)
        {
            var graph = new Graph();
            var id    = GraphNodeId.GetNested(
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, new Uri(projectPath, UriKind.RelativeOrAbsolute)),
                GraphNodeId.GetPartial(CodeGraphNodeIdName.File, new Uri(nodeIdString, UriKind.RelativeOrAbsolute))
                );

            var graphNode = graph.Nodes.GetOrCreate(id);

            if (node != null)
            {
                graphNode.SetValue(DependenciesGraphSchema.DependencyNodeProperty, node);
            }

            return(graphNode);
        }
Ejemplo n.º 11
0
        private static async Task <GraphNodeId> GetPartialForArrayTypeAsync(IArrayTypeSymbol arrayType, GraphNodeIdName nodeName, Solution solution, CancellationToken cancellationToken)
        {
            var partials = new List <GraphNodeId>();

            var underlyingType = ChaseToUnderlyingType(arrayType);

            if (underlyingType.TypeKind == TypeKind.Dynamic)
            {
                partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, "Object"));
            }
            else if (underlyingType.TypeKind != TypeKind.TypeParameter)
            {
                partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, underlyingType.Name));
            }

            partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.ArrayRank, arrayType.Rank.ToString()));
            partials.Add(await GetPartialForTypeAsync(arrayType.ElementType, CodeGraphNodeIdName.ParentType, solution, cancellationToken).ConfigureAwait(false));

            return(GraphNodeId.GetPartial(nodeName, MakeCollectionIfNecessary(false, partials.ToArray())));
        }
Ejemplo n.º 12
0
 private void PopulateChildrenOfNodes(IGraphContext context)
 {
     using (var scope = new GraphTransactionScope())
     {
         foreach (var file in context.InputNodes.Where(IsMdFile))
         {
             Graph graph = file.Owner;
             var   fn    = file.Id.GetNestedValueByName <Uri>(CodeGraphNodeIdName.File).LocalPath;
             foreach (var heading in GetMdHeadings(file))
             {
                 GraphNodeId valueId = file.Id + GraphNodeId.GetPartial(MarkdownSchema.MdValueName, heading.Item1);
                 GraphNode   node    = graph.Nodes.GetOrCreate(valueId, heading.Item1, MarkdownSchema.Heading);
                 node.SetValue(CodeNodeProperties.SourceLocation, heading.Item2);
                 GraphLink link = graph.Links.GetOrCreate(file, node, null, MarkdownSchema.File2HeadingLink);
                 context.OutputNodes.Add(node);
             }
         }
         scope.Complete();
     }
 }
Ejemplo n.º 13
0
        private void CreateValues(IGraphContext context, GraphNode node)
        {
            StyleSheet  stylesheet = CssGraphProvider.GetOrCreateStyleSheet(node, _fileService);
            GraphNodeId urlPart    = node.Id + GraphNodeId.GetPartial(CssGraphSchema.CssStyleSheet, stylesheet);

            // Mixin
            if (FindCssItems <LessMixinDeclaration>(stylesheet).Count > 0)
            {
                GraphNode mixinNode = CreateParentNode(context, urlPart, "Mixins", LessGraphSchema.LessMixinParent);
                context.Graph.Links.GetOrCreate(node, mixinNode, "mixin", GraphCommonSchema.Contains);
                context.OutputNodes.Add(mixinNode);
            }

            // Variable
            if (FindCssItems <LessVariableDeclaration>(stylesheet).Count > 0)
            {
                GraphNode variableNode = CreateParentNode(context, urlPart, "Variables", LessGraphSchema.LessVariableParent);
                context.Graph.Links.GetOrCreate(node, variableNode, "hat", GraphCommonSchema.Contains);
                context.OutputNodes.Add(variableNode);
            }
        }
Ejemplo n.º 14
0
        private static async Task <GraphNodeId> GetPartialForPointerTypeAsync(IPointerTypeSymbol pointerType, GraphNodeIdName nodeName, Solution solution, CancellationToken cancellationToken)
        {
            var indirection = 1;

            while (pointerType.PointedAtType.TypeKind == TypeKind.Pointer)
            {
                indirection++;
                pointerType = (IPointerTypeSymbol)pointerType.PointedAtType;
            }

            var partials = new List <GraphNodeId>();

            partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, pointerType.PointedAtType.Name));
            partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Indirection, indirection.ToString()));

            if (pointerType.PointedAtType.ContainingType != null)
            {
                partials.Add(await GetPartialForTypeAsync(pointerType.PointedAtType.ContainingType, CodeGraphNodeIdName.ParentType, solution, cancellationToken).ConfigureAwait(false));
            }

            return(GraphNodeId.GetPartial(nodeName, MakeCollectionIfNecessary(false, partials.ToArray())));
        }
Ejemplo n.º 15
0
        private GraphNodeId GetTopLevelGraphNodeId(string projectPath, IDependencyNode nodeInfo)
        {
            var partialValues = new List <GraphNodeId>();

            partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly,
                                                     new Uri(projectPath, UriKind.RelativeOrAbsolute)));
            if (nodeInfo.Flags.Contains(DependencyNode.GenericDependencyFlags))
            {
                var projectFolder = Path.GetDirectoryName(projectPath)?.ToLowerInvariant();
                if (nodeInfo.Flags.Contains(DependencyNode.CustomItemSpec))
                {
                    var name = DependencyNode.GetName(nodeInfo);
                    if (name != null)
                    {
                        partialValues.Add(GraphNodeId.GetPartial(
                                              CodeGraphNodeIdName.File,
                                              new Uri(Path.Combine(projectFolder, name.ToLowerInvariant()),
                                                      UriKind.RelativeOrAbsolute)));
                    }
                }
                else
                {
                    var fullItemSpecPath = MakeRooted(projectFolder, nodeInfo.Id.ItemSpec);
                    if (!string.IsNullOrEmpty(fullItemSpecPath))
                    {
                        partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.File,
                                                                 new Uri(fullItemSpecPath.ToLowerInvariant(), UriKind.RelativeOrAbsolute)));
                    }
                }
            }
            else
            {
                partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.File,
                                                         new Uri(nodeInfo.Id.ToString().ToLowerInvariant(), UriKind.RelativeOrAbsolute)));
            }

            return(GraphNodeId.GetNested(partialValues.ToArray()));
        }
Ejemplo n.º 16
0
        private void CreateNode(IGraphContext context, GraphNode parent, PaketMetadata metadata)
        {
            var parentId = parent.GetValue <GraphNodeId>("Id");
            var id       = GraphNodeId.GetNested(
                parentId,
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Member, metadata.Id),
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Parameter, metadata.VersionString));

            var node = context.Graph.Nodes.Get(id);

            if (node == null)
            {
                string label = metadata.Id + " " + metadata.VersionString;

                node = context.Graph.Nodes.GetOrCreate(id, label, PaketGraphSchema.PaketCategory);

                node.SetValue(DgmlNodeProperties.ContainsChildren, false);
                node.SetValue(CodeNodeProperties.SourceLocation, new SourceLocation(new Uri(parentId.GetFileName(), UriKind.Absolute),
                                                                                    new Position(PaketGraphSchema.GetDisplayIndex(node), 1)));
                node.SetValue(DgmlNodeProperties.Icon, GraphIcons.Package);
            }

            context.Graph.Links.GetOrCreate(parent, node, null, GraphCommonSchema.Contains);
        }
        private GraphNodeId GetGraphNodeId(string projectPath, IDependencyNode nodeInfo, GraphNode parentNode)
        {
            var partialValues = new List <GraphNodeId>
            {
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly,
                                       new Uri(projectPath, UriKind.RelativeOrAbsolute)),
                GraphNodeId.GetPartial(CodeGraphNodeIdName.File,
                                       new Uri(nodeInfo.Id.ToString().ToLowerInvariant(),
                                               UriKind.RelativeOrAbsolute))
            };

            // to ensure Graph id for node is unique we add a hashcodes for node's parents separated by ';'
            var parents = parentNode.Id.GetNestedValueByName <string>(CodeGraphNodeIdName.Namespace);

            if (string.IsNullOrEmpty(parents))
            {
                parents = projectPath.GetHashCode().ToString();
            }

            parents = parents + ";" + nodeInfo.Id.GetHashCode();
            partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Namespace, parents));

            return(GraphNodeId.GetNested(partialValues.ToArray()));
        }
Ejemplo n.º 18
0
        public static async Task <GraphNodeId> GetIdForMemberAsync(ISymbol member, Solution solution, CancellationToken cancellationToken)
        {
            var partials = new List <GraphNodeId>();

            partials.AddRange(await GetPartialsForNamespaceAndTypeAsync(member.ContainingType, true, solution, cancellationToken).ConfigureAwait(false));

            var parameters = member.GetParameters();

            if (parameters.Any() || member.GetArity() > 0)
            {
                var memberPartials = new List <GraphNodeId>();

                memberPartials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, member.MetadataName));

                if (member.GetArity() > 0)
                {
                    memberPartials.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.GenericParameterCountIdentifier, member.GetArity().ToString()));
                }

                if (parameters.Any())
                {
                    var parameterTypeIds = new List <GraphNodeId>();
                    foreach (var p in parameters)
                    {
                        var parameterIds = await GetPartialsForNamespaceAndTypeAsync(p.Type, true, solution, cancellationToken).ConfigureAwait(false);

                        var nodes = parameterIds.ToList();
                        if (p.IsRefOrOut())
                        {
                            nodes.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.ParamKind, ParamKind.Ref));
                        }

                        parameterTypeIds.Add(GraphNodeId.GetNested(nodes.ToArray()));
                    }

                    if (member is IMethodSymbol methodSymbol && methodSymbol.MethodKind == MethodKind.Conversion)
                    {
                        // For explicit/implicit conversion operators, we need to include the return type in the method Id,
                        // because there can be several conversion operators with same parameters and only differ by return type.
                        // For example,
                        //
                        //     public class Class1
                        //     {
                        //         public static explicit (explicit) operator int(Class1 c) { ... }
                        //         public static explicit (explicit) operator double(Class1 c) { ... }
                        //     }

                        var nodes = await GetPartialsForNamespaceAndTypeAsync(methodSymbol.ReturnType, true, solution, cancellationToken).ConfigureAwait(false);

                        List <GraphNodeId> returnTypePartial = nodes.ToList();
                        returnTypePartial.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.ParamKind, Microsoft.VisualStudio.GraphModel.CodeSchema.ParamKind.Return));

                        GraphNodeId returnCollection = GraphNodeId.GetNested(returnTypePartial.ToArray());
                        parameterTypeIds.Add(returnCollection);
                    }

                    memberPartials.Add(GraphNodeId.GetArray(
                                           CodeGraphNodeIdName.OverloadingParameters,
                                           parameterTypeIds.ToArray()));
                }

                partials.Add(GraphNodeId.GetPartial(
                                 CodeGraphNodeIdName.Member,
                                 MakeCollectionIfNecessary(false, memberPartials.ToArray())));
            }
            else
            {
                partials.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Member, member.MetadataName));
            }

            return(GraphNodeId.GetNested(partials.ToArray()));
        }
Ejemplo n.º 19
0
 private static GraphNodeId GetPartialForDynamicType(IDynamicTypeSymbol dt, GraphNodeIdName nodeName)
 {
     // We always consider this to be the "Object" type since Progression takes a very metadata-ish view of the type
     return(GraphNodeId.GetPartial(nodeName, "Object"));
 }
Ejemplo n.º 20
0
 public static GraphNodeId GetId(this IItemNode node)
 {
     return(GraphNodeId.GetNested(
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, GetProjectFileUri(node.OwningProject.As <Project>())),
                GraphNodeId.GetPartial(CodeGraphNodeIdName.File, new Uri(node.PhysicalPath, UriKind.RelativeOrAbsolute))));
 }
Ejemplo n.º 21
0
        private static async Task <GraphNodeId> GetPartialForNamedTypeAsync(
            INamedTypeSymbol namedType,
            GraphNodeIdName nodeName,
            Solution solution,
            CancellationToken cancellationToken,
            bool isInGenericArguments = false
            )
        {
            // If this is a simple type, then we don't have much to do
            if (
                namedType.ContainingType == null &&
                Equals(namedType.ConstructedFrom, namedType) &&
                namedType.Arity == 0
                )
            {
                return(GraphNodeId.GetPartial(nodeName, namedType.Name));
            }
            else
            {
                // For a generic type, we need to populate "type" property with the following form:
                //
                //      Type = (Name =...GenericParameterCount = GenericArguments =...ParentType =...)
                //
                //  where "Name" contains a symbol name
                //    and "GenericParameterCount" contains the number of type parameters,
                //    and "GenericArguments" contains its type parameters' node information.
                //    and "ParentType" contains its containing type's node information.

                var partials = new List <GraphNodeId>();

                partials.Add(GraphNodeId.GetPartial(CodeQualifiedName.Name, namedType.Name));

                if (namedType.Arity > 0)
                {
                    partials.Add(
                        GraphNodeId.GetPartial(
                            CodeGraphNodeIdName.GenericParameterCountIdentifier,
                            namedType.Arity.ToString()
                            )
                        );
                }

                // For the property "GenericArguments", we only populate them
                // when type parameters are constructed using instance types (i.e., namedType.ConstructedFrom != namedType).
                // However, there is a case where we need to populate "GenericArguments" even though arguments are not marked as "constructed"
                // because a symbol is not marked as "constructed" when a type is constructed using its own type parameters.
                // To distinguish this case, we use "isInGenericArguments" flag which we pass either to populate arguments recursively or to populate "ParentType".

                var hasGenericArguments =
                    (!Equals(namedType.ConstructedFrom, namedType) || isInGenericArguments) &&
                    namedType.TypeArguments != null &&
                    namedType.TypeArguments.Any();

                if (hasGenericArguments)
                {
                    var genericArguments = new List <GraphNodeId>();
                    foreach (var arg in namedType.TypeArguments)
                    {
                        var nodes = await GetPartialsForNamespaceAndTypeAsync(
                            arg,
                            includeNamespace : true,
                            solution : solution,
                            cancellationToken : cancellationToken,
                            isInGenericArguments : true
                            )
                                    .ConfigureAwait(false);

                        genericArguments.Add(GraphNodeId.GetNested(nodes.ToArray()));
                    }

                    partials.Add(
                        GraphNodeId.GetArray(
                            CodeGraphNodeIdName.GenericArgumentsIdentifier,
                            genericArguments.ToArray()
                            )
                        );
                }

                if (namedType.ContainingType != null)
                {
                    partials.Add(
                        await GetPartialForTypeAsync(
                            namedType.ContainingType,
                            CodeGraphNodeIdName.ParentType,
                            solution,
                            cancellationToken,
                            hasGenericArguments
                            )
                        .ConfigureAwait(false)
                        );
                }

                return(GraphNodeId.GetPartial(
                           nodeName,
                           MakeCollectionIfNecessary(partials.ToArray())
                           ));
            }
        }