monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

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

Open thegedge opened this issue 2 years ago • 1 comments

Reproducible in vscode.dev or in VS Code Desktop?

  • [X] 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

thegedge avatar Jul 19 '22 20:07 thegedge

This looks like as if the model doesn't receive an event to update the markers.

hediet avatar Jul 20 '22 13:07 hediet