From 8136c4c275d68ead3db48f36330f16785be2d302 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Sun, 11 Jun 2023 12:48:08 -0400 Subject: [PATCH] Renames constants --- src/commands/resetViewsLayout.ts | 4 ++-- src/constants.ts | 40 +++++++++++++++++++++----------------- src/eventBus.ts | 8 ++++---- src/system/webview.ts | 6 +++--- src/views/viewBase.ts | 4 ++-- src/webviews/webviewController.ts | 13 ++++++++----- src/webviews/webviewsController.ts | 14 ++++++------- 7 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/commands/resetViewsLayout.ts b/src/commands/resetViewsLayout.ts index 7c22a69..5d3f6ca 100644 --- a/src/commands/resetViewsLayout.ts +++ b/src/commands/resetViewsLayout.ts @@ -1,4 +1,4 @@ -import type { QualifiedViewIds } from '../constants'; +import type { ViewIds } from '../constants'; import { Commands, viewIdsByDefaultContainerId } from '../constants'; import type { Container } from '../container'; import { command, executeCoreCommand } from '../system/command'; @@ -19,7 +19,7 @@ export class ResetViewsLayoutCommand extends Command { for (const [containerId, viewIds] of viewIdsByDefaultContainerId) { try { void (await executeCoreCommand('vscode.moveViews', { - viewIds: viewIds.map(v => `gitlens.views.${v}`), + viewIds: viewIds.map(v => `gitlens.views.${v}`), destinationId: containerId, })); } catch {} diff --git a/src/constants.ts b/src/constants.ts index a2d7ce5..59aa23c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -314,8 +314,10 @@ export const enum Commands { Deprecated_ShowFileHistoryInView = 'gitlens.showFileHistoryInView', } -export type CustomEditorIds = 'rebase'; -export type TreeViewIds = +export type CustomEditorTypes = 'rebase'; +export type CustomEditorIds = `gitlens.${CustomEditorTypes}`; + +export type TreeViewTypes = | 'branches' | 'commits' | 'contributors' @@ -328,19 +330,24 @@ export type TreeViewIds = | 'tags' | 'workspaces' | 'worktrees'; -export type WebviewIds = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus'; -export type WebviewViewIds = 'account' | 'commitDetails' | 'graph' | 'graphDetails' | 'home' | 'timeline'; +export type TreeViewIds = `gitlens.views.${TreeViewTypes}`; + +export type WebviewTypes = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus'; +export type WebviewIds = `gitlens.views.${WebviewTypes}`; + +export type WebviewViewTypes = 'account' | 'commitDetails' | 'graph' | 'graphDetails' | 'home' | 'timeline'; +export type WebviewViewIds = `gitlens.views.${WebviewViewTypes}`; +export type ViewTypes = TreeViewTypes | WebviewViewTypes; export type ViewIds = TreeViewIds | WebviewViewIds; -export type QualifiedViewIds = `gitlens.views.${ViewIds}`; -export type ViewContainerIds = 'gitlens' | 'gitlensInspect' | 'gitlensPanel'; -export type QualifiedViewContainerIds = `workbench.view.extension.${ViewContainerIds}`; +export type ViewContainerTypes = 'gitlens' | 'gitlensInspect' | 'gitlensPanel'; +export type ViewContainerIds = `workbench.view.extension.${ViewContainerTypes}`; -export type CoreViewContainerIds = 'scm'; -export type QualifiedCoreViewContainerIds = `workbench.view.${CoreViewContainerIds}`; +export type CoreViewContainerTypes = 'scm'; +export type CoreViewContainerIds = `workbench.view.${CoreViewContainerTypes}`; -// export const viewIds: ViewIds[] = [ +// export const viewTypes: ViewTypes[] = [ // 'account', // 'branches', // 'commits', @@ -361,10 +368,7 @@ export type QualifiedCoreViewContainerIds = `workbench.view.${CoreViewContainerI // 'worktrees', // ]; -export const viewIdsByDefaultContainerId = new Map< - QualifiedViewContainerIds | QualifiedCoreViewContainerIds, - ViewIds[] ->([ +export const viewIdsByDefaultContainerId = new Map([ [ 'workbench.view.scm', ['branches', 'commits', 'remotes', 'repositories', 'stashes', 'tags', 'worktrees', 'contributors'], @@ -380,12 +384,12 @@ export const viewIdsByDefaultContainerId = new Map< export type ContextKeys = | `${typeof extensionPrefix}:action:${string}` | `${typeof extensionPrefix}:key:${Keys}` - | `${typeof extensionPrefix}:webview:${WebviewIds | CustomEditorIds}:${ + | `${typeof extensionPrefix}:webview:${WebviewTypes | CustomEditorTypes}:${ | 'active' | 'focus' | 'inputFocus' | 'visible'}` - | `${typeof extensionPrefix}:webviewView:${WebviewViewIds}:${'active' | 'focus' | 'inputFocus' | 'visible'}` + | `${typeof extensionPrefix}:webviewView:${WebviewViewTypes}:${'active' | 'focus' | 'inputFocus' | 'visible'}` | `${typeof extensionPrefix}:activeFileStatus` | `${typeof extensionPrefix}:annotationStatus` | `${typeof extensionPrefix}:debugging` @@ -446,8 +450,8 @@ export type CoreCommands = | 'workbench.files.action.focusFilesExplorer' | 'workbench.view.explorer' | 'workbench.view.scm' - | `${QualifiedViewContainerIds | QualifiedCoreViewContainerIds}.resetViewContainerLocation` - | `${QualifiedViewIds}.${'focus' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`; + | `${ViewContainerIds | CoreViewContainerIds}.resetViewContainerLocation` + | `${ViewIds}.${'focus' | 'removeView' | 'resetViewLocation' | 'toggleVisibility'}`; export type CoreGitCommands = | 'git.fetch' diff --git a/src/eventBus.ts b/src/eventBus.ts index 140daa9..379d053 100644 --- a/src/eventBus.ts +++ b/src/eventBus.ts @@ -1,7 +1,7 @@ import type { Disposable, Uri } from 'vscode'; import { EventEmitter } from 'vscode'; import type { ViewsConfigKeys } from './config'; -import type { CustomEditorIds, WebviewIds, WebviewViewIds } from './constants'; +import type { CustomEditorTypes, WebviewTypes, WebviewViewTypes } from './constants'; import type { GitCaches } from './git/gitProvider'; import type { GitCommit } from './git/models/commit'; import type { GitRevisionReference } from './git/models/reference'; @@ -40,9 +40,9 @@ interface EventBusEvent { } export type EventBusSource = - | `gitlens.${CustomEditorIds}` - | `gitlens.${WebviewIds}` - | `gitlens.views.${WebviewViewIds}` + | `gitlens.${CustomEditorTypes}` + | `gitlens.${WebviewTypes}` + | `gitlens.views.${WebviewViewTypes}` | `gitlens.views.${ViewsConfigKeys}`; export type EventBusOptions = { diff --git a/src/system/webview.ts b/src/system/webview.ts index 8f95d8d..0755534 100644 --- a/src/system/webview.ts +++ b/src/system/webview.ts @@ -1,7 +1,7 @@ -import type { WebviewIds, WebviewViewIds } from '../constants'; +import type { WebviewTypes, WebviewViewTypes } from '../constants'; export interface WebviewItemContext { - webview?: `gitlens.${WebviewIds}` | `gitlens.views.${WebviewViewIds}`; + webview?: `gitlens.${WebviewTypes}` | `gitlens.views.${WebviewViewTypes}`; webviewItem: string; webviewItemValue: TValue; } @@ -15,7 +15,7 @@ export function isWebviewItemContext( } export interface WebviewItemGroupContext { - webview?: `gitlens.${WebviewIds}` | `gitlens.views.${WebviewViewIds}`; + webview?: `gitlens.${WebviewTypes}` | `gitlens.views.${WebviewViewTypes}`; webviewItemGroup: string; webviewItemGroupValue: TValue; } diff --git a/src/views/viewBase.ts b/src/views/viewBase.ts index c5408ed..7e5a393 100644 --- a/src/views/viewBase.ts +++ b/src/views/viewBase.ts @@ -28,7 +28,7 @@ import type { WorktreesViewConfig, } from '../config'; import { viewsCommonConfigKeys, viewsConfigKeys } from '../config'; -import type { TreeViewIds } from '../constants'; +import type { TreeViewTypes } from '../constants'; import type { Container } from '../container'; import { executeCoreCommand } from '../system/command'; import { configuration } from '../system/configuration'; @@ -138,7 +138,7 @@ export abstract class ViewBase< constructor( public readonly container: Container, - public readonly id: `gitlens.views.${TreeViewIds}`, + public readonly id: `gitlens.views.${TreeViewTypes}`, public readonly name: string, private readonly trackingFeature: TrackedUsageFeatures, ) { diff --git a/src/webviews/webviewController.ts b/src/webviews/webviewController.ts index 97a1d2d..4779460 100644 --- a/src/webviews/webviewController.ts +++ b/src/webviews/webviewController.ts @@ -1,7 +1,7 @@ import type { ViewBadge, Webview, WebviewPanel, WebviewView, WindowState } from 'vscode'; import { Disposable, EventEmitter, Uri, ViewColumn, window, workspace } from 'vscode'; import { getNonce } from '@env/crypto'; -import type { Commands, CustomEditorIds, WebviewIds, WebviewViewIds } from '../constants'; +import type { Commands, CustomEditorTypes, WebviewTypes, WebviewViewTypes } from '../constants'; import type { Container } from '../container'; import { executeCommand, executeCoreCommand } from '../system/command'; import { setContext } from '../system/context'; @@ -585,18 +585,18 @@ export function replaceWebviewHtmlTokens( } export function resetContextKeys( - contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`, + contextKeyPrefix: `gitlens:webview:${WebviewTypes | CustomEditorTypes}` | `gitlens:webviewView:${WebviewViewTypes}`, ): void { void setContext(`${contextKeyPrefix}:visible`, false); void setContext(`${contextKeyPrefix}:inputFocus`, false); void setContext(`${contextKeyPrefix}:focus`, false); if (contextKeyPrefix.startsWith('gitlens:webview:')) { - void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, false); + void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewTypes | CustomEditorTypes}`}:active`, false); } } export function setContextKeys( - contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`, + contextKeyPrefix: `gitlens:webview:${WebviewTypes | CustomEditorTypes}` | `gitlens:webviewView:${WebviewViewTypes}`, active?: boolean, focus?: boolean, inputFocus?: boolean, @@ -604,7 +604,10 @@ export function setContextKeys( void setContext(`${contextKeyPrefix}:visible`, true); if (contextKeyPrefix.startsWith('gitlens:webview:')) { if (active != null) { - void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, active); + void setContext( + `${contextKeyPrefix as `gitlens:webview:${WebviewTypes | CustomEditorTypes}`}:active`, + active, + ); if (!active) { focus = false; diff --git a/src/webviews/webviewsController.ts b/src/webviews/webviewsController.ts index 793a650..d10b0a1 100644 --- a/src/webviews/webviewsController.ts +++ b/src/webviews/webviewsController.ts @@ -7,7 +7,7 @@ import type { WebviewViewResolveContext, } from 'vscode'; import { Disposable, Uri, ViewColumn, window } from 'vscode'; -import type { Commands, WebviewIds, WebviewViewIds } from '../constants'; +import type { Commands, WebviewTypes, WebviewViewTypes } from '../constants'; import type { Container } from '../container'; import { ensurePlusFeaturesEnabled } from '../plus/subscription/utils'; import { executeCoreCommand, registerCommand } from '../system/command'; @@ -19,11 +19,11 @@ import type { WebviewProvider } from './webviewController'; import { WebviewController } from './webviewController'; export interface WebviewPanelDescriptor { - id: `gitlens.${WebviewIds}`; + id: `gitlens.${WebviewTypes}`; readonly fileName: string; readonly iconPath: string; readonly title: string; - readonly contextKeyPrefix: `gitlens:webview:${WebviewIds}`; + readonly contextKeyPrefix: `gitlens:webview:${WebviewTypes}`; readonly trackingFeature: TrackedUsageFeatures; readonly plusFeature: boolean; readonly column?: ViewColumn; @@ -37,7 +37,7 @@ interface WebviewPanelRegistration { } export interface WebviewPanelProxy extends Disposable { - readonly id: `gitlens.${WebviewIds}`; + readonly id: `gitlens.${WebviewTypes}`; readonly ready: boolean; readonly visible: boolean; close(): void; @@ -46,10 +46,10 @@ export interface WebviewPanelProxy extends Disposable { } export interface WebviewViewDescriptor { - id: `gitlens.views.${WebviewViewIds}`; + id: `gitlens.views.${WebviewViewTypes}`; readonly fileName: string; readonly title: string; - readonly contextKeyPrefix: `gitlens:webviewView:${WebviewViewIds}`; + readonly contextKeyPrefix: `gitlens:webviewView:${WebviewViewTypes}`; readonly trackingFeature: TrackedUsageFeatures; readonly plusFeature: boolean; readonly webviewOptions?: WebviewOptions; @@ -65,7 +65,7 @@ interface WebviewViewRegistration { } export interface WebviewViewProxy extends Disposable { - readonly id: `gitlens.views.${WebviewViewIds}`; + readonly id: `gitlens.views.${WebviewViewTypes}`; readonly ready: boolean; readonly visible: boolean; refresh(force?: boolean): Promise;