Skip to content

Commit

Permalink
checkProposedApiEnabled and isProposedApiEnabled must be called w…
Browse files Browse the repository at this point in the history
…ith proposal name, add proposals for `package.json`-based API, microsoft/vscode#131165
  • Loading branch information
jrieken committed Nov 12, 2021
1 parent 23f7918 commit e79a9c8
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/viewsExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class ViewsExtensionHandler implements IWorkbenchContribution {
return;
}

if (entry.key === 'remote' && !isProposedApiEnabled(extension.description, undefined)) {
if (entry.key === 'remote' && !isProposedApiEnabled(extension.description, 'contribViewsRemote')) {
collector.warn(localize('ViewContainerRequiresProposedAPI', "View container '{0}' requires 'enableProposedApi' turned on to be added to 'Remote'.", entry.key));
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return <Thenable<any>>extHostMessageService.showMessage(extension, Severity.Error, message, rest[0], <Array<string | vscode.MessageItem>>rest.slice(1));
},
showQuickPick(items: any, options?: vscode.QuickPickOptions, token?: vscode.CancellationToken): any {
return extHostQuickOpen.showQuickPick(items, isProposedApiEnabled(extension, undefined), options, token);
return extHostQuickOpen.showQuickPick(items, options, token);
},
showWorkspaceFolderPick(options?: vscode.WorkspaceFolderPickOptions) {
return extHostQuickOpen.showWorkspaceFolderPick(options);
Expand Down Expand Up @@ -689,7 +689,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostUrls.registerUriHandler(extension.identifier, handler);
},
createQuickPick<T extends vscode.QuickPickItem>(): vscode.QuickPick<T> {
return extHostQuickOpen.createQuickPick(extension.identifier, isProposedApiEnabled(extension, undefined));
return extHostQuickOpen.createQuickPick(extension.identifier);
},
createInputBox(): vscode.InputBox {
return extHostQuickOpen.createInputBox(extension.identifier);
Expand Down
20 changes: 10 additions & 10 deletions src/vs/workbench/api/common/extHostQuickOpen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import { ThemeIcon as ThemeIconUtils } from 'vs/platform/theme/common/themeServi
export type Item = string | QuickPickItem;

export interface ExtHostQuickOpen {
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, enableProposedApi: boolean, options: QuickPickOptions & { canPickMany: true; }, token?: CancellationToken): Promise<QuickPickItem[] | undefined>;
showQuickPick(itemsOrItemsPromise: string[] | Promise<string[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<string | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<QuickPickItem | undefined>;
showQuickPick(itemsOrItemsPromise: Item[] | Promise<Item[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<Item | Item[] | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, options: QuickPickOptions & { canPickMany: true; }, token?: CancellationToken): Promise<QuickPickItem[] | undefined>;
showQuickPick(itemsOrItemsPromise: string[] | Promise<string[]>, options?: QuickPickOptions, token?: CancellationToken): Promise<string | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, options?: QuickPickOptions, token?: CancellationToken): Promise<QuickPickItem | undefined>;
showQuickPick(itemsOrItemsPromise: Item[] | Promise<Item[]>, options?: QuickPickOptions, token?: CancellationToken): Promise<Item | Item[] | undefined>;

showInput(options?: InputBoxOptions, token?: CancellationToken): Promise<string | undefined>;

showWorkspaceFolderPick(options?: WorkspaceFolderPickOptions, token?: CancellationToken): Promise<WorkspaceFolder | undefined>

createQuickPick<T extends QuickPickItem>(extensionId: ExtensionIdentifier, enableProposedApi: boolean): QuickPick<T>;
createQuickPick<T extends QuickPickItem>(extensionId: ExtensionIdentifier): QuickPick<T>;

createInputBox(extensionId: ExtensionIdentifier): InputBox;
}
Expand All @@ -56,10 +56,10 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx
this._commands = commands;
}

showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, enableProposedApi: boolean, options: QuickPickOptions & { canPickMany: true; }, token?: CancellationToken): Promise<QuickPickItem[] | undefined>;
showQuickPick(itemsOrItemsPromise: string[] | Promise<string[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<string | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, enableProposedApi: boolean, options?: QuickPickOptions, token?: CancellationToken): Promise<QuickPickItem | undefined>;
showQuickPick(itemsOrItemsPromise: Item[] | Promise<Item[]>, enableProposedApi: boolean, options?: QuickPickOptions, token: CancellationToken = CancellationToken.None): Promise<Item | Item[] | undefined> {
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, options: QuickPickOptions & { canPickMany: true; }, token?: CancellationToken): Promise<QuickPickItem[] | undefined>;
showQuickPick(itemsOrItemsPromise: string[] | Promise<string[]>, options?: QuickPickOptions, token?: CancellationToken): Promise<string | undefined>;
showQuickPick(itemsOrItemsPromise: QuickPickItem[] | Promise<QuickPickItem[]>, options?: QuickPickOptions, token?: CancellationToken): Promise<QuickPickItem | undefined>;
showQuickPick(itemsOrItemsPromise: Item[] | Promise<Item[]>, options?: QuickPickOptions, token: CancellationToken = CancellationToken.None): Promise<Item | Item[] | undefined> {

// clear state from last invocation
this._onDidSelectItem = undefined;
Expand Down Expand Up @@ -192,7 +192,7 @@ export function createExtHostQuickOpen(mainContext: IMainContext, workspace: IEx

// ---- QuickInput

createQuickPick<T extends QuickPickItem>(extensionId: ExtensionIdentifier, enableProposedApi: boolean): QuickPick<T> {
createQuickPick<T extends QuickPickItem>(extensionId: ExtensionIdentifier): QuickPick<T> {
const session: ExtHostQuickPick<T> = new ExtHostQuickPick(extensionId, () => this._sessions.delete(session._id));
this._sessions.set(session._id, session);
return session;
Expand Down
35 changes: 10 additions & 25 deletions src/vs/workbench/api/common/menusExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { Iterable } from 'vs/base/common/iterator';
import { index } from 'vs/base/common/arrays';
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { ApiProposalName } from 'vs/workbench/services/extensions/common/extensionsApiProposals';

interface IAPIMenu {
readonly key: string;
readonly id: MenuId;
readonly description: string;
readonly proposed?: boolean; // defaults to false
readonly proposed?: ApiProposalName;
readonly supportsSubmenus?: boolean; // defaults to true
readonly deprecationMessage?: string;
}

const apiMenus: IAPIMenu[] = [
Expand Down Expand Up @@ -85,17 +85,11 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.DebugToolBar,
description: localize('menus.debugToolBar', "The debug toolbar menu")
},
{
key: 'menuBar/file',
id: MenuId.MenubarFileMenu,
description: localize('menus.file', "The top level file menu"),
proposed: true
},
{
key: 'menuBar/home',
id: MenuId.MenubarHomeMenu,
description: localize('menus.home', "The home indicator context menu (web only)"),
proposed: true,
proposed: 'contribMenuBarHome',
supportsSubmenus: false
},
{
Expand Down Expand Up @@ -133,14 +127,6 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.SCMChangeContext,
description: localize('menus.changeTitle', "The Source Control inline change menu")
},
{
key: 'statusBar/windowIndicator',
id: MenuId.StatusBarWindowIndicatorMenu,
description: localize('menus.statusBarWindowIndicator', "The window indicator menu in the status bar"),
proposed: true,
supportsSubmenus: false,
deprecationMessage: localize('menus.statusBarWindowIndicator.deprecated', "Use menu 'statusBar/remoteIndicator' instead."),
},
{
key: 'statusBar/remoteIndicator',
id: MenuId.StatusBarRemoteIndicatorMenu,
Expand Down Expand Up @@ -198,19 +184,19 @@ const apiMenus: IAPIMenu[] = [
key: 'notebook/cell/executePrimary',
id: MenuId.NotebookCellExecutePrimary,
description: localize('notebook.cell.executePrimary', "The contributed primary notebook cell execution button"),
proposed: true
proposed: 'notebookEditor'
},
{
key: 'interactive/toolbar',
id: MenuId.InteractiveToolbar,
description: localize('interactive.toolbar', "The contributed interactive toolbar menu"),
proposed: true
proposed: 'notebookEditor'
},
{
key: 'interactive/cell/title',
id: MenuId.InteractiveCellTitle,
description: localize('interactive.cell.title', "The contributed interactive cell title menu"),
proposed: true
proposed: 'notebookEditor'
},
{
key: 'testing/item/context',
Expand Down Expand Up @@ -263,7 +249,7 @@ const apiMenus: IAPIMenu[] = [
id: MenuId.InlineCompletionsActions,
description: localize('inlineCompletions.actions', "The actions shown when hovering on an inline completion"),
supportsSubmenus: false,
proposed: true
proposed: 'inlineCompletions'
},
];

Expand Down Expand Up @@ -451,8 +437,7 @@ namespace schema {
description: localize('vscode.extension.contributes.menus', "Contributes menu items to the editor"),
type: 'object',
properties: index(apiMenus, menu => menu.key, menu => ({
description: menu.proposed ? `(${localize('proposed', "Proposed API")}) ${menu.description}` : menu.description,
deprecationMessage: menu.deprecationMessage,
markdownDescription: menu.proposed ? localize('proposed', "Proposed API, requires `enabledApiProposal: [\"{0}\"]` - {1}", menu.proposed, menu.description) : menu.description,
type: 'array',
items: menu.supportsSubmenus === false ? menuItem : { oneOf: [menuItem, submenuItem] }
})),
Expand Down Expand Up @@ -634,7 +619,7 @@ commandsExtensionPoint.setHandler(extensions => {
title,
source: extension.description.displayName ?? extension.description.name,
shortTitle,
tooltip: isProposedApiEnabled(extension.description, undefined) ? title : undefined,
tooltip: title,
category,
precondition: ContextKeyExpr.deserialize(enablement),
icon: absoluteIcon
Expand Down Expand Up @@ -764,7 +749,7 @@ menusExtensionPoint.setHandler(extensions => {
return;
}

if (menu.proposed && !isProposedApiEnabled(extension.description, undefined)) {
if (menu.proposed && !isProposedApiEnabled(extension.description, menu.proposed)) {
collector.error(localize('proposedAPI.invalid', "{0} is a proposed menu identifier and is only available when running out of dev or with the following command line switch: --enable-proposed-api {1}", entry.key, extension.description.identifier.value));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/remote/browser/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ export class RemoteViewPaneContainer extends FilterViewPaneContainer implements
}

private _handleRemoteInfoExtensionPoint(extension: IExtensionPointUser<HelpInformation>, helpInformation: HelpInformation[]) {
if (!isProposedApiEnabled(extension.description, undefined)) {
if (!isProposedApiEnabled(extension.description, 'contribRemoteHelp')) {
return;
}

Expand Down
7 changes: 2 additions & 5 deletions src/vs/workbench/services/extensions/common/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,14 @@ export interface IExtensionHost {
dispose(): void;
}

export function isProposedApiEnabled(extension: IExtensionDescription, proposal: ApiProposalName | undefined): boolean {
if (!proposal) {
return Boolean(extension.enableProposedApi);
}
export function isProposedApiEnabled(extension: IExtensionDescription, proposal: ApiProposalName): boolean {
if (extension.enabledApiProposals?.includes(proposal)) {
return true;
}
return Boolean(extension.enableProposedApi);
}

export function checkProposedApiEnabled(extension: IExtensionDescription, proposal: ApiProposalName | undefined): void {
export function checkProposedApiEnabled(extension: IExtensionDescription, proposal: ApiProposalName): void {
if (!isProposedApiEnabled(extension, proposal)) {
throw new Error(`[${extension.identifier.value}]: Proposed API is only available when running out of dev or with the following command line switch: --enable-proposed-api ${extension.identifier.value}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

export const allApiProposals = Object.freeze({
authSession: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.authSession.d.ts',
contribIconFonts: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribIconFonts.d.ts',
contribIcons: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribIcons.d.ts',
contribLabelFormatterWorkspaceTooltip: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribLabelFormatterWorkspaceTooltip.d.ts',
contribMenuBarHome: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribMenuBarHome.d.ts',
contribRemoteHelp: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribRemoteHelp.d.ts',
contribViewsRemote: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribViewsRemote.d.ts',
contribViewsWelcome: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribViewsWelcome.d.ts',
customEditorMove: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.customEditorMove.d.ts',
diffCommand: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.diffCommand.d.ts',
Expand Down
4 changes: 0 additions & 4 deletions src/vs/workbench/services/extensions/node/proxyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { URI } from 'vs/base/common/uri';
import { ILogService } from 'vs/platform/log/common/log';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { LogLevel, createHttpPatch, ProxyResolveEvent, createProxyResolver, createTlsPatch, ProxySupportSetting } from 'vscode-proxy-agent';
import { isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';

export function connectProxyResolver(
extHostWorkspace: IExtHostWorkspaceProvider,
Expand Down Expand Up @@ -130,9 +129,6 @@ function configureModuleLoading(extensionService: ExtHostExtensionService, looku
}
if (!cache[request]) {
let mod = modules.default;
if (ext && isProposedApiEnabled(ext, undefined)) {
mod = (modules as any)[(<any>ext).proxySupport] || modules.onRequest;
}
cache[request] = <any>{ ...mod }; // Copy to work around #93167.
}
return cache[request];
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/services/label/common/labelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ResourceLabelFormattersHandler implements IWorkbenchContribution {
constructor(@ILabelService labelService: ILabelService) {
resourceLabelFormattersExtPoint.setHandler((extensions, delta) => {
delta.added.forEach(added => added.value.forEach(formatter => {
if (!isProposedApiEnabled(added.description, undefined) && formatter.formatting.workspaceTooltip) {
if (!isProposedApiEnabled(added.description, 'contribLabelFormatterWorkspaceTooltip') && formatter.formatting.workspaceTooltip) {
// workspaceTooltip is only proposed
formatter.formatting.workspaceTooltip = undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/services/themes/common/iconExtensionPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class IconExtensionPoint {
const extensionValue = <IIconExtensionPoint[]>extension.value;
const collector = extension.collector;

if (!isProposedApiEnabled(extension.description, undefined)) {
if (!isProposedApiEnabled(extension.description, 'contribIcons')) {
collector.error(nls.localize('invalid.icons.proposedAPI', "'configuration.icons is a proposed contribution point and only available when running out of dev or with the following command line switch: --enable-proposed-api {0}", extension.description.identifier.value));
return;
}
Expand Down Expand Up @@ -180,7 +180,7 @@ export class IconFontExtensionPoint {
const extensionValue = <IIconFontExtensionPoint[]>extension.value;
const collector = extension.collector;

if (!isProposedApiEnabled(extension.description, undefined)) {
if (!isProposedApiEnabled(extension.description, 'contribIconFonts')) {
collector.error(nls.localize('invalid.iconFonts.proposedAPI', "'configuration.iconFonts is a proposed contribution point and only available when running out of dev or with the following command line switch: --enable-proposed-api {0}", extension.description.identifier.value));
return;
}
Expand Down
6 changes: 6 additions & 0 deletions src/vscode-dts/vscode.proposed.contribIconFonts.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `iconFonts`-contribution point
6 changes: 6 additions & 0 deletions src/vscode-dts/vscode.proposed.contribIcons.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `icons`-contribution point
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `workspaceTooltip`-property of the `resourceLabelFormatters` contribution poain
6 changes: 6 additions & 0 deletions src/vscode-dts/vscode.proposed.contribMenuBarHome.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `menuBar/home` menu
6 changes: 6 additions & 0 deletions src/vscode-dts/vscode.proposed.contribRemoteHelp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `remoteHelp`-contribution point
6 changes: 6 additions & 0 deletions src/vscode-dts/vscode.proposed.contribViewsRemote.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty placeholder declaration for the `remote`-property of the `views`-contribution
2 changes: 1 addition & 1 deletion src/vscode-dts/vscode.proposed.contribViewsWelcome.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// empty place holder declaration for the `viewsWelcome`-contribution point
// empty placeholder declaration for the `viewsWelcome`-contribution point

0 comments on commit e79a9c8

Please sign in to comment.