From 83ad75e41dd003760bb8978ddcf9128aa9f81d0b Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sat, 7 Nov 2020 02:44:24 -0500 Subject: [PATCH] Updates view format settings --- README.md | 26 ++++------ package.json | 104 +++++++++++++++++++++---------------- src/config.ts | 35 ++++++------- src/extension.ts | 63 +++++----------------- src/views/nodes/commitFileNode.ts | 32 +++++------- src/views/nodes/commitNode.ts | 4 +- src/views/nodes/resultsFileNode.ts | 5 +- src/views/nodes/stashFileNode.ts | 18 ++----- src/views/nodes/stashNode.ts | 4 +- src/views/nodes/statusFileNode.ts | 4 +- 10 files changed, 123 insertions(+), 172 deletions(-) diff --git a/README.md b/README.md index 64ebd88..acd5709 100644 --- a/README.md +++ b/README.md @@ -752,21 +752,17 @@ GitLens is highly customizable and provides many configuration settings to allow ## View Settings [#](#view-settings- 'View Settings') -| Name | Description | -| ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `gitlens.views.commitFileFormat` | Specifies the format of a committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | -| `gitlens.views.commitFileDescriptionFormat` | Specifies the description format of a committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | -| `gitlens.views.commitFormat` | Specifies the format of committed changes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | -| `gitlens.views.commitDescriptionFormat` | Specifies the description format of committed changes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | -| `gitlens.views.defaultItemLimit` | Specifies the default number of items to show in a view list. Use 0 to specify no limit | -| `gitlens.views.pageItemLimit` | Specifies the number of items to show in a each page when paginating a view list. Use 0 to specify no limit | -| `gitlens.views.showRelativeDateMarkers` | Specifies whether to show relative date markers (_Less than a week ago_, _Over a week ago_, _Over a month ago_, etc) on revision (commit) histories in the views | -| `gitlens.views.stashFileFormat` | Specifies the format of a stashed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | -| `gitlens.views.stashFileDescriptionFormat` | Specifies the description format of a stashed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | -| `gitlens.views.stashFormat` | Specifies the format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | -| `gitlens.views.stashDescriptionFormat` | Specifies the description format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | -| `gitlens.views.statusFileFormat` | Specifies the format of the status of a working or committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | -| `gitlens.views.statusFileDescriptionFormat` | Specifies the description format of the status of a working or committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | +| Name | Description | +| ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `gitlens.views.defaultItemLimit` | Specifies the default number of items to show in a view list. Use 0 to specify no limit | +| `gitlens.views.formats.commits.label` | Specifies the format of commits in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | +| `gitlens.views.formats.commits.description` | Specifies the description format of commits in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | +| `gitlens.views.formats.files.label` | Specifies the format of a file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | +| `gitlens.views.formats.files.description` | Specifies the description format of a file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs | +| `gitlens.views.formats.stashes.label` | Specifies the format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | +| `gitlens.views.formats.stashes.description` | Specifies the description format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs | +| `gitlens.views.pageItemLimit` | Specifies the number of items to show in a each page when paginating a view list. Use 0 to specify no limit | +| `gitlens.views.showRelativeDateMarkers` | Specifies whether to show relative date markers (_Less than a week ago_, _Over a week ago_, _Over a month ago_, etc) on revision (commit) histories in the views | ## Commits View Settings [#](#commits-view-settings- 'Commits View Settings') diff --git a/package.json b/package.json index b586309..818c986 100644 --- a/package.json +++ b/package.json @@ -1640,28 +1640,20 @@ "scope": "window" }, "gitlens.views.commitFileFormat": { - "type": "string", - "default": "${file}", - "markdownDescription": "Specifies the format of a committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.files.label` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.files.label#` instead" }, "gitlens.views.commitFileDescriptionFormat": { - "type": "string", - "default": "${directory}${ ← originalPath}", - "markdownDescription": "Specifies the description format of a committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.files.description` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.files.description#` instead" }, "gitlens.views.commitFormat": { - "type": "string", - "default": "${❰ tips ❱➤ }${message}", - "markdownDescription": "Specifies the format of committed changes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.commits.label` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.commits.files.label#` instead" }, "gitlens.views.commitDescriptionFormat": { - "type": "string", - "default": "${author, }${agoOrDate}", - "markdownDescription": "Specifies the description format of committed changes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.commits.description` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.commits.description#` instead" }, "gitlens.views.commits.avatars": { "type": "boolean", @@ -1790,10 +1782,40 @@ "markdownDescription": "Specifies the default number of items to show in a view list. Use 0 to specify no limit", "scope": "window" }, - "gitlens.views.pageItemLimit": { - "type": "number", - "default": 20, - "markdownDescription": "Specifies the number of items to show in a each page when paginating a view list. Use 0 to specify no limit", + "gitlens.views.formats.commits.label": { + "type": "string", + "default": "${❰ tips ❱➤ }${message}", + "markdownDescription": "Specifies the format of commits in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", + "scope": "window" + }, + "gitlens.views.formats.commits.description": { + "type": "string", + "default": "${author, }${agoOrDate}", + "markdownDescription": "Specifies the description format of commits in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", + "scope": "window" + }, + "gitlens.views.formats.files.label": { + "type": "string", + "default": "${working }${file}", + "markdownDescription": "Specifies the format of a file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", + "scope": "window" + }, + "gitlens.views.formats.files.description": { + "type": "string", + "default": "${directory}${ ← originalPath}", + "markdownDescription": "Specifies the description format of a file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", + "scope": "window" + }, + "gitlens.views.formats.stashes.label": { + "type": "string", + "default": "${message}", + "markdownDescription": "Specifies the format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", + "scope": "window" + }, + "gitlens.views.formats.stashes.description": { + "type": "string", + "default": "${agoOrDate}", + "markdownDescription": "Specifies the description format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", "scope": "window" }, "gitlens.views.fileHistory.avatars": { @@ -1814,6 +1836,12 @@ "markdownDescription": "Specifies whether to show the _Line History_ view", "scope": "window" }, + "gitlens.views.pageItemLimit": { + "type": "number", + "default": 20, + "markdownDescription": "Specifies the number of items to show in a each page when paginating a view list. Use 0 to specify no limit", + "scope": "window" + }, "gitlens.views.remotes.avatars": { "type": "boolean", "default": true, @@ -2052,28 +2080,20 @@ "scope": "window" }, "gitlens.views.stashFileFormat": { - "type": "string", - "default": "${file}", - "markdownDescription": "Specifies the format of a stashed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.files.label` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.files.label#` instead" }, "gitlens.views.stashFileDescriptionFormat": { - "type": "string", - "default": "${directory}${ ← originalPath}", - "markdownDescription": "Specifies the description format of a stashed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.files.description` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.files.description#` instead" }, "gitlens.views.stashFormat": { - "type": "string", - "default": "${message}", - "markdownDescription": "Specifies the format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.stashes.label` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.stashes.files.label#` instead" }, "gitlens.views.stashDescriptionFormat": { - "type": "string", - "default": "${changes • }${agoOrDate}", - "markdownDescription": "Specifies the description format of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.stashes.description` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.stashes.description#` instead" }, "gitlens.views.stashes.files.compact": { "type": "boolean", @@ -2104,16 +2124,12 @@ "scope": "window" }, "gitlens.views.statusFileFormat": { - "type": "string", - "default": "${working }${file}", - "markdownDescription": "Specifies the format of the status of a working or committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.files.label` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.files.label#` instead" }, "gitlens.views.statusFileDescriptionFormat": { - "type": "string", - "default": "${directory}${ ← originalPath}", - "markdownDescription": "Specifies the description format of the status of a working or committed file in the views. See [_File Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#file-tokens) in the GitLens docs", - "scope": "window" + "deprecationMessage": "Deprecated. Use `gitlens.views.formats.files.description` instead", + "markdownDeprecationMessage": "Depreciated: Use `#gitlens.views.formats.files.description#` instead" }, "gitlens.views.tags.avatars": { "type": "boolean", diff --git a/src/config.ts b/src/config.ts index d1d5a44..87400e6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -400,35 +400,30 @@ export interface RemotesUrlsConfig { } export interface ViewsCommonConfig { - commitFileDescriptionFormat: string; - commitFileFormat: string; - commitDescriptionFormat: string; - commitFormat: string; defaultItemLimit: number; + formats: { + commits: { + label: string; + description: string; + }; + files: { + label: string; + description: string; + }; + stashes: { + label: string; + description: string; + }; + }; pageItemLimit: number; showRelativeDateMarkers: boolean; - stashFileDescriptionFormat: string; - stashFileFormat: string; - stashDescriptionFormat: string; - stashFormat: string; - statusFileDescriptionFormat: string; - statusFileFormat: string; } export const viewsCommonConfigKeys: (keyof ViewsCommonConfig)[] = [ - 'commitFileDescriptionFormat', - 'commitFileFormat', - 'commitDescriptionFormat', - 'commitFormat', 'defaultItemLimit', + 'formats', 'pageItemLimit', 'showRelativeDateMarkers', - 'stashFileDescriptionFormat', - 'stashFileFormat', - 'stashDescriptionFormat', - 'stashFormat', - 'statusFileDescriptionFormat', - 'statusFileFormat', ]; interface ViewsConfigs { diff --git a/src/extension.ts b/src/extension.ts index ed095da..1959b72 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,7 +1,6 @@ 'use strict'; import { commands, ExtensionContext, extensions, window, workspace } from 'vscode'; import { Commands, registerCommands } from './commands'; -import { ViewShowBranchComparison } from './config'; import { configuration, Configuration } from './configuration'; import { ContextKeys, extensionQualifiedId, GlobalState, GlyphChars, setContext } from './constants'; import { Container } from './container'; @@ -10,7 +9,7 @@ import { GitService } from './git/gitService'; import { GitUri } from './git/gitUri'; import { Logger } from './logger'; import { Messages } from './messages'; -import { Strings, Versions } from './system'; +import { Strings } from './system'; import { ViewNode } from './views/nodes'; export async function activate(context: ExtensionContext) { @@ -71,7 +70,7 @@ export async function activate(context: ExtensionContext) { const cfg = configuration.get(); - await migrateSettings(context, previousVersion); + // await migrateSettings(context, previousVersion); try { await GitService.initialize(); @@ -115,56 +114,18 @@ export async function setEnabled(enabled: boolean): Promise { await Promise.all([setContext(ContextKeys.Enabled, enabled), setContext(ContextKeys.Disabled, !enabled)]); } -async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) { - if (previousVersion === undefined) return; +// async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) { +// if (previousVersion === undefined) return; - const previous = Versions.fromString(previousVersion); +// const previous = Versions.fromString(previousVersion); - try { - if (Versions.compare(previous, Versions.from(9, 8, 5)) !== 1) { - const value = configuration.get('views', 'commitFormat'); - if (!/\btips\b/.test(value)) { - await configuration.updateEffective('views', 'commitFormat', `\${❰ tips ❱➤ }${value}`); - } - } else if (Versions.compare(previous, Versions.from(9, 8, 2)) !== 1) { - const name = configuration.name('views', 'repositories', 'showBranchComparison'); - await configuration.migrate(name, 'views', 'repositories', 'showBranchComparison', { - migrationFn: (v: boolean) => (v === false ? false : ViewShowBranchComparison.Working), - }); - } else if (Versions.compare(previous, Versions.from(9, 6, 3)) !== 1) { - const formatMigrationFn = (v: string) => { - if (v == null || v.length === 0) return v; - - return ( - v - // eslint-disable-next-line no-template-curly-in-string - .replace(/\$\{authorAgo\}/g, '${author}, ${ago}') - // eslint-disable-next-line no-template-curly-in-string - .replace(/\$\{authorAgoOrDate\}/g, '${author}, ${agoOrDate}') - ); - }; - - await Promise.all( - [ - configuration.name('blame', 'format'), - configuration.name('currentLine', 'format'), - configuration.name('hovers', 'detailsMarkdownFormat'), - configuration.name('statusBar', 'format'), - configuration.name('views', 'commitFormat'), - configuration.name('views', 'commitDescriptionFormat'), - configuration.name('views', 'stashFormat'), - configuration.name('views', 'stashDescriptionFormat'), - ].map(s => - configuration.migrate(s, s as any, { - migrationFn: formatMigrationFn, - }), - ), - ); - } - } catch (ex) { - Logger.error(ex, 'migrateSettings'); - } -} +// try { +// if (Versions.compare(previous, Versions.from(11, 0, 0)) !== 1) { +// } +// } catch (ex) { +// Logger.error(ex, 'migrateSettings'); +// } +// } function notifyOnUnsupportedGitVersion(version: string) { if (GitService.compareGitVersion('2.7.2') !== -1) return; diff --git a/src/views/nodes/commitFileNode.ts b/src/views/nodes/commitFileNode.ts index 75eff77..18e0514 100644 --- a/src/views/nodes/commitFileNode.ts +++ b/src/views/nodes/commitFileNode.ts @@ -121,11 +121,11 @@ export class CommitFileNode extends ViewRefFileNode { private get description() { return this._options.displayAsCommit - ? CommitFormatter.fromTemplate(this.getCommitDescriptionTemplate(), this.commit, { + ? CommitFormatter.fromTemplate(this.getDescriptionFormat(), this.commit, { dateFormat: Container.config.defaultDateFormat, messageTruncateAtNewLine: true, }) - : StatusFileFormatter.fromTemplate(this.getCommitFileDescriptionTemplate(), this.file, { + : StatusFileFormatter.fromTemplate(this.view.config.formats.files.description, this.file, { relativePath: this.relativePath, }); } @@ -142,11 +142,11 @@ export class CommitFileNode extends ViewRefFileNode { get label() { if (this._label === undefined) { this._label = this._options.displayAsCommit - ? CommitFormatter.fromTemplate(this.getCommitTemplate(), this.commit, { + ? CommitFormatter.fromTemplate(this.getLabelFormat(), this.commit, { dateFormat: Container.config.defaultDateFormat, messageTruncateAtNewLine: true, }) - : StatusFileFormatter.fromTemplate(this.getCommitFileTemplate(), this.file, { + : StatusFileFormatter.fromTemplate(this.view.config.formats.files.label, this.file, { relativePath: this.relativePath, }); } @@ -192,22 +192,6 @@ export class CommitFileNode extends ViewRefFileNode { ); } - protected getCommitTemplate() { - return this.view.config.commitFormat; - } - - protected getCommitDescriptionTemplate() { - return this.view.config.commitDescriptionFormat; - } - - protected getCommitFileTemplate() { - return this.view.config.commitFileFormat; - } - - protected getCommitFileDescriptionTemplate() { - return this.view.config.commitFileDescriptionFormat; - } - getCommand(): Command | undefined { let line; if (this.commit.line !== undefined) { @@ -231,4 +215,12 @@ export class CommitFileNode extends ViewRefFileNode { arguments: [undefined, commandArgs], }; } + + protected getLabelFormat() { + return this.view.config.formats.commits.label; + } + + protected getDescriptionFormat() { + return this.view.config.formats.commits.description; + } } diff --git a/src/views/nodes/commitNode.ts b/src/views/nodes/commitNode.ts index 10575dc..24c177d 100644 --- a/src/views/nodes/commitNode.ts +++ b/src/views/nodes/commitNode.ts @@ -99,7 +99,7 @@ export class CommitNode extends ViewRefNode { - const label = CommitFormatter.fromTemplate(this.view.config.commitFormat, this.commit, { + const label = CommitFormatter.fromTemplate(this.view.config.formats.commits.label, this.commit, { dateFormat: Container.config.defaultDateFormat, getBranchAndTagTips: (sha: string) => this.getBranchAndTagTips?.(sha, true), messageTruncateAtNewLine: true, @@ -114,7 +114,7 @@ export class CommitNode extends ViewRefNode { getTreeItem(): TreeItem { const item = new TreeItem( - CommitFormatter.fromTemplate(this.view.config.stashFormat, this.commit, { + CommitFormatter.fromTemplate(this.view.config.formats.stashes.label, this.commit, { messageTruncateAtNewLine: true, dateFormat: Container.config.defaultDateFormat, }), TreeItemCollapsibleState.Collapsed, ); item.id = this.id; - item.description = CommitFormatter.fromTemplate(this.view.config.stashDescriptionFormat, this.commit, { + item.description = CommitFormatter.fromTemplate(this.view.config.formats.stashes.description, this.commit, { messageTruncateAtNewLine: true, dateFormat: Container.config.defaultDateFormat, }); diff --git a/src/views/nodes/statusFileNode.ts b/src/views/nodes/statusFileNode.ts index cdc0c07..d625d29 100644 --- a/src/views/nodes/statusFileNode.ts +++ b/src/views/nodes/statusFileNode.ts @@ -137,7 +137,7 @@ export class StatusFileNode extends ViewNode { get description() { if (this._description == null) { this._description = StatusFileFormatter.fromTemplate( - this.view.config.statusFileDescriptionFormat, + this.view.config.formats.files.description, { ...this.file, commit: this.commit, @@ -162,7 +162,7 @@ export class StatusFileNode extends ViewNode { get label() { if (this._label == null) { this._label = StatusFileFormatter.fromTemplate( - this.view.config.statusFileFormat, + this.view.config.formats.files.label, { ...this.file, commit: this.commit,