-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Status codes and well-defined errors in XYZProvider interfaces #15454
Comments
In the long run we should have two concepts (1) provider specific status and (2) language specific status. For (1), and that is short term, a provider could do this
The UI side will have these the status errors accordingly. Open questions
Wrt a language status, we should add something that allows to broadcast more general, less feature specific status, like [info] You are using version x of language y or [Error] Cannot validate because lib-foo is missing. That could look like
|
@jrieken I like this approach. There is one additional thing I would like to have: when clicking on the ESLint status icon it currently reveal the corresponding output channel which usually contains additional information. Will we be able to do the same. And there is another feature I have: when you have errors in .eslintrc.json files I show the ESLint status icon even if no JS file is selected since technically the .eslinttc.json belongs to ESLint. And how would that work in the case that ESLint can validate HTML, vue, ... Would I register that for all languages ? |
@dbaeumer re #15454 (comment): It might be enough to allow for a languages.pushInformationStatus(['javascript', { pattern: '**/.eslintrc.json' }], 'Some message') |
Still having thoughts on the API... Unsure if throwing/rejecting is proper enough despite its appeal for simplicity. These are the three options: Option 1 - throwing/rejected promisesProviders can go the error-route (throw/Promise.reject) and signal their status using well-defined errors. This is inspired by HTTP status codes. It is stateless as each request ( // API:
export class Status {
message: string;
...
}
// sample:
registerCompletionItemProvider('foo-lang', {
provideCompletionItems(doc, pos, token) {
if(somePreconditionNotMet) {
throw new Status('short message', 'long message')
}
}
}) Pros:
Cons:
Option 2 - status objects knowing providersA global function to create a provider-specific status object for which we can track updates etc. Allows to speak for multiple providers but is stateful // API:
export interface ProviderStatus {
unset(): void;
set(message: string, more...)
}
export type Provider = CompletionItemProvider | DefinitionProvider | ...
export function createProviderStatus(provider: Provider, ...providers: Provider[]): LanguageStatus;
// sample:
const status = createProviderStatus(completionProvider, definitionProvider);
onDidChangeSomeStatus((message) => {
if(message) {
status.set('Fetching data for better IntelliSense')
} else {
status.unset();
}
}) Pros:
Cons:
Option 3 - provider specific statusEach provider signals its status via a property. // API:
export interface CompletionItemProvider {
// signal provider status
status: ProviderStatus;
provideCompletionItems(document: TextDocument, position: Position, token: CancellationToken): ProviderResult<CompletionItem[] | CompletionList>;
resolveCompletionItem?(item: CompletionItem, token: CancellationToken): ProviderResult<CompletionItem>;
}
// sample:
registerCompletionItemProvider('foo-lang', new class {
status?: ProviderStatus;
provideCompletionItems(doc, pos, token) {
if(somePreconditionNotMet) {
this.status = new ProviderStatus(someData);
}
// still possible to return a result
}
}) Pros:
Cons:
|
I like option 3 the best since it is easy to explain and local to the provider. However I don't see how this would help with stuff that a |
We should explore a list of well defined errors and status codes with which data provider can signal reasons for not producing a result. A sample would be a
DefinitionProvider
which can produce a result because it lacks configuration or is still fetching required data (d.ts
-loading)The text was updated successfully, but these errors were encountered: