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

fix regressions related to tasks support #8340

Merged
merged 2 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/debug/src/browser/debug-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 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 { JsonSchemaRegisterContext, JsonSchemaContribution } 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';
Expand All @@ -31,8 +31,12 @@ export class DebugSchemaUpdater implements JsonSchemaContribution {
@inject(InMemoryResources) protected readonly inmemoryResources: InMemoryResources;
@inject(DebugService) protected readonly debug: DebugService;

registerSchemas(context: JsonSchemaRegisterContext): void {
@postConstruct()
protected init(): void {
this.inmemoryResources.add(this.uri, '');
}

registerSchemas(context: JsonSchemaRegisterContext): void {
context.registerSchema({
fileMatch: ['launch.json'],
url: this.uri.toString()
Expand Down
17 changes: 7 additions & 10 deletions packages/task/src/browser/task-configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,14 @@ export class TaskConfigurationManager {
protected async doCreate(model: TaskConfigurationModel): Promise<URI | undefined> {
const content = await this.getInitialConfigurationContent();
if (content) {
await this.folderPreferences.setPreference('tasks', {}, model.getWorkspaceFolder()); // create dummy tasks.json in the correct place
const { configUri } = this.folderPreferences.resolve('tasks', model.getWorkspaceFolder()); // get uri to write content to it

let uri: URI;
if (configUri && configUri.path.base === 'tasks.json') {
uri = configUri;
} else { // fallback
uri = new URI(model.getWorkspaceFolder()).resolve(`${this.preferenceConfigurations.getPaths()[0]}/tasks.json`);
await model.preferences.setPreference('tasks', {}, model.getWorkspaceFolder()); // create dummy tasks.json in the correct place
const { configUri } = model.preferences.resolve('tasks', model.getWorkspaceFolder()); // get uri to write content to it

if (!configUri || configUri.path.base !== 'tasks.json') {
return undefined;
}
await this.fileService.write(uri, content);
return uri;
await this.fileService.write(configUri, content);
return configUri;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/task/src/browser/task-configuration-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export class TaskConfigurationModel implements Disposable {
);

constructor(
public readonly scope: TaskConfigurationScope,
protected readonly preferences: PreferenceProvider
readonly scope: TaskConfigurationScope,
readonly preferences: PreferenceProvider
) {
this.reconcile();
this.toDispose.push(this.preferences.onDidPreferencesChanged((e: PreferenceProviderDataChanges) => {
Expand Down
9 changes: 1 addition & 8 deletions packages/task/src/browser/task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import { TaskSourceResolver } from './task-source-resolver';
import { Disposable, DisposableCollection } from '@theia/core/lib/common';
import { FileChangeType } from '@theia/filesystem/lib/common/filesystem-watcher-protocol';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { OpenerService } from '@theia/core/lib/browser';
import { UserStorageUri } from '@theia/userstorage/lib/browser/user-storage-uri';

export interface TaskConfigurationClient {
/**
Expand All @@ -42,8 +40,6 @@ export interface TaskConfigurationClient {
taskConfigurationChanged: (event: string[]) => void;
}

export const USER_TASKS_URI = UserStorageUri.resolve('tasks.json');

/**
* Watches a tasks.json configuration file and provides a parsed version of the contained task configurations
*/
Expand Down Expand Up @@ -71,9 +67,6 @@ export class TaskConfigurations implements Disposable {
@inject(WorkspaceService)
protected readonly workspaceService: WorkspaceService;

@inject(OpenerService)
protected readonly openerService: OpenerService;

@inject(TaskDefinitionRegistry)
protected readonly taskDefinitionRegistry: TaskDefinitionRegistry;

Expand Down Expand Up @@ -303,7 +296,7 @@ export class TaskConfigurations implements Disposable {
}

async openUserTasks(): Promise<void> {
await this.openerService.getOpener(USER_TASKS_URI).then(opener => opener.open(USER_TASKS_URI));
await this.taskConfigurationManager.openConfiguration(TaskScope.Global);
}

/** Adds given task to a config file and opens the file to provide ability to edit task configuration. */
Expand Down
28 changes: 15 additions & 13 deletions 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 * as Ajv from 'ajv';
import debounce = require('p-debounce');
import { injectable, inject } from 'inversify';
import { postConstruct, injectable, inject } from 'inversify';
import { JsonSchemaContribution, JsonSchemaRegisterContext } from '@theia/core/lib/browser/json-schema-store';
import { InMemoryResources, deepClone, Emitter } from '@theia/core/lib/common';
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
Expand All @@ -31,7 +31,7 @@ import URI from '@theia/core/lib/common/uri';
import { ProblemMatcherRegistry } from './task-problem-matcher-registry';
import { TaskDefinitionRegistry } from './task-definition-registry';
import { TaskServer } from '../common';
import { USER_TASKS_URI } from './task-configurations';
import { UserStorageUri } from '@theia/userstorage/lib/browser';

export const taskSchemaId = 'vscode://schemas/tasks';

Expand All @@ -53,19 +53,16 @@ export class TaskSchemaUpdater implements JsonSchemaContribution {
protected readonly onDidChangeTaskSchemaEmitter = new Emitter<void>();
readonly onDidChangeTaskSchema = this.onDidChangeTaskSchemaEmitter.event;

registerSchemas(context: JsonSchemaRegisterContext): void {
const taskSchemaUri = new URI(taskSchemaId);
const resource = this.inmemoryResources.add(taskSchemaUri, '');
protected readonly uri = new URI(taskSchemaId);

@postConstruct()
protected init(): void {
const resource = this.inmemoryResources.add(this.uri, '');
if (resource.onDidChangeContents) {
resource.onDidChangeContents(() => {
this.onDidChangeTaskSchemaEmitter.fire(undefined);
});
}
context.registerSchema({
fileMatch: ['tasks.json', USER_TASKS_URI.toString()],
url: taskSchemaUri.toString()
});

this.updateProblemMatcherNames();
this.updateSupportedTaskTypes();
// update problem matcher names in the task schema every time a problem matcher is added or disposed
Expand All @@ -75,16 +72,21 @@ export class TaskSchemaUpdater implements JsonSchemaContribution {
this.taskDefinitionRegistry.onDidUnregisterTaskDefinition(() => this.updateSupportedTaskTypes());
}

registerSchemas(context: JsonSchemaRegisterContext): void {
context.registerSchema({
fileMatch: ['tasks.json', UserStorageUri.resolve('tasks.json').toString()],
url: this.uri.toString()
});
}

readonly update = debounce(() => this.doUpdate(), 0);
protected doUpdate(): void {
const taskSchemaUri = new URI(taskSchemaId);

taskConfigurationSchema.anyOf = [processTaskConfigurationSchema, ...customizedDetectedTasks, ...customSchemas];

const schema = this.getTaskSchema();
this.doValidate = new Ajv().compile(schema);
const schemaContent = JSON.stringify(schema);
this.inmemoryResources.update(taskSchemaUri, schemaContent);
this.inmemoryResources.update(this.uri, schemaContent);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down