提交 b8b1b243 编写于 作者: B Benjamin Pasero

quick access - debug picker

上级 b0791e52
......@@ -16,12 +16,12 @@ import { withNullAsUndefined } from 'vs/base/common/types';
import { AbstractEditorQuickAccessProvider } from 'vs/editor/contrib/quickAccess/quickAccess';
import { IPosition } from 'vs/editor/common/core/position';
export const GOTO_LINE_PREFIX = ':';
interface IGotoLineQuickPickItem extends IQuickPickItem, Partial<IPosition> { }
export abstract class AbstractGotoLineQuickAccessProvider extends AbstractEditorQuickAccessProvider {
static PREFIX = ':';
provide(picker: IQuickPick<IGotoLineQuickPickItem>, token: CancellationToken): IDisposable {
const disposables = new DisposableStore();
......@@ -88,7 +88,7 @@ export abstract class AbstractGotoLineQuickAccessProvider extends AbstractEditor
// React to picker changes
const updatePickerAndEditor = () => {
const position = this.parsePosition(editor, picker.value.trim().substr(GOTO_LINE_PREFIX.length));
const position = this.parsePosition(editor, picker.value.trim().substr(AbstractGotoLineQuickAccessProvider.PREFIX.length));
const label = this.getPickLabel(editor, position.lineNumber, position.column);
// Picker
......
......@@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AbstractGotoLineQuickAccessProvider, GOTO_LINE_PREFIX } from 'vs/editor/contrib/quickAccess/gotoLine';
import { AbstractGotoLineQuickAccessProvider } from 'vs/editor/contrib/quickAccess/gotoLine';
import { Registry } from 'vs/platform/registry/common/platform';
import { IQuickAccessRegistry, Extensions } from 'vs/platform/quickinput/common/quickAccess';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
......@@ -26,6 +26,6 @@ export class StandaloneGotoLineQuickAccessProvider extends AbstractGotoLineQuick
Registry.as<IQuickAccessRegistry>(Extensions.Quickaccess).registerQuickAccessProvider({
ctor: StandaloneGotoLineQuickAccessProvider,
prefix: GOTO_LINE_PREFIX,
prefix: AbstractGotoLineQuickAccessProvider.PREFIX,
helpEntries: [{ description: GoToLineNLS.gotoLineActionLabel, needsEditor: true }]
});
......@@ -16,6 +16,8 @@ interface IHelpQuickAccessPickItem extends IQuickPickItem {
export class HelpQuickAccessProvider implements IQuickAccessProvider {
static PREFIX = '?';
private readonly registry = Registry.as<IQuickAccessRegistry>(Extensions.Quickaccess);
constructor(@IQuickInputService private readonly quickInputService: IQuickInputService) { }
......
......@@ -8,7 +8,7 @@ import { IKeyMods } from 'vs/platform/quickinput/common/quickInput';
import { IEditor } from 'vs/editor/common/editorCommon';
import { IEditorService, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IRange } from 'vs/editor/common/core/range';
import { AbstractGotoLineQuickAccessProvider, GOTO_LINE_PREFIX } from 'vs/editor/contrib/quickAccess/gotoLine';
import { AbstractGotoLineQuickAccessProvider } from 'vs/editor/contrib/quickAccess/gotoLine';
import { Registry } from 'vs/platform/registry/common/platform';
import { IQuickAccessRegistry, Extensions } from 'vs/platform/quickinput/common/quickAccess';
......@@ -40,7 +40,7 @@ export class GotoLineQuickAccessProvider extends AbstractGotoLineQuickAccessProv
Registry.as<IQuickAccessRegistry>(Extensions.Quickaccess).registerQuickAccessProvider({
ctor: GotoLineQuickAccessProvider,
prefix: GOTO_LINE_PREFIX,
prefix: AbstractGotoLineQuickAccessProvider.PREFIX,
placeholder: localize('gotoLineQuickAccessPlaceholder', "Type the line number and optional column to go to (e.g. 42:5 for line 42 and column 5)."),
helpEntries: [{ description: localize('gotoLineQuickAccess', "Go to Line"), needsEditor: true }]
});
......@@ -52,6 +52,8 @@ import { CallStackEditorContribution } from 'vs/workbench/contrib/debug/browser/
import { BreakpointEditorContribution } from 'vs/workbench/contrib/debug/browser/breakpointEditorContribution';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
import { IQuickAccessRegistry, Extensions as QuickAccessExtensions } from 'vs/platform/quickinput/common/quickAccess';
import { StartDebugQuickAccessProvider } from 'vs/workbench/contrib/debug/browser/debugQuickAccess';
class OpenDebugViewletAction extends ShowViewletAction {
public static readonly ID = VIEWLET_ID;
......@@ -173,6 +175,14 @@ registerDebugCommandPaletteItem(TOGGLE_INLINE_BREAKPOINT_ID, nls.localize('inlin
)
);
// Register Quick Access
Registry.as<IQuickAccessRegistry>(QuickAccessExtensions.Quickaccess).registerQuickAccessProvider({
ctor: StartDebugQuickAccessProvider,
prefix: StartDebugQuickAccessProvider.PREFIX,
placeholder: nls.localize('startDebugPlaceholder', "Type the name of a launch configuration to run."),
helpEntries: [{ description: nls.localize('startDebugHelp', "Start Debug Configurations"), needsEditor: false }]
});
// register service
registerSingleton(IDebugService, service.DebugService);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IQuickPick, IQuickPickItem, IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput';
import { IQuickAccessProvider } from 'vs/platform/quickinput/common/quickAccess';
import { CancellationToken } from 'vs/base/common/cancellation';
import { localize } from 'vs/nls';
import { DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IDebugService } from 'vs/workbench/contrib/debug/common/debug';
import { IWorkspaceContextService, WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { matchesFuzzy } from 'vs/base/common/filters';
import { StartAction } from 'vs/workbench/contrib/debug/browser/debugActions';
import { withNullAsUndefined } from 'vs/base/common/types';
interface IDebugQuickPickItem extends IQuickPickItem {
run: () => Promise<unknown>;
}
export class StartDebugQuickAccessProvider implements IQuickAccessProvider {
static PREFIX = 'debug ';
constructor(
@IDebugService private readonly debugService: IDebugService,
@IWorkspaceContextService private readonly contextService: IWorkspaceContextService,
@ICommandService private readonly commandService: ICommandService,
@INotificationService private readonly notificationService: INotificationService
) { }
provide(picker: IQuickPick<IDebugQuickPickItem>, token: CancellationToken): IDisposable {
const disposables = new DisposableStore();
// Disable filtering & sorting, we control the results
picker.matchOnLabel = picker.matchOnDescription = picker.matchOnDetail = picker.sortByLabel = false;
// Add all view items & filter on type
const updatePickerItems = () => picker.items = this.getDebugPickItems(picker.value.trim().substr(StartDebugQuickAccessProvider.PREFIX.length));
disposables.add(picker.onDidChangeValue(() => updatePickerItems()));
updatePickerItems();
// Open extensions view on accept
disposables.add(picker.onDidAccept(() => {
const [item] = picker.selectedItems;
if (item) {
picker.hide();
item.run();
}
}));
return disposables;
}
private getDebugPickItems(value: string): Array<IDebugQuickPickItem | IQuickPickSeparator> {
const picks: Array<IDebugQuickPickItem | IQuickPickSeparator> = [];
const configManager = this.debugService.getConfigurationManager();
// Entries: configs
let lastGroup: string | undefined;
for (let config of configManager.getAllConfigurations()) {
const highlights = matchesFuzzy(value, config.name, true);
if (highlights) {
// Separator
if (lastGroup !== config.presentation?.group) {
picks.push({ type: 'separator' });
lastGroup = config.presentation?.group;
}
// Launch entry
picks.push({
label: config.name,
ariaLabel: localize('entryAriaLabel', "{0}, debug", config.name),
description: this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? config.launch.name : '',
highlights: { label: highlights },
run: async () => {
if (StartAction.isEnabled(this.debugService)) {
this.debugService.getConfigurationManager().selectConfiguration(config.launch, config.name);
try {
await this.debugService.startDebugging(config.launch);
} catch (error) {
this.notificationService.error(error);
}
}
}
});
}
}
// Entries: launches
const visibleLaunches = configManager.getLaunches().filter(launch => !launch.hidden);
// Separator
if (visibleLaunches.length > 0) {
picks.push({ type: 'separator' });
}
for (const launch of visibleLaunches) {
const label = this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ?
localize("addConfigTo", "Add Config ({0})...", launch.name) :
localize('addConfiguration', "Add Configuration...");
// Add Config entry
picks.push({
label,
ariaLabel: localize('entryAriaLabel', "{0}, debug", label),
description: this.contextService.getWorkbenchState() === WorkbenchState.WORKSPACE ? launch.name : '',
highlights: { label: withNullAsUndefined(matchesFuzzy(value, label, true)) },
run: async () => this.commandService.executeCommand('debug.addConfiguration', launch.uri.toString())
});
}
return picks;
}
}
......@@ -181,4 +181,3 @@ async function openExtensionsViewlet(viewletService: IViewletService, search = '
view?.search(search);
view?.focus();
}
......@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
import { IQuickAccessRegistry, Extensions } from 'vs/platform/quickinput/common/quickAccess';
import { Registry } from 'vs/platform/registry/common/platform';
import { HelpQuickAccessProvider } from 'vs/platform/quickinput/browser/helpQuickAccess';
import { ViewQuickAccessProvider, VIEW_QUICK_ACCESS_PREFIX } from 'vs/workbench/contrib/quickaccess/browser/viewQuickAccess';
import { ViewQuickAccessProvider } from 'vs/workbench/contrib/quickaccess/browser/viewQuickAccess';
import { QUICK_ACCESS_COMMAND_ID } from 'vs/workbench/contrib/quickaccess/browser/quickAccessCommands';
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
......@@ -16,20 +16,20 @@ const registry = Registry.as<IQuickAccessRegistry>(Extensions.Quickaccess);
registry.defaultProvider = {
ctor: HelpQuickAccessProvider,
prefix: '',
placeholder: localize('helpQuickAccessPlaceholder', "Type '?' to get help on the actions you can take from here."),
placeholder: localize('defaultAccessPlaceholder', "Type the name of a file to open."),
helpEntries: [{ description: localize('gotoFileQuickAccess', "Go to File"), needsEditor: false }]
};
registry.registerQuickAccessProvider({
ctor: HelpQuickAccessProvider,
prefix: '?',
placeholder: localize('helpQuickAccessPlaceholder', "Type '?' to get help on the actions you can take from here."),
prefix: HelpQuickAccessProvider.PREFIX,
placeholder: localize('helpQuickAccessPlaceholder', "Type '{0}' to get help on the actions you can take from here.", HelpQuickAccessProvider.PREFIX),
helpEntries: [{ description: localize('helpQuickAccess', "Show all Quick Access Providers"), needsEditor: false }]
});
registry.registerQuickAccessProvider({
ctor: ViewQuickAccessProvider,
prefix: VIEW_QUICK_ACCESS_PREFIX,
prefix: ViewQuickAccessProvider.PREFIX,
placeholder: localize('viewQuickAccessPlaceholder', "Type the name of a view, output channel or terminal to open."),
helpEntries: [{ description: localize('viewQuickAccess', "Open View"), needsEditor: false }]
});
......
......@@ -20,8 +20,6 @@ import { matchesFuzzy } from 'vs/base/common/filters';
import { fuzzyContains } from 'vs/base/common/strings';
import { withNullAsUndefined } from 'vs/base/common/types';
export const VIEW_QUICK_ACCESS_PREFIX = 'view ';
interface IViewQuickPickItem extends IQuickPickItem {
containerLabel: string;
run: () => Promise<unknown>;
......@@ -29,6 +27,8 @@ interface IViewQuickPickItem extends IQuickPickItem {
export class ViewQuickAccessProvider implements IQuickAccessProvider {
static PREFIX = 'view ';
constructor(
@IViewletService private readonly viewletService: IViewletService,
@IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService,
......@@ -47,7 +47,7 @@ export class ViewQuickAccessProvider implements IQuickAccessProvider {
picker.matchOnLabel = picker.matchOnDescription = picker.matchOnDetail = picker.sortByLabel = false;
// Add all view items & filter on type
const updatePickerItems = () => picker.items = this.getViewPickItems(picker.value.trim().substr(VIEW_QUICK_ACCESS_PREFIX.length));
const updatePickerItems = () => picker.items = this.getViewPickItems(picker.value.trim().substr(ViewQuickAccessProvider.PREFIX.length));
disposables.add(picker.onDidChangeValue(() => updatePickerItems()));
updatePickerItems();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册