Пример #1
0
 public Task PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysisEntry)
     {
         Console.WriteLine($"New entry in {e.AnalysisEntry?.Analyzer}");
         if (e.AnalysisEntry != null)
         {
             var tcs = Interlocked.Exchange(ref _tcs, null);
             tcs?.SetResult(e.AnalysisEntry);
         }
     }
     return(Task.CompletedTask);
 }
Пример #2
0
 public Task PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysis)
     {
         if (_info.LastAnalysisReceivedVersion.VersionNumber >= _info.Buffer.CurrentSnapshot.Version.VersionNumber)
         {
             try {
                 _event.Set();
             } catch (ObjectDisposedException) {
             }
             _info.RemoveSink(this);
         }
     }
     return(Task.CompletedTask);
 }
 async Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (_triggerEvents.Contains(e.Event))
     {
         await OnNewAnalysis(sender, e.AnalysisEntry);
     }
 }
Пример #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)
     {
         AnalysisEntry analysisEntry = e.AnalysisEntry;
         await RefreshNavigationsFromAnalysisEntry(analysisEntry);
     }
 }
Пример #5
0
 Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysis)
     {
         return(OnNewAnalysisAsync(sender, e.AnalysisEntry));
     }
     else if (e.Event == PythonTextBufferInfoEvents.NewTextBufferInfo)
     {
         var entry = sender.AnalysisEntry;
         if (entry != null)
         {
             return(OnNewAnalysisAsync(sender, entry));
         }
     }
     return(Task.CompletedTask);
 }
Пример #6
0
        Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
        {
            switch (e.Event)
            {
            case PythonTextBufferInfoEvents.TextContentChangedLowPriority:
                lock (this) {
                    // only immediately re-parse on line changes after we've seen a text change.
                    var ne = (e as PythonTextBufferInfoNestedEventArgs)?.NestedEventArgs as TextContentChangedEventArgs;

                    if (_parsing)
                    {
                        // we are currently parsing, just reque when we complete
                        _requeue = true;
                        _timer.Change(Timeout.Infinite, Timeout.Infinite);
                    }
                    else if (_parseImmediately)
                    {
                        // we are a test buffer, we should requeue immediately
                        Requeue();
                    }
                    else if (ne == null)
                    {
                        // failed to get correct type for this event
                        Debug.Fail("Failed to get correct event type");
                    }
                    else if (LineAndTextChanges(ne))
                    {
                        // user pressed enter, we should requeue immediately
                        Requeue();
                    }
                    else
                    {
                        // parse if the user doesn't do anything for a while.
                        _textChange = IncludesTextChanges(ne);
                        _timer.Change(ReparseDelay, Timeout.Infinite);
                    }
                }
                break;

            case PythonTextBufferInfoEvents.DocumentEncodingChanged:
                lock (this) {
                    if (_parsing)
                    {
                        // we are currently parsing, just reque when we complete
                        _requeue = true;
                        _timer.Change(Timeout.Infinite, Timeout.Infinite);
                    }
                    else
                    {
                        Requeue();
                    }
                }
                break;
            }
            return(Task.CompletedTask);
        }
Пример #7
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) {
                }
            }
        }
Пример #8
0
 public async Task PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysis)
     {
         var snapshot = _info.LastAnalysisSnapshot;
         for (int retries = 100; retries > 0 && (snapshot = _info.LastAnalysisSnapshot) == null; --retries)
         {
             await Task.Delay(100);
         }
         if (snapshot == null)
         {
             throw new NullReferenceException("LastAnalysisSnapshot was not set");
         }
         if (snapshot.Version.VersionNumber >= _info.Buffer.CurrentSnapshot.Version.VersionNumber)
         {
             try {
                 _event.Set();
             } catch (ObjectDisposedException) {
             }
             _info.RemoveSink(this);
         }
     }
 }
Пример #9
0
 Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysis)
     {
         SuggestedActionsChanged?.Invoke(this, EventArgs.Empty);
     }
     return(Task.CompletedTask);
 }
Пример #10
0
 Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysisEntry)
     {
         return(OnNewAnalysisEntryAsync(sender, e.AnalysisEntry));
     }
     else if (e.Event == PythonTextBufferInfoEvents.TextContentChangedOnBackgroundThread)
     {
         return(OnTextContentChangedAsync(sender, (e as PythonTextBufferInfoNestedEventArgs)?.NestedEventArgs as TextContentChangedEventArgs));
     }
     else if (e.Event == PythonTextBufferInfoEvents.NewTextBufferInfo)
     {
         var entry = sender.AnalysisEntry;
         if (entry != null)
         {
             return(OnNewAnalysisEntryAsync(sender, entry));
         }
     }
     return(Task.CompletedTask);
 }
Пример #11
0
 Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysisEntry)
     {
         return(OnNewAnalysisEntryAsync(sender, e.AnalysisEntry));
     }
     else if (e.Event == PythonTextBufferInfoEvents.ContentTypeChanged)
     {
         _tokenCache.Clear();
     }
     else if (e.Event == PythonTextBufferInfoEvents.TextContentChanged)
     {
         return(OnTextContentChangedAsync(sender, (e as PythonTextBufferInfoNestedEventArgs)?.NestedEventArgs as TextContentChangedEventArgs));
     }
     return(Task.CompletedTask);
 }
Пример #12
0
 async Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewParseTree)
     {
         // TODO: Reconsider whether we process asynchronously and then marshal
         // at the end.
         await _services.Site.GetUIThread().InvokeTask(() => UpdateTagsAsync(sender, e.AnalysisEntry));
     }
 }
Пример #13
0
 Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysis)
     {
         return(OnNewAnalysisAsync(sender, e.AnalysisEntry));
     }
     return(Task.CompletedTask);
 }
Пример #14
0
 async Task IPythonTextBufferInfoEventSink.PythonTextBufferEventAsync(PythonTextBufferInfo sender, PythonTextBufferInfoEventArgs e)
 {
     if (e.Event == PythonTextBufferInfoEvents.NewAnalysis)
     {
         await OnNewAnalysis(sender, e.AnalysisEntry);
     }
 }