ソースを参照

Simplies to one constant prefix

main
Eric Amodio 1年前
コミット
4d97e946b9
4個のファイルの変更85行の追加88行の削除
  1. +63
    -66
      src/constants.ts
  2. +7
    -7
      src/storage.ts
  3. +10
    -10
      src/system/configuration.ts
  4. +5
    -5
      src/system/keyboard.ts

+ 63
- 66
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<string, string> = {
@ -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'

+ 7
- 7
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<T extends keyof GlobalStorage>(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<void> {
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<T extends keyof GlobalStorage>(key: T, value: GlobalStorage[T] | undefined): Promise<void> {
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<void> {
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<void> {
await this.context.workspaceState.update(`${storagePrefix}:${key}`, value);
await this.context.workspaceState.update(`${extensionPrefix}:${key}`, value);
this._onDidChange.fire({ key: key, workspace: true });
}
}

+ 10
- 10
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<S> {
const value =
defaultValue === undefined
? workspace.getConfiguration(configPrefix, scope).get<ConfigPathValue<S>>(section)!
: workspace.getConfiguration(configPrefix, scope).get<ConfigPathValue<S>>(section, defaultValue)!;
? workspace.getConfiguration(extensionPrefix, scope).get<ConfigPathValue<S>>(section)!
: workspace.getConfiguration(extensionPrefix, scope).get<ConfigPathValue<S>>(section, defaultValue)!;
return skipOverrides || this._overrides?.get == null ? value : this._overrides.get<S>(section, value);
}
getAll(skipOverrides?: boolean): Config {
const config = workspace.getConfiguration().get<Config>(configPrefix)!;
const config = workspace.getConfiguration().get<Config>(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<S extends string>(
@ -122,8 +122,8 @@ export class Configuration {
inspect<S extends ConfigPath, V extends ConfigPathValue<S>>(section: S, scope?: ConfigurationScope | null) {
return workspace
.getConfiguration(configPrefix, scope)
.inspect<V>(section === undefined ? configPrefix : section);
.getConfiguration(extensionPrefix, scope)
.inspect<V>(section === undefined ? extensionPrefix : section);
}
inspectAny<S extends string, T>(section: S, scope?: ConfigurationScope | null) {
@ -288,7 +288,7 @@ export class Configuration {
value: ConfigPathValue<S> | undefined,
target: ConfigurationTarget,
): Thenable<void> {
return workspace.getConfiguration(configPrefix).update(section, value, target);
return workspace.getConfiguration(extensionPrefix).update(section, value, target);
}
updateAny<S extends string, T>(

+ 5
- 5
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);
}

読み込み中…
キャンセル
保存