diff --git a/src/extension.ts b/src/extension.ts index 0b9301e..ed095da 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -60,8 +60,7 @@ export async function activate(context: ExtensionContext) { const enabled = workspace.getConfiguration('git', null).get('enabled', true); if (!enabled) { Logger.log(`GitLens (v${gitlensVersion}) was NOT activated -- "git.enabled": false`); - void setContext(ContextKeys.Enabled, false); - void setContext(ContextKeys.Disabled, true); + void setEnabled(false); void Messages.showGitDisabledErrorMessage(); @@ -78,7 +77,7 @@ export async function activate(context: ExtensionContext) { await GitService.initialize(); } catch (ex) { Logger.error(ex, `GitLens (v${gitlensVersion}) activate`); - void setContext(ContextKeys.Enabled, false); + void setEnabled(false); const msg: string = ex?.message ?? ''; if (msg.includes('Unable to find git')) { @@ -112,6 +111,10 @@ export function deactivate() { // nothing to do } +export async function setEnabled(enabled: boolean): Promise { + await Promise.all([setContext(ContextKeys.Enabled, enabled), setContext(ContextKeys.Disabled, !enabled)]); +} + async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) { if (previousVersion === undefined) return; diff --git a/src/git/gitService.ts b/src/git/gitService.ts index 4f3b21b..ff8149d 100644 --- a/src/git/gitService.ts +++ b/src/git/gitService.ts @@ -23,23 +23,7 @@ import { resetAvatarCache } from '../avatars'; import { BranchSorting, configuration, TagSorting } from '../configuration'; import { ContextKeys, DocumentSchemes, GlyphChars, setContext } from '../constants'; import { Container } from '../container'; -import { LogCorrelationContext, Logger } from '../logger'; -import { Messages } from '../messages'; -import { - Arrays, - debug, - Functions, - gate, - Iterables, - log, - Objects, - Promises, - Strings, - TernarySearchTree, - Versions, -} from '../system'; -import { CachedBlame, CachedDiff, CachedLog, GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; -import { vslsUriPrefixRegex } from '../vsls/vsls'; +import { setEnabled } from '../extension'; import { Authentication, BranchDateFormatting, @@ -89,9 +73,26 @@ import { SearchPattern, } from './git'; import { GitUri } from './gitUri'; -import { RemoteProvider, RemoteProviderFactory, RemoteProviders, RemoteProviderWithApi } from './remotes/factory'; +import { LogCorrelationContext, Logger } from '../logger'; +import { Messages } from '../messages'; import { GitReflogParser, GitShortLogParser } from './parsers/parsers'; +import { RemoteProvider, RemoteProviderFactory, RemoteProviders, RemoteProviderWithApi } from './remotes/factory'; import { fsExists, isWindows } from './shell'; +import { + Arrays, + debug, + Functions, + gate, + Iterables, + log, + Objects, + Promises, + Strings, + TernarySearchTree, + Versions, +} from '../system'; +import { CachedBlame, CachedDiff, CachedLog, GitDocumentState, TrackedDocument } from '../trackers/gitDocumentTracker'; +import { vslsUriPrefixRegex } from '../vsls/vsls'; const emptyStr = ''; const slash = '/'; @@ -437,7 +438,7 @@ export class GitService implements Disposable { private async updateContext(repositoryTree: TernarySearchTree) { const hasRepository = repositoryTree.any(); - await setContext(ContextKeys.Enabled, hasRepository); + await setEnabled(hasRepository); let hasRemotes = false; let hasConnectedRemotes = false; diff --git a/src/vsls/guest.ts b/src/vsls/guest.ts index be9297c..a477947 100644 --- a/src/vsls/guest.ts +++ b/src/vsls/guest.ts @@ -1,7 +1,7 @@ 'use strict'; import { CancellationToken, Disposable, window, WorkspaceFolder } from 'vscode'; import { LiveShare, SharedServiceProxy } from 'vsls'; -import { ContextKeys, setContext } from '../constants'; +import { setEnabled } from '../extension'; import { GitCommandOptions, Repository, RepositoryChangeEvent } from '../git/git'; import { Logger } from '../logger'; import { debug, log } from '../system'; @@ -38,11 +38,12 @@ export class VslsGuestService implements Disposable { @log() private onAvailabilityChanged(available: boolean) { if (available) { - void setContext(ContextKeys.Enabled, true); + void setEnabled(true); + return; } - void setContext(ContextKeys.Enabled, false); + void setEnabled(false); void window.showWarningMessage( 'GitLens features will be unavailable. Unable to connect to the host GitLens service. The host may have disabled GitLens guest access or may not have GitLens installed.', );