Skip to content

Commit 49ef020

Browse files
committed
debug start view: debugStartLanguage context key
fixes microsoft#85548
1 parent 68a1013 commit 49ef020

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import * as objects from 'vs/base/common/objects';
1111
import { URI as uri } from 'vs/base/common/uri';
1212
import * as resources from 'vs/base/common/resources';
1313
import { IJSONSchema } from 'vs/base/common/jsonSchema';
14-
import * as editorCommon from 'vs/editor/common/editorCommon';
1514
import { ITextModel } from 'vs/editor/common/model';
1615
import { IEditor } from 'vs/workbench/common/editor';
1716
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
@@ -434,15 +433,8 @@ export class ConfigurationManager implements IConfigurationManager {
434433
return this.debuggers.filter(dbg => strings.equalsIgnoreCase(dbg.type, type)).pop();
435434
}
436435

437-
getDebuggerLabelsForEditor(editor: editorCommon.IEditor | undefined): string[] {
438-
if (isCodeEditor(editor)) {
439-
const model = editor.getModel();
440-
const language = model ? model.getLanguageIdentifier().language : undefined;
441-
442-
return this.debuggers.filter(a => language && a.languages && a.languages.indexOf(language) >= 0).map(d => d.label);
443-
}
444-
445-
return [];
436+
isDebuggerInterestedInLanguage(language: string): boolean {
437+
return this.debuggers.filter(a => language && a.languages && a.languages.indexOf(language) >= 0).length > 0;
446438
}
447439

448440
async guessDebugger(type?: string): Promise<Debugger | undefined> {

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
2121
import { WorkbenchStateContext } from 'vs/workbench/browser/contextkeys';
2222
import { OpenFolderAction, OpenFileAction, OpenFileFolderAction } from 'vs/workbench/browser/actions/workspaceActions';
2323
import { isMacintosh } from 'vs/base/common/platform';
24+
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
2425

25-
const CONTEXT_DEBUGGER_INTERESTED = new RawContextKey<boolean>('debuggerInterested', false);
26+
const CONTEXT_DEBUG_START_LANGUAGE = new RawContextKey<string>('debugStartLanguage', undefined);
27+
const CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR = new RawContextKey<boolean>('debuggerInterestedInActiveEditor', false);
2628

2729
export class StartView extends ViewPane {
2830

2931
static ID = 'workbench.debug.startView';
3032
static LABEL = localize('start', "Start");
3133

34+
private debugStartLanguageContext: IContextKey<string>;
3235
private debuggerInterestedContext: IContextKey<boolean>;
3336

3437
constructor(
@@ -46,11 +49,20 @@ export class StartView extends ViewPane {
4649
) {
4750
super({ ...(options as IViewPaneOptions), ariaHeaderLabel: localize('debugStart', "Debug Start Section") }, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService);
4851

49-
this.debuggerInterestedContext = CONTEXT_DEBUGGER_INTERESTED.bindTo(contextKeyService);
52+
this.debugStartLanguageContext = CONTEXT_DEBUG_START_LANGUAGE.bindTo(contextKeyService);
53+
this.debuggerInterestedContext = CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR.bindTo(contextKeyService);
5054
const setContextKey = () => {
51-
const activeEditor = this.editorService.activeTextEditorWidget;
52-
const debuggerLabels = this.debugService.getConfigurationManager().getDebuggerLabelsForEditor(activeEditor);
53-
this.debuggerInterestedContext.set(debuggerLabels.length > 0);
55+
const editor = this.editorService.activeTextEditorWidget;
56+
if (isCodeEditor(editor)) {
57+
const model = editor.getModel();
58+
const language = model ? model.getLanguageIdentifier().language : undefined;
59+
if (language && this.debugService.getConfigurationManager().isDebuggerInterestedInLanguage(language)) {
60+
this.debugStartLanguageContext.set(language);
61+
this.debuggerInterestedContext.set(true);
62+
return;
63+
}
64+
}
65+
this.debuggerInterestedContext.set(false);
5466
};
5567
this._register(editorService.onDidActiveEditorChange(setContextKey));
5668
this._register(this.debugService.getConfigurationManager().onDidRegisterDebugger(setContextKey));
@@ -64,7 +76,7 @@ export class StartView extends ViewPane {
6476
const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
6577
viewsRegistry.registerViewWelcomeContent(StartView.ID, {
6678
content: localize('openAFileWhichCanBeDebugged', "[Open a file](command:{0}) which can be debugged or run.", isMacintosh ? OpenFileFolderAction.ID : OpenFileAction.ID),
67-
when: CONTEXT_DEBUGGER_INTERESTED.toNegated()
79+
when: CONTEXT_DEBUGGER_INTERESTED_IN_ACTIVE_EDITOR
6880
});
6981

7082
viewsRegistry.registerViewWelcomeContent(StartView.ID, {

src/vs/workbench/contrib/debug/common/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ export interface IConfigurationManager {
647647

648648
activateDebuggers(activationEvent: string, debugType?: string): Promise<void>;
649649

650-
getDebuggerLabelsForEditor(editor: editorCommon.IEditor | undefined): string[];
650+
isDebuggerInterestedInLanguage(language: string): boolean;
651651
hasDebugConfigurationProvider(debugType: string): boolean;
652652

653653
registerDebugConfigurationProvider(debugConfigurationProvider: IDebugConfigurationProvider): IDisposable;

0 commit comments

Comments
 (0)