Beispiel #1
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(partials.ToArray())));
        }
Beispiel #2
0
        internal static async Task <GraphNodeId> GetIdForTypeAsync(
            ITypeSymbol symbol,
            Solution solution,
            CancellationToken cancellationToken
            )
        {
            var nodes = await GetPartialsForNamespaceAndTypeAsync(
                symbol,
                true,
                solution,
                cancellationToken
                )
                        .ConfigureAwait(false);

            var partials = nodes.ToArray();

            if (partials.Length == 1)
            {
                return(partials[0]);
            }
            else
            {
                return(GraphNodeId.GetNested(partials));
            }
        }
Beispiel #3
0
        private GraphNodeId GetGraphNodeId(string projectPath, GraphNode parentNode, string modelId)
        {
            var partialValues = new List <GraphNodeId>
            {
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly,
                                       new Uri(projectPath, UriKind.RelativeOrAbsolute)),
                GraphNodeId.GetPartial(CodeGraphNodeIdName.File,
                                       new Uri(modelId.ToLowerInvariant(), UriKind.RelativeOrAbsolute))
            };

            var parents = string.Empty;

            if (parentNode != null)
            {
                // to ensure Graph id for node is unique we add a hashcodes for node's parents separated by ';'
                parents = parentNode.Id.GetNestedValueByName <string>(CodeGraphNodeIdName.Namespace);
                if (string.IsNullOrEmpty(parents))
                {
                    var currentProject = parentNode.Id.GetValue(CodeGraphNodeIdName.Assembly) ?? projectPath;
                    parents = currentProject.GetHashCode().ToString();
                }
            }
            else
            {
                parents = projectPath.GetHashCode().ToString();
            }

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

            return(GraphNodeId.GetNested(partialValues.ToArray()));
        }
Beispiel #4
0
        private GraphNode DoAddGraphNode(
            GraphNodeId graphNodeId,
            IGraphContext graphContext,
            string projectPath,
            GraphNode parentNode,
            IDependencyViewModel viewModel)
        {
            RegisterIcons(viewModel.GetIcons());

            var newNode = graphContext.Graph.Nodes.GetOrCreate(graphNodeId, viewModel.Caption, null);

            newNode.SetValue(DgmlNodeProperties.Icon, GetIconStringName(viewModel.Icon));
            // priority sets correct order among peers
            newNode.SetValue(CodeNodeProperties.SourceLocation,
                             new SourceLocation(projectPath, new Position(viewModel.Priority, 0)));
            newNode.AddCategory(DependenciesGraphSchema.CategoryDependency);

            if (viewModel.OriginalModel != null)
            {
                newNode.SetValue(DependenciesGraphSchema.DependencyIdProperty, viewModel.OriginalModel.Id);
                newNode.SetValue(DependenciesGraphSchema.ResolvedProperty, viewModel.OriginalModel.Resolved);
            }

            graphContext.OutputNodes.Add(newNode);

            if (parentNode != null)
            {
                graphContext.Graph.Links.GetOrCreate(parentNode, newNode, /*label*/ null, CodeLinkCategories.Contains);
            }

            return(newNode);
        }
Beispiel #5
0
        private GraphNode DoAddGraphNode(GraphNodeId graphNodeId,
                                         IGraphContext graphContext,
                                         string projectPath,
                                         IProjectDependenciesSubTreeProvider subTreeProvider,
                                         GraphNode parentNode,
                                         IDependencyNode nodeInfo)
        {
            var newNode = graphContext.Graph.Nodes.GetOrCreate(graphNodeId, nodeInfo.Caption, null);

            newNode.SetValue(DgmlNodeProperties.Icon, GetIconStringName(nodeInfo.Icon));
            newNode.SetValue(DependenciesGraphSchema.DependencyNodeProperty, nodeInfo);
            // priority sets correct order among peers
            newNode.SetValue(CodeNodeProperties.SourceLocation,
                             new SourceLocation(projectPath, new Position(nodeInfo.Priority, 0)));
            newNode.SetValue(DependenciesGraphSchema.ProviderProperty, subTreeProvider);

            newNode.AddCategory(DependenciesGraphSchema.CategoryDependency);

            graphContext.OutputNodes.Add(newNode);

            if (parentNode != null)
            {
                graphContext.Graph.Links.GetOrCreate(parentNode, newNode, /*label*/ null, CodeLinkCategories.Contains);
            }

            return(newNode);
        }
        private void CreateValues(IGraphContext context, GraphNode node)
        {
            StyleSheet  stylesheet = GetOrCreateStyleSheet(node, _fileService);
            GraphNodeId urlPart    = node.Id + GraphNodeId.GetPartial(CssGraphSchema.CssStyleSheet, stylesheet);

            // @-Directives
            if (FindCssItems <AtDirective>(stylesheet).Count > 0)
            {
                GraphNode dirNode = CreateParentNode(context, urlPart, "@-Directives", CssGraphSchema.CssAtDirectivesParent);
                context.Graph.Links.GetOrCreate(node, dirNode, "dir", GraphCommonSchema.Contains);
                context.OutputNodes.Add(node);
            }

            // IDs
            if (FindCssItems <IdSelector>(stylesheet).Count > 0)
            {
                GraphNode idNode = CreateParentNode(context, urlPart, "IDs", CssGraphSchema.CssIdSelectorParent);
                context.Graph.Links.GetOrCreate(node, idNode, "id", GraphCommonSchema.Contains);
                context.OutputNodes.Add(idNode);
            }

            // Class
            if (FindCssItems <ClassSelector>(stylesheet).Count > 0)
            {
                GraphNode classNode = CreateParentNode(context, urlPart, "Classes", CssGraphSchema.CssClassSelectorParent);
                context.Graph.Links.GetOrCreate(node, classNode, "class", GraphCommonSchema.Contains);
                context.OutputNodes.Add(classNode);
            }
        }
 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))));
 }
        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");
            }

            ISymbol containingSymbol = symbol.ContainingSymbol;

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

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

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

            return(null);
        }
        private GraphNodeId GetTopLevelGraphNodeId(string projectPath, IDependencyNode nodeInfo)
        {
            var partialValues = new List <GraphNodeId>
            {
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, new Uri(projectPath, UriKind.RelativeOrAbsolute))
            };

            var projectFolder = Path.GetDirectoryName(projectPath)?.ToLowerInvariant();

            if (nodeInfo.Flags.Contains(DependencyNode.CustomItemSpec))
            {
                if (nodeInfo.Name != null)
                {
                    partialValues.Add(GraphNodeId.GetPartial(
                                          CodeGraphNodeIdName.File,
                                          new Uri(Path.Combine(projectFolder, nodeInfo.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)));
                }
            }

            return(GraphNodeId.GetNested(partialValues.ToArray()));
        }
Beispiel #10
0
        internal static string GetValue(this GraphNodeId id, GraphNodeIdName idPartName)
        {
            if (idPartName == CodeGraphNodeIdName.Assembly || idPartName == CodeGraphNodeIdName.File)
            {
                try
                {
                    Uri value = id.GetNestedValueByName <Uri>(idPartName);

                    // for idPartName == CodeGraphNodeIdName.File it can be null, avoid unnecessary exception
                    if (value == null)
                    {
                        return(null);
                    }

                    // Assembly and File are represented by a Uri, extract LocalPath string from Uri
                    return((value.IsAbsoluteUri ? value.LocalPath : value.ToString()).Trim('/'));
                }
                catch
                {
                    // for some node ids Uri might throw format exception, thus try to get string at least
                    return(id.GetNestedValueByName <string>(idPartName));
                }
            }
            else
            {
                return(id.GetNestedValueByName <string>(idPartName));
            }
        }
        private GraphNode GetOrCreatePackageNode(IGraphContext context, GraphNode parent, IVsPackageMetadata package)
        {
            var parentId = parent.GetValue <GraphNodeId>("Id");
            var nodeId   = GraphNodeId.GetNested(
                parentId,
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Member, package.Id),
                GraphNodeId.GetPartial(CodeGraphNodeIdName.Parameter, package.VersionString));
            var node = context.Graph.Nodes.Get(nodeId);

            if (node == null)
            {
                using (var scope = new GraphTransactionScope())
                {
                    node = context.Graph.Nodes.GetOrCreate(nodeId, package.Id, ReferencesGraphSchema.PackageCategory);

                    node.SetValue <string>(DgmlNodeProperties.Icon, GraphIcons.Package);
                    node.SetValue <IVsPackageMetadata>(ReferencesGraphSchema.PackageProperty, package);

                    // Establish the relationship with the parent node.
                    context.Graph.Links.GetOrCreate(parent, node, null, GraphCommonSchema.Contains);

                    context.OutputNodes.Add(node);
                    scope.Complete();
                }
            }

            return(node);
        }
Beispiel #12
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 && 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".

                bool hasGenericArguments = (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(false, partials.ToArray())));
            }
        }
Beispiel #13
0
        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)));
        }
        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);
        }
Beispiel #15
0
        private static object MakeCollectionIfNecessary(bool isHomogeneous, GraphNodeId[] array)
        {
            // Place the array of GraphNodeId's into the collection if necessary, so to make them appear in VS Properties Panel
            if (array.Length > 1)
            {
                return(new GraphNodeIdCollection(false, array));
            }

            return(GraphNodeId.GetNested(array));
        }
        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);
        }
Beispiel #17
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);
        }
Beispiel #18
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()));
        }
        public GraphNode AddTopLevelGraphNode(
            IGraphContext graphContext,
            string projectPath,
            IDependencyViewModel viewModel)
        {
            Assumes.True(IsInitialized);

            GraphNodeId newNodeId = GetTopLevelGraphNodeId(projectPath, viewModel.OriginalModel.GetTopLevelId());

            return(DoAddGraphNode(newNodeId, graphContext, projectPath, parentNode: null, viewModel: viewModel));
        }
        private GraphNode DoAddGraphNode(
            GraphNodeId graphNodeId,
            IGraphContext graphContext,
            string projectPath,
            GraphNode parentNode,
            IDependency dependency)
        {
            var newNode = DoAddGraphNode(graphNodeId, graphContext, projectPath, parentNode, dependency.ToViewModel());

            newNode.SetValue(DependenciesGraphSchema.DependencyProperty, dependency);
            return(newNode);
        }
Beispiel #21
0
        public GraphNode AddGraphNode(
            IGraphContext graphContext,
            string projectPath,
            GraphNode parentNode,
            IDependencyViewModel viewModel)
        {
            Assumes.True(IsInitialized);

            string      modelId   = viewModel.OriginalModel == null ? viewModel.Caption : viewModel.OriginalModel.Id;
            GraphNodeId newNodeId = GetGraphNodeId(projectPath, parentNode, modelId);

            return(DoAddGraphNode(newNodeId, graphContext, projectPath, parentNode, viewModel));
        }
Beispiel #22
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());
        }
Beispiel #23
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())));
            }
        }
        public void RemoveGraphNode(IGraphContext graphContext,
                                    string projectPath,
                                    string modelId,
                                    GraphNode parentNode)
        {
            Assumes.True(IsInitialized);

            GraphNodeId id           = GetGraphNodeId(projectPath, parentNode, modelId);
            GraphNode   nodeToRemove = graphContext.Graph.Nodes.Get(id);

            if (nodeToRemove != null)
            {
                graphContext.OutputNodes.Remove(nodeToRemove);
                graphContext.Graph.Nodes.Remove(nodeToRemove);
            }
        }
Beispiel #25
0
        public static GraphNodeId GetId(this IProjectNode node)
        {
            var project = node.As <Project>();

            if (project.Kind == EnvDTE.Constants.vsProjectKindUnmodeled)
            {
                return(null);
            }

            var fileName = GetProjectFileUri(project);

            if (fileName == null)
            {
                return(null);
            }

            return(GraphNodeId.GetNested(CodeGraphNodeIdName.Assembly, fileName));
        }
        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);
        }
Beispiel #27
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();
     }
 }
        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);
            }
        }
Beispiel #29
0
        internal static async Task <GraphNodeId> GetIdForLocalVariableAsync(ISymbol symbol, Solution solution, CancellationToken cancellationToken)
        {
            if (symbol.ContainingSymbol == null ||
                (symbol.ContainingSymbol.Kind != SymbolKind.Method && symbol.ContainingSymbol.Kind != SymbolKind.Property))
            {
                // We are only support local variables inside methods or properties.
                throw new ArgumentException("symbol");
            }

            GraphNodeId memberId = await GetIdForMemberAsync(symbol.ContainingSymbol, solution, cancellationToken).ConfigureAwait(false);

            if (memberId != null)
            {
                CodeQualifiedIdentifierBuilder builder = new CodeQualifiedIdentifierBuilder(memberId);
                builder.LocalVariable      = symbol.Name;
                builder.LocalVariableIndex = await GetLocalVariableIndexAsync(symbol, solution, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);

                return(builder.ToQualifiedIdentifier());
            }

            return(null);
        }
Beispiel #30
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())));
        }
        private static object MakeCollectionIfNecessary(bool isHomogeneous, GraphNodeId[] array)
        {
            // Place the array of GraphNodeId's into the collection if necessary, so to make them appear in VS Properties Panel
            if (array.Length > 1)
            {
                return new GraphNodeIdCollection(false, array);
            }

            return GraphNodeId.GetNested(array);
        }