Browse Source

Adds open/copy commit on remote to Timeline view

main
Eric Amodio 4 years ago
parent
commit
cbed5de398
4 changed files with 71 additions and 1 deletions
  1. +8
    -0
      package.json
  2. +22
    -0
      src/@types/timeline.d.ts
  3. +35
    -1
      src/commands/common.ts
  4. +6
    -0
      src/commands/openCommitOnRemote.ts

+ 8
- 0
package.json View File

@ -5814,6 +5814,14 @@
"group": "9_gitlens@1"
}
],
"timeline/item/context": [
{
"command": "gitlens.openCommitInRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && timelineItem =~ /git:file:commit\\b/",
"group": "inline@99",
"alt": "gitlens.copyRemoteCommitUrl"
}
],
"view/title": [
{
"command": "gitlens.closeUpdatesView",

+ 22
- 0
src/@types/timeline.d.ts View File

@ -0,0 +1,22 @@
import { AccessibilityInformation, Command, ThemeIcon, Uri } from 'vscode';
declare module 'vscode' {
export interface TimelineItem {
readonly timestamp: number;
readonly label: string;
readonly id?: string;
readonly iconPath?: Uri | { light: Uri; dark: Uri } | ThemeIcon;
readonly description?: string;
readonly detail?: string;
readonly command?: Command;
readonly contextValue?: string;
readonly accessibilityInformation?: AccessibilityInformation;
}
export interface GitTimelineItem extends TimelineItem {
readonly ref: string;
readonly previousRef: string;
readonly message: string;
}
}

+ 35
- 1
src/commands/common.ts View File

@ -4,12 +4,13 @@ import {
commands,
Disposable,
ExtensionContext,
SourceControl,
GitTimelineItem,
SourceControlResourceGroup,
SourceControlResourceState,
TextDocumentShowOptions,
TextEditor,
TextEditorEdit,
TimelineItem,
Uri,
ViewColumn,
window,
@ -215,6 +216,12 @@ export interface CommandBaseContext {
uri?: Uri;
}
export interface CommandGitTimelineItemContext extends CommandBaseContext {
readonly type: 'timeline-item:git';
readonly item: GitTimelineItem;
readonly uri: Uri;
}
export interface CommandScmGroupsContext extends CommandBaseContext {
readonly type: 'scm-groups';
readonly scmResourceGroups: SourceControlResourceGroup[];
@ -247,6 +254,10 @@ export interface CommandViewNodeContext extends CommandBaseContext {
readonly node: ViewNode;
}
export function isCommandContextGitTimelineItem(context: CommandContext): context is CommandGitTimelineItemContext {
return context.type === 'timeline-item:git';
}
export function isCommandContextViewNodeHasBranch(
context: CommandContext,
): context is CommandViewNodeContext & { node: ViewNode & { branch: GitBranch } } {
@ -344,6 +355,7 @@ export function isCommandContextViewNodeHasTag(
}
export type CommandContext =
| CommandGitTimelineItemContext
| CommandScmGroupsContext
| CommandScmStatesContext
| CommandUnknownContext
@ -369,6 +381,23 @@ function isScmResourceState(resource: any): resource is SourceControlResourceSta
return (resource as SourceControlResourceState).resourceUri != null;
}
function isTimelineItem(item: any): item is TimelineItem {
if (item == null) return false;
return (item as TimelineItem).timestamp != null && (item as TimelineItem).label != null;
}
function isGitTimelineItem(item: any): item is GitTimelineItem {
if (item == null) return false;
return (
isTimelineItem(item) &&
(item as GitTimelineItem).ref != null &&
(item as GitTimelineItem).previousRef != null &&
(item as GitTimelineItem).message != null
);
}
export abstract class Command implements Disposable {
static getMarkdownCommandArgsCore<T>(command: Commands, args: T): string {
return `command:${command}?${encodeURIComponent(JSON.stringify(args))}`;
@ -489,6 +518,11 @@ export abstract class Command implements Disposable {
return [{ command: command, type: 'scm-groups', scmResourceGroups: groups }, args.slice(count)];
}
if (isGitTimelineItem(firstArg)) {
const [item, uri, ...rest] = args as [GitTimelineItem, Uri, any];
return [{ command: command, type: 'timeline-item:git', item: item, uri: uri }, rest];
}
return [{ command: command, type: 'unknown', editor: editor, uri: editor?.document.uri }, args];
}
}

+ 6
- 0
src/commands/openCommitOnRemote.ts View File

@ -7,6 +7,7 @@ import {
Commands,
executeCommand,
getCommandUri,
isCommandContextGitTimelineItem,
isCommandContextViewNodeHasCommit,
} from './common';
import { Container } from '../container';
@ -44,6 +45,11 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand {
uri = context.node.commit.isFile ? context.node.commit.uri : context.node.uri;
}
if (isCommandContextGitTimelineItem(context)) {
args = { sha: context.item.ref };
uri = context.uri;
}
if (context.command === Commands.CopyRemoteCommitUrl) {
args = { ...args, clipboard: true };
}

Loading…
Cancel
Save