Skip to content

Commit f04ef75

Browse files
committed
debug: register contributions only once debug adapter extension got registered
1 parent 8943ec4 commit f04ef75

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

src/vs/workbench/contrib/debug/browser/debug.contribution.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import { CallStackView } from 'vs/workbench/contrib/debug/browser/callStackView'
1717
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
1818
import {
1919
IDebugService, VIEWLET_ID, DEBUG_PANEL_ID, CONTEXT_IN_DEBUG_MODE, INTERNAL_CONSOLE_OPTIONS_SCHEMA,
20-
CONTEXT_DEBUG_STATE, VARIABLES_VIEW_ID, CALLSTACK_VIEW_ID, WATCH_VIEW_ID, BREAKPOINTS_VIEW_ID, LOADED_SCRIPTS_VIEW_ID, CONTEXT_LOADED_SCRIPTS_SUPPORTED, CONTEXT_FOCUSED_SESSION_IS_ATTACH, CONTEXT_STEP_BACK_SUPPORTED, CONTEXT_CALLSTACK_ITEM_TYPE, CONTEXT_RESTART_FRAME_SUPPORTED, CONTEXT_JUMP_TO_CURSOR_SUPPORTED, CONTEXT_DEBUG_UX, BREAKPOINT_EDITOR_CONTRIBUTION_ID, REPL_VIEW_ID, CONTEXT_BREAKPOINTS_EXIST,
20+
CONTEXT_DEBUG_STATE, VARIABLES_VIEW_ID, CALLSTACK_VIEW_ID, WATCH_VIEW_ID, BREAKPOINTS_VIEW_ID, LOADED_SCRIPTS_VIEW_ID, CONTEXT_LOADED_SCRIPTS_SUPPORTED, CONTEXT_FOCUSED_SESSION_IS_ATTACH, CONTEXT_STEP_BACK_SUPPORTED, CONTEXT_CALLSTACK_ITEM_TYPE, CONTEXT_RESTART_FRAME_SUPPORTED, CONTEXT_JUMP_TO_CURSOR_SUPPORTED, CONTEXT_DEBUG_UX, BREAKPOINT_EDITOR_CONTRIBUTION_ID, REPL_VIEW_ID, CONTEXT_BREAKPOINTS_EXIST, EDITOR_CONTRIBUTION_ID,
2121
} from 'vs/workbench/contrib/debug/common/debug';
2222
import { StartAction, AddFunctionBreakpointAction, ConfigureAction, DisableAllBreakpointsAction, EnableAllBreakpointsAction, RemoveAllBreakpointsAction, RunAction, ReapplyBreakpointsAction, SelectAndStartAction } from 'vs/workbench/contrib/debug/browser/debugActions';
2323
import { DebugToolBar } from 'vs/workbench/contrib/debug/browser/debugToolBar';
24-
import * as service from 'vs/workbench/contrib/debug/browser/debugService';
24+
import { DebugService } from 'vs/workbench/contrib/debug/browser/debugService';
2525
import { registerCommands, ADD_CONFIGURATION_ID, TOGGLE_INLINE_BREAKPOINT_ID, COPY_STACK_TRACE_ID, REVERSE_CONTINUE_ID, STEP_BACK_ID, RESTART_SESSION_ID, TERMINATE_THREAD_ID, STEP_OVER_ID, STEP_INTO_ID, STEP_OUT_ID, PAUSE_ID, DISCONNECT_ID, STOP_ID, RESTART_FRAME_ID, CONTINUE_ID, FOCUS_REPL_ID, JUMP_TO_CURSOR_ID, RESTART_LABEL, STEP_INTO_LABEL, STEP_OVER_LABEL, STEP_OUT_LABEL, PAUSE_LABEL, DISCONNECT_LABEL, STOP_LABEL, CONTINUE_LABEL } from 'vs/workbench/contrib/debug/browser/debugCommands';
2626
import { StatusBarColorProvider } from 'vs/workbench/contrib/debug/browser/statusbarColorProvider';
2727
import { IViewsRegistry, Extensions as ViewExtensions, IViewContainersRegistry, ViewContainerLocation, ViewContainer } from 'vs/workbench/common/views';
@@ -51,22 +51,27 @@ import { DebugProgressContribution } from 'vs/workbench/contrib/debug/browser/de
5151
import { DebugTitleContribution } from 'vs/workbench/contrib/debug/browser/debugTitle';
5252
import { Codicon } from 'vs/base/common/codicons';
5353
import { registerColors } from 'vs/workbench/contrib/debug/browser/debugColors';
54+
import { debugAdapterRegisteredEmitter } from 'vs/workbench/contrib/debug/browser/debugConfigurationManager';
55+
import { DebugEditorContribution } from 'vs/workbench/contrib/debug/browser/debugEditorContribution';
5456

5557
const registry = Registry.as<IWorkbenchActionRegistry>(WorkbenchActionRegistryExtensions.WorkbenchActions);
5658
// register service
57-
registerSingleton(IDebugService, service.DebugService, true);
59+
debugAdapterRegisteredEmitter.event(() => {
60+
// Register these contributions lazily only once a debug adapter extension has been registered
61+
registerWorkbenchContributions();
62+
registerColors();
63+
registerCommands();
64+
registerCommandsAndActions();
65+
registerDebugMenu();
66+
registerDebugPanel();
67+
registerEditorActions();
68+
});
69+
registerSingleton(IDebugService, DebugService, true);
5870
registerDebugView();
59-
60-
registerColors();
61-
registerCommands();
62-
registerCommandsAndActions();
63-
registerContributions();
64-
registerDebugMenu();
65-
registerDebugPanel();
6671
registerConfiguration();
67-
registerEditorActions();
72+
regsiterEditorContributions();
6873

69-
function registerContributions(): void {
74+
function registerWorkbenchContributions(): void {
7075
// Register Debug Workbench Contributions
7176
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DebugStatusContribution, LifecyclePhase.Eventually);
7277
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DebugProgressContribution, LifecyclePhase.Eventually);
@@ -77,10 +82,6 @@ function registerContributions(): void {
7782
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(DebugContentProvider, LifecyclePhase.Eventually);
7883
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(StatusBarColorProvider, LifecyclePhase.Eventually);
7984

80-
// Editor contributions
81-
registerEditorContribution('editor.contrib.callStack', CallStackEditorContribution);
82-
registerEditorContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID, BreakpointEditorContribution);
83-
8485
// Register Quick Access
8586
Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQuickAccessProvider({
8687
ctor: StartDebugQuickAccessProvider,
@@ -89,6 +90,13 @@ function registerContributions(): void {
8990
placeholder: nls.localize('startDebugPlaceholder', "Type the name of a launch configuration to run."),
9091
helpEntries: [{ description: nls.localize('startDebuggingHelp', "Start Debugging"), needsEditor: false }]
9192
});
93+
94+
}
95+
96+
function regsiterEditorContributions(): void {
97+
registerEditorContribution('editor.contrib.callStack', CallStackEditorContribution);
98+
registerEditorContribution(BREAKPOINT_EDITOR_CONTRIBUTION_ID, BreakpointEditorContribution);
99+
registerEditorContribution(EDITOR_CONTRIBUTION_ID, DebugEditorContribution);
92100
}
93101

94102
function registerCommandsAndActions(): void {

src/vs/workbench/contrib/debug/browser/debugConfigurationManager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const DEBUG_SELECTED_ROOT = 'debug.selectedroot';
4949

5050
interface IDynamicPickItem { label: string, launch: ILaunch, config: IConfig }
5151

52+
export const debugAdapterRegisteredEmitter = new Emitter<void>();
53+
5254
export class ConfigurationManager implements IConfigurationManager {
5355
private debuggers: Debugger[];
5456
private breakpointModeIdsSet = new Set<string>();
@@ -95,7 +97,12 @@ export class ConfigurationManager implements IConfigurationManager {
9597
// debuggers
9698

9799
registerDebugAdapterFactory(debugTypes: string[], debugAdapterLauncher: IDebugAdapterFactory): IDisposable {
100+
const firstTimeRegistration = debugTypes.length && this.debugAdapterFactories.size === 0;
98101
debugTypes.forEach(debugType => this.debugAdapterFactories.set(debugType, debugAdapterLauncher));
102+
if (firstTimeRegistration) {
103+
debugAdapterRegisteredEmitter.fire();
104+
}
105+
99106
return {
100107
dispose: () => {
101108
debugTypes.forEach(debugType => this.debugAdapterFactories.delete(debugType));

src/vs/workbench/contrib/debug/browser/debugEditorContribution.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import { IKeyboardEvent } from 'vs/base/browser/keyboardEvent';
1414
import { StandardTokenType } from 'vs/editor/common/modes';
1515
import { DEFAULT_WORD_REGEXP } from 'vs/editor/common/model/wordHelper';
1616
import { ICodeEditor, IEditorMouseEvent, MouseTargetType, IPartialEditorMouseEvent } from 'vs/editor/browser/editorBrowser';
17-
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
1817
import { IDecorationOptions } from 'vs/editor/common/editorCommon';
1918
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
2019
import { Range } from 'vs/editor/common/core/range';
2120
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2221
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2322
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2423
import { ICommandService } from 'vs/platform/commands/common/commands';
25-
import { IDebugEditorContribution, IDebugService, State, EDITOR_CONTRIBUTION_ID, IStackFrame, IDebugConfiguration, IExpression, IExceptionInfo, IDebugSession } from 'vs/workbench/contrib/debug/common/debug';
24+
import { IDebugEditorContribution, IDebugService, State, IStackFrame, IDebugConfiguration, IExpression, IExceptionInfo, IDebugSession } from 'vs/workbench/contrib/debug/common/debug';
2625
import { ExceptionWidget } from 'vs/workbench/contrib/debug/browser/exceptionWidget';
2726
import { FloatingClickWidget } from 'vs/workbench/browser/parts/editor/editorWidgets';
2827
import { Position } from 'vs/editor/common/core/position';
@@ -164,7 +163,7 @@ function getWordToLineNumbersMap(model: ITextModel | null): Map<string, number[]
164163
return result;
165164
}
166165

167-
class DebugEditorContribution implements IDebugEditorContribution {
166+
export class DebugEditorContribution implements IDebugEditorContribution {
168167

169168
private toDispose: IDisposable[];
170169
private hoverWidget: DebugHoverWidget;
@@ -545,5 +544,3 @@ class DebugEditorContribution implements IDebugEditorContribution {
545544
this.toDispose = dispose(this.toDispose);
546545
}
547546
}
548-
549-
registerEditorContribution(EDITOR_CONTRIBUTION_ID, DebugEditorContribution);

0 commit comments

Comments
 (0)