Explorar el Código

Adds command to generate deep links to comparisons

main
Ramin Tadayon hace 1 año
padre
commit
570c917051
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 79D60DDE3DFB95F5
Se han modificado 5 ficheros con 82 adiciones y 17 borrados
  1. +17
    -2
      package.json
  2. +13
    -0
      src/commands/base.ts
  3. +17
    -2
      src/commands/copyDeepLink.ts
  4. +1
    -0
      src/constants.ts
  5. +34
    -13
      src/uris/deepLinks/deepLinkService.ts

+ 17
- 2
package.json Ver fichero

@ -5286,6 +5286,12 @@
"icon": "$(copy)"
},
{
"command": "gitlens.copyDeepLinkToComparison",
"title": "Copy Link to Comparison",
"category": "GitLens",
"icon": "$(copy)"
},
{
"command": "gitlens.copyDeepLinkToRepo",
"title": "Copy Link to Repository",
"category": "GitLens",
@ -8392,6 +8398,10 @@
"when": "false"
},
{
"command": "gitlens.copyDeepLinkToComparison",
"when": "false"
},
{
"command": "gitlens.copyDeepLinkToRepo",
"when": "gitlens:enabled"
},
@ -11590,7 +11600,7 @@
},
{
"submenu": "gitlens/share",
"when": "viewItem =~ /gitlens:(branch|commit|remote|repo-folder|repository|stash|tag|file\\b(?=.*?\\b\\+committed\\b))\\b/",
"when": "viewItem =~ /gitlens:(branch|commit|compare:results(?!:)|remote|repo-folder|repository|stash|tag|file\\b(?=.*?\\b\\+committed\\b))\\b/",
"group": "7_gitlens_a_share@1"
},
{
@ -12751,7 +12761,7 @@
},
{
"submenu": "gitlens/share",
"when": "webviewItem =~ /gitlens:(branch|commit|stash|tag)\\b/",
"when": "webviewItem =~ /gitlens:(branch|commit|compare:results(?!:)|stash|tag)\\b/",
"group": "7_gitlens_a_share@1"
},
{
@ -13012,6 +13022,11 @@
"group": "1_gitlens@25"
},
{
"command": "gitlens.copyDeepLinkToComparison",
"when": "viewItem =~ /gitlens:compare:results(?!:)\\b/",
"group": "1_gitlens@25"
},
{
"command": "gitlens.copyRemoteFileUrlWithoutRange",
"when": "gitlens:hasRemotes && viewItem =~ /gitlens:(file\\b(?=.*?\\b\\+committed\\b)|history:(file|line)|status:file)\\b/",
"group": "2_gitlens@1"

+ 13
- 0
src/commands/base.ts Ver fichero

@ -159,6 +159,19 @@ export function isCommandContextViewNodeHasFileRefs(context: CommandContext): co
);
}
export function isCommandContextViewNodeHasComparison(
context: CommandContext,
): context is CommandViewNodeContext & { node: ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } } } {
if (context.type !== 'viewItem') return false;
return (
typeof (context.node as ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } })._ref?.ref ===
'string' &&
typeof (context.node as ViewNode & { _ref: { ref: string }; _compareWith: { ref: string } })._compareWith
?.ref === 'string'
);
}
export function isCommandContextViewNodeHasRef(
context: CommandContext,
): context is CommandViewNodeContext & { node: ViewNode & { ref: GitReference } } {

+ 17
- 2
src/commands/copyDeepLink.ts Ver fichero

@ -16,12 +16,15 @@ import {
getCommandUri,
isCommandContextViewNodeHasBranch,
isCommandContextViewNodeHasCommit,
isCommandContextViewNodeHasComparison,
isCommandContextViewNodeHasRemote,
isCommandContextViewNodeHasTag,
} from './base';
export interface CopyDeepLinkCommandArgs {
refOrRepoPath?: GitReference | string;
compareRef?: string;
compareWithRef?: string;
remote?: string;
prePickRemote?: boolean;
}
@ -34,6 +37,7 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
Commands.CopyDeepLinkToCommit,
Commands.CopyDeepLinkToRepo,
Commands.CopyDeepLinkToTag,
Commands.CopyDeepLinkToComparison,
]);
}
@ -47,6 +51,12 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
args = { refOrRepoPath: context.node.tag };
} else if (isCommandContextViewNodeHasRemote(context)) {
args = { refOrRepoPath: context.node.remote.repoPath, remote: context.node.remote.name };
} else if (isCommandContextViewNodeHasComparison(context)) {
args = {
refOrRepoPath: context.node.uri.fsPath,
compareRef: context.node._ref.ref,
compareWithRef: context.node._compareWith.ref,
};
}
}
@ -67,7 +77,7 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
await getBestRepositoryOrShowPicker(gitUri, editor, `Copy Link to ${deepLinkTypeToString(type)}`)
)?.path;
} else if (typeof args.refOrRepoPath === 'string') {
type = DeepLinkType.Repository;
type = args.compareRef == null ? DeepLinkType.Repository : DeepLinkType.Comparison;
repoPath = args.refOrRepoPath;
args.refOrRepoPath = undefined;
} else {
@ -115,7 +125,12 @@ export class CopyDeepLinkCommand extends ActiveEditorCommand {
if (chosenRemote == null) return;
if (args.refOrRepoPath == null) {
await this.container.deepLinks.copyDeepLinkUrl(repoPath, chosenRemote.url);
await this.container.deepLinks.copyDeepLinkUrl(
repoPath,
chosenRemote.url,
args.compareRef,
args.compareWithRef,
);
} else {
await this.container.deepLinks.copyDeepLinkUrl(args.refOrRepoPath, chosenRemote.url);
}

+ 1
- 0
src/constants.ts Ver fichero

@ -120,6 +120,7 @@ export const enum Commands {
CopyCurrentBranch = 'gitlens.copyCurrentBranch',
CopyDeepLinkToBranch = 'gitlens.copyDeepLinkToBranch',
CopyDeepLinkToCommit = 'gitlens.copyDeepLinkToCommit',
CopyDeepLinkToComparison = 'gitlens.copyDeepLinkToComparison',
CopyDeepLinkToRepo = 'gitlens.copyDeepLinkToRepo',
CopyDeepLinkToTag = 'gitlens.copyDeepLinkToTag',
CopyMessageToClipboard = 'gitlens.copyMessageToClipboard',

+ 34
- 13
src/uris/deepLinks/deepLinkService.ts Ver fichero

@ -685,18 +685,18 @@ export class DeepLinkService implements Disposable {
async copyDeepLinkUrl(
repoPath: string,
remoteUrl: string,
targetType?: DeepLinkType,
targetId?: string,
compareRef?: string,
compareToRef?: string,
): Promise<void>;
async copyDeepLinkUrl(
refOrRepoPath: string | GitReference,
remoteUrl: string,
targetType?: DeepLinkType,
targetId?: string,
compareRef?: string,
compareToRef?: string,
): Promise<void> {
const url = await (typeof refOrRepoPath !== 'string'
? this.generateDeepLinkUrl(refOrRepoPath, remoteUrl)
: this.generateDeepLinkUrl(refOrRepoPath, remoteUrl, targetType, targetId));
const url = await (typeof refOrRepoPath === 'string'
? this.generateDeepLinkUrl(refOrRepoPath, remoteUrl, compareRef, compareToRef)
: this.generateDeepLinkUrl(refOrRepoPath, remoteUrl));
await env.clipboard.writeText(url.toString());
}
@ -704,18 +704,26 @@ export class DeepLinkService implements Disposable {
async generateDeepLinkUrl(
repoPath: string,
remoteUrl: string,
targetType?: DeepLinkType,
targetId?: string,
compareRef?: string,
compareToRef?: string,
): Promise<URL>;
async generateDeepLinkUrl(
refOrRepoPath: string | GitReference,
remoteUrl: string,
targetType?: DeepLinkType,
targetId?: string,
compareRef?: string,
compareToRef?: string,
): Promise<URL> {
const repoPath = typeof refOrRepoPath !== 'string' ? refOrRepoPath.repoPath : refOrRepoPath;
const repoId = await this.container.git.getUniqueRepositoryId(repoPath);
let repoId;
try {
repoId = await this.container.git.getUniqueRepositoryId(repoPath);
} catch {
repoId = '-';
}
let targetType: DeepLinkType | undefined;
let targetId: string | undefined;
let compareTargetId: string | undefined;
if (typeof refOrRepoPath !== 'string') {
switch (refOrRepoPath.refType) {
case 'branch':
@ -735,9 +743,22 @@ export class DeepLinkService implements Disposable {
}
}
if (compareRef != null && compareToRef != null) {
targetType = DeepLinkType.Comparison;
targetId = compareRef;
compareTargetId = compareToRef;
}
const schemeOverride = configuration.get('deepLinks.schemeOverride');
const scheme = !schemeOverride ? 'vscode' : schemeOverride === true ? env.uriScheme : schemeOverride;
const target = targetType != null && targetType !== DeepLinkType.Repository ? `/${targetType}/${targetId}` : '';
let target;
if (targetType === DeepLinkType.Comparison) {
target = `/${targetType}/${targetId}...${compareTargetId}`;
} else if (targetType != null && targetType !== DeepLinkType.Repository) {
target = `/${targetType}/${targetId}`;
} else {
target = '';
}
// Start with the prefix, add the repo prefix and the repo ID to the URL, and then add the target tag and target ID to the URL (if applicable)
const url = new URL(

Cargando…
Cancelar
Guardar