diff --git a/src/annotations/annotationProvider.ts b/src/annotations/annotationProvider.ts index cdf4caa..5235139 100644 --- a/src/annotations/annotationProvider.ts +++ b/src/annotations/annotationProvider.ts @@ -10,7 +10,7 @@ import { window, } from 'vscode'; import { FileAnnotationType } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; +import { ContextKeys, setContext } from '../context'; import { Logger } from '../logger'; import { GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; diff --git a/src/annotations/fileAnnotationController.ts b/src/annotations/fileAnnotationController.ts index 67b0525..aea882d 100644 --- a/src/annotations/fileAnnotationController.ts +++ b/src/annotations/fileAnnotationController.ts @@ -23,8 +23,9 @@ import { configuration, FileAnnotationType, } from '../configuration'; -import { Colors, ContextKeys, isTextEditor, setContext } from '../constants'; +import { Colors, isTextEditor } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { KeyboardScope } from '../keyboard'; import { Logger } from '../logger'; import { once } from '../system/event'; diff --git a/src/api/actionRunners.ts b/src/api/actionRunners.ts index cfe1542..738390e 100644 --- a/src/api/actionRunners.ts +++ b/src/api/actionRunners.ts @@ -1,8 +1,8 @@ import { commands, Disposable, Event, EventEmitter, QuickPickItem, window } from 'vscode'; import { Commands } from '../commands/common'; import { Config, configuration } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { getQuickPickIgnoreFocusOut } from '../quickpicks'; import { Strings } from '../system'; import type { Action, ActionContext, ActionRunner } from './gitlens'; diff --git a/src/codelens/codeLensController.ts b/src/codelens/codeLensController.ts index 9c34b87..dc578b9 100644 --- a/src/codelens/codeLensController.ts +++ b/src/codelens/codeLensController.ts @@ -1,7 +1,7 @@ import { ConfigurationChangeEvent, Disposable, languages } from 'vscode'; import { configuration } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { Logger } from '../logger'; import { once } from '../system/event'; import { diff --git a/src/commands/closeView.ts b/src/commands/closeView.ts index fa71ebf..f1e037a 100644 --- a/src/commands/closeView.ts +++ b/src/commands/closeView.ts @@ -1,5 +1,5 @@ -import { ContextKeys, setContext } from '../constants'; import type { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { SyncedState } from '../storage'; import { command, Command, CommandContext, Commands } from './common'; diff --git a/src/commands/showView.ts b/src/commands/showView.ts index c8d46a5..de51f0a 100644 --- a/src/commands/showView.ts +++ b/src/commands/showView.ts @@ -1,6 +1,6 @@ import { commands } from 'vscode'; -import { ContextKeys, setContext } from '../constants'; import type { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { SyncedState } from '../storage'; import { command, Command, CommandContext, Commands } from './common'; diff --git a/src/constants.ts b/src/constants.ts index bc5c5b9..0a0cece 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,4 @@ -import { commands, TextDocument, TextEditor, window } from 'vscode'; +import { TextDocument, TextEditor, window } from 'vscode'; export const quickPickTitleMaxChars = 80; export const ImageMimetypes: Record = { @@ -50,35 +50,6 @@ export const enum BuiltInGitConfiguration { UseForcePushWithLease = 'git.useForcePushWithLease', } -export const enum ContextKeys { - ActionPrefix = 'gitlens:action:', - ActiveFileStatus = 'gitlens:activeFileStatus', - AnnotationStatus = 'gitlens:annotationStatus', - DisabledToggleCodeLens = 'gitlens:disabledToggleCodeLens', - Disabled = 'gitlens:disabled', - Enabled = 'gitlens:enabled', - HasConnectedRemotes = 'gitlens:hasConnectedRemotes', - HasRemotes = 'gitlens:hasRemotes', - HasRichRemotes = 'gitlens:hasRichRemotes', - Key = 'gitlens:key', - Readonly = 'gitlens:readonly', - 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', - ViewsWelcomeVisible = 'gitlens:views:welcome:visible', - Vsls = 'gitlens:vsls', -} - -export function setContext(key: ContextKeys | string, value: any) { - return commands.executeCommand(BuiltInCommands.SetContext, key, value); -} - export const enum Colors { GutterBackgroundColor = 'gitlens.gutterBackgroundColor', GutterForegroundColor = 'gitlens.gutterForegroundColor', diff --git a/src/context.ts b/src/context.ts new file mode 100644 index 0000000..55e1c7b --- /dev/null +++ b/src/context.ts @@ -0,0 +1,42 @@ +import { commands } from 'vscode'; +import { BuiltInCommands } from './constants'; + +export const enum ContextKeys { + ActionPrefix = 'gitlens:action:', + KeyPrefix = 'gitlens:key:', + + ActiveFileStatus = 'gitlens:activeFileStatus', + AnnotationStatus = 'gitlens:annotationStatus', + DisabledToggleCodeLens = 'gitlens:disabledToggleCodeLens', + Disabled = 'gitlens:disabled', + Enabled = 'gitlens:enabled', + HasConnectedRemotes = 'gitlens:hasConnectedRemotes', + HasRemotes = 'gitlens:hasRemotes', + HasRichRemotes = 'gitlens:hasRichRemotes', + Readonly = 'gitlens:readonly', + 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', + ViewsWelcomeVisible = 'gitlens:views:welcome:visible', + Vsls = 'gitlens:vsls', +} + +// const contextStorage = new Map(); + +// export function getContext(key: ContextKeys): unknown | undefined { +// return contextStorage.get(key); +// } + +export async function setContext( + key: ContextKeys | `${ContextKeys.ActionPrefix}${string}` | `${ContextKeys.KeyPrefix}${string}`, + value: unknown, +): Promise { + // contextStorage.set(key, value); + void (await commands.executeCommand(BuiltInCommands.SetContext, key, value)); +} diff --git a/src/extension.ts b/src/extension.ts index e848935..1be98b0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,8 +5,8 @@ import type { CreatePullRequestActionContext, GitLensApi, OpenPullRequestActionC import { Commands, executeCommand, OpenPullRequestOnRemoteCommandArgs, registerCommands } from './commands'; import { CreatePullRequestOnRemoteCommandArgs } from './commands/createPullRequestOnRemote'; import { configuration, Configuration, OutputLevel } from './configuration'; -import { ContextKeys, setContext } from './constants'; import { Container } from './container'; +import { ContextKeys, setContext } from './context'; import { GitUri } from './git/gitUri'; import { GitBranch, GitCommit } from './git/models'; import { Logger, LogLevel } from './logger'; diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 3de7283..0c4311a 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -17,8 +17,9 @@ import { } from 'vscode'; import { resetAvatarCache } from '../avatars'; import { configuration } from '../configuration'; -import { BuiltInGitConfiguration, ContextKeys, GlyphChars, Schemes, setContext } from '../constants'; +import { BuiltInGitConfiguration, GlyphChars, Schemes } from '../constants'; import type { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { ProviderNotFoundError } from '../errors'; import { Logger } from '../logger'; import { asRepoComparisonKey, RepoComparisionKey, Repositories } from '../repositories'; diff --git a/src/keyboard.ts b/src/keyboard.ts index 8f53857..cceb56d 100644 --- a/src/keyboard.ts +++ b/src/keyboard.ts @@ -1,5 +1,5 @@ import { commands, Disposable } from 'vscode'; -import { ContextKeys, setContext } from './constants'; +import { ContextKeys, setContext } from './context'; import { Logger } from './logger'; import { log } from './system/decorators/log'; @@ -83,7 +83,7 @@ export class KeyboardScope implements Disposable { } mapping[key] = undefined; - await setContext(`${ContextKeys.Key}:${key}`, false); + await setContext(`${ContextKeys.KeyPrefix}${key}`, false); } @log({ @@ -137,12 +137,12 @@ export class KeyboardScope implements Disposable { mapping[key] = command; if (!set) { - await setContext(`${ContextKeys.Key}:${key}`, true); + await setContext(`${ContextKeys.KeyPrefix}${key}`, true); } } private async updateKeyCommandsContext(mapping: KeyMapping) { - await Promise.all(keys.map(key => setContext(`${ContextKeys.Key}:${key}`, Boolean(mapping?.[key])))); + await Promise.all(keys.map(key => setContext(`${ContextKeys.KeyPrefix}${key}`, Boolean(mapping?.[key])))); } } diff --git a/src/trackers/documentTracker.ts b/src/trackers/documentTracker.ts index 1b22946..127000e 100644 --- a/src/trackers/documentTracker.ts +++ b/src/trackers/documentTracker.ts @@ -16,8 +16,9 @@ import { workspace, } from 'vscode'; import { configuration } from '../configuration'; -import { ContextKeys, isActiveDocument, isTextEditor, setContext } from '../constants'; +import { isActiveDocument, isTextEditor } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { RepositoriesChangeEvent } from '../git/gitProviderService'; import { GitUri } from '../git/gitUri'; import { RepositoryChange, RepositoryChangeComparisonMode, RepositoryChangeEvent } from '../git/models'; diff --git a/src/trackers/trackedDocument.ts b/src/trackers/trackedDocument.ts index e973d1c..41d3260 100644 --- a/src/trackers/trackedDocument.ts +++ b/src/trackers/trackedDocument.ts @@ -1,6 +1,7 @@ import { Disposable, Event, EventEmitter, TextDocument, TextEditor } from 'vscode'; -import { ContextKeys, getEditorIfActive, isActiveDocument, setContext } from '../constants'; +import { getEditorIfActive, isActiveDocument } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { GitUri } from '../git/gitUri'; import { GitRevision } from '../git/models'; import { Logger } from '../logger'; diff --git a/src/views/commitsView.ts b/src/views/commitsView.ts index 358f069..acd9dcd 100644 --- a/src/views/commitsView.ts +++ b/src/views/commitsView.ts @@ -9,8 +9,9 @@ import { window, } from 'vscode'; import { CommitsViewConfig, configuration, ViewFilesLayout, ViewShowBranchComparison } from '../configuration'; -import { ContextKeys, GlyphChars, setContext } from '../constants'; +import { GlyphChars } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { GitUri } from '../git/gitUri'; import { GitCommit, diff --git a/src/views/fileHistoryView.ts b/src/views/fileHistoryView.ts index 4456853..4fb35d8 100644 --- a/src/views/fileHistoryView.ts +++ b/src/views/fileHistoryView.ts @@ -1,7 +1,7 @@ import { commands, ConfigurationChangeEvent, Disposable } from 'vscode'; import { configuration, FileHistoryViewConfig } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { GitUri } from '../git/gitUri'; import { FileHistoryTrackerNode, LineHistoryTrackerNode } from './nodes'; import { ViewBase } from './viewBase'; diff --git a/src/views/lineHistoryView.ts b/src/views/lineHistoryView.ts index 1065b55..a4179c0 100644 --- a/src/views/lineHistoryView.ts +++ b/src/views/lineHistoryView.ts @@ -1,7 +1,7 @@ import { commands, ConfigurationChangeEvent, Disposable } from 'vscode'; import { configuration, LineHistoryViewConfig } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { LineHistoryTrackerNode } from './nodes'; import { ViewBase } from './viewBase'; diff --git a/src/views/nodes/fileHistoryTrackerNode.ts b/src/views/nodes/fileHistoryTrackerNode.ts index 3dc00eb..48cc7a9 100644 --- a/src/views/nodes/fileHistoryTrackerNode.ts +++ b/src/views/nodes/fileHistoryTrackerNode.ts @@ -1,6 +1,7 @@ import { Disposable, FileType, TextEditor, TreeItem, TreeItemCollapsibleState, window, workspace } from 'vscode'; import { UriComparer } from '../../comparers'; -import { ContextKeys, Schemes, setContext } from '../../constants'; +import { Schemes } from '../../constants'; +import { ContextKeys, setContext } from '../../context'; import { GitCommitish, GitUri } from '../../git/gitUri'; import { GitReference, GitRevision } from '../../git/models'; import { Logger } from '../../logger'; diff --git a/src/views/nodes/lineHistoryTrackerNode.ts b/src/views/nodes/lineHistoryTrackerNode.ts index 4b5949a..df70dad 100644 --- a/src/views/nodes/lineHistoryTrackerNode.ts +++ b/src/views/nodes/lineHistoryTrackerNode.ts @@ -1,6 +1,6 @@ import { Selection, TreeItem, TreeItemCollapsibleState, window } from 'vscode'; import { UriComparer } from '../../comparers'; -import { ContextKeys, setContext } from '../../constants'; +import { ContextKeys, setContext } from '../../context'; import { GitCommitish, GitUri } from '../../git/gitUri'; import { GitReference, GitRevision } from '../../git/models'; import { Logger } from '../../logger'; diff --git a/src/views/repositoriesView.ts b/src/views/repositoriesView.ts index 1d52aa3..643b063 100644 --- a/src/views/repositoriesView.ts +++ b/src/views/repositoriesView.ts @@ -15,8 +15,8 @@ import { ViewFilesLayout, ViewShowBranchComparison, } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { GitBranch, GitBranchReference, diff --git a/src/views/searchAndCompareView.ts b/src/views/searchAndCompareView.ts index e085d62..de8dd7e 100644 --- a/src/views/searchAndCompareView.ts +++ b/src/views/searchAndCompareView.ts @@ -1,8 +1,8 @@ import { commands, ConfigurationChangeEvent, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode'; import { getRepoPathOrPrompt } from '../commands'; import { configuration, SearchAndCompareViewConfig, ViewFilesLayout } from '../configuration'; -import { ContextKeys, setContext } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { GitUri } from '../git/gitUri'; import { GitLog, GitRevision } from '../git/models'; import { SearchPattern } from '../git/search'; diff --git a/src/views/viewCommands.ts b/src/views/viewCommands.ts index 2f3b3b3..59a68a6 100644 --- a/src/views/viewCommands.ts +++ b/src/views/viewCommands.ts @@ -12,8 +12,9 @@ import { OpenFileAtRevisionCommandArgs, } from '../commands'; import { configuration, FileAnnotationType, ViewShowBranchComparison } from '../configuration'; -import { BuiltInCommands, BuiltInGitCommands, ContextKeys, setContext } from '../constants'; +import { BuiltInCommands, BuiltInGitCommands } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { GitUri } from '../git/gitUri'; import { GitReference, GitRevision } from '../git/models'; import { debug } from '../system'; diff --git a/src/vsls/vsls.ts b/src/vsls/vsls.ts index 7c44449..651bf18 100644 --- a/src/vsls/vsls.ts +++ b/src/vsls/vsls.ts @@ -1,7 +1,8 @@ import { Disposable, extensions, workspace } from 'vscode'; import type { LiveShare, LiveShareExtension, SessionChangeEvent } from '../@types/vsls'; -import { ContextKeys, Schemes, setContext } from '../constants'; +import { Schemes } from '../constants'; import { Container } from '../container'; +import { ContextKeys, setContext } from '../context'; import { Logger } from '../logger'; import { debug } from '../system/decorators/log'; import { timeout } from '../system/decorators/timeout';