From 4d97e946b916ba2f846af433026412b145b859cd Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 27 Mar 2023 02:00:43 -0400 Subject: [PATCH] Simplies to one constant prefix --- src/constants.ts | 129 ++++++++++++++++++++++---------------------- src/storage.ts | 14 ++--- src/system/configuration.ts | 20 +++---- src/system/keyboard.ts | 10 ++-- 4 files changed, 85 insertions(+), 88 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 071d584..bd34b99 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,7 +1,4 @@ -export const commandPrefix = 'gitlens'; -export const configPrefix = 'gitlens'; -export const keyPrefix = 'gitlens:key'; -export const storagePrefix = 'gitlens'; +export const extensionPrefix = 'gitlens'; export const quickPickTitleMaxChars = 80; export const ImageMimetypes: Record = { @@ -56,35 +53,35 @@ export const enum CharCode { } export type Colors = - | 'gitlens.closedAutolinkedIssueIconColor' - | 'gitlens.closedPullRequestIconColor' - | 'gitlens.decorations.addedForegroundColor' - | 'gitlens.decorations.branchAheadForegroundColor' - | 'gitlens.decorations.branchBehindForegroundColor' - | 'gitlens.decorations.branchDivergedForegroundColor' - | 'gitlens.decorations.branchMissingUpstreamForegroundColor' - | 'gitlens.decorations.branchUpToDateForegroundColor' - | 'gitlens.decorations.branchUnpublishedForegroundColor' - | 'gitlens.decorations.copiedForegroundColor' - | 'gitlens.decorations.deletedForegroundColor' - | 'gitlens.decorations.ignoredForegroundColor' - | 'gitlens.decorations.modifiedForegroundColor' - | 'gitlens.decorations.renamedForegroundColor' - | 'gitlens.decorations.untrackedForegroundColor' - | 'gitlens.decorations.worktreeView.hasUncommittedChangesForegroundColor' - | 'gitlens.gutterBackgroundColor' - | 'gitlens.gutterForegroundColor' - | 'gitlens.gutterUncommittedForegroundColor' - | 'gitlens.lineHighlightBackgroundColor' - | 'gitlens.lineHighlightOverviewRulerColor' - | 'gitlens.mergedPullRequestIconColor' - | 'gitlens.openAutolinkedIssueIconColor' - | 'gitlens.openPullRequestIconColor' - | 'gitlens.trailingLineBackgroundColor' - | 'gitlens.trailingLineForegroundColor' - | 'gitlens.unpublishedChangesIconColor' - | 'gitlens.unpublishedCommitIconColor' - | 'gitlens.unpulledChangesIconColor'; + | `${typeof extensionPrefix}.closedAutolinkedIssueIconColor` + | `${typeof extensionPrefix}.closedPullRequestIconColor` + | `${typeof extensionPrefix}.decorations.addedForegroundColor` + | `${typeof extensionPrefix}.decorations.branchAheadForegroundColor` + | `${typeof extensionPrefix}.decorations.branchBehindForegroundColor` + | `${typeof extensionPrefix}.decorations.branchDivergedForegroundColor` + | `${typeof extensionPrefix}.decorations.branchMissingUpstreamForegroundColor` + | `${typeof extensionPrefix}.decorations.branchUpToDateForegroundColor` + | `${typeof extensionPrefix}.decorations.branchUnpublishedForegroundColor` + | `${typeof extensionPrefix}.decorations.copiedForegroundColor` + | `${typeof extensionPrefix}.decorations.deletedForegroundColor` + | `${typeof extensionPrefix}.decorations.ignoredForegroundColor` + | `${typeof extensionPrefix}.decorations.modifiedForegroundColor` + | `${typeof extensionPrefix}.decorations.renamedForegroundColor` + | `${typeof extensionPrefix}.decorations.untrackedForegroundColor` + | `${typeof extensionPrefix}.decorations.worktreeView.hasUncommittedChangesForegroundColor` + | `${typeof extensionPrefix}.gutterBackgroundColor` + | `${typeof extensionPrefix}.gutterForegroundColor` + | `${typeof extensionPrefix}.gutterUncommittedForegroundColor` + | `${typeof extensionPrefix}.lineHighlightBackgroundColor` + | `${typeof extensionPrefix}.lineHighlightOverviewRulerColor` + | `${typeof extensionPrefix}.mergedPullRequestIconColor` + | `${typeof extensionPrefix}.openAutolinkedIssueIconColor` + | `${typeof extensionPrefix}.openPullRequestIconColor` + | `${typeof extensionPrefix}.trailingLineBackgroundColor` + | `${typeof extensionPrefix}.trailingLineForegroundColor` + | `${typeof extensionPrefix}.unpublishedChangesIconColor` + | `${typeof extensionPrefix}.unpublishedCommitIconColor` + | `${typeof extensionPrefix}.unpulledChangesIconColor`; export type CoreColors = | 'editorOverviewRuler.addedForeground' @@ -308,39 +305,39 @@ export type WebviewIds = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus' export type WebviewViewIds = 'commitDetails' | 'graph' | 'home' | 'timeline'; export type ContextKeys = - | `gitlens:action:${string}` - | `${typeof keyPrefix}:${string}` - | `gitlens:webview:${WebviewIds | CustomEditorIds}:${'active' | 'focus' | 'inputFocus'}` - | `gitlens:webviewView:${WebviewViewIds}:${'active' | 'focus' | 'inputFocus'}` - | 'gitlens:activeFileStatus' - | 'gitlens:annotationStatus' - | 'gitlens:debugging' - | 'gitlens:disabledToggleCodeLens' - | 'gitlens:disabled' - | 'gitlens:enabled' - | 'gitlens:focus:focused' // TODO@eamodio do we need this? - | 'gitlens:hasConnectedRemotes' - | 'gitlens:hasRemotes' - | 'gitlens:hasRichRemotes' - | 'gitlens:hasVirtualFolders' - | 'gitlens:prerelease' - | 'gitlens:readonly' - | 'gitlens:untrusted' - | 'gitlens:views:canCompare' - | 'gitlens:views:canCompare:file' - | 'gitlens:views:commits:myCommitsOnly' - | 'gitlens:views:fileHistory:canPin' - | 'gitlens:views:fileHistory:cursorFollowing' - | 'gitlens:views:fileHistory:editorFollowing' - | 'gitlens:views:lineHistory:editorFollowing' - | 'gitlens:views:repositories:autoRefresh' - | 'gitlens:views:searchAndCompare:keepResults' - | 'gitlens:vsls' - | 'gitlens:plus' - | 'gitlens:plus:disallowedRepos' - | 'gitlens:plus:enabled' - | 'gitlens:plus:required' - | 'gitlens:plus:state'; + | `${typeof extensionPrefix}:action:${string}` + | `${typeof extensionPrefix}:key:${string}` + | `${typeof extensionPrefix}:webview:${WebviewIds | CustomEditorIds}:${'active' | 'focus' | 'inputFocus'}` + | `${typeof extensionPrefix}:webviewView:${WebviewViewIds}:${'active' | 'focus' | 'inputFocus'}` + | `${typeof extensionPrefix}:activeFileStatus` + | `${typeof extensionPrefix}:annotationStatus` + | `${typeof extensionPrefix}:debugging` + | `${typeof extensionPrefix}:disabledToggleCodeLens` + | `${typeof extensionPrefix}:disabled` + | `${typeof extensionPrefix}:enabled` + | `${typeof extensionPrefix}:focus:focused` // TODO@eamodio do we need this + | `${typeof extensionPrefix}:hasConnectedRemotes` + | `${typeof extensionPrefix}:hasRemotes` + | `${typeof extensionPrefix}:hasRichRemotes` + | `${typeof extensionPrefix}:hasVirtualFolders` + | `${typeof extensionPrefix}:prerelease` + | `${typeof extensionPrefix}:readonly` + | `${typeof extensionPrefix}:untrusted` + | `${typeof extensionPrefix}:views:canCompare` + | `${typeof extensionPrefix}:views:canCompare:file` + | `${typeof extensionPrefix}:views:commits:myCommitsOnly` + | `${typeof extensionPrefix}:views:fileHistory:canPin` + | `${typeof extensionPrefix}:views:fileHistory:cursorFollowing` + | `${typeof extensionPrefix}:views:fileHistory:editorFollowing` + | `${typeof extensionPrefix}:views:lineHistory:editorFollowing` + | `${typeof extensionPrefix}:views:repositories:autoRefresh` + | `${typeof extensionPrefix}:views:searchAndCompare:keepResults` + | `${typeof extensionPrefix}:vsls` + | `${typeof extensionPrefix}:plus` + | `${typeof extensionPrefix}:plus:disallowedRepos` + | `${typeof extensionPrefix}:plus:enabled` + | `${typeof extensionPrefix}:plus:required` + | `${typeof extensionPrefix}:plus:state`; export type CoreCommands = | 'cursorMove' diff --git a/src/storage.ts b/src/storage.ts index 6f81f50..8756e9f 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -1,7 +1,7 @@ import type { Disposable, Event, ExtensionContext, SecretStorageChangeEvent } from 'vscode'; import { EventEmitter } from 'vscode'; import type { ViewShowBranchComparison } from './config'; -import { storagePrefix } from './constants'; +import { extensionPrefix } from './constants'; import type { Environment } from './container'; import type { StoredSearchQuery } from './git/search'; import type { Subscription } from './subscription'; @@ -51,18 +51,18 @@ export class Storage implements Disposable { get(key: T, defaultValue: GlobalStorage[T]): GlobalStorage[T]; @debug({ logThreshold: 50 }) get(key: keyof (GlobalStorage & DeprecatedGlobalStorage), defaultValue?: unknown): unknown | undefined { - return this.context.globalState.get(`${storagePrefix}:${key}`, defaultValue); + return this.context.globalState.get(`${extensionPrefix}:${key}`, defaultValue); } @debug({ logThreshold: 250 }) async delete(key: keyof (GlobalStorage & DeprecatedGlobalStorage)): Promise { - await this.context.globalState.update(`${storagePrefix}:${key}`, undefined); + await this.context.globalState.update(`${extensionPrefix}:${key}`, undefined); this._onDidChange.fire({ key: key, workspace: false }); } @debug({ args: { 1: false }, logThreshold: 250 }) async store(key: T, value: GlobalStorage[T] | undefined): Promise { - await this.context.globalState.update(`${storagePrefix}:${key}`, value); + await this.context.globalState.update(`${extensionPrefix}:${key}`, value); this._onDidChange.fire({ key: key, workspace: false }); } @@ -90,18 +90,18 @@ export class Storage implements Disposable { key: keyof (WorkspaceStorage & DeprecatedWorkspaceStorage), defaultValue?: unknown, ): unknown | undefined { - return this.context.workspaceState.get(`${storagePrefix}:${key}`, defaultValue); + return this.context.workspaceState.get(`${extensionPrefix}:${key}`, defaultValue); } @debug({ logThreshold: 250 }) async deleteWorkspace(key: keyof (WorkspaceStorage & DeprecatedWorkspaceStorage)): Promise { - await this.context.workspaceState.update(`${storagePrefix}:${key}`, undefined); + await this.context.workspaceState.update(`${extensionPrefix}:${key}`, undefined); this._onDidChange.fire({ key: key, workspace: true }); } @debug({ args: { 1: false }, logThreshold: 250 }) async storeWorkspace(key: keyof WorkspaceStorage, value: unknown | undefined): Promise { - await this.context.workspaceState.update(`${storagePrefix}:${key}`, value); + await this.context.workspaceState.update(`${extensionPrefix}:${key}`, value); this._onDidChange.fire({ key: key, workspace: true }); } } diff --git a/src/system/configuration.ts b/src/system/configuration.ts index ac5eb1e..5584015 100644 --- a/src/system/configuration.ts +++ b/src/system/configuration.ts @@ -1,7 +1,7 @@ import type { ConfigurationChangeEvent, ConfigurationScope, Event, ExtensionContext } from 'vscode'; import { ConfigurationTarget, EventEmitter, workspace } from 'vscode'; import type { Config } from '../config'; -import { configPrefix } from '../constants'; +import { extensionPrefix } from '../constants'; import { areEqual } from './object'; interface ConfigurationOverrides { @@ -34,7 +34,7 @@ export class Configuration { } private onConfigurationChanged(e: ConfigurationChangeEvent) { - if (!e.affectsConfiguration(configPrefix)) { + if (!e.affectsConfiguration(extensionPrefix)) { this._onDidChangeOther.fire(e); return; @@ -78,13 +78,13 @@ export class Configuration { ): ConfigPathValue { const value = defaultValue === undefined - ? workspace.getConfiguration(configPrefix, scope).get>(section)! - : workspace.getConfiguration(configPrefix, scope).get>(section, defaultValue)!; + ? workspace.getConfiguration(extensionPrefix, scope).get>(section)! + : workspace.getConfiguration(extensionPrefix, scope).get>(section, defaultValue)!; return skipOverrides || this._overrides?.get == null ? value : this._overrides.get(section, value); } getAll(skipOverrides?: boolean): Config { - const config = workspace.getConfiguration().get(configPrefix)!; + const config = workspace.getConfiguration().get(extensionPrefix)!; return skipOverrides || this._overrides?.getAll == null ? config : this._overrides.getAll(config); } @@ -104,8 +104,8 @@ export class Configuration { if (e == null) return true; return Array.isArray(section) - ? section.some(s => e.affectsConfiguration(`${configPrefix}.${s}`, scope!)) - : e.affectsConfiguration(`${configPrefix}.${section}`, scope!); + ? section.some(s => e.affectsConfiguration(`${extensionPrefix}.${s}`, scope!)) + : e.affectsConfiguration(`${extensionPrefix}.${section}`, scope!); } changedAny( @@ -122,8 +122,8 @@ export class Configuration { inspect>(section: S, scope?: ConfigurationScope | null) { return workspace - .getConfiguration(configPrefix, scope) - .inspect(section === undefined ? configPrefix : section); + .getConfiguration(extensionPrefix, scope) + .inspect(section === undefined ? extensionPrefix : section); } inspectAny(section: S, scope?: ConfigurationScope | null) { @@ -288,7 +288,7 @@ export class Configuration { value: ConfigPathValue | undefined, target: ConfigurationTarget, ): Thenable { - return workspace.getConfiguration(configPrefix).update(section, value, target); + return workspace.getConfiguration(extensionPrefix).update(section, value, target); } updateAny( diff --git a/src/system/keyboard.ts b/src/system/keyboard.ts index c471cd6..4563c1c 100644 --- a/src/system/keyboard.ts +++ b/src/system/keyboard.ts @@ -1,5 +1,5 @@ import { Disposable } from 'vscode'; -import { commandPrefix, keyPrefix } from '../constants'; +import { extensionPrefix } from '../constants'; import { setContext } from '../context'; import { registerCommand } from './command'; import { log } from './decorators/log'; @@ -88,7 +88,7 @@ export class KeyboardScope implements Disposable { } mapping[key] = undefined; - await setContext(`${keyPrefix}:${key}`, false); + await setContext(`${extensionPrefix}:key:${key}`, false); } @log({ @@ -142,12 +142,12 @@ export class KeyboardScope implements Disposable { mapping[key] = command; if (!set) { - await setContext(`${keyPrefix}:${key}`, true); + await setContext(`${extensionPrefix}:key:${key}`, true); } } private async updateKeyCommandsContext(mapping: KeyMapping) { - await Promise.all(keys.map(key => setContext(`${keyPrefix}:${key}`, Boolean(mapping?.[key])))); + await Promise.all(keys.map(key => setContext(`${extensionPrefix}:key:${key}`, Boolean(mapping?.[key])))); } } @@ -156,7 +156,7 @@ export class Keyboard implements Disposable { constructor() { const subscriptions = keys.map(key => - registerCommand(`${commandPrefix}.key.${key}`, () => this.execute(key), this), + registerCommand(`${extensionPrefix}.key.${key}`, () => this.execute(key), this), ); this._disposable = Disposable.from(...subscriptions); }