Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Jul 4, 2017 · 12 comments
Closed

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

ghost opened this issue Jul 4, 2017 · 12 comments
Assignees
Labels
api api-proposal feature-request Request for new features or functionality languages-diagnostics Source problems reporting on-testplan
Milestone

Comments

@ghost
Copy link

ghost commented Jul 4, 2017

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?

@vscodebot vscodebot bot added the api label Jul 4, 2017
@jrieken jrieken added the feature-request Request for new features or functionality label Jul 10, 2017
@sghung
Copy link

sghung commented Oct 30, 2017

I am also a VSCode extension builder who wants to write automated tests for verifying a language server from the client side. Since I'm unable to programatically access the DiagnosticCollection, it is quite difficult to automate. Having additional API to access these problems would be very helpful.

@sandy081 sandy081 removed their assignment Dec 4, 2017
@jrieken
Copy link
Member

jrieken commented Mar 1, 2018

fyi @dbaeumer

@jrieken jrieken added the languages-diagnostics Source problems reporting label Mar 1, 2018
@lggomez
Copy link
Contributor

lggomez commented Mar 11, 2018

+1 to this

I'm writing an extension that performs actions based on json content and this would be very useful to make preemptive validations based on existing diagnostics

@jrieken
Copy link
Member

jrieken commented Mar 13, 2018

Proposal for an event describing a change to markers. We should maybe think of adding a real event type as this allows for future growth

export const onDidChangeDiagnostics: Event<Uri[]>;

The proposal for reading diagnostics is a little harder because the Diagnostics-type doesn't know the resource it is targeting - therefore we use tuple-types, e.g [Uri, Diagnostics[]]. However, that doesn't work well with reading diagnostics for just one resource...

One idea is a type like a readonly-diagnostics collection. That could look like this:

export interface DiagnosticInformation {
	has(uri: Uri): boolean;
	get(uri: Uri): Diagnostic[] | undefined;
	all(): [Uri, Diagnostic[]][];
}

export namespace languages {
	export const diagnostics: DiagnosticInformation;
}

Or, a more simple approach using a callback (similar to DiagnosticsCollection#forEach). The downside of this approach is that we are inventing our own iteration protocol.

export namespace languages {
  // read one
  forEachDiagnostic(resource: Uri, callback:(resource: Uri, diagnostics: Diagnostics[]) => any):void;

  // read all
  forEachDiagnostic(callback:(resource: Uri, diagnostics: Diagnostics[]) => any):void;
}

cc @alexandrudima @dbaeumer for feedback

@dbaeumer
Copy link
Member

@jrieken: I would definitely go with a real event type.

For the API I have a question first: are all diagnostics mirrored into the extension host? If not we need to get the async. So I would make the API dependent on that. If we need to get the async DiagnosticInformation might get a little cumbersome.

BTW: I need to add a comparable API for tasks which I would need to get async and I would like to copy what we decided to do for diagnostics.

jrieken added a commit that referenced this issue Mar 14, 2018
@jrieken
Copy link
Member

jrieken commented Mar 14, 2018

I would definitely go with a real event type.

I like, pushed a change for.

For the API I have a question first: are all diagnostics mirrored into the extension host? If not we need to get the async. So I would make the API dependent on that.

Read APIs should always be synchronous and 'no' diagnostics aren't mirrored. Afaik only the task framework is writing diagnostics outside the extension host and the current implementation doesn't provide read access to them. We have to either eagerly mirror those to the extension host or find a way for the task framework to report errors via the extension host infrastructure...

BTW: I need to add a comparable API for tasks which I would need to get async and I would like to copy what we decided to do for diagnostics.

Not sure what that means...

@jrieken
Copy link
Member

jrieken commented Mar 14, 2018

So, this is the API I am proposing - it's little and in the same spirit of existing API (returns an array, is sync).

export interface DiagnosticChangeEvent {
  uris: Uri[];
}

export namespace languages {
  export const onDidChangeDiagnostics: Event<DiagnosticChangeEvent>;
  export function getDiagnostics(resource?: Uri): Diagnostic[];
}

The challenge with this proposal is that Diagnostics-objects don't know their location, only their range. That was a mistake and something can and should fix now by adding a location-property to diagnostic-objects, e.g.

export class Diagnostic {

  /**
   * @deprecated Use location
   */
  range: Range;

  location: Location;
  
  // ...
}

The plan is to deprecate the existing constructor and encourage extension authors to provide a location when creating diagnostics. For those that don't we can synthesise the location when a diagnostic object is added to a collection, e.g via set(uri: Uri, diagnostics: Diagnostic[] | undefined): void; or set(entries: [Uri, Diagnostic[] | undefined][]): void;

@dbaeumer
Copy link
Member

Makes sense to me.

@jrieken
Copy link
Member

jrieken commented Mar 20, 2018

fyi @DanTup

@julienhenry
Copy link

julienhenry commented Mar 20, 2018

Thanks for the recent commits. Can you explain what to put in my package.json file to be able to use these new API methods in my extension right away?

@jrieken
Copy link
Member

jrieken commented Mar 21, 2018

@julienhenry It is proposed API, to try it you must copy the vscode.proposed.d.ts-file into your project and then also add "enableProposedApi": true to your package.json file. That will allow you tryout proposed API locally but you cannot publish an extension using it. Still, we would love to get your feedback on this.

@jrieken jrieken removed this from the March 2018 milestone Mar 28, 2018
@jrieken jrieken added this to the April 2018 milestone Mar 28, 2018
@jrieken
Copy link
Member

jrieken commented Apr 6, 2018

We will ship this in April but diagnostics from the task framework are likely not accessible, see #47292

jrieken added a commit that referenced this issue Apr 6, 2018
jrieken added a commit that referenced this issue Apr 6, 2018
@jrieken jrieken closed this as completed Apr 12, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators May 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-proposal feature-request Request for new features or functionality languages-diagnostics Source problems reporting on-testplan
Projects
None yet
Development

No branches or pull requests

7 participants