Skip to content

Commit

Permalink
Reorganize tasks when task schema is updated
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Nov 29, 2019
1 parent 0b810f8 commit bf5dbc2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
10 changes: 9 additions & 1 deletion packages/core/src/browser/json-schema-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class JsonSchemaStore {
protected readonly onSchemasChangedEmitter = new Emitter<void>();
readonly onSchemasChanged = this.onSchemasChangedEmitter.event;

protected readonly onDidChangeSchemaEmitter = new Emitter<URI>();
readonly onDidChangeSchema = this.onDidChangeSchemaEmitter.event;

protected notifyChanged = debounce(() => {
this.onSchemasChangedEmitter.fire(undefined);
}, 500);
Expand All @@ -48,17 +51,22 @@ export class JsonSchemaStore {
if (uri.scheme === 'vscode') {
const resource = this.inMemoryResources.resolve(new URI(config.url));
if (resource && resource.onDidChangeContents) {
toDispose.push(resource.onDidChangeContents(() => this.notifyChanged()));
toDispose.push(resource.onDidChangeContents(() => {
this.onDidChangeSchemaEmitter.fire(uri);
this.notifyChanged();
}));
}
}
this.schemas.push(config);
toDispose.push(Disposable.create(() => {
const idx = this.schemas.indexOf(config);
if (idx > -1) {
this.schemas.splice(idx, 1);
this.onDidChangeSchemaEmitter.fire(uri);
this.notifyChanged();
}
}));
this.onDidChangeSchemaEmitter.fire(uri);
this.notifyChanged();
return toDispose;
}
Expand Down
5 changes: 1 addition & 4 deletions packages/task/src/browser/task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ export class TaskConfigurations implements Disposable {
})
);
this.reorgnizeTasks();
this.toDispose.pushAll([
this.taskDefinitionRegistry.onDidRegisterTaskDefinition(() => this.reorgnizeTasks()),
this.taskDefinitionRegistry.onDidUnregisterTaskDefinition(() => this.reorgnizeTasks())
]);
this.toDispose.push(this.taskSchemaUpdater.onDidChangeTaskSchema(() => this.reorgnizeTasks()));
}

setClient(client: TaskConfigurationClient): void {
Expand Down
12 changes: 11 additions & 1 deletion packages/task/src/browser/task-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

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 { InMemoryResources, deepClone, Emitter } 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';
Expand All @@ -49,8 +49,18 @@ export class TaskSchemaUpdater {
@inject(TaskServer)
protected readonly taskServer: TaskServer;

protected readonly onDidChangeTaskSchemaEmitter = new Emitter<void>();
readonly onDidChangeTaskSchema = this.onDidChangeTaskSchemaEmitter.event;

@postConstruct()
protected init(): void {
const taskSchemaUri = new URI(taskSchemaId);
this.jsonSchemaStore.onDidChangeSchema(uri => {
if (uri.toString() === taskSchemaUri.toString()) {
this.onDidChangeTaskSchemaEmitter.fire(undefined);
}
});

this.updateProblemMatcherNames();
this.updateSupportedTaskTypes();
// update problem matcher names in the task schema every time a problem matcher is added or disposed
Expand Down

0 comments on commit bf5dbc2

Please sign in to comment.