Skip to content

Commit

Permalink
Finalize data file reading API (microsoft#152127)
Browse files Browse the repository at this point in the history
Fixes microsoft#147481
Also reverts microsoft#150963 since the `kind` field is not being finalized
  • Loading branch information
mjbvz authored Jun 15, 2022
1 parent d132489 commit 354e1a0
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 95 deletions.
1 change: 0 additions & 1 deletion extensions/markdown-language-features/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"src/**/*",
"../../src/vscode-dts/vscode.d.ts",
"../../src/vscode-dts/vscode.proposed.textEditorDrop.d.ts",
"../../src/vscode-dts/vscode.proposed.dataTransferFiles.d.ts",
"../../src/vscode-dts/vscode.proposed.documentPaste.d.ts"
]
}
5 changes: 2 additions & 3 deletions src/vs/workbench/api/browser/mainThreadTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ export class MainThreadTreeViews extends Disposable implements MainThreadTreeVie
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTreeViews);
}

async $registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: string[]; dragMimeTypes: string[]; hasHandleDrag: boolean; hasHandleDrop: boolean; supportsFileDataTransfers: boolean }): Promise<void> {
async $registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: string[]; dragMimeTypes: string[]; hasHandleDrag: boolean; hasHandleDrop: boolean }): Promise<void> {
this.logService.trace('MainThreadTreeViews#$registerTreeViewDataProvider', treeViewId, options);

this.extensionService.whenInstalledExtensionsRegistered().then(() => {
const dataProvider = new TreeViewDataProvider(treeViewId, this._proxy, this.notificationService);
this._dataProviders.set(treeViewId, dataProvider);
const dndController = (options.hasHandleDrag || options.hasHandleDrop)
? new TreeViewDragAndDropController(treeViewId, options.dropMimeTypes, options.dragMimeTypes, options.hasHandleDrag, options.supportsFileDataTransfers, this._proxy) : undefined;
? new TreeViewDragAndDropController(treeViewId, options.dropMimeTypes, options.dragMimeTypes, options.hasHandleDrag, this._proxy) : undefined;
const viewer = this.getTreeView(treeViewId);
if (viewer) {
// Order is important here. The internal tree isn't created until the dataProvider is set.
Expand Down Expand Up @@ -201,7 +201,6 @@ class TreeViewDragAndDropController implements ITreeViewDragAndDropController {
readonly dropMimeTypes: string[],
readonly dragMimeTypes: string[],
readonly hasWillDrop: boolean,
readonly supportsFileDataTransfers: boolean,
private readonly _proxy: ExtHostTreeViewsShape) { }

async handleDrop(dataTransfer: VSDataTransfer, targetTreeItem: ITreeItem | undefined, token: CancellationToken,
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
TextSearchCompleteMessageType: TextSearchCompleteMessageType,
DataTransfer: extHostTypes.DataTransfer,
DataTransferItem: extHostTypes.DataTransferItem,
DataTransferItemKind: extHostTypes.DataTransferItemKind,
CoveredCount: extHostTypes.CoveredCount,
FileCoverage: extHostTypes.FileCoverage,
StatementCoverage: extHostTypes.StatementCoverage,
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface MainThreadTextEditorsShape extends IDisposable {
}

export interface MainThreadTreeViewsShape extends IDisposable {
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: readonly string[]; dragMimeTypes: readonly string[]; hasHandleDrag: boolean; hasHandleDrop: boolean; supportsFileDataTransfers: boolean }): Promise<void>;
$registerTreeViewDataProvider(treeViewId: string, options: { showCollapseAll: boolean; canSelectMany: boolean; dropMimeTypes: readonly string[]; dragMimeTypes: readonly string[]; hasHandleDrag: boolean; hasHandleDrop: boolean }): Promise<void>;
$refresh(treeViewId: string, itemsToRefresh?: { [treeItemHandle: string]: ITreeItem }): Promise<void>;
$reveal(treeViewId: string, itemInfo: { item: ITreeItem; parentChain: ITreeItem[] } | undefined, options: IRevealOptions): Promise<void>;
$setMessage(treeViewId: string, message: string): void;
Expand Down
5 changes: 2 additions & 3 deletions src/vs/workbench/api/common/extHostTreeViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { IMarkdownString } from 'vs/base/common/htmlContent';
import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cancellation';
import { Command } from 'vs/editor/common/languages';
import { ITreeViewsService, TreeviewsService } from 'vs/workbench/services/views/common/treeViewsService';
import { checkProposedApiEnabled, isProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';

type TreeItemHandle = string;

Expand Down Expand Up @@ -92,8 +92,7 @@ export class ExtHostTreeViews implements ExtHostTreeViewsShape {
const dragMimeTypes = options.dragAndDropController?.dragMimeTypes ?? [];
const hasHandleDrag = !!options.dragAndDropController?.handleDrag;
const hasHandleDrop = !!options.dragAndDropController?.handleDrop;
const supportsFileDataTransfers = isProposedApiEnabled(extension, 'dataTransferFiles');
const registerPromise = this._proxy.$registerTreeViewDataProvider(viewId, { showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany, dropMimeTypes, dragMimeTypes, hasHandleDrag, hasHandleDrop, supportsFileDataTransfers });
const registerPromise = this._proxy.$registerTreeViewDataProvider(viewId, { showCollapseAll: !!options.showCollapseAll, canSelectMany: !!options.canSelectMany, dropMimeTypes, dragMimeTypes, hasHandleDrag, hasHandleDrop });
const treeView = this.createExtHostTreeView(viewId, options, extension);
return {
get onDidCollapseElement() { return treeView.onDidCollapseElement; },
Expand Down
2 changes: 0 additions & 2 deletions src/vs/workbench/api/common/extHostTypeConverters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1953,8 +1953,6 @@ export namespace DataTransferItem {
const file = item.fileData;
if (file) {
return new class extends types.DataTransferItem {
override get kind() { return types.DataTransferItemKind.File; }

override asFile(): vscode.DataTransferFile {
return {
name: file.name,
Expand Down
7 changes: 0 additions & 7 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2428,16 +2428,9 @@ export enum TreeItemCollapsibleState {
Expanded = 2
}

export enum DataTransferItemKind {
String = 1,
File = 2,
}

@es5ClassCompat
export class DataTransferItem {

get kind(): DataTransferItemKind { return DataTransferItemKind.String; }

async asString(): Promise<string> {
return typeof this.value === 'string' ? this.value : JSON.stringify(this.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ suite('MainThreadHostTreeView', function () {
}
drain(): any { return null; }
}, new TestViewsService(), new TestNotificationService(), testExtensionService, new NullLogService());
mainThreadTreeViews.$registerTreeViewDataProvider(testTreeViewId, { showCollapseAll: false, canSelectMany: false, dropMimeTypes: [], dragMimeTypes: [], hasHandleDrag: false, hasHandleDrop: false, supportsFileDataTransfers: false });
mainThreadTreeViews.$registerTreeViewDataProvider(testTreeViewId, { showCollapseAll: false, canSelectMany: false, dropMimeTypes: [], dragMimeTypes: [], hasHandleDrag: false, hasHandleDrop: false });
await testExtensionService.whenInstalledExtensionsRegistered();
});

Expand Down
4 changes: 1 addition & 3 deletions src/vs/workbench/browser/parts/views/treeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1528,9 +1528,7 @@ export class CustomTreeViewDragAndDrop implements ITreeDragAndDrop<ITreeItem> {
const file = dataItem.getAsFile();
if (file) {
uris.push(URI.file(file.path));
if (dndController.supportsFileDataTransfers) {
treeDataTransfer.append(type, createFileDataTransferItemFromFile(file));
}
treeDataTransfer.append(type, createFileDataTransferItemFromFile(file));
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/vs/workbench/common/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,6 @@ export interface ITreeViewDataProvider {
export interface ITreeViewDragAndDropController {
readonly dropMimeTypes: string[];
readonly dragMimeTypes: string[];
readonly supportsFileDataTransfers: boolean;
handleDrag(sourceTreeItemHandles: string[], operationUuid: string, token: CancellationToken): Promise<VSDataTransfer | undefined>;
handleDrop(elements: VSDataTransfer, target: ITreeItem | undefined, token: CancellationToken, operationUuid?: string, sourceTreeId?: string, sourceTreeItemHandles?: string[]): Promise<void>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const allApiProposals = Object.freeze({
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',
dataTransferFiles: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.dataTransferFiles.d.ts',
diffCommand: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.diffCommand.d.ts',
documentFiltersExclusive: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.documentFiltersExclusive.d.ts',
documentPaste: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.documentPaste.d.ts',
Expand Down
31 changes: 31 additions & 0 deletions src/vscode-dts/vscode.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10054,7 +10054,28 @@ declare module 'vscode' {
* `true` if the {@link TreeView tree view} is visible otherwise `false`.
*/
readonly visible: boolean;
}

/**
* A file associated with a {@linkcode DataTransferItem}.
*/
export interface DataTransferFile {
/**
* The name of the file.
*/
readonly name: string;

/**
* The full file path of the file.
*
* May be `undefined` on web.
*/
readonly uri?: Uri;

/**
* The full file contents of the file.
*/
data(): Thenable<Uint8Array>;
}

/**
Expand All @@ -10068,6 +10089,16 @@ declare module 'vscode' {
*/
asString(): Thenable<string>;

/**
* Try getting the {@link DataTransferFile file} associated with this data transfer item.
*
* Note that the file object is only valid for the scope of the drag and drop operation.
*
* @returns The file for the data transfer or `undefined` if the item is either not a file or the
* file data cannot be accessed.
*/
asFile(): DataTransferFile | undefined;

/**
* Custom data stored on this item.
*
Expand Down
71 changes: 0 additions & 71 deletions src/vscode-dts/vscode.proposed.dataTransferFiles.d.ts

This file was deleted.

0 comments on commit 354e1a0

Please sign in to comment.