Skip to content

Commit b801f93

Browse files
committed
Adds new contribution point for better labels on gitlens:// uris
1 parent 39f6830 commit b801f93

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4752,6 +4752,16 @@
47524752
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
47534753
}
47544754
],
4755+
"resourceLabelFormatters": [
4756+
{
4757+
"scheme": "gitlens",
4758+
"authority": "*",
4759+
"formatting": {
4760+
"label": "${path} (${authority})",
4761+
"separator": "/"
4762+
}
4763+
}
4764+
],
47554765
"viewsContainers": {
47564766
"activitybar": [
47574767
{

src/git/gitUri.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ export class GitUri extends ((Uri as any) as UriEx) {
326326
static git(fileName: string, repoPath?: string) {
327327
const path = GitUri.resolve(fileName, repoPath);
328328
return Uri.parse(
329-
`git:${encodeURIComponent(path)}?${encodeURIComponent(
329+
// Change encoded / back to / otherwise uri parsing won't work properly
330+
`git:${encodeURIComponent(path).replace(/%2F/g, '/')}?${encodeURIComponent(
330331
JSON.stringify({
331332
// Ensure we use the fsPath here, otherwise the url won't open properly
332333
path: Uri.file(path).fsPath,
@@ -389,19 +390,18 @@ export class GitUri extends ((Uri as any) as UriEx) {
389390
shortSha = uriOrRef.shortSha;
390391
}
391392

392-
repoPath = Strings.normalizePath(repoPath!);
393-
const repoName = paths.basename(repoPath);
394-
395393
const filePath = Strings.normalizePath(fileName, { addLeadingSlash: true });
396394
const data: IUriRevisionData = {
397395
path: filePath,
398396
ref: ref,
399-
repoPath: repoPath
397+
repoPath: Strings.normalizePath(repoPath!)
400398
};
401399

402400
const uri = Uri.parse(
403-
`${DocumentSchemes.GitLens}:///${encodeURIComponent(repoName)}@${shortSha}${
404-
filePath === slash ? empty : encodeURIComponent(filePath)
401+
// Replace / in the authority with a similar unicode characters otherwise parsing will be wrong
402+
`${DocumentSchemes.GitLens}://${encodeURIComponent(shortSha!.replace(/\//g, '\u200A\u2215\u200A'))}${
403+
// Change encoded / back to / otherwise uri parsing won't work properly
404+
filePath === slash ? empty : encodeURIComponent(filePath).replace(/%2F/g, '/')
405405
}?${encodeURIComponent(JSON.stringify(data))}`
406406
);
407407
return uri;

0 commit comments

Comments
 (0)