Ejemplo n.º 1
0
        public BackgroundRequest BeginBackgroundRequest(int line, int idx, TokenInfo info, BackgroundRequestReason reason, IVsTextView view, RequireFreshResults requireFreshResults, BackgroundRequestResultHandler callback, MethodTipMiscellany methodTipMiscellany = 0)
        {
            var wpfTextView = GetWpfTextViewFromVsTextView(view);
            var snapshot = wpfTextView.TextSnapshot;

            if (this.disposed) return null;
            string fname = this.GetFilePath();

            Debug.Assert(snapshot != null);
            Debug.Assert(callback != null);

            // Check if we can shortcut executing the background request and just fill in the latest
            // cached scope for the active view from this.service.RecentFullTypeCheckResults.
            //
            // This must only kick in if ExecuteBackgroundRequest is equivalent to fetching a recent,
            // perhaps out-of-date scope.
            if (!this.NeedsVisualRefresh &&
                this.service.IsRecentScopeSufficientForBackgroundRequest(reason) &&
                (this.service.RecentFullTypeCheckResults != null) &&
                this.service.RecentFullTypeCheckFile.Equals(fname) &&
                requireFreshResults != RequireFreshResults.Yes)
            {
                BackgroundRequest request = this.service.CreateBackgroundRequest(this, line, idx, info, null, snapshot, methodTipMiscellany, fname, reason, view);
                request.ResultScope = this.service.RecentFullTypeCheckResults;
                request.ResultClearsDirtinessOfFile = false;
                request.Timestamp = this.ChangeCount;
                request.IsSynchronous = true;
                callback(request);
                return request;
            }
            else
            {

                string text = this.GetText(); // get all the text
                BackgroundRequest request = this.service.CreateBackgroundRequest(this, line, idx, info, text, snapshot, methodTipMiscellany, fname, reason, view);
                request.Timestamp = this.ChangeCount;
                request.DirtySpan = this.dirtySpan;
                request.RequireFreshResults = requireFreshResults;

                if (!this.LanguageService.Preferences.EnableAsyncCompletion)
                {
                    request.IsSynchronous = true; //unless registry value indicates that sync ops always prefer async 
                }
                if (request.IsSynchronous)
                {
                    this.service.ExecuteBackgroundRequest(request);
                    callback(request);
                }
                else
                {
                    request.result = this.service.BeginBackgroundRequest(request, callback);
                }
                return request;
            }
        }
Ejemplo n.º 2
0
 internal BackgroundRequestAsyncResult BeginBackgroundRequest(BackgroundRequest request, BackgroundRequestResultHandler handler)
 {
     EnsureBackgroundThreadStarted();
     lock (this)
     {
         request.Callback = handler;
         this.requests.Enqueue(request);
         this.isServingBackgroundRequest = true;
         this.backgroundRequestPending.Set();
         this.backgroundRequestDone.Reset();
         // Return a capability to wait on the completion of the background request
         return new BackgroundRequestAsyncResult(request, this.backgroundRequestDone);
     }
 }