Skip to content

Add API proposal for reading files in data transfer#148596

Merged
mjbvz merged 7 commits into
mainfrom
dev/mjbvz/data-transfer-files
May 4, 2022
Merged

Add API proposal for reading files in data transfer#148596
mjbvz merged 7 commits into
mainfrom
dev/mjbvz/data-transfer-files

Conversation

@mjbvz

@mjbvz mjbvz commented May 2, 2022

Copy link
Copy Markdown
Contributor

Fixes #147481

Adds a new DataTransfer.asFile method which lets you get file objects from a DataTransfer. This is currently only hooked up for drop into editors.

A few follow ups:

  • Right now the file data is also read eagerly when it is transfered to the extension host. Before shipping this we would make this happen lazily instead

  • The drop into editor api does not provide a nice way to do anything with the dropped files.

    We should at least support returning a WorkspaceEdit. However WorkspaceEdit only supports text files, so we would also need to add an API that lets it deal with binary files

    See Support creating binary files in a WorkspaceEdit #148667

@mjbvz mjbvz added this to the May 2022 milestone May 2, 2022
@mjbvz
mjbvz requested review from alexr00 and jrieken May 2, 2022 22:56
@mjbvz mjbvz self-assigned this May 2, 2022
Comment on lines +10 to +26
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>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dom API returns a File with getAsFile(), so this makes sense to me. However, the dom API offers both a stream() and text() methods on File. Should we also have a stream() method to encourage extension authors not to read whole files into memory? Since the file will need to be transered cross process (or across the network in the case of remote), supporting files at all could be quite expensive and slow.

@mjbvz mjbvz May 4, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a change to make the file transfer lazy

However I did not yet add a way to read part of the file contents. Our existing fs apis also only allow working with whole files, so I wanted to stay consistent with them

I definitely think this is something we could add in the future to this api though

Matt Bierner added 2 commits May 3, 2022 15:07
Adds a new `DataTransfer.asFile` method which lets you get file objects from a `DataTransfer`. This is currently only hooked up for drop into editors.

A few follow ups:

- Right now the file data is also read eagerly when it is transfered to the extension host. Before shipping this we would make this happen lazily instead
- The drop into editor api does not provide a nice way to do anything with the dropped files.

    We should at least support returning a `WorkspaceEdit`. However `WorkspaceEdit` only supports text files, so we would also need to add an API that lets it deal with binary files
`asFile().data()` already returns a promise so `asFile` doesn't also need to be async
@mjbvz
mjbvz force-pushed the dev/mjbvz/data-transfer-files branch from 7ec6824 to 2ad751d Compare May 3, 2022 22:12

@mjbvz mjbvz left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexr00 I've tried hooking this up for tree views but need to test more. Right now we also don't allow extensions to add a file to the dataTransfer on drag


const replacementRange = new vscode.Range(position, position);

const files: Array<vscode.DataTransferFile> = [];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the PR is for testing purposes and should not be merged as is

@mjbvz mjbvz changed the title Add experimental support for reading files in data transfer Add API proposal for reading files in data transfer May 4, 2022
@mjbvz
mjbvz marked this pull request as ready for review May 4, 2022 17:53
Comment thread extensions/markdown-language-features/tsconfig.json
Comment thread src/vs/editor/common/dnd.ts
@mjbvz
mjbvz merged commit 93fd393 into main May 4, 2022
@mjbvz
mjbvz deleted the dev/mjbvz/data-transfer-files branch May 4, 2022 19:59
@mjbvz

mjbvz commented May 4, 2022

Copy link
Copy Markdown
Contributor Author

Merging. Will continue testing and polishing this iteration

@github-actions github-actions Bot locked and limited conversation to collaborators Jun 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support reading files in DataTransfer api

3 participants