Skip to content

Commit

Permalink
Alexr00/showLocalAPI (microsoft#173798)
Browse files Browse the repository at this point in the history
* Propose "allowLocal" open dialog option API
Part of microsoft#131138

* Update comment

* allowUIResources API proposal
Part of microsoft#131138

* Fix scheme ordering and update doc comment
  • Loading branch information
alexr00 authored Feb 9, 2023
1 parent 7f48e7c commit 89c4f61
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .eslintplugin/vscode-dts-interface-naming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TSESTree } from '@typescript-eslint/experimental-utils';

export = new class ApiInterfaceNaming implements eslint.Rule.RuleModule {

private static _nameRegExp = /I[A-Z]/;
private static _nameRegExp = /^I[A-Z]/;

readonly meta: eslint.Rule.RuleMetaData = {
messages: {
Expand Down
3 changes: 2 additions & 1 deletion src/vs/workbench/api/browser/mainThreadDialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { URI } from 'vs/base/common/uri';
import { MainThreadDiaglogsShape, MainContext, MainThreadDialogOpenOptions, MainThreadDialogSaveOptions } from '../common/extHost.protocol';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { IFileDialogService, IOpenDialogOptions, ISaveDialogOptions } from 'vs/platform/dialogs/common/dialogs';
import { Schemas } from 'vs/base/common/network';

@extHostNamedCustomer(MainContext.MainThreadDialogs)
export class MainThreadDialogs implements MainThreadDiaglogsShape {
Expand Down Expand Up @@ -46,7 +47,7 @@ export class MainThreadDialogs implements MainThreadDiaglogsShape {
canSelectMany: options?.canSelectMany,
defaultUri: options?.defaultUri ? URI.revive(options.defaultUri) : undefined,
title: options?.title || undefined,
availableFileSystems: []
availableFileSystems: options?.allowUIResources ? [Schemas.vscodeRemote, Schemas.file] : []
};
if (options?.filters) {
result.filters = [];
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
return extHostQuickOpen.showInput(options, token);
},
showOpenDialog(options) {
return extHostDialogs.showOpenDialog(options);
return extHostDialogs.showOpenDialog(extension, options);
},
showSaveDialog(options) {
return extHostDialogs.showSaveDialog(options);
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface MainThreadDialogOpenOptions {
canSelectMany?: boolean;
filters?: { [name: string]: string[] };
title?: string;
allowUIResources?: boolean;
}

export interface MainThreadDialogSaveOptions {
Expand Down
7 changes: 6 additions & 1 deletion src/vs/workbench/api/common/extHostDialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import type * as vscode from 'vscode';
import { URI } from 'vs/base/common/uri';
import { MainContext, MainThreadDiaglogsShape, IMainContext } from 'vs/workbench/api/common/extHost.protocol';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { IRelaxedExtensionDescription } from 'vs/platform/extensions/common/extensions';

export class ExtHostDialogs {

Expand All @@ -15,7 +17,10 @@ export class ExtHostDialogs {
this._proxy = mainContext.getProxy(MainContext.MainThreadDialogs);
}

showOpenDialog(options?: vscode.OpenDialogOptions): Promise<URI[] | undefined> {
showOpenDialog(extension: IRelaxedExtensionDescription, options?: vscode.OpenDialogOptions): Promise<URI[] | undefined> {
if (options?.allowUIResources) {
checkProposedApiEnabled(extension, 'showLocal');
}
return this._proxy.$showOpenDialog(options).then(filepaths => {
return filepaths ? filepaths.map(p => URI.revive(p)) : undefined;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const allApiProposals = Object.freeze({
scmActionButton: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmActionButton.d.ts',
scmSelectedProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmSelectedProvider.d.ts',
scmValidation: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.scmValidation.d.ts',
showLocal: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.showLocal.d.ts',
tabInputTextMerge: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.tabInputTextMerge.d.ts',
taskPresentationGroup: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.taskPresentationGroup.d.ts',
telemetry: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.telemetry.d.ts',
Expand Down
19 changes: 19 additions & 0 deletions src/vscode-dts/vscode.proposed.showLocal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// https://github.com/microsoft/vscode/issues/131138

declare module 'vscode' {

export interface OpenDialogOptions {
/**
* Controls whether the dialog allows users to select local files via the "Show Local" button.
* Extensions that set this to `true` should check the scheme of the selected file.
* Resources with the `file` scheme come from the same extension host as the extension.
* Resources with the `vscode-local` scheme come from an extension host running in the same place as the UI.
*/
allowUIResources?: boolean;
}
}

0 comments on commit 89c4f61

Please sign in to comment.