Skip to content

Commit

Permalink
Playground: Fix error squiggle updates getting dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
minestarks committed Sep 9, 2024
1 parent 72c32aa commit 2719334
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions playground/src/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,10 @@ export function Editor(props: {
>([]);
const [hasCheckErrors, setHasCheckErrors] = useState(false);

function markErrors(version?: number) {
function markErrors() {
const model = editor.current?.getModel();
if (!model) return;

if (version != null && version !== model.getVersionId()) {
// Diagnostics event received for an outdated model
return;
}

const errs = [
...errMarks.current.checkDiags,
...errMarks.current.shotDiags,
Expand Down Expand Up @@ -260,7 +255,11 @@ export function Editor(props: {
// will be invalid as it captures the *original* props.languageService
// and not the updated one. Not a problem currently since the language
// service is never updated, but not correct either.
srcModel.onDidChangeContent(async () => {
srcModel.onDidChangeContent(async (e) => {
e.changes.forEach((change) => {
log.debug("changes for version %d are: %o", e.versionId, change);
});

// Reset the shot errors whenever the document changes.
// The markers will be refreshed by the onDiagnostics callback
// when the language service finishes checking the document.
Expand Down Expand Up @@ -304,7 +303,7 @@ export function Editor(props: {
function onDiagnostics(evt: LanguageServiceEvent) {
const diagnostics = evt.detail.diagnostics;
errMarks.current.checkDiags = diagnostics;
markErrors(evt.detail.version);
markErrors();
setHasCheckErrors(
diagnostics.filter((d) => d.severity === "error").length > 0,
);
Expand Down

0 comments on commit 2719334

Please sign in to comment.