dericcain
dericcain

Reputation: 2290

Get all problems (errors, warnings, etc.) using VSCode extensions API

I am creating a VSCode extension and I need a way to access all of the current errors, warnings, etc in the Problems pane but I am not even sure if the API provides access to this. I see that I can create Diagnostics and it appears that I can get those diagnostics with the DiagnosticCollection but I don't see where I can get a list of all of the errors and such. Does anyone have experience with this.

p.s. I have tried

console.log(vscode.DiagnosticCollection) // undefined
console.log(vscode) // Looked through the object and found nothing of use
console.log(window) // Same thing. Nothing of use.

Upvotes: 3

Views: 1379

Answers (2)

Mark
Mark

Reputation: 180805

There are now 2 api's for this, see api reference: language diagnostics:

getDiagnostics(): [Uri, Diagnostic[]][] get diagnostics for all files

let diagnostics = vscode.languages.getDiagnostics();

getDiagnostics(resource: Uri): Diagnostic[] get the diagnostics for a specific uri

const uri = vscode.window.activeTextEditor.document.uri;
let diagnostics = vscode.languages.getDiagnostics(uri);  // returns an array

Upvotes: 2

Shahar Kazaz
Shahar Kazaz

Reputation: 1206

According to the documentation seems like it's not possible at the moment.
but I saw some discussions on adding an API to the problem view so that might be available in one of the next versions.

Upvotes: 1

Related Questions