Skip to content

Commit

Permalink
Add task related context keys (#14757)
Browse files Browse the repository at this point in the history
  • Loading branch information
msujew authored Jan 29, 2025
1 parent 3f05454 commit 95f90ad
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
74 changes: 74 additions & 0 deletions packages/task/src/browser/task-context-key-service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// *****************************************************************************
// 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;

// 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<boolean>;
protected shellExecutionSupported: ContextKey<boolean>;
protected processExecutionSupported: ContextKey<boolean>;
protected serverlessWebContext: ContextKey<boolean>;
protected taskCommandsRegistered: ContextKey<boolean>;

@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);
}

}
2 changes: 2 additions & 0 deletions packages/task/src/browser/task-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =>
Expand Down

0 comments on commit 95f90ad

Please sign in to comment.