Skip to content

Commit 9233e27

Browse files
committed
Splits command handling for inspecting details
Renames "Open Inspect" to "Inspect Commit Details" Renames "Open Line Inspect" to "Inspect Line Commit Details" Renames "Open Details" to "Inspect Details" Adds "Search for Commits within Selection" to editor context menu if there is a selection
1 parent 445cb04 commit 9233e27

File tree

12 files changed

+147
-84
lines changed

12 files changed

+147
-84
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Adds _Search for Commits within Selection_ command to the editor context menu when there is a selection
12+
913
### Changed
1014

1115
- Renames `Reset Stored AI Key` command to `Reset Stored AI Keys...` and adds confirmation prompt with options to reset only the current or all AI keys
16+
- Renames _Open Inspect_ to _Inspect Commit Details_
17+
- Renames _Open Line Inspect_ to _Inspect Line Commit Details_
18+
- Renames _Open Details_ to _Inspect Commit Details_
1219

1320
### Fixed
1421

package.json

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,19 +6247,19 @@
62476247
},
62486248
{
62496249
"command": "gitlens.showCommitInView",
6250-
"title": "Open Inspect",
6250+
"title": "Inspect Commit Details",
62516251
"category": "GitLens",
62526252
"icon": "$(eye)"
62536253
},
62546254
{
62556255
"command": "gitlens.showLineCommitInView",
6256-
"title": "Open Line Inspect",
6256+
"title": "Inspect Line Commit Details",
62576257
"category": "GitLens",
62586258
"icon": "$(eye)"
62596259
},
62606260
{
62616261
"command": "gitlens.showInDetailsView",
6262-
"title": "Open Details",
6262+
"title": "Inspect Details",
62636263
"category": "GitLens",
62646264
"icon": "$(eye)"
62656265
},
@@ -8748,7 +8748,7 @@
87488748
},
87498749
{
87508750
"command": "gitlens.graph.showInDetailsView",
8751-
"title": "Open Details",
8751+
"title": "Inspect Details",
87528752
"category": "GitLens",
87538753
"icon": "$(eye)"
87548754
},
@@ -16033,27 +16033,32 @@
1603316033
"group": "2_gitlens@4"
1603416034
},
1603516035
{
16036-
"command": "gitlens.showLineCommitInView",
16036+
"command": "gitlens.showQuickCommitFileDetails",
1603716037
"group": "3_gitlens@1"
1603816038
},
1603916039
{
16040-
"command": "gitlens.showQuickCommitFileDetails",
16040+
"command": "gitlens.showLineCommitInView",
16041+
"group": "3_gitlens@2"
16042+
},
16043+
{
16044+
"command": "gitlens.showCommitsInView",
16045+
"when": "editorTextFocus && editorHasSelection",
1604116046
"group": "3_gitlens@2"
1604216047
},
1604316048
{
1604416049
"command": "gitlens.showQuickRevisionDetails",
1604516050
"when": "gitlens:enabled && resourceScheme =~ /^(gitlens|git|pr)$/ && !isInDiffEditor",
16046-
"group": "3_gitlens@2"
16051+
"group": "3_gitlens_1@1"
1604716052
},
1604816053
{
1604916054
"command": "gitlens.showQuickRevisionDetailsInDiffLeft",
1605016055
"when": "gitlens:enabled && resourceScheme =~ /^(gitlens|git|pr)$/ && isInDiffEditor && !isInDiffRightEditor",
16051-
"group": "3_gitlens@2"
16056+
"group": "3_gitlens_1@1"
1605216057
},
1605316058
{
1605416059
"command": "gitlens.showQuickRevisionDetailsInDiffRight",
1605516060
"when": "gitlens:enabled && resourceScheme =~ /^(gitlens|git|pr)$/ && isInDiffRightEditor",
16056-
"group": "3_gitlens@2"
16061+
"group": "3_gitlens_1@1"
1605716062
}
1605816063
],
1605916064
"gitlens/editor/context/openOn": [
@@ -16128,11 +16133,11 @@
1612816133
"group": "1_gitlens@2"
1612916134
},
1613016135
{
16131-
"command": "gitlens.showLineCommitInView",
16136+
"command": "gitlens.showQuickCommitFileDetails",
1613216137
"group": "3_gitlens@1"
1613316138
},
1613416139
{
16135-
"command": "gitlens.showQuickCommitFileDetails",
16140+
"command": "gitlens.showLineCommitInView",
1613616141
"group": "3_gitlens@2"
1613716142
}
1613816143
],

src/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import './commands/generateCommitMessage';
2525
import './commands/ghpr/openOrCreateWorktree';
2626
import './commands/gitCommands';
2727
import './commands/inviteToLiveShare';
28+
import './commands/inspect';
2829
import './commands/logging';
2930
import './commands/openAssociatedPullRequestOnRemote';
3031
import './commands/openBranchesOnRemote';

src/commands/inspect.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import type { TextEditor, Uri } from 'vscode';
2+
import { Commands } from '../constants';
3+
import type { Container } from '../container';
4+
import { showDetailsView } from '../git/actions/commit';
5+
import { GitUri } from '../git/gitUri';
6+
import type { GitRevisionReference } from '../git/models/reference';
7+
import { createReference, getReferenceFromRevision } from '../git/models/reference';
8+
import {
9+
showFileNotUnderSourceControlWarningMessage,
10+
showGenericErrorMessage,
11+
showLineUncommittedWarningMessage,
12+
} from '../messages';
13+
import { command } from '../system/command';
14+
import { Logger } from '../system/logger';
15+
import type { CommandContext } from './base';
16+
import { ActiveEditorCommand, getCommandUri, isCommandContextViewNodeHasCommit } from './base';
17+
18+
export interface InspectCommandArgs {
19+
ref?: GitRevisionReference;
20+
}
21+
22+
@command()
23+
export class InspectCommand extends ActiveEditorCommand {
24+
static getMarkdownCommandArgs(sha: string, repoPath: string): string;
25+
static getMarkdownCommandArgs(args: InspectCommandArgs): string;
26+
static getMarkdownCommandArgs(argsOrSha: InspectCommandArgs | string, repoPath?: string): string {
27+
const args =
28+
typeof argsOrSha === 'string'
29+
? { ref: createReference(argsOrSha, repoPath!, { refType: 'revision' }), repoPath: repoPath }
30+
: argsOrSha;
31+
return super.getMarkdownCommandArgsCore<InspectCommandArgs>(Commands.ShowCommitInView, args);
32+
}
33+
34+
constructor(private readonly container: Container) {
35+
super([Commands.ShowCommitInView, Commands.ShowInDetailsView, Commands.ShowLineCommitInView]);
36+
}
37+
38+
protected override preExecute(context: CommandContext, args?: InspectCommandArgs) {
39+
if (context.type === 'viewItem') {
40+
args = { ...args };
41+
if (isCommandContextViewNodeHasCommit(context)) {
42+
args.ref = getReferenceFromRevision(context.node.commit);
43+
}
44+
}
45+
46+
return this.execute(context.editor, context.uri, args);
47+
}
48+
49+
async execute(editor?: TextEditor, uri?: Uri, args?: InspectCommandArgs) {
50+
args = { ...args };
51+
52+
if (args.ref == null) {
53+
uri = getCommandUri(uri, editor);
54+
if (uri == null) return undefined;
55+
56+
const gitUri = await GitUri.fromUri(uri);
57+
58+
const blameLine = editor?.selection.active.line;
59+
if (blameLine == null) return;
60+
61+
try {
62+
const blame = await this.container.git.getBlameForLine(gitUri, blameLine);
63+
if (blame == null) {
64+
void showFileNotUnderSourceControlWarningMessage('Unable to inspect commit details');
65+
66+
return;
67+
}
68+
69+
// Because the previous sha of an uncommitted file isn't trust worthy we just have to kick out
70+
if (blame.commit.isUncommitted) {
71+
void showLineUncommittedWarningMessage('Unable to inspect commit details');
72+
73+
return;
74+
}
75+
76+
args.ref = blame.commit;
77+
} catch (ex) {
78+
Logger.error(ex, 'InspectCommand', `getBlameForLine(${blameLine})`);
79+
void showGenericErrorMessage('Unable to inspect commit details');
80+
81+
return;
82+
}
83+
}
84+
85+
return showDetailsView(args.ref);
86+
}
87+
}

src/commands/quickCommand.buttons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export const SetRemoteAsDefaultQuickInputButton: QuickInputButton = {
183183

184184
export const ShowDetailsViewQuickInputButton: QuickInputButton = {
185185
iconPath: new ThemeIcon('eye'),
186-
tooltip: 'Open Details',
186+
tooltip: 'Inspect Details',
187187
};
188188

189189
export const OpenChangesViewQuickInputButton: QuickInputButton = {

src/commands/showCommitsInView.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ import type { TextEditor, Uri } from 'vscode';
22
import { Commands } from '../constants';
33
import type { Container } from '../container';
44
import { executeGitCommand } from '../git/actions';
5-
import { showDetailsView } from '../git/actions/commit';
65
import { GitUri } from '../git/gitUri';
7-
import type { GitRevisionReference } from '../git/models/reference';
8-
import { createReference, getReferenceFromRevision } from '../git/models/reference';
96
import { createSearchQueryForCommits } from '../git/search';
107
import { showFileNotUnderSourceControlWarningMessage, showGenericErrorMessage } from '../messages';
118
import { command } from '../system/command';
129
import { filterMap } from '../system/iterable';
1310
import { Logger } from '../system/logger';
14-
import type { CommandContext } from './base';
15-
import { ActiveEditorCommand, getCommandUri, isCommandContextViewNodeHasCommit } from './base';
11+
import { ActiveEditorCommand, getCommandUri } from './base';
1612

1713
export interface ShowCommitsInViewCommandArgs {
18-
ref?: GitRevisionReference;
1914
refs?: string[];
2015
repoPath?: string;
2116
}
@@ -26,30 +21,17 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand {
2621
static getMarkdownCommandArgs(args: ShowCommitsInViewCommandArgs): string;
2722
static getMarkdownCommandArgs(argsOrSha: ShowCommitsInViewCommandArgs | string, repoPath?: string): string {
2823
const args = typeof argsOrSha === 'string' ? { refs: [argsOrSha], repoPath: repoPath } : argsOrSha;
29-
return super.getMarkdownCommandArgsCore<ShowCommitsInViewCommandArgs>(Commands.ShowCommitInView, args);
24+
return super.getMarkdownCommandArgsCore<ShowCommitsInViewCommandArgs>(Commands.ShowCommitsInView, args);
3025
}
3126

3227
constructor(private readonly container: Container) {
33-
super([Commands.ShowCommitInView, Commands.ShowInDetailsView, Commands.ShowCommitsInView]);
34-
}
35-
36-
protected override preExecute(context: CommandContext, args?: ShowCommitsInViewCommandArgs) {
37-
if (context.type === 'viewItem') {
38-
args = { ...args };
39-
if (isCommandContextViewNodeHasCommit(context)) {
40-
args.ref = getReferenceFromRevision(context.node.commit);
41-
}
42-
}
43-
44-
return this.execute(context.editor, context.uri, args);
28+
super(Commands.ShowCommitsInView);
4529
}
4630

4731
async execute(editor?: TextEditor, uri?: Uri, args?: ShowCommitsInViewCommandArgs) {
4832
args = { ...args };
4933

50-
if (args.ref != null) return showDetailsView(args.ref);
51-
52-
if (args.refs === undefined) {
34+
if (args.refs == null) {
5335
uri = getCommandUri(uri, editor);
5436
if (uri == null) return undefined;
5537

@@ -83,9 +65,9 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand {
8365
}
8466
}
8567

86-
if (args.refs.length === 1) {
87-
return showDetailsView(createReference(args.refs[0], args.repoPath!, { refType: 'revision' }));
88-
}
68+
// if (args.refs.length === 1) {
69+
// return showDetailsView(createReference(args.refs[0], args.repoPath!, { refType: 'revision' }));
70+
// }
8971

9072
return executeGitCommand({
9173
command: 'search',

src/commands/showQuickCommitFile.ts

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,17 @@ import {
1313
showGenericErrorMessage,
1414
showLineUncommittedWarningMessage,
1515
} from '../messages';
16-
import { command, executeCommand } from '../system/command';
16+
import { command } from '../system/command';
1717
import { Logger } from '../system/logger';
1818
import type { CommandContext } from './base';
1919
import { ActiveEditorCachedCommand, getCommandUri, isCommandContextViewNodeHasCommit } from './base';
20-
import type { ShowCommitsInViewCommandArgs } from './showCommitsInView';
2120

2221
export interface ShowQuickCommitFileCommandArgs {
2322
commit?: GitCommit | GitStashCommit;
2423
line?: number;
2524
fileLog?: GitLog;
2625
revisionUri?: string;
2726
sha?: string;
28-
29-
inView?: boolean;
3027
}
3128

3229
@command()
@@ -41,7 +38,6 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
4138
Commands.ShowQuickCommitRevision,
4239
Commands.ShowQuickCommitRevisionInDiffLeft,
4340
Commands.ShowQuickCommitRevisionInDiffRight,
44-
Commands.ShowLineCommitInView,
4541
]);
4642
}
4743

@@ -50,10 +46,6 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
5046
args = { ...args, line: context.line };
5147
}
5248

53-
if (context.command === Commands.ShowLineCommitInView) {
54-
args = { ...args, inView: true };
55-
}
56-
5749
if (context.editor != null && context.command.startsWith(Commands.ShowQuickCommitRevision)) {
5850
const gitUri = await GitUri.fromUri(context.editor.document.uri);
5951

@@ -151,21 +143,14 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand {
151143
}
152144
}
153145

154-
if (args.inView) {
155-
await executeCommand<ShowCommitsInViewCommandArgs>(Commands.ShowCommitsInView, {
156-
refs: [args.commit.sha],
157-
repoPath: args.commit.repoPath,
158-
});
159-
} else {
160-
await executeGitCommand({
161-
command: 'show',
162-
state: {
163-
repo: args.commit.repoPath,
164-
reference: args.commit,
165-
fileName: path,
166-
},
167-
});
168-
}
146+
await executeGitCommand({
147+
command: 'show',
148+
state: {
149+
repo: args.commit.repoPath,
150+
reference: args.commit,
151+
fileName: path,
152+
},
153+
});
169154
} catch (ex) {
170155
Logger.error(ex, 'ShowQuickCommitFileDetailsCommand');
171156
void showGenericErrorMessage('Unable to show commit file details');

0 commit comments

Comments
 (0)