Пример #1
0
        private void AnalyzeExpression(CaretPosition position)
        {
            var trackingSpan = position.CreateTrackingSpan(buffer);

            if (trackingSpan != null)
            {
                var vars = buffer.CurrentSnapshot.AnalyzeExpression(
                    trackingSpan,
                    false,
                    _provider._PublicFunctionProvider,
                    _provider._DatabaseInfoProvider,
                    _provider._ProgramFileProvider
                    );

                if (String.IsNullOrWhiteSpace(vars.Expression))
                {
                    Clear();
                    return;
                }

                if (vars.Value != null && vars.Variables != null)
                {
                    IProjectEntry currProj = buffer.GetAnalysis();
                    if (currProj != null)
                    {
                        var references = vars.Variables
                                         .Where(x =>
                        {
                            if (x.Location != null)
                            {
                                if ((x.Location.ProjectEntry != null && x.Location.ProjectEntry != currProj) ||
                                    (!string.IsNullOrWhiteSpace(x.Location.FilePath) && !x.Location.FilePath.Equals(currProj.FilePath, StringComparison.OrdinalIgnoreCase)))
                                {
                                    return(false);
                                }
                                return(true);
                            }
                            return(false);
                        })
                                         .Select(x => new IndexSpan(x.Location.Index, vars.Value.Name.Length));
                        if (references != null)
                        {
                            ITextSnapshot currentSnapshot          = this.buffer.CurrentSnapshot;
                            NormalizedSnapshotSpanCollection spans = new NormalizedSnapshotSpanCollection(references.Where(x => x.Start >= 0 && x.End < currentSnapshot.Length).Select(x => x.ToSnapshotSpan(currentSnapshot)));
                            if (this.highlightReferencesSpans != spans)
                            {
                                this.highlightReferencesSpans = spans;
                                this.FireTagsChangedEvent();
                            }
                            return;
                        }
                    }
                }
            }
            Clear();
        }
Пример #2
0
        /// <summary>
        /// Gets a list of signatuers available for the expression at the provided location in the snapshot.
        /// </summary>
        public SignatureAnalysis GetSignatures(ITextSnapshot snapshot, ITextBuffer buffer, ITrackingSpan span)
        {
            ReverseExpressionParser parser = new ReverseExpressionParser(snapshot, buffer, span);

            var loc = parser.Span.GetSpan(parser.Snapshot.Version);

            int           paramIndex;
            SnapshotPoint?sigStart;
            var           exprRange = parser.GetExpressionRange(1, out paramIndex, out sigStart);

            if (exprRange == null || sigStart == null)
            {
                return(new SignatureAnalysis("", 0, new ISignature[0]));
            }

            Debug.Assert(sigStart != null);
            var text = new SnapshotSpan(exprRange.Value.Snapshot, new Span(exprRange.Value.Start, sigStart.Value.Position - exprRange.Value.Start)).GetText();
            //var text = exprRange.Value.GetText();
            var applicableSpan = parser.Snapshot.CreateTrackingSpan(exprRange.Value.Span, SpanTrackingMode.EdgeInclusive);

            var liveSigs = TryGetLiveSignatures(snapshot, paramIndex, text, applicableSpan);

            if (liveSigs != null)
            {
                return(liveSigs);
            }

            var start = Stopwatch.ElapsedMilliseconds;

            var analysisItem = buffer.GetAnalysis();

            if (analysisItem != null)
            {
                var analysis = ((IPythonProjectEntry)analysisItem).Analysis;
                if (analysis != null)
                {
                    var lineNo = parser.Snapshot.GetLineNumberFromPosition(loc.Start);

                    var sigs = analysis.GetSignatures(text, lineNo + 1);
                    var end  = Stopwatch.ElapsedMilliseconds;

                    if (/*Logging &&*/ (end - start) > CompletionAnalysis.TooMuchTime)
                    {
                        Trace.WriteLine(String.Format("{0} lookup time {1} for signatures", text, end - start));
                    }

                    var result = new List <ISignature>();
                    foreach (var sig in sigs)
                    {
                        result.Add(new PythonSignature(applicableSpan, sig, paramIndex));
                    }

                    return(new SignatureAnalysis(
                               text,
                               paramIndex,
                               result
                               ));
                }
            }
            return(new SignatureAnalysis(text, paramIndex, new ISignature[0]));
        }
        private int AddDropDownBar()
        {
            var cpc = (IConnectionPointContainer)_window;

            if (cpc != null)
            {
                IConnectionPoint cp;
                cpc.FindConnectionPoint(typeof(IVsCodeWindowEvents).GUID, out cp);
                if (cp != null)
                {
                    cp.Advise(this, out _cookieVsCodeWindowEvents);
                }
            }

            var pythonProjectEntry = _textBuffer.GetAnalysis() as IGeneroProjectEntry;

            if (pythonProjectEntry == null)
            {
                return(VSConstants.E_FAIL);
            }

            IWpfTextView wpfTextView = null;
            IVsTextView  vsTextView;

            if (ErrorHandler.Succeeded(_window.GetLastActiveView(out vsTextView)) && vsTextView != null)
            {
                wpfTextView = VsEditorAdaptersFactoryService.GetWpfTextView(vsTextView);
            }
            if (wpfTextView == null)
            {
                return(VSConstants.E_FAIL);
            }

            // pass on the text view
            //GeneroFileParserManager fpm = VSGeneroPackage.Instance.UpdateBufferFileParserManager(_textBuffer);
            _client = new DropDownBarClient(wpfTextView, pythonProjectEntry);

            IVsDropdownBarManager manager = (IVsDropdownBarManager)_window;

            int instancesOpen = 0;

            if (!_textBuffer.Properties.TryGetProperty <int>("InstancesOpen", out instancesOpen))
            {
                _textBuffer.Properties.AddProperty("InstancesOpen", 1);
            }
            else
            {
                _textBuffer.Properties["InstancesOpen"] = instancesOpen + 1;
            }

            IVsDropdownBar dropDownBar;
            int            hr = manager.GetDropdownBar(out dropDownBar);

            if (ErrorHandler.Succeeded(hr) && dropDownBar != null)
            {
                hr = manager.RemoveDropdownBar();
                if (!ErrorHandler.Succeeded(hr))
                {
                    return(hr);
                }
            }

            int res = manager.AddDropdownBar(1, _client);

            if (ErrorHandler.Succeeded(res))
            {
                // A buffer may have multiple DropDownBarClients, given one may open multiple CodeWindows
                // over a single buffer using Window/New Window
                List <DropDownBarClient> listDropDownBarClient;
                if (!_textBuffer.Properties.TryGetProperty(typeof(DropDownBarClient), out listDropDownBarClient) || listDropDownBarClient == null)
                {
                    listDropDownBarClient = new List <DropDownBarClient>();
                    _textBuffer.Properties[typeof(DropDownBarClient)] = listDropDownBarClient;
                }
                listDropDownBarClient.Add(_client);
            }
            return(res);
        }