Clear the diagnostics before processing (#3118)

clear diagnostics when we update the text

Signed-off-by: Paul R. Tagliamonte <paul@zoo.dev>
This commit is contained in:
Paul Tagliamonte
2024-07-24 16:11:56 -04:00
committed by GitHub
parent 22df47fa96
commit 385589ddf9
4 changed files with 20 additions and 11 deletions

View File

@ -17,6 +17,7 @@ import type {
PluginSpec,
ViewPlugin,
} from '@codemirror/view'
import { setDiagnosticsEffect } from '@codemirror/lint'
import { EditorView, Tooltip } from '@codemirror/view'
import type { PublishDiagnosticsParams } from 'vscode-languageserver-protocol'
@ -214,6 +215,21 @@ export class LanguageServerPlugin implements PluginValue {
}
if (!this.client.ready) return
// TODO(paultag): This is the *wrong* place for this to live.
//
// We need to clear diagnostics before updating the code, because
// if the code shrinks, the errors/diagnostics can go out of range
// of the source code, which cause an exception, breaking all the
// things.
//
// We need some sort of clear diagnostics boolean on the editor
// and we can drop this.
this.view.dispatch({
effects: [setDiagnosticsEffect.of([])],
annotations: [],
})
try {
// Update the state (not the editor) with the new code.
this.client.textDocumentDidChange({