diff --git a/IDE/src/CommandQueueManager.bf b/IDE/src/CommandQueueManager.bf index 22b1f0bc..224cad1a 100644 --- a/IDE/src/CommandQueueManager.bf +++ b/IDE/src/CommandQueueManager.bf @@ -15,8 +15,9 @@ namespace IDE public Action mOnThreadDone ~ delete _; [ThreadStatic] public static bool mBpSetThreadName; + WaitEvent mWaitEvent = new WaitEvent() ~ delete _; - public void DoBackground(ThreadStart threadStart, Action onThreadDone = null) + public void DoBackground(ThreadStart threadStart, Action onThreadDone = null, int maxWait = 0) { Debug.Assert(Thread.CurrentThread == IDEApp.sApp.mMainThread); @@ -32,6 +33,7 @@ namespace IDE mOnThreadDone = onThreadDone; mThreadRunning = true; + mWaitEvent.Reset(); ThreadPool.QueueUserWorkItem(new () => { @@ -51,7 +53,15 @@ namespace IDE mThread = null; mThreadRunning = false; BeefPerf.Event("DoBackground:threadEnd", ""); + + mWaitEvent.Set(); }); + + if (maxWait != 0) + { + if (mWaitEvent.WaitFor(maxWait)) + CheckThreadDone(); + } //mBfSystem.PerfZoneEnd(); } @@ -180,10 +190,10 @@ namespace IDE return (mThreadWorker.mThreadRunning || mThreadWorkerHi.mThreadRunning); } - public void DoBackground(ThreadStart threadStart, Action onThreadDone = null) + public void DoBackground(ThreadStart threadStart, Action onThreadDone = null, int maxWait = 0) { CancelBackground(); - mThreadWorker.DoBackground(threadStart, onThreadDone); + mThreadWorker.DoBackground(threadStart, onThreadDone, maxWait); } public void DoBackgroundHi(ThreadStart threadStart, Action onThreadDone = null) diff --git a/IDE/src/ui/SourceViewPanel.bf b/IDE/src/ui/SourceViewPanel.bf index 19770134..32346931 100644 --- a/IDE/src/ui/SourceViewPanel.bf +++ b/IDE/src/ui/SourceViewPanel.bf @@ -1148,11 +1148,16 @@ namespace IDE.ui compiler.DoBackgroundHi(new () => { DoClassify(.Autocomplete, resolveParams, true); }, new => ClassifyThreadDone); //BackgroundResolve(new () => { DoClassify(.Autocomplete, resolveParams); }); else if (useResolveType == .ClassifyFullRefresh) + { + // To avoid "flashing" on proper colorization vs FastClassify, we wait a bit for the proper classifying to finish + // on initial show + int maxWait = (mUpdateCnt <= 1) ? 50 : 0; compiler.DoBackground(new () => { DoClassify(.ClassifyFullRefresh, resolveParams, false); }, new () => { ClassifyThreadDone(); - }); + }, maxWait); + } else if (useResolveType == .GetCurrentLocation) compiler.DoBackgroundHi(new () => { DoClassify(.GetCurrentLocation, resolveParams, true); }, new => ClassifyThreadDone); else if (useResolveType == .GetSymbolInfo) @@ -5425,6 +5430,8 @@ namespace IDE.ui // Wait longer for Clang since it'll delay autocompletions whereas Beef can be interrupted int32 classifyDelayTicks = (mIsBeefSource || (mUpdateCnt < 40)) ? 2 : 40; + if (mUpdateCnt <= 1) + classifyDelayTicks = 0; if (mWantsBackgroundAutocomplete) {