Esempio n. 1
0
        /// <summary>
        /// Wired to parser event for when the parser has completed parsing a new tree and we need
        /// to update the navigation bar with the new data.
        /// </summary>
        private async void ParserOnNewParseTree(AnalysisEntry entry)
        {
            var dropDownBar = _dropDownBar;

            if (dropDownBar == null)
            {
                return;
            }

            var navigations = await _uiThread.InvokeTask(() => _analysisEntry.Analyzer.GetNavigationsAsync(_textView));

            lock (_navigationsLock) {
                _navigations = navigations;
                for (int i = 0; i < _curSelection.Length; i++)
                {
                    _curSelection[i] = -1;
                }
            }

            Action callback = () => CaretPositionChanged(
                this,
                new CaretPositionChangedEventArgs(
                    _textView,
                    _textView.Caret.Position,
                    _textView.Caret.Position
                    )
                );

            try {
                await _dispatcher.BeginInvoke(callback, DispatcherPriority.Background);
            } catch (TaskCanceledException) {
            }
        }
Esempio n. 2
0
#pragma warning restore 0067

        private async Task <VsProjectAnalyzer> FindAnalyzerAsync(Uri uri)
        {
            if (uri == null)
            {
                return(null);
            }

            if (!_analyzerCache.TryGetValue(uri, out var analyzer))
            {
                var filePath = uri.LocalPath;
                if (string.IsNullOrEmpty(filePath))
                {
                    return(null);
                }

                if (_uiThread != null)
                {
                    // TODO: Use URI for more accurate lookup
                    analyzer = await _uiThread.InvokeTask(async() =>
                                                          (await _serviceProvider.FindAllAnalyzersForFile(filePath)).FirstOrDefault() as VsProjectAnalyzer
                                                          );
                }

                analyzer = _analyzerCache.GetOrAdd(uri, analyzer);
            }

            return(analyzer);
        }
Esempio n. 3
0
        private async Task <List <AnalysisVariable> > GetKeywordParameters(string expr, string originalName)
        {
            List <AnalysisVariable> paramVars = new List <AnalysisVariable>();

            if (expr.IndexOf('.') == -1)
            {
                // let's check if we'r re-naming a keyword argument...
                ITrackingSpan span = _view.GetCaretSpan();
                var           sigs = await _uiThread.InvokeTask(() => _serviceProvider.GetPythonToolsService().GetSignaturesAsync(_view, _view.TextBuffer.CurrentSnapshot, span))
                                     .ConfigureAwait(false);

                foreach (var sig in sigs.Signatures)
                {
                    PythonSignature overloadRes = sig as PythonSignature;
                    if (overloadRes != null)
                    {
                        foreach (PythonParameter param in overloadRes.Parameters)
                        {
                            if (param.Name == originalName && param.Variables != null)
                            {
                                paramVars.AddRange(param.Variables);
                            }
                        }
                    }
                }
            }

            return(paramVars);
        }
Esempio n. 4
0
        /// <summary>
        /// Wired to parser event for when the parser has completed parsing a new tree and we need
        /// to update the navigation bar with the new data.
        /// </summary>
        async Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
        {
            if (e.Event == PythonTextBufferInfoEvents.NewParseTree)
            {
                var dropDownBar = _dropDownBar;
                if (dropDownBar == null)
                {
                    return;
                }

                var navigations = await _uiThread.InvokeTask(() => e.AnalysisEntry.Analyzer.GetNavigationsAsync(_textView));

                lock (_navigationsLock) {
                    _navigations = navigations;
                    for (int i = 0; i < _curSelection.Length; i++)
                    {
                        _curSelection[i] = -1;
                    }
                }

                Action callback = () => CaretPositionChanged(
                    this,
                    new CaretPositionChangedEventArgs(
                        _textView,
                        _textView.Caret.Position,
                        _textView.Caret.Position
                        )
                    );

                try {
                    await _dispatcher.BeginInvoke(callback, DispatcherPriority.Background);
                } catch (TaskCanceledException) {
                }
            }
        }
Esempio n. 5
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);
        }