Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable it to open multiple files #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class OpenController implements vscode.Disposable {
constructor() {

const subscriptions: vscode.Disposable[] = [];
const disposable = vscode.commands.registerCommand('workbench.action.files.openFileWithDefaultApplication', (uri: vscode.Uri | undefined) => {
this.open(uri);
const disposable = vscode.commands.registerCommand('workbench.action.files.openFileWithDefaultApplication', (uri: vscode.Uri | undefined, uris: vscode.Uri[] | undefined) => {
this.open(uri, uris);
});
subscriptions.push(disposable);

Expand Down Expand Up @@ -48,7 +48,16 @@ class OpenController implements vscode.Disposable {
this._disposable.dispose();
}

private open(uri: vscode.Uri | undefined): void {
private open(uri: vscode.Uri | undefined, uris: vscode.Uri[] | undefined): void {
Copy link
Owner

Choose a reason for hiding this comment

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

You should look at combining these parameters into one

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for reviewing.

Do you mean removing uri parameter and use only uris parameter like as below

  this.open(uris);
  ---
  private open(uris: vscode.Uri[] | undefined): void {

or combining two parameters into one as tuple like as below.

  this.open(uri, uris);
  ---
  private open(uriArgs: [vscode.Uri | undefined, vscode.Uri[] | undefined]): void {

If the former, it might be good but I am still not sure callback function always has uris parameter when it has uri parameter. Because it's not described clearly in reference.
What I found is only this as below.

Note 1: When a command is invoked from a (context) menu, VS Code tries to infer the currently selected resource and passes that as a parameter when invoking the command. For instance, a menu item inside the Explorer is passed the URI of the selected resource and a menu item inside an editor is passed the URI of the document.
vscode api reference

If the latter, I don't understand why.

If the other, could you explain me more detail.

Copy link
Author

Choose a reason for hiding this comment

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

I found a case, when selecting folder, uri argument has a value, but uris argument is undefined.
so that we need both of uri and uris parameter in my opinion.

if (uris && uris.some((uri) => uri?.scheme)) {
uris
.filter((uri) => uri?.scheme)
.forEach((uri) => {
console.log("Opening from uris", uri.toString());
this.openFile(uri.toString());
});
return;
}

if (uri?.scheme) {
console.log("Opening from uri", uri.toString());
Expand Down