Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Add support to ignore certain diagnostics #46

Merged
merged 1 commit into from
Dec 17, 2019

Conversation

spahnke
Copy link
Contributor

@spahnke spahnke commented Oct 7, 2019

Adds the property diagnosticCodesToIgnore to the interface DiagnosticsOptions which allows users to ignore certain diagnostics. A prime example would be A 'return' statement can only be used within a function body. (1108) if the editor is used in scripting environments where the actual code is implicitly wrapped in a function.

Fixes microsoft/monaco-editor#1069
Fixes microsoft/monaco-editor#1452

Example

monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
    diagnosticCodesToIgnore: [/*top-level return*/ 1108]
});

@@ -181,6 +181,7 @@ export class DiagnosticsAdapter extends Adapter {
}
const markers = diagnostics
.reduce((p, c) => c.concat(p), [])
.filter(d => (this._defaults.getDiagnosticsOptions().diagnosticCodesToIgnore || []).indexOf(d.code) === -1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use indexOf to be compatible with IE 11

@orta
Copy link
Contributor

orta commented Nov 5, 2019

+1 - I'd like this for the TypeScript playground

@alexdima
Copy link
Member

Nice, thank you! ❤️

@alexdima alexdima added this to the December 2019 milestone Dec 17, 2019
@alexdima alexdima merged commit e91b33e into microsoft:master Dec 17, 2019
@spahnke spahnke deleted the ignore-diagnostics branch December 19, 2019 19:01
@hems
Copy link

hems commented May 1, 2020

Super awesome!

I'm trying to find the list of diagnosticCodesToIgnore, but I'm a bit lost..

Does anybody spare have a link to spare for a lost programmer stranger? 😓

@alexdima
Copy link
Member

alexdima commented May 4, 2020

@hems This is written in the first comment in the PR:

monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({ diagnosticCodesToIgnore: [1108] });

@spahnke
Copy link
Contributor Author

spahnke commented May 4, 2020

I don't know if there's a designated list with all diagnostic codes, but the code is always shown with the diagnostic itself. In fact, this is how I found the code for the A 'return' statement can only be used within a function body. (1108) diagnostic.

@hems
Copy link

hems commented May 5, 2020

I don't know if there's a designated list with all diagnostic codes, but the code is always shown with the diagnostic itself. In fact, this is how I found the code for the A 'return' statement can only be used within a function body. (1108) diagnostic.

Thanks @spahnke, that's exactly what I was trying to figure out!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convince Monaco/TSC a TS file is actually a function body? Allow top-level return statements in JavaScript
4 participants