-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Comments
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. |
fyi @dbaeumer |
+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 |
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 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 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 |
@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. |
I like, pushed a change for.
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...
Not sure what that means... |
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 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 |
Makes sense to me. |
fyi @DanTup |
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? |
@julienhenry It is proposed API, to try it you must copy the |
We will ship this in April but diagnostics from the task framework are likely not accessible, see #47292 |
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?
The text was updated successfully, but these errors were encountered: