As discussed elsewhere, KDevelop doesn't currently provide a means of job control over the background parser, except when parsing a complete project.
This WIP patch introduces the simplest form of such control: a possibility to stop all background parsing processes that are not part of a project (re)parse. This includes documents that were part of such a (re)parse, got parsed, and then were rescheduled to be parsed again.
The underlying approach I used consists of an instance of a proxy/stub job controller (one per background parser instance, of which there is apparently never more than 1 at the moment). This proxy and the BGParser d class keep track of which documents are under control of the proxy so that only those jobs are cancelled at the user's request.
Most of the change is transparent outside of the BackgroundParser implementation (and doesn't cost much as far as I can tell) but I did have to add a new method to that class for client code that already implements its own job control.
Initially I just dequeued all concerned ThreadWeaver jobs but this caused intermittent crashes that looked as if they were caused by a race condition if one of those jobs was actually running. This was addressed by suspending the weaver first, which also means that the running job is allowed to finish first - not ideal but I haven't found a safe way around that yet.
As a side-effect this change also avoids queuing a reparse of a document that is already queued for parsing, which is probably a good thing.
An alternative would be to implement a "cancel all background parsing" action, but this would also need to cancel the project parse jobs and I don't really see how to do that properly without using the current approach and then sending abort commands to all JobController entries.