diff --git a/src/vs/workbench/contrib/debug/browser/debugAdapterManager.ts b/src/vs/workbench/contrib/debug/browser/debugAdapterManager.ts index 107d8bbcf4e3ee3c89b77b42b27b7914fdece275..d369f0ecd6d72bdf042a0cf10ee536b9529541ad 100644 --- a/src/vs/workbench/contrib/debug/browser/debugAdapterManager.ts +++ b/src/vs/workbench/contrib/debug/browser/debugAdapterManager.ts @@ -181,7 +181,7 @@ export class AdapterManager extends Disposable implements IAdapterManager { hasEnabledDebuggers(): boolean { for (let [type] of this.debugAdapterFactories) { const dbg = this.getDebugger(type); - if (dbg && this.isDebuggerEnabled(dbg)) { + if (dbg && dbg.enabled) { return true; } } @@ -270,24 +270,20 @@ export class AdapterManager extends Disposable implements IAdapterManager { return this.breakpointModeIdsSet.has(languageId); } - isDebuggerEnabled(dbg: Debugger): boolean { - return !dbg.when || this.contextKeyService.contextMatchesRules(dbg.when); - } - getDebugger(type: string): Debugger | undefined { return this.debuggers.find(dbg => strings.equalsIgnoreCase(dbg.type, type)); } isDebuggerInterestedInLanguage(language: string): boolean { return !!this.debuggers - .filter(d => this.isDebuggerEnabled(d)) + .filter(d => d.enabled) .find(a => language && a.languages && a.languages.indexOf(language) >= 0); } async guessDebugger(gettingConfigurations: boolean, type?: string): Promise { if (type) { const adapter = this.getDebugger(type); - return adapter && this.isDebuggerEnabled(adapter) ? adapter : undefined; + return adapter && adapter.enabled ? adapter : undefined; } const activeTextEditorControl = this.editorService.activeTextEditorControl; @@ -301,7 +297,7 @@ export class AdapterManager extends Disposable implements IAdapterManager { languageLabel = this.modeService.getLanguageName(language); } const adapters = this.debuggers - .filter(a => this.isDebuggerEnabled(a)) + .filter(a => a.enabled) .filter(a => language && a.languages && a.languages.indexOf(language) >= 0); if (adapters.length === 1) { return adapters[0]; @@ -316,7 +312,7 @@ export class AdapterManager extends Disposable implements IAdapterManager { if ((!languageLabel || gettingConfigurations || (model && this.canSetBreakpointsIn(model))) && candidates.length === 0) { await this.activateDebuggers('onDebugInitialConfigurations'); candidates = this.debuggers - .filter(a => this.isDebuggerEnabled(a)) + .filter(a => a.enabled) .filter(dbg => dbg.hasInitialConfiguration() || dbg.hasConfigurationProvider()); } diff --git a/src/vs/workbench/contrib/debug/browser/debugService.ts b/src/vs/workbench/contrib/debug/browser/debugService.ts index 6874ae92fc345bef40d7d2a47d498f28bf068406..8fb5e4762053c9abc39a2f790b05f4a3e1939be6 100644 --- a/src/vs/workbench/contrib/debug/browser/debugService.ts +++ b/src/vs/workbench/contrib/debug/browser/debugService.ts @@ -36,7 +36,7 @@ import { DEBUG_CONFIGURE_COMMAND_ID, DEBUG_CONFIGURE_LABEL } from 'vs/workbench/ import { ConfigurationManager } from 'vs/workbench/contrib/debug/browser/debugConfigurationManager'; import { DebugSession } from 'vs/workbench/contrib/debug/browser/debugSession'; import { DebugTaskRunner, TaskRunResult } from 'vs/workbench/contrib/debug/browser/debugTaskRunner'; -import { CALLSTACK_VIEW_ID, CONTEXT_BREAKPOINTS_EXIST, CONTEXT_DEBUG_STATE, CONTEXT_DEBUG_TYPE, CONTEXT_DEBUG_UX, CONTEXT_DISASSEMBLY_VIEW_FOCUS, CONTEXT_IN_DEBUG_MODE, getStateLabel, IAdapterManager, IBreakpoint, IBreakpointData, ICompound, IConfig, IConfigurationManager, IDebugConfiguration, IDebugModel, IDebugService, IDebugSession, IDebugSessionOptions, IEnablement, IExceptionBreakpoint, IGlobalConfig, ILaunch, IStackFrame, IThread, IViewModel, REPL_VIEW_ID, State, VIEWLET_ID } from 'vs/workbench/contrib/debug/common/debug'; +import { CALLSTACK_VIEW_ID, CONTEXT_BREAKPOINTS_EXIST, CONTEXT_DEBUG_STATE, CONTEXT_DEBUG_TYPE, CONTEXT_DEBUG_UX, CONTEXT_DISASSEMBLY_VIEW_FOCUS, CONTEXT_IN_DEBUG_MODE, debuggerDisabledMessage, getStateLabel, IAdapterManager, IBreakpoint, IBreakpointData, ICompound, IConfig, IConfigurationManager, IDebugConfiguration, IDebugModel, IDebugService, IDebugSession, IDebugSessionOptions, IEnablement, IExceptionBreakpoint, IGlobalConfig, ILaunch, IStackFrame, IThread, IViewModel, REPL_VIEW_ID, State, VIEWLET_ID } from 'vs/workbench/contrib/debug/common/debug'; import { DebugCompoundRoot } from 'vs/workbench/contrib/debug/common/debugCompoundRoot'; import { Debugger } from 'vs/workbench/contrib/debug/common/debugger'; import { Breakpoint, DataBreakpoint, DebugModel, FunctionBreakpoint, InstructionBreakpoint } from 'vs/workbench/contrib/debug/common/debugModel'; @@ -492,9 +492,8 @@ export class DebugService implements IDebugService { return false; } - if (!this.adapterManager.isDebuggerEnabled(dbg)) { - const message = nls.localize('debuggerDisabled', "Configured debug type '{0}' is installed but not supported in this environment.", dbg.type); - await this.showError(message, []); + if (!dbg.enabled) { + await this.showError(debuggerDisabledMessage(dbg.type), []); return false; } diff --git a/src/vs/workbench/contrib/debug/common/debug.ts b/src/vs/workbench/contrib/debug/common/debug.ts index eb56984946ac113af3fa8b56175dedba58e7385a..a03e911132939c3be772dcc2bd3df2d7dfe7ab6b 100644 --- a/src/vs/workbench/contrib/debug/common/debug.ts +++ b/src/vs/workbench/contrib/debug/common/debug.ts @@ -88,6 +88,8 @@ export const CONTEXT_DISASSEMBLY_VIEW_FOCUS = new RawContextKey('disass export const CONTEXT_LANGUAGE_SUPPORTS_DISASSEMBLE_REQUEST = new RawContextKey('languageSupportsDisassembleRequest', false, { type: 'boolean', description: nls.localize('languageSupportsDisassembleRequest', "True when the language in the current editor supports disassemble request.") }); export const CONTEXT_FOCUSED_STACK_FRAME_HAS_INSTRUCTION_POINTER_REFERENCE = new RawContextKey('focusedStackFrameHasInstructionReference', false, { type: 'boolean', description: nls.localize('focusedStackFrameHasInstructionReference', "True when the focused stack frame has instruction pointer reference.") }); +export const debuggerDisabledMessage = (debugType: string) => nls.localize('debuggerDisabled', "Configured debug type '{0}' is installed but not supported in this environment.", debugType); + export const EDITOR_CONTRIBUTION_ID = 'editor.contrib.debug'; export const BREAKPOINT_EDITOR_CONTRIBUTION_ID = 'editor.contrib.breakpoint'; export const DEBUG_SCHEME = 'debug'; diff --git a/src/vs/workbench/contrib/debug/common/debugger.ts b/src/vs/workbench/contrib/debug/common/debugger.ts index b775ae8320dad932e148d25fb7f96927c1fcf911..5bf7c732a38cd23c410c18919e6d8f23af1869d4 100644 --- a/src/vs/workbench/contrib/debug/common/debugger.ts +++ b/src/vs/workbench/contrib/debug/common/debugger.ts @@ -7,7 +7,7 @@ import * as nls from 'vs/nls'; import { isObject } from 'vs/base/common/types'; import { IJSONSchema, IJSONSchemaMap, IJSONSchemaSnippet } from 'vs/base/common/jsonSchema'; import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace'; -import { IConfig, IDebuggerContribution, IDebugAdapter, IDebugger, IDebugSession, IAdapterManager, IDebugService } from 'vs/workbench/contrib/debug/common/debug'; +import { IConfig, IDebuggerContribution, IDebugAdapter, IDebugger, IDebugSession, IAdapterManager, IDebugService, debuggerDisabledMessage } from 'vs/workbench/contrib/debug/common/debug'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationResolverService } from 'vs/workbench/services/configurationResolver/common/configurationResolver'; import * as ConfigurationResolverUtils from 'vs/workbench/services/configurationResolver/common/configurationResolverUtils'; @@ -19,7 +19,7 @@ import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' import { ITelemetryEndpoint } from 'vs/platform/telemetry/common/telemetry'; import { cleanRemoteAuthority } from 'vs/platform/telemetry/common/telemetryUtils'; import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; -import { ContextKeyExpr, ContextKeyExpression } from 'vs/platform/contextkey/common/contextkey'; +import { ContextKeyExpr, ContextKeyExpression, IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; export class Debugger implements IDebugger { @@ -37,7 +37,8 @@ export class Debugger implements IDebugger { @ITextResourcePropertiesService private readonly resourcePropertiesService: ITextResourcePropertiesService, @IConfigurationResolverService private readonly configurationResolverService: IConfigurationResolverService, @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService, - @IDebugService private readonly debugService: IDebugService + @IDebugService private readonly debugService: IDebugService, + @IContextKeyService private readonly contextKeyService: IContextKeyService, ) { this.debuggerContribution = { type: dbgContribution.type }; this.merge(dbgContribution, extensionDescription); @@ -142,6 +143,10 @@ export class Debugger implements IDebugger { return this.debuggerWhen; } + get enabled() { + return !this.debuggerWhen || this.contextKeyService.contextMatchesRules(this.debuggerWhen); + } + hasInitialConfiguration(): boolean { return !!this.debuggerContribution.initialConfigurations; } @@ -221,6 +226,7 @@ export class Debugger implements IDebugger { enum: [this.type], description: nls.localize('debugType', "Type of configuration."), pattern: '^(?!node2)', + deprecationMessage: this.enabled ? undefined : debuggerDisabledMessage(this.type), errorMessage: nls.localize('debugTypeNotRecognised', "The debug type is not recognized. Make sure that you have a corresponding debug extension installed and that it is enabled."), patternErrorMessage: nls.localize('node2NotSupported', "\"node2\" is no longer supported, use \"node\" instead and set the \"protocol\" attribute to \"inspector\".") }; diff --git a/src/vs/workbench/contrib/debug/test/node/debugger.test.ts b/src/vs/workbench/contrib/debug/test/node/debugger.test.ts index fb93786d406a6486acf4b6eca3f34122c3ee5fd3..a42e4d128d958b584b2c4cd938412cd0335ec1e0 100644 --- a/src/vs/workbench/contrib/debug/test/node/debugger.test.ts +++ b/src/vs/workbench/contrib/debug/test/node/debugger.test.ts @@ -132,7 +132,7 @@ suite('Debug - Debugger', () => { const testResourcePropertiesService = new TestTextResourcePropertiesService(configurationService); setup(() => { - _debugger = new Debugger(adapterManager, debuggerContribution, extensionDescriptor0, configurationService, testResourcePropertiesService, undefined!, undefined!, undefined!); + _debugger = new Debugger(adapterManager, debuggerContribution, extensionDescriptor0, configurationService, testResourcePropertiesService, undefined!, undefined!, undefined!, undefined!); }); teardown(() => {