Skip to content

Commit

Permalink
debug: add run statusbar item
Browse files Browse the repository at this point in the history
- adds the `select and run` statusbar item for debugging.
- the item is registered when a debug session starts, and reflects the
  current configuration.
- triggering the item will prompt the debug prefix quick-open menu.

Signed-off-by: vince-fugnitto <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Jul 6, 2020
1 parent 8a029e2 commit b81e6a3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/debug/src/browser/debug-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export const debugPreferencesSchema: PreferenceSchema = {
type: 'boolean',
default: false,
description: 'Show variable values inline in editor while debugging.'
},
'debug.showInStatusBar': {
enum: ['never', 'always', 'onFirstSessionStart'],
description: 'Controls when the debug status bar should be visible.',
default: 'onFirstSessionStart'
}
}
};
Expand All @@ -54,6 +59,7 @@ export class DebugConfiguration {
'debug.openDebug': 'neverOpen' | 'openOnSessionStart' | 'openOnFirstSessionStart' | 'openOnDebugBreak';
'debug.internalConsoleOptions': 'neverOpen' | 'openOnSessionStart' | 'openOnFirstSessionStart';
'debug.inlineValues': boolean;
'debug.showInStatusBar': 'never' | 'always' | 'onFirstSessionStart';
}

export const DebugPreferences = Symbol('DebugPreferences');
Expand Down
61 changes: 60 additions & 1 deletion packages/debug/src/browser/debug-prefix-configuration.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 { inject, injectable } from 'inversify';
import { inject, injectable, postConstruct } from 'inversify';
import { Command, CommandContribution, CommandHandler, CommandRegistry } from '@theia/core/lib/common/command';
import {
QuickOpenContribution, QuickOpenHandler, QuickOpenModel,
Expand All @@ -27,6 +27,8 @@ import { DebugSessionOptions } from './debug-session-options';
import { WorkspaceService } from '@theia/workspace/lib/browser';
import { LabelProvider } from '@theia/core/lib/browser/label-provider';
import URI from '@theia/core/lib/common/uri';
import { StatusBar, StatusBarAlignment } from '@theia/core/lib/browser';
import { DebugPreferences } from './debug-preferences';

@injectable()
export class DebugPrefixConfiguration implements CommandContribution, CommandHandler, QuickOpenContribution, QuickOpenHandler, QuickOpenModel {
Expand All @@ -37,6 +39,9 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan
@inject(DebugSessionManager)
protected readonly debugSessionManager: DebugSessionManager;

@inject(DebugPreferences)
protected readonly preference: DebugPreferences;

@inject(DebugConfigurationManager)
protected readonly debugConfigurationManager: DebugConfigurationManager;

Expand All @@ -49,15 +54,34 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan
@inject(LabelProvider)
protected readonly labelProvider: LabelProvider;

@inject(StatusBar)
protected readonly statusBar: StatusBar;

readonly prefix = 'debug ';
readonly description = 'Debug Configuration';
readonly statusBarId = 'select-run-debug-statusbar-item';

private readonly command: Command = {
id: 'select.debug.configuration',
category: 'Debug',
label: 'Select and Start Debugging'
};

@postConstruct()
protected update(): void {
this.handleDebugStatusBarVisibility();
this.preference.onPreferenceChanged(e => {
if (e.preferenceName === 'debug.showInStatusBar') {
this.handleDebugStatusBarVisibility();
}
});
const toDisposeOnStart = this.debugSessionManager.onDidStartDebugSession(() => {
toDisposeOnStart.dispose();
this.handleDebugStatusBarVisibility(true);
this.debugConfigurationManager.onDidChange(() => this.handleDebugStatusBarVisibility(true));
});
}

execute(): void {
this.prefixQuickOpenService.open(this.prefix);
}
Expand Down Expand Up @@ -119,4 +143,39 @@ export class DebugPrefixConfiguration implements CommandContribution, CommandHan
this.debugConfigurationManager.current = { ...configuration };
this.commandRegistry.executeCommand(DebugCommands.START.id);
}

/**
* Handle the visibility of the debug status bar.
* @param event the preference change event.
*/
protected handleDebugStatusBarVisibility(started?: boolean): void {
const showInStatusBar = this.preference['debug.showInStatusBar'];
if (showInStatusBar === 'never') {
return this.removeDebugStatusBar();
} else if (showInStatusBar === 'always' || started) {
return this.updateStatusBar();
}
}

/**
* Update the debug status bar element based on the current configuration.
*/
protected updateStatusBar(): void {
const text: string = this.debugConfigurationManager.current
? this.debugConfigurationManager.current.configuration.name
: '';
this.statusBar.setElement(this.statusBarId, {
alignment: StatusBarAlignment.LEFT,
text: '$(play) ' + text,
tooltip: this.command.label,
command: this.command.id,
});
}

/**
* Remove the debug status bar element.
*/
protected removeDebugStatusBar(): void {
this.statusBar.removeElement(this.statusBarId);
}
}

0 comments on commit b81e6a3

Please sign in to comment.