https://bugs.kde.org/show_bug.cgi?id=372040
Scanning for fixes of "unknown declaration problems" involve scanning all available headerfiles, which can take a significant amount of time. This is currently done on the main thread, which means that any unknown variable or function can halt event processing and render the editor unresponsive. On Mac this will display the dreaded beachball cursor.
This patch proposes a relatively simple solution that moves the scan to a background thread with only minimal refactoring that is purely internal to the implementation.
It is based on the presumption that
- only a single unknown declaration problem can be tackled at a time
- there is no point in continuing the search for solutions if the user changes the focus of interest, regardless of whether the new (cursor) location has another unknown declaration or not.
Thus, fixUnknownDeclaration() is moved to a new class, UDPWorkerThread that inherits QThread, of which a single global instance is allocated by UnknownDeclarationProblem::solutionAssistant(). That method also interrupts still running scans before starting a new scan.
Event processing is ensured by a UDPScanEventLoop instance that inherits QEventLoop; this class also has an event sniffer that raises an interrupt request to the scan worker thread when events occur that justify bailing out of the current scan.