private async void OnNewAnalysis(AnalysisEntry entry, ITextBuffer buffer) { if (!_enabled && !_alwaysCreateSquiggle) { _taskProvider.Clear(entry, VsProjectAnalyzer.UnresolvedImportMoniker); return; } var missingImports = await entry.Analyzer.GetMissingImportsAsync(entry, buffer); if (missingImports != null) { var missing = missingImports.Data; if (missing.unresolved.Any()) { var translator = missingImports.GetTracker(missingImports.Data.version); if (translator != null) { var f = new TaskProviderItemFactory(translator); _taskProvider.ReplaceItems( entry, VsProjectAnalyzer.UnresolvedImportMoniker, missingImports.Data.unresolved.Select(t => f.FromUnresolvedImport( _serviceProvider, entry.Analyzer.InterpreterFactory as IPythonInterpreterFactoryWithDatabase, t.name, new SourceSpan( new SourceLocation(t.startIndex, t.startLine, t.startColumn), new SourceLocation(t.endIndex, t.endLine, t.endColumn) ) )).ToList() ); } } else { _taskProvider.Clear(entry, VsProjectAnalyzer.UnresolvedImportMoniker); } } }
private void UpdateErrorsAndWarnings( IProjectEntry entry, ITextSnapshot snapshot, CollectingErrorSink errorSink, List<TaskProviderItem> commentTasks ) { // Update the warn-on-launch state for this entry bool changed = false; lock (_hasParseErrorsLock) { changed = errorSink.Errors.Any() ? _hasParseErrors.Add(entry) : _hasParseErrors.Remove(entry); } if (changed) { OnShouldWarnOnLaunchChanged(entry); } // Update the parser warnings/errors. var factory = new TaskProviderItemFactory(snapshot); if (errorSink.Warnings.Any() || errorSink.Errors.Any()) { _errorProvider.ReplaceItems( entry, ParserTaskMoniker, errorSink.Warnings .Select(er => factory.FromErrorResult(_serviceProvider, er, VSTASKPRIORITY.TP_NORMAL, VSTASKCATEGORY.CAT_BUILDCOMPILE)) .Concat(errorSink.Errors.Select(er => factory.FromErrorResult(_serviceProvider, er, VSTASKPRIORITY.TP_HIGH, VSTASKCATEGORY.CAT_BUILDCOMPILE))) .ToList() ); } else { _errorProvider.Clear(entry, ParserTaskMoniker); } // Update comment tasks. if (commentTasks.Count != 0) { _commentTaskProvider.ReplaceItems(entry, ParserTaskMoniker, commentTasks); } else { _commentTaskProvider.Clear(entry, ParserTaskMoniker); } }
private void OnNewAnalysis(object sender, EventArgs e) { if (!_alwaysCreateSquiggle) { var service = _serviceProvider.GetPythonToolsService(); if (service == null || !service.GeneralOptions.UnresolvedImportWarning) { return; } } var entry = sender as IPythonProjectEntry; if (entry == null || string.IsNullOrEmpty(entry.ModuleName) || string.IsNullOrEmpty(entry.FilePath) ) { return; } var analysis = entry.Analysis; var analyzer = analysis != null ? analysis.ProjectState : null; if (analyzer == null) { return; } PythonAst ast; IAnalysisCookie cookie; entry.GetTreeAndCookie(out ast, out cookie); var snapshotCookie = cookie as SnapshotCookie; var snapshot = snapshotCookie != null ? snapshotCookie.Snapshot : null; if (ast == null || snapshot == null) { return; } var walker = new ImportStatementWalker(entry, analyzer); ast.Walk(walker); if (walker.Imports.Any()) { var f = new TaskProviderItemFactory(snapshot); _taskProvider.ReplaceItems( entry, VsProjectAnalyzer.UnresolvedImportMoniker, walker.Imports.Select(t => f.FromUnresolvedImport( _serviceProvider, analyzer.InterpreterFactory as IPythonInterpreterFactoryWithDatabase, t.Item1, t.Item2.GetSpan(ast) )).ToList() ); } else { _taskProvider.Clear(entry, VsProjectAnalyzer.UnresolvedImportMoniker); } }
private void UpdateErrorsAndWarnings( IProjectEntry entry, ITextSnapshot snapshot, CollectingErrorSink errorSink ) { // There are some scenarios during ES6 Mode where a textview is still opened using NodeLS. // In these cases, we do not properly parse ES6 syntax, and therefore do not want to display errors. if (NodejsPackage.Instance.IntellisenseOptionsPage.AnalysisLevel == AnalysisLevel.Preview) { return; } // Update the warn-on-launch state for this entry bool changed = false; lock (_hasParseErrors) { if (errorSink.Errors.Any() ? _hasParseErrors.Add(entry) : _hasParseErrors.Remove(entry)) { changed = true; } } if (changed) { OnShouldWarnOnLaunchChanged(entry); } var f = new TaskProviderItemFactory(snapshot); // Update the parser warnings/errors if (errorSink.Warnings.Any() || errorSink.Errors.Any()) { TaskProvider.ReplaceItems( entry, ParserTaskMoniker, errorSink.Warnings .Where(ShouldIncludeWarning) .Select(er => f.FromParseWarning(er)) .Concat(errorSink.Errors.Select(er => f.FromParseError(er))) .ToList() ); } else { TaskProvider.Clear(entry, ParserTaskMoniker); } #if FALSE // Add a handler for the next complete analysis _unresolvedSquiggles.ListenForNextNewAnalysis(entry as IJsProjectEntry); #endif }
private void UpdateErrorsAndWarnings( IProjectEntry entry, ITextSnapshot snapshot, CollectingErrorSink errorSink ) { // Update the warn-on-launch state for this entry bool changed = false; lock (_hasParseErrors) { if (errorSink.Errors.Any() ? _hasParseErrors.Add(entry) : _hasParseErrors.Remove(entry)) { changed = true; } } if (changed) { OnShouldWarnOnLaunchChanged(entry); } var f = new TaskProviderItemFactory(snapshot); // Update the parser warnings/errors if (errorSink.Warnings.Any() || errorSink.Errors.Any()) { TaskProvider.ReplaceItems( entry, ParserTaskMoniker, errorSink.Warnings .Where(ShouldIncludeWarning) .Select(er => f.FromParseWarning(er)) .Concat(errorSink.Errors.Select(er => f.FromParseError(er))) .ToList() ); } else { TaskProvider.Clear(entry, ParserTaskMoniker); } #if FALSE // Add a handler for the next complete analysis _unresolvedSquiggles.ListenForNextNewAnalysis(entry as IJsProjectEntry); #endif }