Issue Extension: Is it possible to debounce parsing of issues?

I am working on an issue-extension that lints code. It appears that the linter is run at every key-stroke. Is there a way to implement a debounce, so that it only runs after a certain time after typing stops, for example 250ms?


There’s an API Method on the TextEditor that does exactly this: onDidStopChanging.

Adds an event listener that invokes the provided callback a short time after the editor stops changing. Multiple changes to text in a short time will be coalesced into one event that can be acted upon performantly. The callback will receive as an argument the TextEditor object.

1 Like

@apexskier Thanks for the info! So the problem I would then face is what to return from the provideIssues(editor) method. This method appears to get triggered by the editor, and I don’t think I have control of that, or can configure it with a debounce. My worry is that if I track the debounce from the textEditor as you suggest, and I return early if it is not debounced, that it will clear all the existing errors, when it shouldn’t. I guess I could track the previously successful lint results and return that. Hmmm. Lots to think about. This seems more like a work-around than a clean solution.

In a perfect world, Issue extensions could be configured with a debounce parameter that Nova automatically respects.

To my best knowledge, the issues framework provided by the AssistantRegistry uses the onDidStopChanging event under the hood. The debounce this provides can be quite short, though, and if your linting operation has variable reaction times – not entirely unheard of when using async CLI processes –, that might not be enough. For my own extension, I implemented a kind of primitive queue where I track the order in which async lint operations start and drop those that return out of order; you can find the relevant code here, if you are interested.