private void AddMissingImports(List <string> importList) { if (importList.Count > 0) { var projEntry = _textView.TextBuffer.GetPythonProjectEntry(); if (projEntry != null) { PythonAst ast; IAnalysisCookie cookie; projEntry.GetTreeAndCookie(out ast, out cookie); if (ast != null) { var walker = new ImportWalker(); ast.Walk(walker); foreach (var import in importList) { if (!walker.Imports.Contains(import)) { MissingImportAnalysis.AddImport( _serviceProvider, _textView.TextBuffer, _textView, null, import ); } } } } } }
public override void Invoke() { MissingImportAnalysis.AddImport( _serviceProvider, _buffer, _view, FromName, Name ); }
private static ReadOnlyCollection <ISmartTagAction> GetImportTags( IServiceProvider serviceProvider, ITextBuffer textBuffer, ITextView textView, MissingImportAnalysis imports, CancellationToken cancel ) { var actions = new List <ISmartTagAction>(); try { foreach (var import in imports.AvailableImports) { cancel.ThrowIfCancellationRequested(); if (import.IsDefinedInModule) { int lastDot; if ((lastDot = import.Name.LastIndexOf('.')) == -1) { // simple import actions.Add(new ImportSmartTagAction(import.Name, textBuffer, textView, serviceProvider)); } else { // importing a package or member of a module actions.Add(new ImportSmartTagAction( import.Name.Substring(0, lastDot), import.Name.Substring(lastDot + 1), textBuffer, textView, serviceProvider )); } } } if (actions.Any()) { actions.Sort(SmartTagComparer); } return(new ReadOnlyCollection <ISmartTagAction>(actions)); } catch (OperationCanceledException) { throw; } catch (Exception ex) { if (ex.IsCriticalException()) { throw; } Debug.Fail(ex.ToString()); return(null); } }
public void Invoke(CancellationToken cancellationToken) { Debug.Assert(!string.IsNullOrEmpty(_name)); MissingImportAnalysis.AddImport( _source._provider, _buffer, _source._view, _fromModule, _name ); }
public SmartTagAugmentTask( IServiceProvider serviceProvider, ITextBuffer textBuffer, ITextView textView, MissingImportAnalysis imports ) { ApplicableToSpan = imports.ApplicableToSpan; _cancel = new CancellationTokenSource(); _task = Task.Run(() => GetImportTags( serviceProvider, textBuffer, textView, imports, _cancel.Token ), _cancel.Token); }
private static ReadOnlyCollection<ISmartTagAction> GetImportTags( IServiceProvider serviceProvider, ITextBuffer textBuffer, ITextView textView, MissingImportAnalysis imports, CancellationToken cancel ) { var actions = new List<ISmartTagAction>(); try { foreach (var import in imports.AvailableImports) { cancel.ThrowIfCancellationRequested(); int lastDot; if ((lastDot = import.Name.LastIndexOf('.')) == -1) { // simple import actions.Add(new ImportSmartTagAction(import.Name, textBuffer, textView, serviceProvider)); } else { // importing a package or member of a module actions.Add(new ImportSmartTagAction( import.Name.Substring(0, lastDot), import.Name.Substring(lastDot + 1), textBuffer, textView, serviceProvider )); } } if (actions.Any()) { actions.Sort(SmartTagComparer); } return new ReadOnlyCollection<ISmartTagAction>(actions); } catch (OperationCanceledException) { throw; } catch (Exception ex) { if (ex.IsCriticalException()) { throw; } Debug.Fail(ex.ToString()); return null; } }