From 470a031dddeca21abe20a64fe16158e872695805 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 27 Mar 2023 01:12:05 -0400 Subject: [PATCH] Replaces enums with types --- src/annotations/annotationProvider.ts | 5 +- src/annotations/fileAnnotationController.ts | 12 ++-- src/api/actionRunners.ts | 4 +- src/avatars.ts | 3 +- src/codelens/codeLensController.ts | 3 +- src/commands/git/search.ts | 4 +- src/commands/git/stash.ts | 8 +-- src/commands/gitCommands.utils.ts | 6 +- src/constants.ts | 74 +++++++++++----------- src/context.ts | 30 ++------- src/eventBus.ts | 2 +- src/extension.ts | 12 ++-- src/git/gitProviderService.ts | 12 ++-- src/plus/github/githubGitProvider.ts | 4 +- src/plus/subscription/subscriptionService.ts | 12 ++-- src/plus/subscription/utils.ts | 3 +- src/plus/webviews/focus/focusWebview.ts | 8 +-- src/plus/webviews/focus/registration.ts | 4 +- src/plus/webviews/graph/graphWebview.ts | 10 +-- src/plus/webviews/graph/registration.ts | 6 +- src/plus/webviews/graph/statusbar.ts | 6 +- src/plus/webviews/timeline/registration.ts | 6 +- src/plus/webviews/timeline/timelineWebview.ts | 2 +- src/system/keyboard.ts | 8 +-- src/trackers/documentTracker.ts | 2 +- src/trackers/trackedDocument.ts | 5 +- src/views/commitsView.ts | 4 +- src/views/fileHistoryView.ts | 10 +-- src/views/lineHistoryView.ts | 6 +- src/views/nodes/branchNode.ts | 4 +- src/views/nodes/commitNode.ts | 4 +- src/views/nodes/fileHistoryTrackerNode.ts | 2 +- src/views/nodes/lineHistoryTrackerNode.ts | 3 +- src/views/nodes/worktreeNode.ts | 4 +- src/views/repositoriesView.ts | 4 +- src/views/searchAndCompareView.ts | 10 +-- src/views/viewCommands.ts | 6 +- src/vsls/vsls.ts | 14 ++-- src/webviews/commitDetails/commitDetailsWebview.ts | 7 +- src/webviews/commitDetails/registration.ts | 3 +- src/webviews/home/homeWebview.ts | 7 +- src/webviews/home/registration.ts | 3 +- src/webviews/rebase/rebaseEditor.ts | 2 +- src/webviews/settings/registration.ts | 2 +- src/webviews/webviewController.ts | 37 +++-------- src/webviews/webviewWithConfigBase.ts | 3 +- src/webviews/webviewsController.ts | 10 +-- src/webviews/welcome/registration.ts | 2 +- 48 files changed, 173 insertions(+), 225 deletions(-) diff --git a/src/annotations/annotationProvider.ts b/src/annotations/annotationProvider.ts index c80b420..24c609c 100644 --- a/src/annotations/annotationProvider.ts +++ b/src/annotations/annotationProvider.ts @@ -9,7 +9,6 @@ import type { } from 'vscode'; import { Disposable, window } from 'vscode'; import type { FileAnnotationType } from '../config'; -import { ContextKeys } from '../constants'; import { setContext } from '../context'; import { Logger } from '../system/logger'; import type { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; @@ -116,7 +115,7 @@ export abstract class AnnotationProviderBase) => { - await setContext(ContextKeys.AnnotationStatus, AnnotationStatus.Computing); + await setContext('gitlens:annotationStatus', AnnotationStatus.Computing); const computingAnnotations = this.showAnnotationsCore(currentProvider, editor, type, context, progress); const provider = await computingAnnotations; if (editor === this._editor) { - await setContext(ContextKeys.AnnotationStatus, provider?.status); + await setContext('gitlens:annotationStatus', provider?.status); } return computingAnnotations; @@ -408,7 +408,7 @@ export class FileAnnotationController implements Disposable { provider.dispose(); if (this._annotationProviders.size === 0 || key === getEditorCorrelationKey(this._editor)) { - await setContext(ContextKeys.AnnotationStatus, undefined); + await setContext('gitlens:annotationStatus', undefined); await this.detachKeyboardHook(); } diff --git a/src/api/actionRunners.ts b/src/api/actionRunners.ts index 96d3066..bc8f76e 100644 --- a/src/api/actionRunners.ts +++ b/src/api/actionRunners.ts @@ -1,7 +1,7 @@ import type { Event, QuickPickItem } from 'vscode'; import { Disposable, EventEmitter, window } from 'vscode'; import type { Config } from '../config'; -import { Commands, ContextKeys } from '../constants'; +import { Commands } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import { registerCommand } from '../system/command'; @@ -326,7 +326,7 @@ export class ActionRunners implements Disposable { } private async _updateContextKeys(action: Actions) { - await setContext(`${ContextKeys.ActionPrefix}${action}`, this.count(action)); + await setContext(`gitlens:action:${action}`, this.count(action)); } private async _updateAllContextKeys() { diff --git a/src/avatars.ts b/src/avatars.ts index a33c365..4509082 100644 --- a/src/avatars.ts +++ b/src/avatars.ts @@ -1,7 +1,6 @@ import { EventEmitter, Uri } from 'vscode'; import { md5 } from '@env/crypto'; import { GravatarDefaultStyle } from './config'; -import { ContextKeys } from './constants'; import { Container } from './container'; import { getContext } from './context'; import { getGitHubNoReplyAddressParts } from './git/remotes/github'; @@ -126,7 +125,7 @@ function getAvatarUriCore( const avatar = createOrUpdateAvatar(key, email, size, hash, options?.defaultStyle); if (avatar.uri != null) return avatar.uri; - if (!options?.cached && repoPathOrCommit != null && getContext(ContextKeys.HasConnectedRemotes)) { + if (!options?.cached && repoPathOrCommit != null && getContext('gitlens:hasConnectedRemotes')) { let query = avatarQueue.get(key); if (query == null && hasAvatarExpired(avatar)) { query = getAvatarUriFromRemoteProvider(avatar, key, email, repoPathOrCommit, { size: size }).then( diff --git a/src/codelens/codeLensController.ts b/src/codelens/codeLensController.ts index bc2c95f..25450af 100644 --- a/src/codelens/codeLensController.ts +++ b/src/codelens/codeLensController.ts @@ -1,6 +1,5 @@ import type { ConfigurationChangeEvent } from 'vscode'; import { Disposable, languages } from 'vscode'; -import { ContextKeys } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import { configuration } from '../system/configuration'; @@ -49,7 +48,7 @@ export class GitCodeLensController implements Disposable { } this._canToggle = cfg.recentChange.enabled || cfg.authors.enabled; - void setContext(ContextKeys.DisabledToggleCodeLens, !this._canToggle); + void setContext('gitlens:disabledToggleCodeLens', !this._canToggle); } } diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index dc0b8d0..d79656e 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -1,4 +1,4 @@ -import { ContextKeys, GlyphChars } from '../../constants'; +import { GlyphChars } from '../../constants'; import type { Container } from '../../container'; import { getContext } from '../../context'; import { showDetailsView } from '../../git/actions/commit'; @@ -114,7 +114,7 @@ export class SearchGitCommand extends QuickCommand { repos: this.container.git.openRepositories, associatedView: this.container.searchAndCompareView, commit: undefined, - hasVirtualFolders: getContext(ContextKeys.HasVirtualFolders, false), + hasVirtualFolders: getContext('gitlens:hasVirtualFolders', false), resultsKey: undefined, resultsPromise: undefined, title: this.title, diff --git a/src/commands/git/stash.ts b/src/commands/git/stash.ts index b3db949..96d5f7f 100644 --- a/src/commands/git/stash.ts +++ b/src/commands/git/stash.ts @@ -1,6 +1,6 @@ import type { QuickPickItem, Uri } from 'vscode'; import { QuickInputButtons, window } from 'vscode'; -import { ContextKeys, GlyphChars } from '../../constants'; +import { GlyphChars } from '../../constants'; import type { Container } from '../../container'; import { getContext } from '../../context'; import { reveal, showDetailsView } from '../../git/actions/stash'; @@ -168,9 +168,9 @@ export class StashGitCommand extends QuickCommand { repos: this.container.git.openRepositories, associatedView: this.container.stashesView, readonly: - getContext(ContextKeys.Readonly, false) || - getContext(ContextKeys.Untrusted, false) || - getContext(ContextKeys.HasVirtualFolders, false), + getContext('gitlens:readonly', false) || + getContext('gitlens:untrusted', false) || + getContext('gitlens:hasVirtualFolders', false), title: this.title, }; diff --git a/src/commands/gitCommands.utils.ts b/src/commands/gitCommands.utils.ts index 36f7e8a..0df0b87 100644 --- a/src/commands/gitCommands.utils.ts +++ b/src/commands/gitCommands.utils.ts @@ -55,11 +55,11 @@ export class PickCommandStep implements QuickPickStep { readonly title = 'GitLens'; constructor(private readonly container: Container, args?: GitCommandsCommandArgs) { - const hasVirtualFolders = getContext(ContextKeys.HasVirtualFolders, false); + const hasVirtualFolders = getContext('gitlens:hasVirtualFolders', false); const readonly = hasVirtualFolders || - getContext(ContextKeys.Readonly, false) || - getContext(ContextKeys.Untrusted, false); + getContext('gitlens:readonly', false) || + getContext('gitlens:untrusted', false); this.items = [ readonly ? undefined : new BranchGitCommand(container, args?.command === 'branch' ? args : undefined), diff --git a/src/constants.ts b/src/constants.ts index 293c816..9ced13a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,5 +1,6 @@ export const commandPrefix = 'gitlens'; export const configPrefix = 'gitlens'; +export const keyPrefix = 'gitlens:key'; export const storagePrefix = 'gitlens'; export const quickPickTitleMaxChars = 80; @@ -281,43 +282,44 @@ export const enum Commands { Deprecated_ShowFileHistoryInView = 'gitlens.showFileHistoryInView', } -export const enum ContextKeys { - ActionPrefix = 'gitlens:action:', - KeyPrefix = 'gitlens:key:', - WebviewPrefix = `gitlens:webview:`, - WebviewViewPrefix = `gitlens:webviewView:`, +export type CustomEditorIds = 'rebaseEditor'; +export type WebviewIds = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus'; +export type WebviewViewIds = 'commitDetails' | 'graph' | 'home' | 'timeline'; - ActiveFileStatus = 'gitlens:activeFileStatus', - AnnotationStatus = 'gitlens:annotationStatus', - Debugging = 'gitlens:debugging', - DisabledToggleCodeLens = 'gitlens:disabledToggleCodeLens', - Disabled = 'gitlens:disabled', - Enabled = 'gitlens:enabled', - FocusFocused = 'gitlens:focus:focused', - HasConnectedRemotes = 'gitlens:hasConnectedRemotes', - HasRemotes = 'gitlens:hasRemotes', - HasRichRemotes = 'gitlens:hasRichRemotes', - HasVirtualFolders = 'gitlens:hasVirtualFolders', - PreRelease = 'gitlens:prerelease', - Readonly = 'gitlens:readonly', - Untrusted = 'gitlens:untrusted', - ViewsCanCompare = 'gitlens:views:canCompare', - ViewsCanCompareFile = 'gitlens:views:canCompare:file', - ViewsCommitsMyCommitsOnly = 'gitlens:views:commits:myCommitsOnly', - ViewsFileHistoryCanPin = 'gitlens:views:fileHistory:canPin', - ViewsFileHistoryCursorFollowing = 'gitlens:views:fileHistory:cursorFollowing', - ViewsFileHistoryEditorFollowing = 'gitlens:views:fileHistory:editorFollowing', - ViewsLineHistoryEditorFollowing = 'gitlens:views:lineHistory:editorFollowing', - ViewsRepositoriesAutoRefresh = 'gitlens:views:repositories:autoRefresh', - ViewsSearchAndCompareKeepResults = 'gitlens:views:searchAndCompare:keepResults', - Vsls = 'gitlens:vsls', - - Plus = 'gitlens:plus', - PlusDisallowedRepos = 'gitlens:plus:disallowedRepos', - PlusEnabled = 'gitlens:plus:enabled', - PlusRequired = 'gitlens:plus:required', - PlusState = 'gitlens:plus:state', -} +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'; export type CoreCommands = | 'cursorMove' diff --git a/src/context.ts b/src/context.ts index cd232fc..e8952e6 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,39 +1,19 @@ import { EventEmitter } from 'vscode'; import type { ContextKeys } from './constants'; import { executeCoreCommand } from './system/command'; -import type { WebviewIds, WebviewViewIds } from './webviews/webviewsController'; const contextStorage = new Map(); -type WebviewContextKeys = - | `${ContextKeys.WebviewPrefix}${WebviewIds}:active` - | `${ContextKeys.WebviewPrefix}${WebviewIds}:focus` - | `${ContextKeys.WebviewPrefix}${WebviewIds}:inputFocus` - | `${ContextKeys.WebviewPrefix}rebaseEditor:active` - | `${ContextKeys.WebviewPrefix}rebaseEditor:focus` - | `${ContextKeys.WebviewPrefix}rebaseEditor:inputFocus`; - -type WebviewViewContextKeys = - | `${ContextKeys.WebviewViewPrefix}${WebviewViewIds}:focus` - | `${ContextKeys.WebviewViewPrefix}${WebviewViewIds}:inputFocus`; - -type AllContextKeys = - | ContextKeys - | WebviewContextKeys - | WebviewViewContextKeys - | `${ContextKeys.ActionPrefix}${string}` - | `${ContextKeys.KeyPrefix}${string}`; - -const _onDidChangeContext = new EventEmitter(); +const _onDidChangeContext = new EventEmitter(); export const onDidChangeContext = _onDidChangeContext.event; -export function getContext(key: AllContextKeys): T | undefined; -export function getContext(key: AllContextKeys, defaultValue: T): T; -export function getContext(key: AllContextKeys, defaultValue?: T): T | undefined { +export function getContext(key: ContextKeys): T | undefined; +export function getContext(key: ContextKeys, defaultValue: T): T; +export function getContext(key: ContextKeys, defaultValue?: T): T | undefined { return (contextStorage.get(key) as T | undefined) ?? defaultValue; } -export async function setContext(key: AllContextKeys, value: unknown): Promise { +export async function setContext(key: ContextKeys, value: unknown): Promise { contextStorage.set(key, value); void (await executeCoreCommand('setContext', key, value)); _onDidChangeContext.fire(key); diff --git a/src/eventBus.ts b/src/eventBus.ts index 4e3ac46..f761f0e 100644 --- a/src/eventBus.ts +++ b/src/eventBus.ts @@ -1,10 +1,10 @@ import type { Disposable, Uri } from 'vscode'; import { EventEmitter } from 'vscode'; import type { ViewsConfigKeys } from './config'; +import type { WebviewIds, WebviewViewIds } from './constants'; import type { GitCaches } from './git/gitProvider'; import type { GitCommit } from './git/models/commit'; import type { GitRevisionReference } from './git/models/reference'; -import type { WebviewIds, WebviewViewIds } from './webviews/webviewsController'; export type CommitSelectedEvent = EventBusEvent<'commit:selected'>; interface CommitSelectedEventArgs { diff --git a/src/extension.ts b/src/extension.ts index 6279986..6ee3776 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,7 +6,7 @@ import { Api } from './api/api'; import type { CreatePullRequestActionContext, GitLensApi, OpenPullRequestActionContext } from './api/gitlens'; import type { CreatePullRequestOnRemoteCommandArgs, OpenPullRequestOnRemoteCommandArgs } from './commands'; import { fromOutputLevel, OutputLevel } from './config'; -import { Commands, ContextKeys } from './constants'; +import { Commands } from './constants'; import { Container } from './container'; import { setContext } from './context'; import { isGitUri } from './git/gitUri'; @@ -85,7 +85,7 @@ export async function activate(context: ExtensionContext): Promise { - void setContext(ContextKeys.Untrusted, undefined); + void setContext('gitlens:untrusted', undefined); container.telemetry.setGlobalAttribute('workspace.isTrusted', workspace.isTrusted); }), ); @@ -166,11 +166,11 @@ export async function activate(context: ExtensionContext): Promise { @@ -1003,9 +1003,9 @@ export class SubscriptionService implements Disposable { } } - void setContext(ContextKeys.PlusEnabled, Boolean(allowed) || plusFeatures); - void setContext(ContextKeys.PlusRequired, allowed === false); - void setContext(ContextKeys.PlusDisallowedRepos, disallowedRepos); + void setContext('gitlens:plus:enabled', Boolean(allowed) || plusFeatures); + void setContext('gitlens:plus:required', allowed === false); + void setContext('gitlens:plus:disallowedRepos', disallowedRepos); } private updateStatusBar(): void { diff --git a/src/plus/subscription/utils.ts b/src/plus/subscription/utils.ts index 81d786c..7d5e7bd 100644 --- a/src/plus/subscription/utils.ts +++ b/src/plus/subscription/utils.ts @@ -1,11 +1,10 @@ import type { MessageItem } from 'vscode'; import { window } from 'vscode'; -import { ContextKeys } from '../../constants'; import { getContext } from '../../context'; import { configuration } from '../../system/configuration'; export function arePlusFeaturesEnabled(): boolean { - return getContext(ContextKeys.PlusEnabled, configuration.get('plusFeatures.enabled', undefined, true)); + return getContext('gitlens:plus:enabled', configuration.get('plusFeatures.enabled', undefined, true)); } export async function ensurePlusFeaturesEnabled(): Promise { diff --git a/src/plus/webviews/focus/focusWebview.ts b/src/plus/webviews/focus/focusWebview.ts index 7d5e10a..544ae02 100644 --- a/src/plus/webviews/focus/focusWebview.ts +++ b/src/plus/webviews/focus/focusWebview.ts @@ -1,6 +1,7 @@ import { Disposable, Uri, window } from 'vscode'; import type { GHPRPullRequest } from '../../../commands'; -import { Commands, ContextKeys } from '../../../constants'; +import type { WebviewIds, WebviewViewIds } from '../../../constants'; +import { Commands } from '../../../constants'; import type { Container } from '../../../container'; import { setContext } from '../../../context'; import { PlusFeatures } from '../../../features'; @@ -26,7 +27,6 @@ import { executeCommand, registerCommand } from '../../../system/command'; import type { IpcMessage } from '../../../webviews/protocol'; import { onIpc } from '../../../webviews/protocol'; import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController'; -import type { WebviewIds, WebviewViewIds } from '../../../webviews/webviewsController'; import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService'; import type { OpenWorktreeParams, State, SwitchToBranchParams } from './protocol'; import { @@ -78,12 +78,12 @@ export class FocusWebviewProvider implements WebviewProvider { onFocusChanged(focused: boolean): void { if (focused) { // If we are becoming focused, delay it a bit to give the UI time to update - setTimeout(() => void setContext(ContextKeys.FocusFocused, focused), 0); + setTimeout(() => void setContext('gitlens:focus:focused', focused), 0); return; } - void setContext(ContextKeys.FocusFocused, focused); + void setContext('gitlens:focus:focused', focused); } onMessageReceived(e: IpcMessage) { diff --git a/src/plus/webviews/focus/registration.ts b/src/plus/webviews/focus/registration.ts index 9905511..cc6efca 100644 --- a/src/plus/webviews/focus/registration.ts +++ b/src/plus/webviews/focus/registration.ts @@ -1,4 +1,4 @@ -import { Commands, ContextKeys } from '../../../constants'; +import { Commands } from '../../../constants'; import type { WebviewsController } from '../../../webviews/webviewsController'; import type { State } from './protocol'; @@ -7,7 +7,7 @@ export function registerFocusWebviewPanel(controller: WebviewsController) { fileName: 'focus.html', iconPath: 'images/gitlens-icon.png', title: 'Focus View', - contextKeyPrefix: `${ContextKeys.WebviewPrefix}focus`, + contextKeyPrefix: `gitlens:webview:focus`, trackingFeature: 'focusWebview', plusFeature: true, resolveWebviewProvider: async function (container, id, host) { diff --git a/src/plus/webviews/graph/graphWebview.ts b/src/plus/webviews/graph/graphWebview.ts index b62e102..55ef5a6 100644 --- a/src/plus/webviews/graph/graphWebview.ts +++ b/src/plus/webviews/graph/graphWebview.ts @@ -12,7 +12,8 @@ import type { } from '../../../commands'; import { parseCommandContext } from '../../../commands/base'; import type { Config } from '../../../config'; -import { Commands, ContextKeys, GlyphChars } from '../../../constants'; +import type { WebviewIds, WebviewViewIds } from '../../../constants'; +import { Commands, GlyphChars } from '../../../constants'; import type { Container } from '../../../container'; import { getContext, onDidChangeContext } from '../../../context'; import type { CommitSelectedEvent } from '../../../eventBus'; @@ -73,7 +74,6 @@ import { RepositoryFolderNode } from '../../../views/nodes/viewNode'; import type { IpcMessage, IpcMessageParams, IpcNotificationType } from '../../../webviews/protocol'; import { onIpc } from '../../../webviews/protocol'; import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController'; -import type { WebviewIds, WebviewViewIds } from '../../../webviews/webviewsController'; import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService'; import type { DimMergeCommitsParams, @@ -753,7 +753,7 @@ export class GraphWebviewProvider implements WebviewProvider { } private async onGetMissingRefMetadata(e: GetMissingRefsMetadataParams) { - if (this._graph == null || this._refsMetadata === null || !getContext(ContextKeys.HasConnectedRemotes)) return; + if (this._graph == null || this._refsMetadata === null || !getContext('gitlens:hasConnectedRemotes')) return; const repoPath = this._graph.repoPath; @@ -1379,7 +1379,7 @@ export class GraphWebviewProvider implements WebviewProvider { repo.startWatchingFileSystem(), repo.onDidChangeFileSystem(this.onRepositoryFileSystemChanged, this), onDidChangeContext(key => { - if (key !== ContextKeys.HasConnectedRemotes) return; + if (key !== 'gitlens:hasConnectedRemotes') return; this.resetRefsMetadata(); this.updateRefsMetadata(); @@ -1892,7 +1892,7 @@ export class GraphWebviewProvider implements WebviewProvider { } private resetRefsMetadata(): null | undefined { - this._refsMetadata = getContext(ContextKeys.HasConnectedRemotes) ? undefined : null; + this._refsMetadata = getContext('gitlens:hasConnectedRemotes') ? undefined : null; return this._refsMetadata; } diff --git a/src/plus/webviews/graph/registration.ts b/src/plus/webviews/graph/registration.ts index 10b7d5f..322d657 100644 --- a/src/plus/webviews/graph/registration.ts +++ b/src/plus/webviews/graph/registration.ts @@ -1,5 +1,5 @@ import { Disposable } from 'vscode'; -import { Commands, ContextKeys } from '../../../constants'; +import { Commands } from '../../../constants'; import type { Container } from '../../../container'; import type { Repository } from '../../../git/models/repository'; import { executeCommand, registerCommand } from '../../../system/command'; @@ -17,7 +17,7 @@ export function registerGraphWebviewPanel(controller: WebviewsController) { fileName: 'graph.html', iconPath: 'images/gitlens-icon.png', title: 'Commit Graph', - contextKeyPrefix: `${ContextKeys.WebviewPrefix}graph`, + contextKeyPrefix: `gitlens:webview:graph`, trackingFeature: 'graphWebview', plusFeature: true, panelOptions: { @@ -38,7 +38,7 @@ export function registerGraphWebviewView(controller: WebviewsController) { return controller.registerWebviewView('gitlens.views.graph', { fileName: 'graph.html', title: 'Commit Graph', - contextKeyPrefix: `${ContextKeys.WebviewViewPrefix}graph`, + contextKeyPrefix: `gitlens:webviewView:graph`, trackingFeature: 'graphView', plusFeature: true, canResolveWebviewProvider: function (_container, _id) { diff --git a/src/plus/webviews/graph/statusbar.ts b/src/plus/webviews/graph/statusbar.ts index c3236e8..00a2a57 100644 --- a/src/plus/webviews/graph/statusbar.ts +++ b/src/plus/webviews/graph/statusbar.ts @@ -1,6 +1,6 @@ import type { ConfigurationChangeEvent, StatusBarItem } from 'vscode'; import { Disposable, MarkdownString, StatusBarAlignment, window } from 'vscode'; -import { Commands, ContextKeys } from '../../../constants'; +import { Commands } from '../../../constants'; import type { Container } from '../../../container'; import { getContext, onDidChangeContext } from '../../../context'; import { configuration } from '../../../system/configuration'; @@ -18,7 +18,7 @@ export class GraphStatusBarController implements Disposable { container.subscription.onDidChange(this.onSubscriptionChanged, this), once(container.onReady)(() => queueMicrotask(() => this.updateStatusBar())), onDidChangeContext(key => { - if (key !== ContextKeys.Enabled && key !== ContextKeys.PlusEnabled) return; + if (key !== 'gitlens:enabled' && key !== 'gitlens:plus:enabled') return; this.updateStatusBar(); }), { dispose: () => this._statusBarItem?.dispose() }, @@ -41,7 +41,7 @@ export class GraphStatusBarController implements Disposable { private updateStatusBar() { const enabled = - configuration.get('graph.statusBar.enabled') && getContext(ContextKeys.Enabled) && arePlusFeaturesEnabled(); + configuration.get('graph.statusBar.enabled') && getContext('gitlens:enabled') && arePlusFeaturesEnabled(); if (enabled) { if (this._statusBarItem == null) { this._statusBarItem = window.createStatusBarItem('gitlens.graph', StatusBarAlignment.Left, 10000 - 3); diff --git a/src/plus/webviews/timeline/registration.ts b/src/plus/webviews/timeline/registration.ts index 0765cd7..9467694 100644 --- a/src/plus/webviews/timeline/registration.ts +++ b/src/plus/webviews/timeline/registration.ts @@ -1,4 +1,4 @@ -import { Commands, ContextKeys } from '../../../constants'; +import { Commands } from '../../../constants'; import type { WebviewsController } from '../../../webviews/webviewsController'; import type { State } from './protocol'; @@ -7,7 +7,7 @@ export function registerTimelineWebviewPanel(controller: WebviewsController) { fileName: 'timeline.html', iconPath: 'images/gitlens-icon.png', title: 'Visual File History', - contextKeyPrefix: `${ContextKeys.WebviewPrefix}timeline`, + contextKeyPrefix: `gitlens:webview:timeline`, trackingFeature: 'timelineWebview', plusFeature: true, resolveWebviewProvider: async function (container, id, host) { @@ -21,7 +21,7 @@ export function registerTimelineWebviewView(controller: WebviewsController) { return controller.registerWebviewView('gitlens.views.timeline', { fileName: 'timeline.html', title: 'Visual File History', - contextKeyPrefix: `${ContextKeys.WebviewViewPrefix}timeline`, + contextKeyPrefix: `gitlens:webviewView:timeline`, trackingFeature: 'timelineView', plusFeature: true, resolveWebviewProvider: async function (container, id, host) { diff --git a/src/plus/webviews/timeline/timelineWebview.ts b/src/plus/webviews/timeline/timelineWebview.ts index 7a6e68f..34b14b9 100644 --- a/src/plus/webviews/timeline/timelineWebview.ts +++ b/src/plus/webviews/timeline/timelineWebview.ts @@ -1,5 +1,6 @@ import type { TextEditor, ViewColumn } from 'vscode'; import { commands, Disposable, Uri, window } from 'vscode'; +import type { WebviewIds, WebviewViewIds } from '../../../constants'; import { Commands } from '../../../constants'; import type { Container } from '../../../container'; import type { FileSelectedEvent } from '../../../eventBus'; @@ -20,7 +21,6 @@ import { hasVisibleTextEditor, isTextEditor } from '../../../system/utils'; import type { IpcMessage } from '../../../webviews/protocol'; import { onIpc } from '../../../webviews/protocol'; import type { WebviewController, WebviewProvider } from '../../../webviews/webviewController'; -import type { WebviewIds, WebviewViewIds } from '../../../webviews/webviewsController'; import type { SubscriptionChangeEvent } from '../../subscription/subscriptionService'; import type { Commit, Period, State } from './protocol'; import { DidChangeNotificationType, OpenDataPointCommandType, UpdatePeriodCommandType } from './protocol'; diff --git a/src/system/keyboard.ts b/src/system/keyboard.ts index 3939937..c471cd6 100644 --- a/src/system/keyboard.ts +++ b/src/system/keyboard.ts @@ -1,5 +1,5 @@ import { Disposable } from 'vscode'; -import { commandPrefix, ContextKeys } from '../constants'; +import { commandPrefix, keyPrefix } 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(`${ContextKeys.KeyPrefix}${key}`, false); + await setContext(`${keyPrefix}:${key}`, false); } @log({ @@ -142,12 +142,12 @@ export class KeyboardScope implements Disposable { mapping[key] = command; if (!set) { - await setContext(`${ContextKeys.KeyPrefix}${key}`, true); + await setContext(`${keyPrefix}:${key}`, true); } } private async updateKeyCommandsContext(mapping: KeyMapping) { - await Promise.all(keys.map(key => setContext(`${ContextKeys.KeyPrefix}${key}`, Boolean(mapping?.[key])))); + await Promise.all(keys.map(key => setContext(`${keyPrefix}:${key}`, Boolean(mapping?.[key])))); } } diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index 6597404..715b007 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -112,7 +112,7 @@ export class DocumentTracker implements Disposable { this._timer = setTimeout(() => { this._timer = undefined; - void setContext(ContextKeys.ActiveFileStatus, undefined); + void setContext('gitlens:activeFileStatus', undefined); }, 250); return; diff --git a/src/trackers/trackedDocument.ts b/src/trackers/trackedDocument.ts index 3dfb839..1c49722 100644 --- a/src/trackers/trackedDocument.ts +++ b/src/trackers/trackedDocument.ts @@ -1,6 +1,5 @@ import type { Disposable, Event, TextDocument, TextEditor } from 'vscode'; import { EventEmitter } from 'vscode'; -import { ContextKeys } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import { GitUri } from '../git/gitUri'; @@ -108,7 +107,7 @@ export class TrackedDocument implements Disposable { if (this._requiresUpdate) { await this.update(); } - void setContext(ContextKeys.ActiveFileStatus, this.getStatus()); + void setContext('gitlens:activeFileStatus', this.getStatus()); } is(document: TextDocument) { @@ -188,7 +187,7 @@ export class TrackedDocument implements Disposable { if (active != null) { const blameable = this.isBlameable; - void setContext(ContextKeys.ActiveFileStatus, this.getStatus()); + void setContext('gitlens:activeFileStatus', this.getStatus()); if (!this.initializing && wasBlameable !== blameable) { const e: DocumentBlameStateChangeEvent = { editor: active, document: this, blameable: blameable }; diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index c76e2da..d30ab99 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -7,7 +7,7 @@ import type { import { Disposable, ProgressLocation, ThemeIcon, TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import type { CommitsViewConfig } from '../config'; import { ViewFilesLayout, ViewShowBranchComparison } from '../config'; -import { Commands, ContextKeys, GlyphChars } from '../constants'; +import { Commands, GlyphChars } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import { GitUri } from '../git/gitUri'; @@ -440,7 +440,7 @@ export class CommitsView extends ViewBase { } private setMyCommitsOnly(enabled: boolean) { - void setContext(ContextKeys.ViewsCommitsMyCommitsOnly, enabled); + void setContext('gitlens:views:commits:myCommitsOnly', enabled); this.state.myCommitsOnly = enabled; void this.refresh(true); } diff --git a/src/views/fileHistoryView.ts b/src/views/fileHistoryView.ts index 29f7bc4..39cf07b 100644 --- a/src/views/fileHistoryView.ts +++ b/src/views/fileHistoryView.ts @@ -1,6 +1,6 @@ import type { ConfigurationChangeEvent, Disposable } from 'vscode'; import type { FileHistoryViewConfig } from '../config'; -import { Commands, ContextKeys } from '../constants'; +import { Commands } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import type { GitUri } from '../git/gitUri'; @@ -22,8 +22,8 @@ export class FileHistoryView extends ViewBase { ref: ref, }); this.children.unshift(this.comparePicker); - void setContext(ContextKeys.ViewsCanCompare, true); + void setContext('gitlens:views:canCompare', true); await this.triggerChange(); @@ -231,7 +231,7 @@ export class SearchAndCompareViewNode extends ViewNode { } private removeComparePicker(silent: boolean = false) { - void setContext(ContextKeys.ViewsCanCompare, false); + void setContext('gitlens:views:canCompare', false); if (this.comparePicker != null) { const index = this.children.indexOf(this.comparePicker); if (index !== -1) { @@ -251,7 +251,7 @@ export class SearchAndCompareView extends ViewBase(Commands.DiffWith, { repoPath: selected.repoPath, @@ -964,7 +964,7 @@ export class ViewCommands { repoPath: node.repoPath, uri: node.uri, }; - void setContext(ContextKeys.ViewsCanCompareFile, true); + void setContext('gitlens:views:canCompare:file', true); } @debug() diff --git a/src/vsls/vsls.ts b/src/vsls/vsls.ts index 6818db1..c460ca5 100644 --- a/src/vsls/vsls.ts +++ b/src/vsls/vsls.ts @@ -1,6 +1,6 @@ import { Disposable, extensions, workspace } from 'vscode'; import type { LiveShare, LiveShareExtension, SessionChangeEvent } from '../@types/vsls'; -import { ContextKeys, Schemes } from '../constants'; +import { Schemes } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import { configuration } from '../system/configuration'; @@ -68,14 +68,14 @@ export class VslsController implements Disposable { this._api = this.getLiveShareApi(); const api = await this._api; if (api == null) { - void setContext(ContextKeys.Vsls, false); + void setContext('gitlens:vsls', false); // Tear it down if we can't talk to live share this._ready.fulfill(); return; } - void setContext(ContextKeys.Vsls, true); + void setContext('gitlens:vsls', true); this._disposable = Disposable.from( this._disposable, @@ -97,7 +97,7 @@ export class VslsController implements Disposable { switch (e.session.role) { case 1 /*Role.Host*/: this.setReadonly(false); - void setContext(ContextKeys.Vsls, 'host'); + void setContext('gitlens:vsls', 'host'); if (configuration.get('liveshare.allowGuestAccess')) { this._host = await VslsHostService.share(api, this.container); } @@ -108,7 +108,7 @@ export class VslsController implements Disposable { case 2 /*Role.Guest*/: this.setReadonly(true); - void setContext(ContextKeys.Vsls, 'guest'); + void setContext('gitlens:vsls', 'guest'); this._guest = await VslsGuestService.connect(api, this.container); this._ready.fulfill(); @@ -117,7 +117,7 @@ export class VslsController implements Disposable { default: this.setReadonly(false); - void setContext(ContextKeys.Vsls, true); + void setContext('gitlens:vsls', true); this._ready = defer(); @@ -145,7 +145,7 @@ export class VslsController implements Disposable { } private setReadonly(value: boolean) { this._readonly = value; - void setContext(ContextKeys.Readonly, value ? true : undefined); + void setContext('gitlens:readonly', value ? true : undefined); } async guest() { diff --git a/src/webviews/commitDetails/commitDetailsWebview.ts b/src/webviews/commitDetails/commitDetailsWebview.ts index 60e3376..af856ce 100644 --- a/src/webviews/commitDetails/commitDetailsWebview.ts +++ b/src/webviews/commitDetails/commitDetailsWebview.ts @@ -2,8 +2,8 @@ import type { CancellationToken, ConfigurationChangeEvent, TextDocumentShowOptio import { CancellationTokenSource, Disposable, Uri, ViewColumn, window } from 'vscode'; import { serializeAutolink } from '../../annotations/autolinks'; import type { CopyShaToClipboardCommandArgs } from '../../commands'; -import type { CoreConfiguration } from '../../constants'; -import { Commands, ContextKeys } from '../../constants'; +import type { CoreConfiguration, WebviewIds, WebviewViewIds } from '../../constants'; +import { Commands } from '../../constants'; import type { Container } from '../../container'; import { getContext } from '../../context'; import type { CommitSelectedEvent } from '../../eventBus'; @@ -46,7 +46,6 @@ import type { LinesChangeEvent } from '../../trackers/lineTracker'; import type { IpcMessage } from '../protocol'; import { onIpc } from '../protocol'; import type { WebviewController, WebviewProvider } from '../webviewController'; -import type { WebviewIds, WebviewViewIds } from '../webviewsController'; import type { CommitDetails, FileActionParams, Preferences, State } from './protocol'; import { AutolinkSettingsCommandType, @@ -519,7 +518,7 @@ export class CommitDetailsWebviewProvider implements WebviewProvider>('gitlens.views.commitDetails', { fileName: 'commitDetails.html', title: 'Commit Details', - contextKeyPrefix: `${ContextKeys.WebviewViewPrefix}commitDetails`, + contextKeyPrefix: `gitlens:webviewView:commitDetails`, trackingFeature: 'commitDetailsView', plusFeature: false, resolveWebviewProvider: async function (container, id, host) { diff --git a/src/webviews/home/homeWebview.ts b/src/webviews/home/homeWebview.ts index 06b2703..3c2f618 100644 --- a/src/webviews/home/homeWebview.ts +++ b/src/webviews/home/homeWebview.ts @@ -2,7 +2,7 @@ import type { ConfigurationChangeEvent } from 'vscode'; import { Disposable, window } from 'vscode'; import { getAvatarUriFromGravatarEmail } from '../../avatars'; import { ViewsLayout } from '../../commands/setViewsLayout'; -import { ContextKeys } from '../../constants'; +import type { WebviewIds, WebviewViewIds } from '../../constants'; import type { Container } from '../../container'; import { getContext, onDidChangeContext } from '../../context'; import type { RepositoriesVisibility } from '../../git/gitProviderService'; @@ -16,7 +16,6 @@ import { debounce } from '../../system/function'; import type { IpcMessage } from '../protocol'; import { onIpc } from '../protocol'; import type { WebviewController, WebviewProvider } from '../webviewController'; -import type { WebviewIds, WebviewViewIds } from '../webviewsController'; import type { CompleteStepParams, DismissBannerParams, DismissSectionParams, State } from './protocol'; import { CompletedActions, @@ -41,7 +40,7 @@ export class HomeWebviewProvider implements WebviewProvider { this._disposable = Disposable.from( this.container.subscription.onDidChange(this.onSubscriptionChanged, this), onDidChangeContext(key => { - if (key !== ContextKeys.Disabled) return; + if (key !== 'gitlens:disabled') return; this.notifyExtensionEnabled(); }), configuration.onDidChange(e => { @@ -262,7 +261,7 @@ export class HomeWebviewProvider implements WebviewProvider { } private getExtensionEnabled() { - return !getContext(ContextKeys.Disabled, false); + return !getContext('gitlens:disabled', false); } private notifyExtensionEnabled() { diff --git a/src/webviews/home/registration.ts b/src/webviews/home/registration.ts index a594e07..9693bc3 100644 --- a/src/webviews/home/registration.ts +++ b/src/webviews/home/registration.ts @@ -1,4 +1,3 @@ -import { ContextKeys } from '../../constants'; import type { WebviewsController } from '../webviewsController'; import type { State } from './protocol'; @@ -6,7 +5,7 @@ export function registerHomeWebviewView(controller: WebviewsController) { return controller.registerWebviewView('gitlens.views.home', { fileName: 'home.html', title: 'Home', - contextKeyPrefix: `${ContextKeys.WebviewViewPrefix}home`, + contextKeyPrefix: `gitlens:webviewView:home`, trackingFeature: 'homeView', plusFeature: false, resolveWebviewProvider: async function (container, id, host) { diff --git a/src/webviews/rebase/rebaseEditor.ts b/src/webviews/rebase/rebaseEditor.ts index 4fd3250..0faf900 100644 --- a/src/webviews/rebase/rebaseEditor.ts +++ b/src/webviews/rebase/rebaseEditor.ts @@ -134,7 +134,7 @@ export class RebaseEditorProvider implements CustomTextEditorProvider, Disposabl } private get contextKeyPrefix() { - return `${ContextKeys.WebviewPrefix}rebaseEditor` as const; + return `gitlens:webview:rebaseEditor` as const; } get enabled(): boolean { diff --git a/src/webviews/settings/registration.ts b/src/webviews/settings/registration.ts index 1c5a974..5d8fe3d 100644 --- a/src/webviews/settings/registration.ts +++ b/src/webviews/settings/registration.ts @@ -9,7 +9,7 @@ export function registerSettingsWebviewPanel(controller: WebviewsController) { fileName: 'settings.html', iconPath: 'images/gitlens-icon.png', title: 'GitLens Settings', - contextKeyPrefix: `${ContextKeys.WebviewPrefix}settings`, + contextKeyPrefix: `gitlens:webview:settings`, trackingFeature: 'settingsWebview', plusFeature: false, resolveWebviewProvider: async function (container, id, host) { diff --git a/src/webviews/webviewController.ts b/src/webviews/webviewController.ts index f30173f..a0446cc 100644 --- a/src/webviews/webviewController.ts +++ b/src/webviews/webviewController.ts @@ -8,8 +8,7 @@ import type { } from 'vscode'; import { EventEmitter, Uri, ViewColumn, window, workspace } from 'vscode'; import { getNonce } from '@env/crypto'; -import type { Commands } from '../constants'; -import { ContextKeys } from '../constants'; +import type { Commands, CustomEditorIds, WebviewIds, WebviewViewIds } from '../constants'; import type { Container } from '../container'; import { setContext } from '../context'; import { executeCommand } from '../system/command'; @@ -18,13 +17,7 @@ import { serialize } from '../system/decorators/serialize'; import type { TrackedUsageFeatures } from '../telemetry/usageTracker'; import type { IpcMessage, IpcMessageParams, IpcNotificationType, WebviewFocusChangedParams } from './protocol'; import { ExecuteCommandType, onIpc, WebviewFocusChangedCommandType, WebviewReadyCommandType } from './protocol'; -import type { - CustomEditorIds, - WebviewIds, - WebviewPanelDescriptor, - WebviewViewDescriptor, - WebviewViewIds, -} from './webviewsController'; +import type { WebviewPanelDescriptor, WebviewViewDescriptor } from './webviewsController'; const maxSmallIntegerV8 = 2 ** 30; // Max number that can be stored in V8's smis (small integers) const utf8TextDecoder = new TextDecoder('utf8'); @@ -145,9 +138,7 @@ export class WebviewController implements Dispos public readonly parent: WebviewPanel | WebviewView, title: string, private readonly fileName: string, - private readonly contextKeyPrefix: - | `${ContextKeys.WebviewPrefix}${WebviewIds}` - | `${ContextKeys.WebviewViewPrefix}${WebviewViewIds}`, + private readonly contextKeyPrefix: `gitlens:webview:${WebviewIds}` | `gitlens:webviewView:${WebviewViewIds}`, private readonly trackingFeature: TrackedUsageFeatures, resolveProvider: ( host: WebviewController, @@ -501,34 +492,24 @@ export function replaceWebviewHtmlTokens( } export function resetContextKeys( - contextKeyPrefix: - | `${ContextKeys.WebviewPrefix}${WebviewIds | CustomEditorIds}` - | `${ContextKeys.WebviewViewPrefix}${WebviewViewIds}`, + contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`, ): void { void setContext(`${contextKeyPrefix}:inputFocus`, false); void setContext(`${contextKeyPrefix}:focus`, false); - if (contextKeyPrefix.startsWith(ContextKeys.WebviewPrefix)) { - void setContext( - `${contextKeyPrefix as `${ContextKeys.WebviewPrefix}${WebviewIds | CustomEditorIds}`}:active`, - false, - ); + if (contextKeyPrefix.startsWith('gitlens:webview:')) { + void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, false); } } export function setContextKeys( - contextKeyPrefix: - | `${ContextKeys.WebviewPrefix}${WebviewIds | CustomEditorIds}` - | `${ContextKeys.WebviewViewPrefix}${WebviewViewIds}`, + contextKeyPrefix: `gitlens:webview:${WebviewIds | CustomEditorIds}` | `gitlens:webviewView:${WebviewViewIds}`, active?: boolean, focus?: boolean, inputFocus?: boolean, ): void { - if (contextKeyPrefix.startsWith(ContextKeys.WebviewPrefix)) { + if (contextKeyPrefix.startsWith('gitlens:webview:')) { if (active != null) { - void setContext( - `${contextKeyPrefix as `${ContextKeys.WebviewPrefix}${WebviewIds | CustomEditorIds}`}:active`, - active, - ); + void setContext(`${contextKeyPrefix as `gitlens:webview:${WebviewIds | CustomEditorIds}`}:active`, active); if (!active) { focus = false; diff --git a/src/webviews/webviewWithConfigBase.ts b/src/webviews/webviewWithConfigBase.ts index 50cc71a..e602b1e 100644 --- a/src/webviews/webviewWithConfigBase.ts +++ b/src/webviews/webviewWithConfigBase.ts @@ -1,6 +1,6 @@ import type { ConfigurationChangeEvent } from 'vscode'; import { ConfigurationTarget, Disposable } from 'vscode'; -import type { CoreConfiguration } from '../constants'; +import type { CoreConfiguration, WebviewIds, WebviewViewIds } from '../constants'; import type { Container } from '../container'; import { CommitFormatter } from '../git/formatters/commitFormatter'; import { GitCommit, GitCommitIdentity } from '../git/models/commit'; @@ -20,7 +20,6 @@ import { UpdateConfigurationCommandType, } from './protocol'; import type { WebviewController, WebviewProvider } from './webviewController'; -import type { WebviewIds, WebviewViewIds } from './webviewsController'; export abstract class WebviewProviderWithConfigBase implements WebviewProvider { private readonly _disposable: Disposable; diff --git a/src/webviews/webviewsController.ts b/src/webviews/webviewsController.ts index f6209e0..2600dab 100644 --- a/src/webviews/webviewsController.ts +++ b/src/webviews/webviewsController.ts @@ -6,7 +6,7 @@ import type { WebviewViewResolveContext, } from 'vscode'; import { Disposable, Uri, ViewColumn, window } from 'vscode'; -import type { Commands, ContextKeys } from '../constants'; +import type { Commands, WebviewIds, WebviewViewIds } from '../constants'; import type { Container } from '../container'; import { ensurePlusFeaturesEnabled } from '../plus/subscription/utils'; import { executeCommand, registerCommand } from '../system/command'; @@ -14,15 +14,11 @@ import type { TrackedUsageFeatures } from '../telemetry/usageTracker'; import type { WebviewProvider } from './webviewController'; import { WebviewController } from './webviewController'; -export type CustomEditorIds = 'rebaseEditor'; -export type WebviewIds = 'graph' | 'settings' | 'timeline' | 'welcome' | 'focus'; -export type WebviewViewIds = 'commitDetails' | 'graph' | 'home' | 'timeline'; - export interface WebviewPanelDescriptor { readonly fileName: string; readonly iconPath: string; readonly title: string; - readonly contextKeyPrefix: `${ContextKeys.WebviewPrefix}${WebviewIds}`; + readonly contextKeyPrefix: `gitlens:webview:${WebviewIds}`; readonly trackingFeature: TrackedUsageFeatures; readonly plusFeature: boolean; readonly options?: WebviewOptions; @@ -42,7 +38,7 @@ export interface WebviewPanelDescriptor { export interface WebviewViewDescriptor { readonly fileName: string; readonly title: string; - readonly contextKeyPrefix: `${ContextKeys.WebviewViewPrefix}${WebviewViewIds}`; + readonly contextKeyPrefix: `gitlens:webviewView:${WebviewViewIds}`; readonly trackingFeature: TrackedUsageFeatures; readonly plusFeature: boolean; readonly options?: WebviewOptions; diff --git a/src/webviews/welcome/registration.ts b/src/webviews/welcome/registration.ts index 4eaaf14..d358ffb 100644 --- a/src/webviews/welcome/registration.ts +++ b/src/webviews/welcome/registration.ts @@ -7,7 +7,7 @@ export function registerWelcomeWebviewPanel(controller: WebviewsController) { fileName: 'welcome.html', iconPath: 'images/gitlens-icon.png', title: 'Welcome to GitLens', - contextKeyPrefix: `${ContextKeys.WebviewPrefix}welcome`, + contextKeyPrefix: `gitlens:webview:welcome`, trackingFeature: 'welcomeWebview', plusFeature: false, resolveWebviewProvider: async function (container, id, host) {