public CompletionAnalysis( ModuleAnalysis analysis, PythonAst tree, SourceLocation position, GetMemberOptions opts, DocumentationBuilder textBuilder, ILogger log, Func <TextReader> openDocument ) { Analysis = analysis ?? throw new ArgumentNullException(nameof(analysis)); Tree = tree ?? throw new ArgumentNullException(nameof(tree)); Position = position; Index = Tree.LocationToIndex(Position); Options = opts; _textBuilder = textBuilder; _log = log; _openDocument = openDocument; var finder = new ExpressionFinder(Tree, new GetExpressionOptions { Names = true, Members = true, NamedArgumentNames = true, ImportNames = true, ImportAsNames = true, Literals = true, Errors = true }); Node node; finder.Get(Index, Index, out node, out _statement, out _scope); int index = Index; int col = Position.Column; while (CanBackUp(Tree, node, _statement, _scope, col)) { col -= 1; index -= 1; finder.Get(index, index, out node, out _statement, out _scope); } Node = node ?? (_statement as ExpressionStatement)?.Expression; }
private async Task DoInitializeAsync(InitializeParams @params) { _analyzer = await CreateAnalyzer(@params.initializationOptions.interpreter); _clientCaps = @params.capabilities; _settings.SetCompletionTimeout(_clientCaps?.python?.completionsTimeout); _traceLogging = _clientCaps?.python?.traceLogging ?? false; _analyzer.EnableDiagnostics = _clientCaps?.python?.liveLinting ?? false; _reloadModulesQueueItem = new ReloadModulesQueueItem(_analyzer); if (@params.initializationOptions.displayOptions != null) { DisplayOptions = @params.initializationOptions.displayOptions; } _displayTextBuilder = DocumentationBuilder.Create(DisplayOptions); if (string.IsNullOrEmpty(_analyzer.InterpreterFactory?.Configuration?.InterpreterPath)) { LogMessage(MessageType.Log, "Initializing for generic interpreter"); } else { LogMessage(MessageType.Log, $"Initializing for {_analyzer.InterpreterFactory.Configuration.InterpreterPath}"); } if (@params.rootUri != null) { _rootDir = @params.rootUri.ToAbsolutePath(); } else if (!string.IsNullOrEmpty(@params.rootPath)) { _rootDir = PathUtils.NormalizePath(@params.rootPath); } SetSearchPaths(@params.initializationOptions.searchPaths); SetTypeStubSearchPaths(@params.initializationOptions.typeStubSearchPaths); if (_rootDir != null && !(_clientCaps?.python?.manualFileLoad ?? false)) { LogMessage(MessageType.Log, $"Loading files from {_rootDir}"); _loadingFromDirectory = LoadFromDirectoryAsync(_rootDir); } }
private async Task DoInitializeAsync(InitializeParams @params, CancellationToken token) { ThrowIfDisposed(); Analyzer = await _queue.ExecuteInQueueAsync(ct => CreateAnalyzer(@params.initializationOptions.interpreter, token), AnalysisPriority.High); ThrowIfDisposed(); _clientCaps = @params.capabilities; _traceLogging = @params.initializationOptions.traceLogging; _analysisUpdates = @params.initializationOptions.analysisUpdates; Analyzer.EnableDiagnostics = _clientCaps?.python?.liveLinting ?? false; _reloadModulesQueueItem = new ReloadModulesQueueItem(Analyzer); if (@params.initializationOptions.displayOptions != null) { DisplayOptions = @params.initializationOptions.displayOptions; } _displayTextBuilder = DocumentationBuilder.Create(DisplayOptions); if (string.IsNullOrEmpty(Analyzer.InterpreterFactory?.Configuration?.InterpreterPath)) { LogMessage(MessageType._General, "Initializing for generic interpreter"); } else { LogMessage(MessageType._General, $"Initializing for {Analyzer.InterpreterFactory.Configuration.InterpreterPath}"); } if (@params.rootUri != null) { _rootDir = @params.rootUri.ToAbsolutePath(); } else if (!string.IsNullOrEmpty(@params.rootPath)) { _rootDir = PathUtils.NormalizePath(@params.rootPath); } SetSearchPaths(@params.initializationOptions.searchPaths); SetTypeStubSearchPaths(@params.initializationOptions.typeStubSearchPaths); Analyzer.Interpreter.ModuleNamesChanged += Interpreter_ModuleNamesChanged; }
public CompletionAnalysis(ModuleAnalysis analysis, PythonAst tree, SourceLocation position, GetMemberOptions opts, DocumentationBuilder textBuilder, ILogger log) { Analysis = analysis ?? throw new ArgumentNullException(nameof(analysis)); Tree = tree ?? throw new ArgumentNullException(nameof(tree)); Position = position; Index = Tree.LocationToIndex(Position); Options = opts; _textBuilder = textBuilder; _log = log; var finder = new ExpressionFinder(Tree, new GetExpressionOptions { Names = true, MemberName = true, NamedArgumentNames = true, ImportNames = true, ImportAsNames = true, Literals = true, }); finder.Get(Index, Index, out _node, out _statement, out _scope); }