Browse Source

Ensures enabled/disabled context is set correctly

main
Eric Amodio 4 years ago
parent
commit
2e6ebb4b83
3 changed files with 30 additions and 25 deletions
  1. +6
    -3
      src/extension.ts
  2. +20
    -19
      src/git/gitService.ts
  3. +4
    -3
      src/vsls/guest.ts

+ 6
- 3
src/extension.ts View File

@ -60,8 +60,7 @@ export async function activate(context: ExtensionContext) {
const enabled = workspace.getConfiguration('git', null).get<boolean>('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<void> {
await Promise.all([setContext(ContextKeys.Enabled, enabled), setContext(ContextKeys.Disabled, !enabled)]);
}
async function migrateSettings(context: ExtensionContext, previousVersion: string | undefined) {
if (previousVersion === undefined) return;

+ 20
- 19
src/git/gitService.ts View File

@ -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<Repository>) {
const hasRepository = repositoryTree.any();
await setContext(ContextKeys.Enabled, hasRepository);
await setEnabled(hasRepository);
let hasRemotes = false;
let hasConnectedRemotes = false;

+ 4
- 3
src/vsls/guest.ts View File

@ -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.',
);

Loading…
Cancel
Save