From 7d5e49e459d66e08864c8789991e6b5b75c8fa29 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Wed, 22 Jan 2025 19:02:17 +0100 Subject: [PATCH 1/2] Add task related context keys --- .../src/browser/task-context-key-service.ts | 72 +++++++++++++++++++ .../task/src/browser/task-frontend-module.ts | 2 + packages/task/src/browser/task-service.ts | 4 ++ 3 files changed, 78 insertions(+) create mode 100644 packages/task/src/browser/task-context-key-service.ts diff --git a/packages/task/src/browser/task-context-key-service.ts b/packages/task/src/browser/task-context-key-service.ts new file mode 100644 index 0000000000000..e05d74507ba4b --- /dev/null +++ b/packages/task/src/browser/task-context-key-service.ts @@ -0,0 +1,72 @@ +// ***************************************************************************** +// Copyright (C) 2024 TypeFox and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// http://www.eclipse.org/legal/epl-2.0. +// +// This Source Code may also be made available under the following Secondary +// Licenses when the conditions for such availability set forth in the Eclipse +// Public License v. 2.0 are satisfied: GNU General Public License, version 2 +// with the GNU Classpath Exception which is available at +// https://www.gnu.org/software/classpath/license.html. +// +// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 +// ***************************************************************************** + +import { injectable, inject, postConstruct } from '@theia/core/shared/inversify'; +import { ContextKeyService, ContextKey } from '@theia/core/lib/browser/context-key-service'; +import { ApplicationServer } from '@theia/core/lib/common/application-protocol'; + +@injectable() +export class TaskContextKeyService { + + @inject(ContextKeyService) + protected readonly contextKeyService: ContextKeyService; + + @inject(ApplicationServer) + protected readonly applicationServer: ApplicationServer; + + protected customExecutionSupported: ContextKey; + protected shellExecutionSupported: ContextKey; + protected processExecutionSupported: ContextKey; + protected serverlessWebContext: ContextKey; + protected taskCommandsRegistered: ContextKey; + + @postConstruct() + protected init(): void { + this.customExecutionSupported = this.contextKeyService.createKey('customExecutionSupported', true); + this.shellExecutionSupported = this.contextKeyService.createKey('shellExecutionSupported', true); + this.processExecutionSupported = this.contextKeyService.createKey('processExecutionSupported', true); + this.serverlessWebContext = this.contextKeyService.createKey('serverlessWebContext', false); + this.taskCommandsRegistered = this.contextKeyService.createKey('taskCommandsRegistered', true); + this.applicationServer.getApplicationPlatform().then(platform => { + if (platform === 'web') { + this.setShellExecutionSupported(false); + this.setProcessExecutionSupported(false); + this.setServerlessWebContext(true); + } + }); + } + + setCustomExecutionSupported(customExecutionSupported: boolean): void { + this.customExecutionSupported.set(customExecutionSupported); + } + + setShellExecutionSupported(shellExecutionSupported: boolean): void { + this.shellExecutionSupported.set(shellExecutionSupported); + } + + setProcessExecutionSupported(processExecutionSupported: boolean): void { + this.processExecutionSupported.set(processExecutionSupported); + } + + setServerlessWebContext(serverlessWebContext: boolean): void { + this.serverlessWebContext.set(serverlessWebContext); + } + + setTaskCommandsRegistered(taskCommandsRegistered: boolean): void { + this.taskCommandsRegistered.set(taskCommandsRegistered); + } + +} diff --git a/packages/task/src/browser/task-frontend-module.ts b/packages/task/src/browser/task-frontend-module.ts index fd3c679169f29..6e332735251b0 100644 --- a/packages/task/src/browser/task-frontend-module.ts +++ b/packages/task/src/browser/task-frontend-module.ts @@ -42,6 +42,7 @@ import { TaskTemplateSelector } from './task-templates'; import { TaskTerminalWidgetManager } from './task-terminal-widget-manager'; import { JsonSchemaContribution } from '@theia/core/lib/browser/json-schema-store'; import { QuickAccessContribution } from '@theia/core/lib/browser/quick-input/quick-access'; +import { TaskContextKeyService } from './task-context-key-service'; export default new ContainerModule(bind => { bind(TaskFrontendContribution).toSelf().inSingletonScope(); @@ -80,6 +81,7 @@ export default new ContainerModule(bind => { bind(TaskSourceResolver).toSelf().inSingletonScope(); bind(TaskTemplateSelector).toSelf().inSingletonScope(); bind(TaskTerminalWidgetManager).toSelf().inSingletonScope(); + bind(TaskContextKeyService).toSelf().inSingletonScope(); bindProcessTaskModule(bind); bindTaskPreferences(bind); diff --git a/packages/task/src/browser/task-service.ts b/packages/task/src/browser/task-service.ts index 8d88ce58a6754..4ba25bb49c04e 100644 --- a/packages/task/src/browser/task-service.ts +++ b/packages/task/src/browser/task-service.ts @@ -67,6 +67,7 @@ import { MonacoWorkspace } from '@theia/monaco/lib/browser/monaco-workspace'; import { TaskTerminalWidgetManager } from './task-terminal-widget-manager'; import { ShellTerminalServerProxy } from '@theia/terminal/lib/common/shell-terminal-protocol'; import { Mutex } from 'async-mutex'; +import { TaskContextKeyService } from './task-context-key-service'; export interface QuickPickProblemMatcherItem { problemMatchers: NamedProblemMatcher[] | undefined; @@ -193,6 +194,9 @@ export class TaskService implements TaskConfigurationClient { @inject(TaskTerminalWidgetManager) protected readonly taskTerminalWidgetManager: TaskTerminalWidgetManager; + @inject(TaskContextKeyService) + protected readonly taskContextKeyService: TaskContextKeyService; + @postConstruct() protected init(): void { this.getRunningTasks().then(tasks => From 595f8611433c4d8081d6a7b7500d48ba745d5048 Mon Sep 17 00:00:00 2001 From: Mark Sujew Date: Wed, 29 Jan 2025 18:21:32 +0100 Subject: [PATCH 2/2] Update task-context-key-service.ts --- packages/task/src/browser/task-context-key-service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/task/src/browser/task-context-key-service.ts b/packages/task/src/browser/task-context-key-service.ts index e05d74507ba4b..6113a63881b94 100644 --- a/packages/task/src/browser/task-context-key-service.ts +++ b/packages/task/src/browser/task-context-key-service.ts @@ -27,6 +27,8 @@ export class TaskContextKeyService { @inject(ApplicationServer) protected readonly applicationServer: ApplicationServer; + // The context keys are supposed to be aligned with VS Code. See also: + // https://github.com/microsoft/vscode/blob/e6125a356ff6ebe7214b183ee1b5fb009a2b8d31/src/vs/workbench/contrib/tasks/common/taskService.ts#L20-L24 protected customExecutionSupported: ContextKey; protected shellExecutionSupported: ContextKey; protected processExecutionSupported: ContextKey;