コード例 #1
0
        public async Task HierarchicalDocumentSymbolsAsync()
        {
            var context            = new IndexTestContext(this);
            var pythonTestFilePath = context.FileWithXVarInRootDir();

            var indexManager = context.GetDefaultIndexManager();

            var symbols = await indexManager.HierarchicalDocumentSymbolsAsync(pythonTestFilePath);

            SymbolsShouldBeOnlyX(symbols);
        }
コード例 #2
0
        public async Task IgnoresNonPythonFiles()
        {
            using (var context = new IndexTestContext(this)) {
                var nonPythonTestFileInfo = MakeFileInfoProxy($"{_rootPath}/bla.txt");
                context.AddFileInfoToRootTestFS(nonPythonTestFileInfo);

                var indexManager = context.GetDefaultIndexManager();
                await indexManager.IndexWorkspace();

                context.FileSystem.DidNotReceive().FileExists(nonPythonTestFileInfo.FullName);
            }
        }
コード例 #3
0
        public async Task WorkspaceSymbolsAddsRootDirectory()
        {
            var context = new IndexTestContext(this);

            var pythonTestFilePath = context.FileWithXVarInRootDir();

            var indexManager = context.GetDefaultIndexManager();

            var symbols = await indexManager.WorkspaceSymbolsAsync("", maxSymbolsCount);

            SymbolsShouldBeOnlyX(symbols);
        }
コード例 #4
0
        public async Task CloseNonWorkspaceFilesRemovesFromIndexAsync()
        {
            using (var context = new IndexTestContext(this)) {
                var pythonTestFileInfo = MakeFileInfoProxy("C:/nonRoot/bla.py");
                context.FileSystem.IsPathUnderRoot(_rootPath, pythonTestFileInfo.FullName).Returns(false);

                var indexManager = context.GetDefaultIndexManager();
                indexManager.ProcessNewFile(pythonTestFileInfo.FullName, DocumentWithAst("x = 1"));
                indexManager.ProcessClosedFile(pythonTestFileInfo.FullName);

                await SymbolIndexShouldBeEmpty(indexManager);
            }
        }
コード例 #5
0
        public async Task AddsRootDirectoryAsync()
        {
            var context = new IndexTestContext(this);

            context.FileWithXVarInRootDir();
            context.AddFileToRoot($"{_rootPath}\foo.py", MakeStream("y = 1"));

            var indexManager = context.GetDefaultIndexManager();

            var symbols = await indexManager.WorkspaceSymbolsAsync("", maxSymbolsCount);

            symbols.Should().HaveCount(2);
        }
コード例 #6
0
        public async Task CanOpenFiles()
        {
            string    nonRootPath        = "C:/nonRoot";
            var       context            = new IndexTestContext(this);
            var       pythonTestFileInfo = MakeFileInfoProxy($"{nonRootPath}/bla.py");
            IDocument doc = DocumentWithAst("x = 1");

            IIndexManager indexManager = context.GetDefaultIndexManager();

            indexManager.ProcessNewFile(pythonTestFileInfo.FullName, doc);

            var symbols = await indexManager.WorkspaceSymbolsAsync("", maxSymbolsCount);

            SymbolsShouldBeOnlyX(symbols);
        }
コード例 #7
0
        public async Task UpdateFilesOnWorkspaceIndexesLatestAsync()
        {
            var context            = new IndexTestContext(this);
            var pythonTestFilePath = context.FileWithXVarInRootDir();

            var indexManager = context.GetDefaultIndexManager();
            await indexManager.IndexWorkspace();

            indexManager.ReIndexFile(pythonTestFilePath, DocumentWithAst("y = 1"));

            var symbols = await indexManager.WorkspaceSymbolsAsync("", maxSymbolsCount);

            symbols.Should().HaveCount(1);
            symbols.First().Kind.Should().BeEquivalentTo(SymbolKind.Variable);
            symbols.First().Name.Should().BeEquivalentTo("y");
        }
コード例 #8
0
        public async Task WorkspaceSymbolsLimited()
        {
            var context = new IndexTestContext(this);

            for (int fileNumber = 0; fileNumber < 10; fileNumber++)
            {
                context.AddFileToRoot($"{_rootPath}\bla{fileNumber}.py", MakeStream($"x{fileNumber} = 1"));
            }
            var indexManager = context.GetDefaultIndexManager();

            const int amountOfSymbols = 3;

            var symbols = await indexManager.WorkspaceSymbolsAsync("", amountOfSymbols);

            symbols.Should().HaveCount(amountOfSymbols);
        }
コード例 #9
0
        public async Task LatestVersionASTVersionIsIndexed()
        {
            var context            = new IndexTestContext(this);
            var pythonTestFilePath = context.FileWithXVarInRootDir();

            var indexManager = context.GetDefaultIndexManager();

            indexManager.ProcessNewFile(pythonTestFilePath, DocumentWithAst("y = 1"));
            indexManager.ProcessClosedFile(pythonTestFilePath);
            indexManager.ProcessNewFile(pythonTestFilePath, DocumentWithAst("z = 1"));

            var symbols = await indexManager.HierarchicalDocumentSymbolsAsync(pythonTestFilePath);

            symbols.Should().HaveCount(1);
            symbols.First().Kind.Should().BeEquivalentTo(SymbolKind.Variable);
            symbols.First().Name.Should().BeEquivalentTo("z");
        }
コード例 #10
0
        public async Task AddFilesToPendingChanges()
        {
            var context = new IndexTestContext(this);
            var f1      = context.AddFileToRoot($"{_rootPath}/fileA.py", MakeStream(""));
            var f2      = context.AddFileToRoot($"{_rootPath}/fileB.py", MakeStream(""));

            var indexManager = context.GetDefaultIndexManager();
            await indexManager.IndexWorkspace();

            indexManager.AddPendingDoc(DocumentWithAst("y = 1", f1));
            indexManager.AddPendingDoc(DocumentWithAst("x = 1", f2));

            context.SetIdleEvent(Raise.Event());

            var symbols = await indexManager.WorkspaceSymbolsAsync("", maxSymbolsCount);

            symbols.Should().HaveCount(2);
        }
コード例 #11
0
        public async Task ProcessFileIfIndexedAfterCloseIgnoresUpdateAsync()
        {
            // If events get to index manager in the order: [open, close, update]
            // it should not reindex file

            var context            = new IndexTestContext(this);
            var pythonTestFileInfo = MakeFileInfoProxy("C:/nonRoot/bla.py");

            var indexManager = context.GetDefaultIndexManager();

            indexManager.ProcessNewFile(pythonTestFileInfo.FullName, DocumentWithAst("x = 1"));
            indexManager.ProcessClosedFile(pythonTestFileInfo.FullName);

            context.FileSystem.IsPathUnderRoot(_rootPath, pythonTestFileInfo.FullName).Returns(false);
            indexManager.ReIndexFile(pythonTestFileInfo.FullName, DocumentWithAst("x = 1"));

            await SymbolIndexShouldBeEmpty(indexManager);
        }
コード例 #12
0
        public async Task CloseWorkspaceFilesReUpdatesIndexAsync()
        {
            var context            = new IndexTestContext(this);
            var pythonTestFilePath = context.FileWithXVarInRootDir();

            context.FileSystem.IsPathUnderRoot(_rootPath, pythonTestFilePath).Returns(true);

            var indexManager = context.GetDefaultIndexManager();
            await indexManager.IndexWorkspace();

            indexManager.ProcessNewFile(pythonTestFilePath, DocumentWithAst("r = 1"));
            // It Needs to remake the stream for the file, previous one is closed
            context.FileSystem.FileExists(pythonTestFilePath).Returns(true);
            context.SetFileOpen(pythonTestFilePath, MakeStream("x = 1"));
            context.FileSystem.IsPathUnderRoot(_rootPath, pythonTestFilePath).Returns(true);
            indexManager.ProcessClosedFile(pythonTestFilePath);

            var symbols = await indexManager.WorkspaceSymbolsAsync("", maxSymbolsCount);

            SymbolsShouldBeOnlyX(symbols);
        }