Browse Source

Adds new contribution point for better labels on gitlens:// uris

main
Eric Amodio 5 years ago
parent
commit
b801f93305
2 changed files with 17 additions and 7 deletions
  1. +10
    -0
      package.json
  2. +7
    -7
      src/git/gitUri.ts

+ 10
- 0
package.json View File

@ -4752,6 +4752,16 @@
"when": "config.gitlens.keymap == chorded && gitlens:enabled" "when": "config.gitlens.keymap == chorded && gitlens:enabled"
} }
], ],
"resourceLabelFormatters": [
{
"scheme": "gitlens",
"authority": "*",
"formatting": {
"label": "${path} (${authority})",
"separator": "/"
}
}
],
"viewsContainers": { "viewsContainers": {
"activitybar": [ "activitybar": [
{ {

+ 7
- 7
src/git/gitUri.ts View File

@ -326,7 +326,8 @@ export class GitUri extends ((Uri as any) as UriEx) {
static git(fileName: string, repoPath?: string) { static git(fileName: string, repoPath?: string) {
const path = GitUri.resolve(fileName, repoPath); const path = GitUri.resolve(fileName, repoPath);
return Uri.parse( return Uri.parse(
`git:${encodeURIComponent(path)}?${encodeURIComponent(
// Change encoded / back to / otherwise uri parsing won't work properly
`git:${encodeURIComponent(path).replace(/%2F/g, '/')}?${encodeURIComponent(
JSON.stringify({ JSON.stringify({
// Ensure we use the fsPath here, otherwise the url won't open properly // Ensure we use the fsPath here, otherwise the url won't open properly
path: Uri.file(path).fsPath, path: Uri.file(path).fsPath,
@ -389,19 +390,18 @@ export class GitUri extends ((Uri as any) as UriEx) {
shortSha = uriOrRef.shortSha; shortSha = uriOrRef.shortSha;
} }
repoPath = Strings.normalizePath(repoPath!);
const repoName = paths.basename(repoPath);
const filePath = Strings.normalizePath(fileName, { addLeadingSlash: true }); const filePath = Strings.normalizePath(fileName, { addLeadingSlash: true });
const data: IUriRevisionData = { const data: IUriRevisionData = {
path: filePath, path: filePath,
ref: ref, ref: ref,
repoPath: repoPath
repoPath: Strings.normalizePath(repoPath!)
}; };
const uri = Uri.parse( const uri = Uri.parse(
`${DocumentSchemes.GitLens}:///${encodeURIComponent(repoName)}@${shortSha}${
filePath === slash ? empty : encodeURIComponent(filePath)
// Replace / in the authority with a similar unicode characters otherwise parsing will be wrong
`${DocumentSchemes.GitLens}://${encodeURIComponent(shortSha!.replace(/\//g, '\u200A\u2215\u200A'))}${
// Change encoded / back to / otherwise uri parsing won't work properly
filePath === slash ? empty : encodeURIComponent(filePath).replace(/%2F/g, '/')
}?${encodeURIComponent(JSON.stringify(data))}` }?${encodeURIComponent(JSON.stringify(data))}`
); );
return uri; return uri;

Loading…
Cancel
Save