public IndexManager(IFileSystem fileSystem, PythonLanguageVersion version, string rootPath, string[] includeFiles, string[] excludeFiles, IIdleTimeService idleTimeService) { Check.ArgumentNotNull(nameof(fileSystem), fileSystem); Check.ArgumentNotNull(nameof(includeFiles), includeFiles); Check.ArgumentNotNull(nameof(excludeFiles), excludeFiles); Check.ArgumentNotNull(nameof(idleTimeService), idleTimeService); _version = version; _fileSystem = fileSystem; _workspaceRootPath = rootPath; _includeFiles = includeFiles; _excludeFiles = excludeFiles; _userCodeSymbolIndex = new SymbolIndex(_fileSystem, version); _libraryCodeSymbolIndex = new SymbolIndex(_fileSystem, version, libraryMode: true); idleTimeService.Idle += OnIdle; _disposables .Add(_userCodeSymbolIndex) .Add(_libraryCodeSymbolIndex) .Add(() => _disposeToken.TryMarkDisposed()) .Add(() => idleTimeService.Idle -= OnIdle); }
public async Task IndexWorkspaceSymbolsNotFoundAsync() { ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); var symbols = await index.WorkspaceSymbolsAsync("", maxSymbols); symbols.Should().BeEmpty(); }
public async Task IndexHierarchicalDocumentNotFoundAsync() { ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); var symbols = await index.HierarchicalDocumentSymbolsAsync(path); symbols.Should().BeEmpty(); }
private void CreateIndices(IEnumerable <IFileSystemInfo> files, ISymbolIndex symbolIndex, CancellationToken cancellationToken) { foreach (var fileInfo in files) { cancellationToken.ThrowIfCancellationRequested(); if (ModulePath.IsPythonSourceFile(fileInfo.FullName)) { symbolIndex.Parse(fileInfo.FullName); } } }
public async Task IndexHierarchicalDocumentAsync() { ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); index.Add(path, DocumentWithAst("x = 1")); var symbols = await index.HierarchicalDocumentSymbolsAsync(path); symbols.Should().BeEquivalentToWithStrictOrdering(new[] { new HierarchicalSymbol("x", SymbolKind.Variable, new SourceSpan(1, 1, 1, 2)), }); }
public async Task SymbolsAfterPendingWaitsForUpdateAsync() { ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); index.Add(path, DocumentWithAst("x = 1")); index.MarkAsPending(path); var t = index.WorkspaceSymbolsAsync("", maxSymbols); index.ReIndex(path, DocumentWithAst("x = 1")); var symbols = await t; symbols.Should().BeEquivalentToWithStrictOrdering(new[] { new FlatSymbol("x", SymbolKind.Variable, path, new SourceSpan(1, 1, 1, 2)), }); }
public async Task IndexWorkspaceSymbolsFilteredAsync() { var code = @"class Foo(object): def foo(self, x): ..."; ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); index.Add(path, DocumentWithAst(code)); var symbols = await index.WorkspaceSymbolsAsync("x", maxSymbols); symbols.Should().BeEquivalentToWithStrictOrdering(new[] { new FlatSymbol("x", SymbolKind.Variable, path, new SourceSpan(2, 19, 2, 20), "foo"), }); }
public async Task IndexWorkspaceSymbolsCaseInsensitiveAsync() { var code = @"class Foo(object): def foo(self, x): ..."; ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); index.Add(path, DocumentWithAst(code)); var symbols = await index.WorkspaceSymbolsAsync("foo", maxSymbols); symbols.Should().BeEquivalentToWithStrictOrdering(new[] { new FlatSymbol("Foo", SymbolKind.Class, path, new SourceSpan(1, 7, 1, 10)), new FlatSymbol("foo", SymbolKind.Method, path, new SourceSpan(2, 9, 2, 12), "Foo"), }); }
public void MarkAsPendingWaitsForUpdates() { ISymbolIndex index = MakeSymbolIndex(); var path = TestData.GetDefaultModulePath(); index.Add(path, DocumentWithAst("x = 1")); index.MarkAsPending(path); var cts = new CancellationTokenSource(); var t = index.HierarchicalDocumentSymbolsAsync(path, cts.Token); t.IsCompleted.Should().BeFalse(); cts.Cancel(); Func <Task> cancelled = async() => { await t; }; cancelled.Should().Throw <OperationCanceledException>(); }
public IndexManager(IFileSystem fileSystem, PythonLanguageVersion version, string rootPath, string[] includeFiles, string[] excludeFiles, IIdleTimeService idleTimeService) { Check.ArgumentNotNull(nameof(fileSystem), fileSystem); Check.ArgumentNotNull(nameof(rootPath), rootPath); Check.ArgumentNotNull(nameof(includeFiles), includeFiles); Check.ArgumentNotNull(nameof(excludeFiles), excludeFiles); Check.ArgumentNotNull(nameof(idleTimeService), idleTimeService); _fileSystem = fileSystem; _workspaceRootPath = rootPath; _includeFiles = includeFiles; _excludeFiles = excludeFiles; _symbolIndex = new SymbolIndex(_fileSystem, version); idleTimeService.Idle += OnIdle; _disposables .Add(_symbolIndex) .Add(() => idleTimeService.Idle -= OnIdle); StartAddRootDir(); }