Skip to content

Commit

Permalink
Use QuickInput (#29096)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Aug 10, 2018
1 parent 15b5eb4 commit 4fa87eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { IDebugConfigurationProvider, ICompound, IDebugConfiguration, IConfig, IGlobalConfig, IConfigurationManager, ILaunch, IAdapterExecutable, IDebugAdapterProvider, IDebugAdapter, ITerminalSettings, ITerminalLauncher } from 'vs/workbench/parts/debug/common/debug';
import { Debugger } from 'vs/workbench/parts/debug/node/debugger';
import { IEditorService, ACTIVE_GROUP, SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
import { IQuickOpenService } from 'vs/platform/quickOpen/common/quickOpen';
import { isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration';
import { IPreferencesService } from 'vs/workbench/services/preferences/common/preferences';
import { TerminalLauncher } from 'vs/workbench/parts/debug/electron-browser/terminalSupport';
import { Registry } from 'vs/platform/registry/common/platform';
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import { launchSchema, debuggersExtPoint, breakpointsExtPoint } from 'vs/workbench/parts/debug/common/debugSchemas';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';

const jsonRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
jsonRegistry.registerSchema(launchSchemaId, launchSchema);
Expand All @@ -57,7 +57,7 @@ export class ConfigurationManager implements IConfigurationManager {
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEditorService private editorService: IEditorService,
@IConfigurationService private configurationService: IConfigurationService,
@IQuickOpenService private quickOpenService: IQuickOpenService,
@IQuickInputService private quickInputService: IQuickInputService,
@IInstantiationService private instantiationService: IInstantiationService,
@ICommandService private commandService: ICommandService,
@IStorageService private storageService: IStorageService,
Expand Down Expand Up @@ -347,10 +347,11 @@ export class ConfigurationManager implements IConfigurationManager {
}

candidates = candidates.sort((first, second) => first.label.localeCompare(second.label));
return this.quickOpenService.pick([...candidates, { label: 'More...', separator: { border: true } }], { placeHolder: nls.localize('selectDebug', "Select Environment") })
const picks = candidates.map(c => ({ label: c.label, debugger: c }));
return this.quickInputService.pick<(typeof picks)[0]>([...picks, { type: 'separator', border: true }, { label: 'More...', debugger: undefined }], { placeHolder: nls.localize('selectDebug', "Select Environment") })
.then(picked => {
if (picked instanceof Debugger) {
return picked;
if (picked.debugger) {
return picked.debugger;
}
if (picked) {
this.commandService.executeCommand('debug.installAdditionalDebuggers');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { writeFile, exists } from 'vs/base/node/pfs';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IQuickOpenService, IPickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { join, basename, dirname, extname } from 'path';
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
Expand All @@ -18,6 +17,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
import URI from 'vs/base/common/uri';
import { ISnippetsService } from 'vs/workbench/parts/snippets/electron-browser/snippets.contribution';
import { values } from 'vs/base/common/map';
import { IQuickPickItem, IQuickInputService, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';

const id = 'workbench.action.openSnippets';

Expand All @@ -27,7 +27,7 @@ namespace ISnippetPick {
}
}

interface ISnippetPick extends IPickOpenEntry {
interface ISnippetPick extends IQuickPickItem {
filepath: string;
hint?: true;
}
Expand Down Expand Up @@ -179,22 +179,23 @@ async function createLanguageSnippetFile(pick: ISnippetPick) {
CommandsRegistry.registerCommand(id, async accessor => {

const snippetService = accessor.get(ISnippetsService);
const quickOpenService = accessor.get(IQuickOpenService);
const quickInputService = accessor.get(IQuickInputService);
const opener = accessor.get(IOpenerService);
const windowService = accessor.get(IWindowService);
const modeService = accessor.get(IModeService);
const envService = accessor.get(IEnvironmentService);

const { existing, future } = await computePicks(snippetService, envService, modeService);
const newGlobalPick = <IPickOpenEntry>{ label: nls.localize('new.global', "New Global Snippets file...") };
const picks = await computePicks(snippetService, envService, modeService);
const existing: QuickPickInput[] = picks.existing;
const newGlobalPick = <IQuickPickItem>{ label: nls.localize('new.global', "New Global Snippets file...") };
if (existing.length > 0) {
existing[0].separator = { label: nls.localize('group.global', "Existing Snippets") };
newGlobalPick.separator = { border: true, label: nls.localize('new.global.sep', "New Snippets") };
existing.unshift({ type: 'separator', label: nls.localize('group.global', "Existing Snippets") });
existing.push({ type: 'separator', border: true, label: nls.localize('new.global.sep', "New Snippets") });
} else {
newGlobalPick.separator = { label: nls.localize('new.global.sep', "New Snippets") };
existing.push({ type: 'separator', label: nls.localize('new.global.sep', "New Snippets") });
}

const pick = await quickOpenService.pick(<(IPickOpenEntry | ISnippetPick)[]>[].concat(existing, newGlobalPick, future), {
const pick = await quickInputService.pick(<(IQuickPickItem | ISnippetPick)[]>[].concat(existing, newGlobalPick, picks.future), {
placeHolder: nls.localize('openSnippet.pickLanguage', "Select Snippets File or Create Snippets"),
matchOnDescription: true
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import * as nls from 'vs/nls';
import { TPromise } from 'vs/base/common/winjs.base';
import { registerEditorAction, ServicesAccessor, EditorAction } from 'vs/editor/browser/editorExtensions';
import { IQuickOpenService, IPickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen';
import { IModeService } from 'vs/editor/common/services/modeService';
import { LanguageId } from 'vs/editor/common/modes';
import { ICommandService, CommandsRegistry } from 'vs/platform/commands/common/commands';
Expand All @@ -16,8 +15,9 @@ import { SnippetController2 } from 'vs/editor/contrib/snippet/snippetController2
import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { Snippet } from 'vs/workbench/parts/snippets/electron-browser/snippetsFile';
import { IQuickPickItem, IQuickInputService, QuickPickInput } from 'vs/platform/quickinput/common/quickInput';

interface ISnippetPick extends IPickOpenEntry {
interface ISnippetPick extends IQuickPickItem {
snippet: Snippet;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ class InsertSnippetAction extends EditorAction {
return undefined;
}

const quickOpenService = accessor.get(IQuickOpenService);
const quickInputService = accessor.get(IQuickInputService);
const { lineNumber, column } = editor.getPosition();
let { snippet, name, langId } = Args.fromUser(arg);

Expand Down Expand Up @@ -116,7 +116,7 @@ class InsertSnippetAction extends EditorAction {
} else {
// let user pick a snippet
const snippets = (await snippetService.getSnippets(languageId)).sort(Snippet.compare);
const picks: ISnippetPick[] = [];
const picks: QuickPickInput<ISnippetPick>[] = [];
let prevSnippet: Snippet;
for (const snippet of snippets) {
const pick: ISnippetPick = {
Expand All @@ -125,14 +125,14 @@ class InsertSnippetAction extends EditorAction {
snippet
};
if (!snippet.isFromExtension && !prevSnippet) {
pick.separator = { label: nls.localize('sep.userSnippet', "User Snippets") };
picks.push({ type: 'separator', label: nls.localize('sep.userSnippet', "User Snippets") });
} else if (snippet.isFromExtension && (!prevSnippet || !prevSnippet.isFromExtension)) {
pick.separator = { label: nls.localize('sep.extSnippet', "Extension Snippets") };
picks.push({ type: 'separator', label: nls.localize('sep.extSnippet', "Extension Snippets") });
}
picks.push(pick);
prevSnippet = snippet;
}
return quickOpenService.pick(picks, { matchOnDetail: true }).then(pick => resolve(pick && pick.snippet), reject);
return quickInputService.pick(picks, { matchOnDetail: true }).then(pick => resolve(pick && pick.snippet), reject);
}
}).then(snippet => {
if (snippet) {
Expand Down

0 comments on commit 4fa87eb

Please sign in to comment.