public void GetEmpty()
        {
            var map = new DocumentMap<string>();
            map.Add(5, "test");
            map.Add(0, "test3");
            map.Add(2, "test2");

            var relativeRanges = map.GetRelativeRange(new Range(1, 7));
            Assert.AreEqual(3, relativeRanges.Count);

            Assert.AreEqual("test3", relativeRanges[1].Source);
            Assert.AreEqual(new Range(0,0), relativeRanges[1].Range);
        }
        public void GetOverlap()
        {
            var map = new DocumentMap<string>();
            map.Add(5, "test");
            map.Add(2, "test2");

            var relativeRanges = map.GetRelativeRange(new Range(1, 7));
            Assert.AreEqual(2, relativeRanges.Count);
            Assert.AreEqual("test", relativeRanges[0].Source);

            Assert.AreEqual(new Range(1, 5), relativeRanges[0].Range);
            Assert.AreEqual("test2", relativeRanges[1].Source);
            Assert.AreEqual(new Range(0, 2), relativeRanges[1].Range);
        }
示例#3
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);
        }
        private async Task<ProjectToDocumentMap> CreateProjectToDocumentMapAsync(ProjectMap projectMap)
        {
            using (Logger.LogBlock(FunctionId.FindReference_CreateDocumentMapAsync, _cancellationToken))
            {
                var finalMap = new ProjectToDocumentMap();

                foreach (var kvp in projectMap)
                {
                    var project = kvp.Key;
                    var projectQueue = kvp.Value;

                    var documentMap = new DocumentMap();

                    foreach (var symbolAndFinder in projectQueue)
                    {
                        _cancellationToken.ThrowIfCancellationRequested();

                        var symbolAndProjectId = symbolAndFinder.symbolAndProjectId;
                        var symbol = symbolAndProjectId.Symbol;
                        var finder = symbolAndFinder.finder;

                        var documents = await finder.DetermineDocumentsToSearchAsync(symbol, project, _documents, _cancellationToken).ConfigureAwait(false);
                        foreach (var document in documents.Distinct().WhereNotNull())
                        {
                            if (_documents == null || _documents.Contains(document))
                            {
                                documentMap.Add(document, symbolAndFinder);
                            }
                        }
                    }

                    Contract.ThrowIfTrue(documentMap.Any(kvp1 => kvp1.Value.Count != kvp1.Value.ToSet().Count));

                    if (documentMap.Count > 0)
                    {
                        finalMap.Add(project, documentMap);
                    }
                }

                return finalMap;
            }
        }
示例#5
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);
        }