Linter that only refreshes on needsRefresh

I can dispatch the TransactionSpec from setDiagnostics to add my Diagnostics. However, the Diagnostics disappear from my editor when the document changes. I tried to dispatch again after each document change with updateListener (and update the Ranges with forEachDiagnostic), but the Diagnostics will disappear instantly.