Ejemplo n.º 1
0
        // Builds a mapping of FileName -> (DocumentId, Requests[])
        // This grouping is later used to process each document at a time.
        static DocumentMap BuildDiffDocumentMap(IEnumerable <DiffRequest> requests)
        {
            var documentIdMap = new DocumentMap();

            foreach (var request in requests)
            {
                if (!(request.filename.EndsWith(".cs") || request.filename.EndsWith(".vb")))
                {
                    Console.WriteLine($"WARNING: {request.filename} is not a .cs or .vb file. Skipping");
                    continue;
                }

                if (documentIdMap.ContainsKey(request.filename))
                {
                    documentIdMap[request.filename].Add(request);
                }
                else
                {
                    documentIdMap.Add(request.filename, new List <DiffRequest>()
                    {
                        request
                    });
                }
            }
            return(documentIdMap);
        }
Ejemplo n.º 2
0
        // Builds a mapping of FileName -> (DocumentId, Requests[])
        // This grouping is later used to process each document at a time.
        static DocumentMap BuildDiffDocumentMap(Workspace workspace, Solution solution, IEnumerable <DiffRequest> requests)
        {
            var documentIdMap = new DocumentMap();

            foreach (var request in requests)
            {
                if (!(request.filename.EndsWith(".cs") || request.filename.EndsWith(".vb")))
                {
                    Console.WriteLine($"WARNING: {request.filename} is not a .cs or .vb file. Skipping");
                    continue;
                }

                if (documentIdMap.ContainsKey(request.filename))
                {
                    documentIdMap[request.filename].requests.Add(request);
                }
                else
                {
                    // Diff always uses unix separators, so we need to replace those with the system separator
                    var correctedFilename = request.filename.Replace('/', System.IO.Path.DirectorySeparatorChar);
                    var fullPath          = System.IO.Path.Combine(Environment.CurrentDirectory, correctedFilename);
                    var documentIds       = solution.GetDocumentIdsWithFilePath(fullPath);

                    if (!documentIds.IsDefaultOrEmpty)
                    {
                        documentIdMap.Add(request.filename, (documentIds.First(), new List <DiffRequest>()
                        {
                            request
                        }));
                    }
                    else
                    {
                        Console.WriteLine($"WARNING: Could not find a document ID for {fullPath}");
                    }
                }
            }
            return(documentIdMap);
        }