Skip to content

Commit

Permalink
Adds debug logging for sync'd settings
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 20, 2020
1 parent 08e1adf commit 8d4a874
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Container } from './container';
import { Git, GitCommit } from './git/git';
import { GitService } from './git/gitService';
import { GitUri } from './git/gitUri';
import { Logger } from './logger';
import { Logger, TraceLevel } from './logger';
import { Messages } from './messages';
import { Strings, Versions } from './system';
import { ViewNode } from './views/nodes';
Expand All @@ -18,26 +18,11 @@ export async function activate(context: ExtensionContext) {
// Pretend we are enabled (until we know otherwise) and set the view contexts to reduce flashing on load
void setContext(ContextKeys.Enabled, true);

const syncedVersion = context.globalState.get<string>(SyncedState.Version);
const previousVersion =
context.globalState.get<string>(GlobalState.Version) ??
context.globalState.get<string>(GlobalState.DeprecatedVersion) ??
syncedVersion;

if (previousVersion == null) {
void context.globalState.update(SyncedState.WelcomeViewVisible, true);
void setContext(ContextKeys.ViewsWelcomeVisible, true);
void setContext(ContextKeys.ViewsUpdatesVisible, false);
} else {
void setContext(
ContextKeys.ViewsWelcomeVisible,
context.globalState.get(SyncedState.WelcomeViewVisible) ?? false,
);
void setContext(
ContextKeys.ViewsUpdatesVisible,
context.globalState.get(SyncedState.UpdatesViewVisible) !== false,
);
}
context.globalState.setKeysForSync([
SyncedState.Version,
SyncedState.UpdatesViewVisible,
SyncedState.WelcomeViewVisible,
]);

Logger.configure(context, configuration.get('outputLevel'), o => {
if (GitUri.is(o)) {
Expand All @@ -60,6 +45,37 @@ export async function activate(context: ExtensionContext) {
const gitlens = extensions.getExtension(extensionQualifiedId)!;
const gitlensVersion = gitlens.packageJSON.version;

const syncedVersion = context.globalState.get<string>(SyncedState.Version);
const previousVersion =
context.globalState.get<string>(GlobalState.Version) ??
context.globalState.get<string>(GlobalState.DeprecatedVersion) ??
syncedVersion;

if (Logger.level === TraceLevel.Debug || Logger.isDebugging) {
Logger.debug(
`GitLens (v${gitlensVersion}): syncedVersion=${syncedVersion}, previousVersion=${previousVersion}, ${
SyncedState.WelcomeViewVisible
}=${context.globalState.get<boolean>(SyncedState.WelcomeViewVisible)}, ${
SyncedState.UpdatesViewVisible
}=${context.globalState.get<boolean>(SyncedState.UpdatesViewVisible)}`,
);
}

if (previousVersion == null) {
void context.globalState.update(SyncedState.WelcomeViewVisible, true);
void setContext(ContextKeys.ViewsWelcomeVisible, true);
void setContext(ContextKeys.ViewsUpdatesVisible, false);
} else {
void setContext(
ContextKeys.ViewsWelcomeVisible,
context.globalState.get<boolean>(SyncedState.WelcomeViewVisible) ?? false,
);
void setContext(
ContextKeys.ViewsUpdatesVisible,
context.globalState.get<boolean>(SyncedState.UpdatesViewVisible) !== false,
);
}

const enabled = workspace.getConfiguration('git', null).get<boolean>('enabled', true);
if (!enabled) {
Logger.log(`GitLens (v${gitlensVersion}) was NOT activated -- "git.enabled": false`);
Expand Down Expand Up @@ -101,12 +117,6 @@ export async function activate(context: ExtensionContext) {
notifyOnUnsupportedGitVersion(gitVersion);
void showWelcomeOrWhatsNew(gitlensVersion, previousVersion);

context.globalState.setKeysForSync([
SyncedState.Version,
SyncedState.UpdatesViewVisible,
SyncedState.WelcomeViewVisible,
]);

void context.globalState.update(GlobalState.Version, gitlensVersion);

// Only update our synced version if the new version is greater
Expand Down

0 comments on commit 8d4a874

Please sign in to comment.