Merge pull request #110 from patrickshipe/prevent-null-model-crash

Fix crashes from null model
This commit is contained in:
Remco Haszing 2021-09-15 21:52:35 +02:00 committed by GitHub
commit 7bf8137107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -62,7 +62,9 @@ export function createDiagnosticsAdapter(
const diagnostics = await worker.doValidation(String(resource));
const markers = diagnostics.map(toDiagnostics);
const model = editor.getModel(resource);
if (model.getModeId() === languageId) {
// Return value from getModel can be null if model not found
// (e.g. if user navigates away from editor)
if (model && model.getModeId() === languageId) {
editor.setModelMarkers(model, languageId, markers);
}
};