1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Added a wait-for-classify on initial showing to reduce color flashing

This commit is contained in:
Brian Fiete 2019-09-18 09:58:40 -07:00
parent 287922693e
commit ba2c4faa59
2 changed files with 21 additions and 4 deletions

View file

@ -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)

View file

@ -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)
{