Browse Source

Changes pr info to be added after date

Changes to single quote for token prefix/suffix grouping
Allows escaping single quote for inclusion in a prefix/suffix grouping
main
Eric Amodio 4 years ago
parent
commit
c45643292c
4 changed files with 33 additions and 14 deletions
  1. +2
    -2
      package.json
  2. +27
    -8
      src/system/string.ts
  3. +3
    -3
      src/views/nodes/commitFileNode.ts
  4. +1
    -1
      src/views/nodes/commitNode.ts

+ 2
- 2
package.json View File

@ -574,7 +574,7 @@
}, },
"gitlens.currentLine.format": { "gitlens.currentLine.format": {
"type": "string", "type": "string",
"default": "${message|50? • }${author}${\" via \"pullRequest}, ${agoOrDate}",
"default": "${author, }${agoOrDate}${' via 'pullRequest}${ • message|50?}",
"markdownDescription": "Specifies the format of the current line blame annotation. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs. Date formatting is controlled by the `#gitlens.currentLine.dateFormat#` setting", "markdownDescription": "Specifies the format of the current line blame annotation. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs. Date formatting is controlled by the `#gitlens.currentLine.dateFormat#` setting",
"scope": "window" "scope": "window"
}, },
@ -921,7 +921,7 @@
}, },
"gitlens.hovers.detailsMarkdownFormat": { "gitlens.hovers.detailsMarkdownFormat": {
"type": "string", "type": "string",
"default": "${avatar}  __${author}__${\" via \"pullRequest}, ${ago}   _(${date})_ \n\n${message}\n\n${commands}",
"default": "${avatar}  __${author}__, ${ago}${' via 'pullRequest}   _(${date})_ \n\n${message}\n\n${commands}",
"markdownDescription": "Specifies the format (in markdown) of the _commit details_ hover. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", "markdownDescription": "Specifies the format (in markdown) of the _commit details_ hover. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
"scope": "window" "scope": "window"
}, },

+ 27
- 8
src/system/string.ts View File

@ -75,8 +75,11 @@ export function getSuperscript(num: number) {
const driveLetterNormalizeRegex = /(?<=^\/?)([A-Z])(?=:\/)/; const driveLetterNormalizeRegex = /(?<=^\/?)([A-Z])(?=:\/)/;
const pathNormalizeRegex = /\\/g; const pathNormalizeRegex = /\\/g;
const pathStripTrailingSlashRegex = /\/$/g; const pathStripTrailingSlashRegex = /\/$/g;
const tokenRegex = /\$\{(".*?"|\W*)?([^|]*?)(?:\|(\d+)(-|\?)?)?(".*?"|\W*)?\}/g;
const tokenSanitizeRegex = /\$\{(?:".*?"|\W*)?(\w*?)(?:".*?"|[\W\d]*)\}/g;
const tokenRegex = /\$\{('.*?[^\\]'|\W*)?([^|]*?)(?:\|(\d+)(-|\?)?)?('.*?[^\\]'|\W*)?\}/g;
const tokenSanitizeRegex = /\$\{(?:'.*?[^\\]'|\W*)?(\w*?)(?:'.*?[^\\]'|[\W\d]*)\}/g;
const tokenGroupCharacter = "'";
const tokenGroupCharacterEscapedRegex = /(\\')/g;
const tokenGroupRegex = /^'?(.*?)'?$/;
export interface TokenOptions { export interface TokenOptions {
collapseWhitespace: boolean; collapseWhitespace: boolean;
@ -94,17 +97,33 @@ export function getTokensFromTemplate(template: string) {
match = tokenRegex.exec(template); match = tokenRegex.exec(template);
if (match == null) break; if (match == null) break;
const [, prefix, key, truncateTo, option, suffix] = match;
// eslint-disable-next-line prefer-const
let [, prefix, key, truncateTo, option, suffix] = match;
// Check for a prefix group
if (prefix != null) {
match = tokenGroupRegex.exec(prefix);
if (match != null) {
[, prefix] = match;
prefix = prefix.replace(tokenGroupCharacterEscapedRegex, tokenGroupCharacter);
}
}
// Check for a suffix group
if (suffix != null) {
match = tokenGroupRegex.exec(suffix);
if (match != null) {
[, suffix] = match;
suffix = suffix.replace(tokenGroupCharacterEscapedRegex, tokenGroupCharacter);
}
}
tokens.push({ tokens.push({
key: key, key: key,
options: { options: {
collapseWhitespace: option === '?', collapseWhitespace: option === '?',
padDirection: option === '-' ? 'left' : 'right', padDirection: option === '-' ? 'left' : 'right',
prefix:
prefix?.length > 1 && prefix?.startsWith('"') && prefix?.endsWith('"')
? prefix.substr(1, prefix.length - 2)
: prefix,
suffix: suffix,
prefix: prefix || undefined,
suffix: suffix || undefined,
truncateTo: truncateTo == null ? undefined : parseInt(truncateTo, 10), truncateTo: truncateTo == null ? undefined : parseInt(truncateTo, 10),
}, },
}); });

+ 3
- 3
src/views/nodes/commitFileNode.ts View File

@ -169,9 +169,9 @@ export class CommitFileNode extends ViewRefFileNode {
return CommitFormatter.fromTemplate( return CommitFormatter.fromTemplate(
this.commit.isUncommitted this.commit.isUncommitted
? `\${author} ${GlyphChars.Dash} \${id}\n${status}\n\${ago} (\${date})` ? `\${author} ${GlyphChars.Dash} \${id}\n${status}\n\${ago} (\${date})`
: `\${author}\${ (email)}\${" via "pullRequest} ${
GlyphChars.Dash
} \${id}\n${status}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({
: `\${author}\${ (email)} ${GlyphChars.Dash} \${id}${
this._options.unpublished ? ' (unpublished)' : ''
}\n${status}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({
expand: true, expand: true,
prefix: '\n\n', prefix: '\n\n',
separator: '\n', separator: '\n',

+ 1
- 1
src/views/nodes/commitNode.ts View File

@ -46,7 +46,7 @@ export class CommitNode extends ViewRefNode
return CommitFormatter.fromTemplate( return CommitFormatter.fromTemplate(
this.commit.isUncommitted this.commit.isUncommitted
? `\${author} ${GlyphChars.Dash} \${id}\n\${ago} (\${date})` ? `\${author} ${GlyphChars.Dash} \${id}\n\${ago} (\${date})`
: `\${author}\${ (email)}\${" via "pullRequest} ${GlyphChars.Dash} \${id}${
: `\${author}\${ (email)} ${GlyphChars.Dash} \${id}${
this.unpublished ? ' (unpublished)' : '' this.unpublished ? ' (unpublished)' : ''
}\${ (tips)}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({ }\${ (tips)}\n\${ago} (\${date})\${\n\nmessage}${this.commit.getFormattedDiffStatus({
expand: true, expand: true,

Loading…
Cancel
Save