-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add registered ProblemMatchers to tasks schema #6422
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,13 +13,14 @@ | |
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { injectable, inject } from 'inversify'; | ||
import { injectable, inject, postConstruct } from 'inversify'; | ||
import { JsonSchemaStore } from '@theia/core/lib/browser/json-schema-store'; | ||
import { InMemoryResources, deepClone } from '@theia/core/lib/common'; | ||
import { IJSONSchema } from '@theia/core/lib/common/json-schema'; | ||
import { inputsSchema } from '@theia/variable-resolver/lib/browser/variable-input-schema'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import { TaskService } from './task-service'; | ||
import { ProblemMatcherRegistry } from './task-problem-matcher-registry'; | ||
|
||
export const taskSchemaId = 'vscode://schemas/tasks'; | ||
|
||
|
@@ -34,8 +35,31 @@ export class TaskSchemaUpdater { | |
@inject(TaskService) | ||
protected readonly taskService: TaskService; | ||
|
||
@inject(ProblemMatcherRegistry) | ||
protected readonly problemMatcherRegistry: ProblemMatcherRegistry; | ||
|
||
@postConstruct() | ||
protected init(): void { | ||
this.updateProblemMatcherNames(); | ||
// update problem matcher names in the task schema every time a problem matcher is added or disposed | ||
this.problemMatcherRegistry.onDidChangeProblemMatcher(() => this.updateProblemMatcherNames()); | ||
} | ||
|
||
async update(): Promise<void> { | ||
const taskSchemaUri = new URI(taskSchemaId); | ||
const schemaContent = await this.getTaskSchema(); | ||
try { | ||
this.inmemoryResources.update(taskSchemaUri, schemaContent); | ||
} catch (e) { | ||
this.inmemoryResources.add(taskSchemaUri, schemaContent); | ||
this.jsonSchemaStore.registerSchema({ | ||
fileMatch: ['tasks.json'], | ||
url: taskSchemaUri.toString() | ||
}); | ||
} | ||
} | ||
|
||
private async getTaskSchema(): Promise<string> { | ||
const taskSchema = { | ||
properties: { | ||
tasks: { | ||
|
@@ -49,17 +73,15 @@ export class TaskSchemaUpdater { | |
}; | ||
const taskTypes = await this.taskService.getRegisteredTaskTypes(); | ||
taskSchema.properties.tasks.items.oneOf![0].allOf![0].properties!.type.enum = taskTypes; | ||
const taskSchemaUri = new URI(taskSchemaId); | ||
const contents = JSON.stringify(taskSchema); | ||
try { | ||
this.inmemoryResources.update(taskSchemaUri, contents); | ||
} catch (e) { | ||
this.inmemoryResources.add(taskSchemaUri, contents); | ||
this.jsonSchemaStore.registerSchema({ | ||
fileMatch: ['tasks.json'], | ||
url: taskSchemaUri.toString() | ||
}); | ||
} | ||
return JSON.stringify(taskSchema); | ||
} | ||
|
||
/** Gets the most up-to-date names of problem matchers from the registry and update the task schema */ | ||
private updateProblemMatcherNames(): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elaihau do you mind documenting this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep i will document this function. This function is called in the callback of I cannot simply do |
||
const matcherNames = this.problemMatcherRegistry.getAll().map(m => m.name.startsWith('$') ? m.name : `$${m.name}`); | ||
problemMatcherNames.length = 0; | ||
problemMatcherNames.push(...matcherNames); | ||
this.update(); | ||
} | ||
} | ||
|
||
|
@@ -110,6 +132,7 @@ const commandOptionsSchema: IJSONSchema = { | |
} | ||
}; | ||
|
||
const problemMatcherNames: string[] = []; | ||
const taskConfigurationSchema: IJSONSchema = { | ||
$id: taskSchemaId, | ||
oneOf: [ | ||
|
@@ -161,6 +184,11 @@ const taskConfigurationSchema: IJSONSchema = { | |
}, | ||
problemMatcher: { | ||
oneOf: [ | ||
{ | ||
type: 'string', | ||
description: 'Name of the problem matcher to parse the output of the task', | ||
enum: problemMatcherNames | ||
}, | ||
{ | ||
type: 'object', | ||
description: 'User defined problem matcher(s) to parse the output of the task', | ||
|
@@ -169,7 +197,8 @@ const taskConfigurationSchema: IJSONSchema = { | |
type: 'array', | ||
description: 'Name(s) of the problem matcher(s) to parse the output of the task', | ||
items: { | ||
type: 'string' | ||
type: 'string', | ||
enum: problemMatcherNames | ||
} | ||
} | ||
] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akosyakov this is the part i am not sure about.
could you please give me more information on what
/* mark as not disposed */
means here? Thank you !There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDisposed
returnstrue
if a collection is empty. If we don't add anything on the initialization when checking it returnsfalse
, so we push an empty disposable object to indicate that it was not disposed yet.