microsoft / microsoft/monaco-editor

[Bug] Programmatic update of a model doesn't remove error markers

Open
#3,202 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted typescript typescript-multifile
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Code
monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
  target: monaco.languages.typescript.ScriptTarget.ES2020,
})

monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
  noSemanticValidation: false,
  noSyntaxValidation: false,

});

const fileA = `import { Test } from "./B";

console.log(Test.func());`;

const fileB = `export class Test {}`;

const modelA = monaco.editor.createModel(fileA, "typescript", monaco.Uri.parse("file:///A.ts"));
const modelB = monaco.editor.createModel(fileB, "typescript", monaco.Uri.parse("file:///B.ts"));

const editor = monaco.editor.create(document.getElementById('container'), {
    model: modelA,
    language: "typescript"
});

const showDiags = () => {
  monaco.languages.typescript.getTypeScriptWorker()
    .then(f => f())
    .then(worker => worker.getSemanticDiagnostics("file:///A.ts"))
    .then(diags => {
        console.info(diags);
        console.info(modelA.getAllDecorations());
    });
};

setTimeout(() => {
  modelB.setValue(`export class Test {
    static func() {
        return 5;
    }
  `);
  monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true);

  setTimeout(showDiags, 1000);
}, 1000);
Reproduction Steps
  1. Simply run the above.
  2. Wait a couple of seconds (note the output in the console).
  3. Add a newline at the end of the file.
Actual (Problematic) Behavior

When updating modelB programmatically, semantic diagnostics are properly updated for modelA to reflect the lack of a missing function, but the markers for the original error remain in modelA. Editing modelA (e.g., adding a newline) removes the error marker.

Expected Behavior

Programmatic update of modelB to resolve a type error in modelA should result in the removal of error markers in modelA

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the case in the Monaco Editor Playground using the modelA/modelB setup and TypeScript diagnostics configuration shown. Trace how the semantic diagnostic refresh is propagated after modelB.setValue; done means resolving the error in modelA also removes its existing markers without editing modelA.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.