Browse Source

Closes #1378 - remote cmds to statusbar/code lens

main
Eric Amodio 3 years ago
parent
commit
5967c85e67
7 changed files with 172 additions and 30 deletions
  1. +2
    -0
      CHANGELOG.md
  2. +31
    -15
      package.json
  3. +72
    -1
      src/codelens/codeLensProvider.ts
  4. +8
    -0
      src/config.ts
  5. +19
    -6
      src/statusbar/statusBarController.ts
  6. +26
    -6
      src/webviews/apps/settings/partials/code-lens.html
  7. +14
    -2
      src/webviews/apps/settings/partials/status-bar.html

+ 2
- 0
CHANGELOG.md View File

@ -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

+ 31
- 15
package.json View File

@ -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"

+ 72
- 1
src/codelens/codeLensProvider.ts View File

@ -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<GitRecentChangeCodeLens>(
title,
lens,
recentCommit,
true,
);
case CodeLensCommand.CopyRemoteFileUrl:
return this.applyCopyOrOpenFileOnRemoteCommand<GitRecentChangeCodeLens>(
title,
lens,
recentCommit,
true,
);
case CodeLensCommand.DiffWithPrevious:
return this.applyDiffWithPreviousCommand<GitRecentChangeCodeLens>(title, lens, recentCommit);
case CodeLensCommand.OpenCommitOnRemote:
return this.applyCopyOrOpenCommitOnRemoteCommand<GitRecentChangeCodeLens>(title, lens, recentCommit);
case CodeLensCommand.OpenFileOnRemote:
return this.applyCopyOrOpenFileOnRemoteCommand<GitRecentChangeCodeLens>(title, lens, recentCommit);
case CodeLensCommand.RevealCommitInView:
return this.applyRevealCommitInViewCommand<GitRecentChangeCodeLens>(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<GitAuthorsCodeLens>(title, lens, commit, true);
case CodeLensCommand.CopyRemoteFileUrl:
return this.applyCopyOrOpenFileOnRemoteCommand<GitAuthorsCodeLens>(title, lens, commit, true);
case CodeLensCommand.DiffWithPrevious:
return this.applyDiffWithPreviousCommand<GitAuthorsCodeLens>(title, lens, commit);
case CodeLensCommand.OpenCommitOnRemote:
return this.applyCopyOrOpenCommitOnRemoteCommand<GitAuthorsCodeLens>(title, lens, commit);
case CodeLensCommand.OpenFileOnRemote:
return this.applyCopyOrOpenFileOnRemoteCommand<GitAuthorsCodeLens>(title, lens, commit);
case CodeLensCommand.RevealCommitInView:
return this.applyRevealCommitInViewCommand<GitAuthorsCodeLens>(title, lens, commit);
case CodeLensCommand.ShowCommitsInView:
@ -610,6 +636,51 @@ export class GitCodeLensProvider implements CodeLensProvider {
return lens;
}
private applyCopyOrOpenCommitOnRemoteCommand<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
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<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
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<T extends GitRecentChangeCodeLens | GitAuthorsCodeLens>(
title: string,
lens: T,

+ 8
- 0
src/config.ts View File

@ -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',

+ 19
- 6
src/statusbar/statusBarController.ts View File

@ -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;
}

+ 26
- 6
src/webviews/apps/settings/partials/code-lens.html View File

@ -66,9 +66,7 @@
data-enablement="codeLens.enabled &amp; codeLens.recentChange.enabled &amp; codeLens.recentChange.command !false"
disabled
>
<option value="gitlens.toggleFileBlame">
toggles the file blame annotations
</option>
<option value="gitlens.toggleFileBlame">toggles the file blame</option>
<option value="gitlens.diffWithPrevious">
opens changes with the previous revision
</option>
@ -88,6 +86,18 @@
<option value="gitlens.showQuickRepoHistory">
shows the current branch history
</option>
<option value="gitlens.openCommitOnRemote">
opens the commit on the remote service (when available)
</option>
<option value="gitlens.copyRemoteCommitUrl">
copies the remote commit url to the clipboard (when available)
</option>
<option value="gitlens.openFileOnRemote">
opens the file revision on the remote service (when available)
</option>
<option value="gitlens.copyRemoteFileUrl">
copies the remote file revision url to the clipboard (when available)
</option>
</select>
</div>
</div>
@ -129,9 +139,7 @@
data-enablement="codeLens.enabled &amp; codeLens.authors.enabled &amp; codeLens.authors.command !false"
disabled
>
<option value="gitlens.toggleFileBlame">
toggles the file blame annotations
</option>
<option value="gitlens.toggleFileBlame">toggles the file blame</option>
<option value="gitlens.diffWithPrevious">
opens changes with the previous revision
</option>
@ -153,6 +161,18 @@
<option value="gitlens.showQuickRepoHistory">
shows the current branch history
</option>
<option value="gitlens.openCommitOnRemote">
opens the commit on the remote service (when available)
</option>
<option value="gitlens.copyRemoteCommitUrl">
copies the remote commit url to the clipboard (when available)
</option>
<option value="gitlens.copyRemoteFileUrl">
copies the remote file revision url to the clipboard (when available)
</option>
<option value="gitlens.openFileOnRemote">
opens the file revision on the remote service (when available)
</option>
</select>
</div>
</div>

+ 14
- 2
src/webviews/apps/settings/partials/status-bar.html View File

@ -85,7 +85,8 @@
<label class="nowrap" for="statusBar.command">When clicked</label>
<div class="select-container">
<select id="statusBar.command" name="statusBar.command" data-setting disabled>
<option value="gitlens.toggleFileBlame">toggles the file blame annotations</option>
<option value="gitlens.toggleFileBlame">toggles the file blame</option>
<option value="gitlens.toggleCodeLens">toggles the Git code lens</option>
<option value="gitlens.diffWithPrevious">
opens line changes with the previous revision
</option>
@ -96,7 +97,6 @@
reveals the commit in the Side Bar
</option>
<option value="gitlens.showCommitsInView">searches for the commit</option>
<option value="gitlens.toggleCodeLens">toggles the Git code lens</option>
<option value="gitlens.showQuickCommitDetails">shows details of the commit</option>
<option value="gitlens.showQuickCommitFileDetails">
shows file details of the commit
@ -105,6 +105,18 @@
<option value="gitlens.showQuickRepoHistory">
shows the current branch history
</option>
<option value="gitlens.openCommitOnRemote">
opens the commit on the remote service (when available)
</option>
<option value="gitlens.copyRemoteCommitUrl">
copies the remote commit url to the clipboard (when available)
</option>
<option value="gitlens.openFileOnRemote">
opens the file revision on the remote service (when available)
</option>
<option value="gitlens.copyRemoteFileUrl">
copies the remote file revision url to the clipboard (when available)
</option>
</select>
</div>
</div>

Loading…
Cancel
Save