Exemplo n.º 1
0
        public async Task <bool> HasSuggestedActionsAsync(ISuggestedActionCategorySet requestedActionCategories, SnapshotSpan range, CancellationToken cancellationToken)
        {
            var pos = _view.Caret.Position.BufferPosition;

            if (pos.Position < pos.GetContainingLine().End.Position)
            {
                pos += 1;
            }
            var targetPoint = _view.BufferGraph.MapDownToFirstMatch(pos, PointTrackingMode.Positive, EditorExtensions.IsPythonContent, PositionAffinity.Successor);

            if (targetPoint == null)
            {
                return(false);
            }
            var textBuffer = targetPoint.Value.Snapshot.TextBuffer;
            var lineStart  = targetPoint.Value.GetContainingLine().Start;

            var span = targetPoint.Value.Snapshot.CreateTrackingSpan(
                lineStart,
                targetPoint.Value.Position - lineStart.Position,
                SpanTrackingMode.EdgePositive,
                TrackingFidelityMode.Forward
                );
            var imports = await _uiThread.InvokeTask(() => VsProjectAnalyzer.GetMissingImportsAsync(_provider, _view, textBuffer.CurrentSnapshot, span));

            if (imports == MissingImportAnalysis.Empty)
            {
                return(false);
            }

            var suggestions      = new List <SuggestedActionSet>();
            var availableImports = await imports.GetAvailableImportsAsync(cancellationToken);

            suggestions.Add(new SuggestedActionSet(
                                availableImports.Select(s => new PythonSuggestedImportAction(this, textBuffer, s))
                                .OrderBy(k => k)
                                .Distinct()
                                ));

            cancellationToken.ThrowIfCancellationRequested();

            if (!suggestions.SelectMany(s => s.Actions).Any())
            {
                return(false);
            }

            lock (_currentLock) {
                cancellationToken.ThrowIfCancellationRequested();
                _current     = suggestions;
                _currentSpan = range;
            }

            return(true);
        }
 /// <summary>
 /// <summary>
 /// Gets a ImportAnalysis providing a list of imports for the selected identifer if the identifier is
 /// currently undefined.
 ///
 /// New in v1.1.
 /// </summary>
 public static Task <MissingImportAnalysis> GetMissingImportsAsync(this ITextSnapshot snapshot, IServiceProvider serviceProvider, ITrackingSpan span)
 {
     return(VsProjectAnalyzer.GetMissingImportsAsync(serviceProvider, snapshot, span));
 }