From 5967c85e673d23cc2b069845ba718ced0ff2b66d Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 16 Feb 2021 02:00:36 -0500 Subject: [PATCH] Closes #1378 - remote cmds to statusbar/code lens --- CHANGELOG.md | 2 + package.json | 46 +++++++++----- src/codelens/codeLensProvider.ts | 73 +++++++++++++++++++++- src/config.ts | 8 +++ src/statusbar/statusBarController.ts | 25 ++++++-- src/webviews/apps/settings/partials/code-lens.html | 32 ++++++++-- .../apps/settings/partials/status-bar.html | 16 ++++- 7 files changed, 172 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27bb016..2f0ee44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ### Added - Adds a new _Open Blame Prior to Change_ command (`gitlens.openBlamePriorToChange`) to open the blame of prior revision of the selected line in the current file — closes [#1014](https://github.com/eamodio/vscode-gitlens/issues/1014) +- Adds new Git code lens action options, _Opens the commit on the remote service (when available)_, _Copies the remote commit url to the clipboard (when available)_, _Opens the file revision on the remote service (when available)_, and _Copies the remote file revision url to the clipboard (when available)_ +- Adds new status bar blame action options, _Opens the commit on the remote service (when available)_, _Copies the remote commit url to the clipboard (when available)_, _Opens the file revision on the remote service (when available)_, and _Copies the remote file revision url to the clipboard (when available)_ — closes [#1378](https://github.com/eamodio/vscode-gitlens/issues/1378) ### Changed diff --git a/package.json b/package.json index 1ba5ce2..2316422 100644 --- a/package.json +++ b/package.json @@ -399,17 +399,25 @@ "gitlens.showQuickCommitDetails", "gitlens.showQuickCommitFileDetails", "gitlens.showQuickFileHistory", - "gitlens.showQuickRepoHistory" + "gitlens.showQuickRepoHistory", + "gitlens.openCommitOnRemote", + "gitlens.copyRemoteCommitUrl", + "gitlens.openFileOnRemote", + "gitlens.copyRemoteFileUrl" ], "enumDescriptions": [ - "Toggles file blame annotations", + "Toggles file blame", "Compares the current committed file with the previous commit", "Reveals the commit in the Side Bar", "Searches for commits within the range", - "Shows a commit details quick pick", - "Shows a commit file details quick pick", - "Shows a file history quick pick", - "Shows a branch history quick pick" + "Shows a commit details quick pick menu", + "Shows a commit file details quick pick menu", + "Shows a file history quick pick menu", + "Shows a branch history quick pick menu", + "Opens the commit on the remote service (when available)", + "Copies the remote commit url to the clipboard (when available)", + "Opens the file revision on the remote service (when available)", + "Copies the remote file url to the clipboard (when available)" ] } ], @@ -455,7 +463,7 @@ "gitlens.showQuickRepoHistory" ], "enumDescriptions": [ - "Toggles file blame annotations", + "Toggles file blame", "Compares the current committed file with the previous commit", "Reveals the commit in the Side Bar", "Searches for the commit", @@ -1600,27 +1608,35 @@ "default": "gitlens.showQuickCommitDetails", "enum": [ "gitlens.toggleFileBlame", + "gitlens.toggleCodeLens", "gitlens.diffWithPrevious", "gitlens.diffWithWorking", - "gitlens.toggleCodeLens", "gitlens.revealCommitInView", "gitlens.showCommitsInView", "gitlens.showQuickCommitDetails", "gitlens.showQuickCommitFileDetails", "gitlens.showQuickFileHistory", - "gitlens.showQuickRepoHistory" + "gitlens.showQuickRepoHistory", + "gitlens.openCommitOnRemote", + "gitlens.copyRemoteCommitUrl", + "gitlens.openFileOnRemote", + "gitlens.copyRemoteFileUrl" ], "enumDescriptions": [ - "Toggles file blame annotations", + "Toggles file blame", + "Toggles Git code lens", "Compares the current line commit with the previous", "Compares the current line commit with the working tree", - "Toggles Git code lens", "Reveals the commit in the Side Bar", "Searches for the commit", - "Shows a commit details quick pick", - "Shows a commit file details quick pick", - "Shows a file history quick pick", - "Shows a branch history quick pick" + "Shows a commit details quick pick menu", + "Shows a commit file details quick pick menu", + "Shows a file history quick pick menu", + "Shows a branch history quick pick menu", + "Opens the commit on the remote service (when available)", + "Copies the remote commit url to the clipboard (when available)", + "Opens the file revision on the remote service (when available)", + "Copies the remote file url to the clipboard (when available)" ], "markdownDescription": "Specifies the command to be executed when the blame status bar item is clicked", "scope": "window" diff --git a/src/codelens/codeLensProvider.ts b/src/codelens/codeLensProvider.ts index 2661243..7148978 100644 --- a/src/codelens/codeLensProvider.ts +++ b/src/codelens/codeLensProvider.ts @@ -34,7 +34,7 @@ import { } from '../configuration'; import { BuiltInCommands, DocumentSchemes } from '../constants'; import { Container } from '../container'; -import { GitBlame, GitBlameLines, GitCommit } from '../git/git'; +import { GitBlame, GitBlameLines, GitCommit, RemoteResourceType } from '../git/git'; import { GitService } from '../git/gitService'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; @@ -521,8 +521,26 @@ export class GitCodeLensProvider implements CodeLensProvider { } switch (lens.desiredCommand) { + case CodeLensCommand.CopyRemoteCommitUrl: + return this.applyCopyOrOpenCommitOnRemoteCommand( + title, + lens, + recentCommit, + true, + ); + case CodeLensCommand.CopyRemoteFileUrl: + return this.applyCopyOrOpenFileOnRemoteCommand( + title, + lens, + recentCommit, + true, + ); case CodeLensCommand.DiffWithPrevious: return this.applyDiffWithPreviousCommand(title, lens, recentCommit); + case CodeLensCommand.OpenCommitOnRemote: + return this.applyCopyOrOpenCommitOnRemoteCommand(title, lens, recentCommit); + case CodeLensCommand.OpenFileOnRemote: + return this.applyCopyOrOpenFileOnRemoteCommand(title, lens, recentCommit); case CodeLensCommand.RevealCommitInView: return this.applyRevealCommitInViewCommand(title, lens, recentCommit); case CodeLensCommand.ShowCommitsInView: @@ -572,8 +590,16 @@ export class GitCodeLensProvider implements CodeLensProvider { Iterables.find(blame.commits.values(), c => c.author === author) ?? Iterables.first(blame.commits.values()); switch (lens.desiredCommand) { + case CodeLensCommand.CopyRemoteCommitUrl: + return this.applyCopyOrOpenCommitOnRemoteCommand(title, lens, commit, true); + case CodeLensCommand.CopyRemoteFileUrl: + return this.applyCopyOrOpenFileOnRemoteCommand(title, lens, commit, true); case CodeLensCommand.DiffWithPrevious: return this.applyDiffWithPreviousCommand(title, lens, commit); + case CodeLensCommand.OpenCommitOnRemote: + return this.applyCopyOrOpenCommitOnRemoteCommand(title, lens, commit); + case CodeLensCommand.OpenFileOnRemote: + return this.applyCopyOrOpenFileOnRemoteCommand(title, lens, commit); case CodeLensCommand.RevealCommitInView: return this.applyRevealCommitInViewCommand(title, lens, commit); case CodeLensCommand.ShowCommitsInView: @@ -610,6 +636,51 @@ export class GitCodeLensProvider implements CodeLensProvider { return lens; } + private applyCopyOrOpenCommitOnRemoteCommand( + title: string, + lens: T, + commit: GitCommit, + clipboard: boolean = false, + ): T { + const commandArgs: OpenOnRemoteCommandArgs = { + resource: { + type: RemoteResourceType.Commit, + sha: commit.sha, + }, + repoPath: commit.repoPath, + clipboard: clipboard, + }; + lens.command = { + title: title, + command: Commands.OpenOnRemote, + arguments: [commandArgs], + }; + return lens; + } + + private applyCopyOrOpenFileOnRemoteCommand( + title: string, + lens: T, + commit: GitCommit, + clipboard: boolean = false, + ): T { + const commandArgs: OpenOnRemoteCommandArgs = { + resource: { + type: RemoteResourceType.Revision, + fileName: commit.fileName, + sha: commit.sha, + }, + repoPath: commit.repoPath, + clipboard: clipboard, + }; + lens.command = { + title: title, + command: Commands.OpenOnRemote, + arguments: [commandArgs], + }; + return lens; + } + private applyRevealCommitInViewCommand( title: string, lens: T, diff --git a/src/config.ts b/src/config.ts index a2735c1..375f46a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -182,7 +182,11 @@ export enum ChangesLocations { } export enum CodeLensCommand { + CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl', + CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrl', DiffWithPrevious = 'gitlens.diffWithPrevious', + OpenCommitOnRemote = 'gitlens.openCommitOnRemote', + OpenFileOnRemote = 'gitlens.openFileOnRemote', RevealCommitInView = 'gitlens.revealCommitInView', ShowCommitsInView = 'gitlens.showCommitsInView', ShowQuickCommitDetails = 'gitlens.showQuickCommitDetails', @@ -248,8 +252,12 @@ export enum KeyMap { } export enum StatusBarCommand { + CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl', + CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrl', DiffWithPrevious = 'gitlens.diffWithPrevious', DiffWithWorking = 'gitlens.diffWithWorking', + OpenCommitOnRemote = 'gitlens.openCommitOnRemote', + OpenFileOnRemote = 'gitlens.openFileOnRemote', RevealCommitInView = 'gitlens.revealCommitInView', ShowCommitsInView = 'gitlens.showCommitsInView', ShowQuickCommitDetails = 'gitlens.showQuickCommitDetails', diff --git a/src/statusbar/statusBarController.ts b/src/statusbar/statusBarController.ts index e29f273..fab0d34 100644 --- a/src/statusbar/statusBarController.ts +++ b/src/statusbar/statusBarController.ts @@ -183,8 +183,12 @@ export class StatusBarController implements Disposable { })}`; switch (cfg.command) { - case StatusBarCommand.ToggleFileBlame: - this._statusBarBlame.tooltip = 'Toggle File Blame Annotations'; + case StatusBarCommand.CopyRemoteCommitUrl: + this._statusBarBlame.tooltip = 'Copy Remote Commit Url'; + break; + case StatusBarCommand.CopyRemoteFileUrl: + this._statusBarBlame.command = Commands.CopyRemoteFileUrl; + this._statusBarBlame.tooltip = 'Copy Remote File Revision Url'; break; case StatusBarCommand.DiffWithPrevious: this._statusBarBlame.command = Commands.DiffLineWithPrevious; @@ -194,8 +198,11 @@ export class StatusBarController implements Disposable { this._statusBarBlame.command = Commands.DiffLineWithWorking; this._statusBarBlame.tooltip = 'Open Line Changes with Working File'; break; - case StatusBarCommand.ToggleCodeLens: - this._statusBarBlame.tooltip = 'Toggle Git CodeLens'; + case StatusBarCommand.OpenCommitOnRemote: + this._statusBarBlame.tooltip = 'Open Commit on Remote'; + break; + case StatusBarCommand.OpenFileOnRemote: + this._statusBarBlame.tooltip = 'Open Revision on Remote'; break; case StatusBarCommand.RevealCommitInView: this._statusBarBlame.tooltip = 'Reveal Commit in the Side Bar'; @@ -209,11 +216,17 @@ export class StatusBarController implements Disposable { case StatusBarCommand.ShowQuickCommitFileDetails: this._statusBarBlame.tooltip = 'Show Commit (file)'; break; + case StatusBarCommand.ShowQuickCurrentBranchHistory: + this._statusBarBlame.tooltip = 'Show Branch History'; + break; case StatusBarCommand.ShowQuickFileHistory: this._statusBarBlame.tooltip = 'Show File History'; break; - case StatusBarCommand.ShowQuickCurrentBranchHistory: - this._statusBarBlame.tooltip = 'Show Branch History'; + case StatusBarCommand.ToggleCodeLens: + this._statusBarBlame.tooltip = 'Toggle Git CodeLens'; + break; + case StatusBarCommand.ToggleFileBlame: + this._statusBarBlame.tooltip = 'Toggle File Blame'; break; } diff --git a/src/webviews/apps/settings/partials/code-lens.html b/src/webviews/apps/settings/partials/code-lens.html index 26aa873..07c33e0 100644 --- a/src/webviews/apps/settings/partials/code-lens.html +++ b/src/webviews/apps/settings/partials/code-lens.html @@ -66,9 +66,7 @@ data-enablement="codeLens.enabled & codeLens.recentChange.enabled & codeLens.recentChange.command !false" disabled > - + @@ -88,6 +86,18 @@ + + + + @@ -129,9 +139,7 @@ data-enablement="codeLens.enabled & codeLens.authors.enabled & codeLens.authors.command !false" disabled > - + @@ -153,6 +161,18 @@ + + + + diff --git a/src/webviews/apps/settings/partials/status-bar.html b/src/webviews/apps/settings/partials/status-bar.html index 4e7db08..82373a7 100644 --- a/src/webviews/apps/settings/partials/status-bar.html +++ b/src/webviews/apps/settings/partials/status-bar.html @@ -85,7 +85,8 @@