Skip to content

Adopt vscode.diff and vscode.open for tree commands - #2334

Merged
Alex Ross (alexr00) merged 2 commits into
masterfrom
alexr00/issue2333
Jan 7, 2021
Merged

Adopt vscode.diff and vscode.open for tree commands#2334
Alex Ross (alexr00) merged 2 commits into
masterfrom
alexr00/issue2333

Conversation

@alexr00

Copy link
Copy Markdown
Member

Start with the GitFileChangeNode
Part of #2333

Start with the GitFileChangeNode
Part of #2333
@alexr00

Copy link
Copy Markdown
Member Author

Rachel Macfarlane (@RMacfarlane) I just picked a place to start. I figured it would be easier if we just to one or two uses of vscode.diff or vscode.open at a time.

@RMacfarlane

Copy link
Copy Markdown
Contributor

I'm a bit confused about these changes overall, previously the commands for the tree items eventually called vscode.diff or vscode.open, does using them directly as the commands change the UI? Or is the goal to simplify the open commands?

@alexr00

Copy link
Copy Markdown
Member Author

Yes, using vscode.diff and vscode.open directly now let the tree handle the commands in the same way they are handled from th explorer and SCM view. For example alt+click will open to the side. Full context is in this issue, with the decided on solution starting aproximately with this comment: microsoft/vscode#85636 (comment)

@alexr00

Copy link
Copy Markdown
Member Author

Even after approval, I won't merge this change until insiders is updated, since it requires changes in the core to add the TreeItem's command to the properties resolved by resolveTreeItem.

Comment thread src/view/treeNodes/fileChangeNode.ts Outdated

async openDiff(folderManager: FolderRepositoryManager): Promise<void> {
const command = await this.openDiffCommand(folderManager);
vscode.commands.executeCommand(command.command, command.arguments);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need to spread the arguments here with ...command.arguments!, otherwise it seems like vscode interprets the whole array as the first argument

}

/**
* File change node whose content can not be resolved locally and we direct users to GitHub.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is an existing issue, but the RemoteFileChangeNode also uses pr.openDiffView as its command but doesn't have a openDiff method

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

package-lock.json on auchenberg/pullrequest-demo#105 is an example. It's a big file, on github.com when you view the file changes it shows a "Load diff" button instead of the file content. At first for these types of changes we just showed a notification asking if you wanted to view it on GitHub, but I believe I made changes to the content provider to go make the additional call for this case. So I think just making the same vscode.diff call would work?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think just making the same vscode.diff call would work. Not sure how that command handles large files.

Comment thread src/view/treeNodes/fileChangeNode.ts Outdated
}

async resolve(): Promise<void> {
console.log('resolving');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

extra console :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

😳

}
}

async resolveTreeItem?(item: vscode.TreeItem, element: TreeNode): Promise<vscode.TreeItem> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

didn't know about this API, cool!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

actually, how often is this called? I'm assuming just once, and then the command would get filled in then? I'm wondering if we will need to refresh the tree or something if the user changes the openDiffOnClick setting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's new! Good catch, yes, we should refresh the tree if that setting is changed.

Comment thread src/commands.ts Outdated
return vscode.commands.executeCommand('review.openFile', value);
}
const command = value instanceof GitFileChangeNode ? value.openFileCommand() : openFileCommand(value);
vscode.commands.executeCommand(command.title, command.arguments);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

typo here, should be command.command, and also ... on arguments

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for catching!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants