Переглянути джерело

Moves all storage access into new class

main
Eric Amodio 2 роки тому
джерело
коміт
5c748e0fb9
19 змінених файлів з 224 додано та 178 видалено
  1. +4
    -4
      src/avatars.ts
  2. +3
    -2
      src/commands/closeView.ts
  3. +4
    -4
      src/commands/gitCommands.ts
  4. +3
    -2
      src/commands/showView.ts
  5. +11
    -102
      src/constants.ts
  6. +8
    -0
      src/container.ts
  7. +4
    -3
      src/env/node/git/localGitProvider.ts
  8. +10
    -9
      src/extension.ts
  9. +4
    -3
      src/git/gitProviderService.ts
  10. +2
    -2
      src/git/models/branch.ts
  11. +3
    -3
      src/git/models/remote.ts
  12. +5
    -4
      src/git/models/repository.ts
  13. +8
    -8
      src/git/remotes/provider.ts
  14. +129
    -0
      src/storage.ts
  15. +8
    -9
      src/views/nodes/compareBranchNode.ts
  16. +2
    -1
      src/views/nodes/comparePickerNode.ts
  17. +1
    -1
      src/views/nodes/compareResultsNode.ts
  18. +5
    -4
      src/views/repositoriesView.ts
  19. +10
    -17
      src/views/searchAndCompareView.ts

+ 4
- 4
src/avatars.ts Переглянути файл

@ -1,8 +1,8 @@
import { EventEmitter, Uri } from 'vscode';
import { GravatarDefaultStyle } from './config';
import { GlobalState } from './constants';
import { Container } from './container';
import { GitRevisionReference } from './git/models';
import { GlobalState } from './storage';
import { debounce } from './system/function';
import { filterMap } from './system/iterable';
import { base64, equalsIgnoreCase, md5 } from './system/string';
@ -27,7 +27,7 @@ _onDidFetchAvatar.event(
),
]
: undefined;
void Container.instance.context.globalState.update(GlobalState.Avatars, avatars);
void Container.instance.storage.store(GlobalState.Avatars, avatars);
}, 1000),
);
@ -137,7 +137,7 @@ function createOrUpdateAvatar(
function ensureAvatarCache(cache: Map<string, Avatar> | undefined): asserts cache is Map<string, Avatar> {
if (cache == null) {
const avatars: [string, Avatar][] | undefined = Container.instance.context.globalState
const avatars: [string, Avatar][] | undefined = Container.instance.storage
.get<[string, SerializedAvatar][]>(GlobalState.Avatars)
?.map<[string, Avatar]>(([key, avatar]) => [
key,
@ -246,7 +246,7 @@ export function getPresenceDataUri(status: ContactPresenceStatus) {
export function resetAvatarCache(reset: 'all' | 'failed' | 'fallback') {
switch (reset) {
case 'all':
void Container.instance.context.globalState.update(GlobalState.Avatars, undefined);
void Container.instance.storage.delete(GlobalState.Avatars);
avatarCache?.clear();
avatarQueue.clear();
break;

+ 3
- 2
src/commands/closeView.ts Переглянути файл

@ -1,5 +1,6 @@
import { ContextKeys, setContext, SyncedState } from '../constants';
import { ContextKeys, setContext } from '../constants';
import type { Container } from '../container';
import { SyncedState } from '../storage';
import { command, Command, CommandContext, Commands } from './common';
@command()
@ -15,7 +16,7 @@ export class CloseViewCommand extends Command {
async execute(command: Commands) {
switch (command) {
case Commands.CloseWelcomeView:
await this.container.context.globalState.update(SyncedState.WelcomeViewVisible, false);
await this.container.storage.store(SyncedState.WelcomeViewVisible, false);
await setContext(ContextKeys.ViewsWelcomeVisible, false);
break;
}

+ 4
- 4
src/commands/gitCommands.ts Переглянути файл

@ -1,9 +1,9 @@
import { Disposable, InputBox, QuickInputButton, QuickInputButtons, QuickPick, QuickPickItem, window } from 'vscode';
import { configuration, GitCommandSorting } from '../configuration';
import { Usage, WorkspaceState } from '../constants';
import type { Container } from '../container';
import { KeyMapping } from '../keyboard';
import { Directive, DirectiveQuickPickItem } from '../quickpicks';
import { Usage, WorkspaceState } from '../storage';
import { log } from '../system/decorators/log';
import { isPromise } from '../system/promise';
import { command, Command, CommandContext, Commands } from './common';
@ -772,7 +772,7 @@ class PickCommandStep implements QuickPickStep {
];
if (this.container.config.gitCommands.sortBy === GitCommandSorting.Usage) {
const usage = this.container.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
const usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (usage != null) {
this.items.sort((a, b) => (usage[b.key] ?? 0) - (usage[a.key] ?? 0));
}
@ -812,12 +812,12 @@ class PickCommandStep implements QuickPickStep {
}
private async updateCommandUsage(id: string, timestamp: number) {
let usage = this.container.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
let usage = this.container.storage.getWorkspace<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (usage === undefined) {
usage = Object.create(null) as Usage;
}
usage[id] = timestamp;
await this.container.context.workspaceState.update(WorkspaceState.GitCommandPaletteUsage, usage);
await this.container.storage.storeWorkspace(WorkspaceState.GitCommandPaletteUsage, usage);
}
}

+ 3
- 2
src/commands/showView.ts Переглянути файл

@ -1,6 +1,7 @@
import { commands } from 'vscode';
import { ContextKeys, setContext, SyncedState } from '../constants';
import { ContextKeys, setContext } from '../constants';
import type { Container } from '../container';
import { SyncedState } from '../storage';
import { command, Command, CommandContext, Commands } from './common';
@command()
@ -49,7 +50,7 @@ export class ShowViewCommand extends Command {
return this.container.tagsView.show();
case Commands.ShowWelcomeView:
await setContext(ContextKeys.ViewsWelcomeVisible, true);
void this.container.context.globalState.update(SyncedState.WelcomeViewVisible, true);
void this.container.storage.store(SyncedState.WelcomeViewVisible, true);
void (await commands.executeCommand('gitlens.views.welcome.focus'));
}

+ 11
- 102
src/constants.ts Переглянути файл

@ -1,8 +1,17 @@
import { commands, TextDocument, TextEditor, window } from 'vscode';
import { ViewShowBranchComparison } from './config';
import { SearchPattern } from './git/search';
export const quickPickTitleMaxChars = 80;
export const ImageMimetypes: Record<string, string> = {
'.png': 'image/png',
'.gif': 'image/gif',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.jpe': 'image/jpeg',
'.webp': 'image/webp',
'.tif': 'image/tiff',
'.tiff': 'image/tiff',
'.bmp': 'image/bmp',
};
export const enum BuiltInCommands {
CloseActiveEditor = 'workbench.action.closeActiveEditor',
@ -174,103 +183,3 @@ export const enum GlyphChars {
Warning = '\u26a0',
ZeroWidthSpace = '\u200b',
}
export const enum SyncedState {
Version = 'gitlens:synced:version',
WelcomeViewVisible = 'gitlens:views:welcome:visible',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
}
export const enum GlobalState {
Avatars = 'gitlens:avatars',
PendingWelcomeOnFocus = 'gitlens:pendingWelcomeOnFocus',
PendingWhatsNewOnFocus = 'gitlens:pendingWhatsNewOnFocus',
Version = 'gitlens:version',
Deprecated_Version = 'gitlensVersion',
}
export const ImageMimetypes: Record<string, string> = {
'.png': 'image/png',
'.gif': 'image/gif',
'.jpg': 'image/jpeg',
'.jpeg': 'image/jpeg',
'.jpe': 'image/jpeg',
'.webp': 'image/webp',
'.tif': 'image/tiff',
'.tiff': 'image/tiff',
'.bmp': 'image/bmp',
};
export interface BranchComparison {
ref: string;
notation: '..' | '...' | undefined;
type: Exclude<ViewShowBranchComparison, false> | undefined;
}
export interface BranchComparisons {
[id: string]: string | BranchComparison;
}
export interface NamedRef {
label?: string;
ref: string;
}
export interface PinnedComparison {
type: 'comparison';
timestamp: number;
path: string;
ref1: NamedRef;
ref2: NamedRef;
notation?: '..' | '...';
}
export interface PinnedSearch {
type: 'search';
timestamp: number;
path: string;
labels: {
label: string;
queryLabel:
| string
| {
label: string;
resultsType?: { singular: string; plural: string };
};
};
search: SearchPattern;
}
export type PinnedItem = PinnedComparison | PinnedSearch;
export interface PinnedItems {
[id: string]: PinnedItem;
}
export interface Starred {
[id: string]: boolean;
}
export interface Usage {
[id: string]: number;
}
export const enum WorkspaceState {
AssumeRepositoriesOnStartup = 'gitlens:assumeRepositoriesOnStartup',
GitPath = 'gitlens:gitPath',
BranchComparisons = 'gitlens:branch:comparisons',
ConnectedPrefix = 'gitlens:connected:',
DefaultRemote = 'gitlens:remote:default',
GitCommandPaletteUsage = 'gitlens:gitComandPalette:usage',
StarredBranches = 'gitlens:starred:branches',
StarredRepositories = 'gitlens:starred:repositories',
ViewsRepositoriesAutoRefresh = 'gitlens:views:repositories:autoRefresh',
ViewsSearchAndCompareKeepResults = 'gitlens:views:searchAndCompare:keepResults',
ViewsSearchAndComparePinnedItems = 'gitlens:views:searchAndCompare:pinned',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
Deprecated_PinnedComparisons = 'gitlens:pinned:comparisons',
}

+ 8
- 0
src/container.ts Переглянути файл

@ -22,6 +22,7 @@ import { LineHoverController } from './hovers/lineHoverController';
import { Keyboard } from './keyboard';
import { Logger } from './logger';
import { StatusBarController } from './statusbar/statusBarController';
import { Storage } from './storage';
import { log } from './system/decorators/log';
import { memoize } from './system/decorators/memoize';
import { GitTerminalLinkProvider } from './terminal/linkProvider';
@ -136,6 +137,8 @@ export class Container {
private constructor(context: ExtensionContext, config: Config) {
this._context = context;
this._config = this.applyMode(config);
this._storage = new Storage(this._context);
context.subscriptions.push(configuration.onWillChange(this.onConfigurationChanging, this));
context.subscriptions.push((this._git = new GitProviderService(this)));
@ -413,6 +416,11 @@ export class Container {
return this._statusBarController;
}
private readonly _storage: Storage;
get storage(): Storage {
return this._storage;
}
private _tagsView: TagsView | undefined;
get tagsView() {
if (this._tagsView == null) {

+ 4
- 3
src/env/node/git/localGitProvider.ts Переглянути файл

@ -23,7 +23,7 @@ import type {
GitExtension,
} from '../../../@types/vscode.git';
import { configuration } from '../../../configuration';
import { BuiltInGitConfiguration, GlyphChars, Schemes, WorkspaceState } from '../../../constants';
import { BuiltInGitConfiguration, GlyphChars, Schemes } from '../../../constants';
import type { Container } from '../../../container';
import { StashApplyError, StashApplyErrorReason } from '../../../git/errors';
import {
@ -95,6 +95,7 @@ import { RemoteProvider, RichRemoteProvider } from '../../../git/remotes/provide
import { SearchPattern } from '../../../git/search';
import { LogCorrelationContext, Logger } from '../../../logger';
import { Messages } from '../../../messages';
import { WorkspaceState } from '../../../storage';
import { countStringLength, filterMap } from '../../../system/array';
import { gate } from '../../../system/decorators/gate';
import { debug, log } from '../../../system/decorators/log';
@ -265,7 +266,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const potentialGitPaths =
configuration.getAny<string | string[]>('git.path') ??
this.container.context.workspaceState.get(WorkspaceState.GitPath, undefined);
this.container.storage.getWorkspace(WorkspaceState.GitPath, undefined);
const start = hrtime();
@ -289,7 +290,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const location = await any<GitLocation>(findGitPromise, findGitFromSCMPromise);
// Save the found git path, but let things settle first to not impact startup performance
setTimeout(() => {
void this.container.context.workspaceState.update(WorkspaceState.GitPath, location.path);
void this.container.storage.storeWorkspace(WorkspaceState.GitPath, location.path);
}, 1000);
if (cc != null) {

+ 10
- 9
src/extension.ts Переглянути файл

@ -5,13 +5,14 @@ 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, GlobalState, setContext, SyncedState } from './constants';
import { ContextKeys, setContext } from './constants';
import { Container } from './container';
import { GitUri } from './git/gitUri';
import { GitBranch, GitCommit } from './git/models';
import { Logger, LogLevel } from './logger';
import { Messages } from './messages';
import { registerPartnerActionRunners } from './partners';
import { GlobalState, SyncedState } from './storage';
import { once } from './system/event';
import { Stopwatch } from './system/stopwatch';
import { compare } from './system/version';
@ -199,19 +200,19 @@ async function showWelcomeOrWhatsNew(container: Container, version: string, prev
if (container.config.showWelcomeOnInstall === false) return;
if (window.state.focused) {
await container.context.globalState.update(GlobalState.PendingWelcomeOnFocus, undefined);
await container.storage.delete(GlobalState.PendingWelcomeOnFocus);
await commands.executeCommand(Commands.ShowWelcomePage);
} else {
// Save pending on window getting focus
await container.context.globalState.update(GlobalState.PendingWelcomeOnFocus, true);
await container.storage.store(GlobalState.PendingWelcomeOnFocus, true);
const disposable = window.onDidChangeWindowState(e => {
if (!e.focused) return;
disposable.dispose();
// If the window is now focused and we are pending the welcome, clear the pending state and show the welcome
if (container.context.globalState.get(GlobalState.PendingWelcomeOnFocus) === true) {
void container.context.globalState.update(GlobalState.PendingWelcomeOnFocus, undefined);
if (container.storage.get(GlobalState.PendingWelcomeOnFocus) === true) {
void container.storage.delete(GlobalState.PendingWelcomeOnFocus);
if (container.config.showWelcomeOnInstall) {
void commands.executeCommand(Commands.ShowWelcomePage);
}
@ -240,19 +241,19 @@ async function showWelcomeOrWhatsNew(container: Container, version: string, prev
if (major !== prevMajor && container.config.showWhatsNewAfterUpgrades) {
if (window.state.focused) {
await container.context.globalState.update(GlobalState.PendingWhatsNewOnFocus, undefined);
await container.storage.delete(GlobalState.PendingWhatsNewOnFocus);
await Messages.showWhatsNewMessage(version);
} else {
// Save pending on window getting focus
await container.context.globalState.update(GlobalState.PendingWhatsNewOnFocus, true);
await container.storage.store(GlobalState.PendingWhatsNewOnFocus, true);
const disposable = window.onDidChangeWindowState(e => {
if (!e.focused) return;
disposable.dispose();
// If the window is now focused and we are pending the what's new, clear the pending state and show the what's new
if (container.context.globalState.get(GlobalState.PendingWhatsNewOnFocus) === true) {
void container.context.globalState.update(GlobalState.PendingWhatsNewOnFocus, undefined);
if (container.storage.get(GlobalState.PendingWhatsNewOnFocus) === true) {
void container.storage.delete(GlobalState.PendingWhatsNewOnFocus);
if (container.config.showWhatsNewAfterUpgrades) {
void Messages.showWhatsNewMessage(version);
}

+ 4
- 3
src/git/gitProviderService.ts Переглянути файл

@ -17,11 +17,12 @@ import {
} from 'vscode';
import { resetAvatarCache } from '../avatars';
import { configuration } from '../configuration';
import { BuiltInGitConfiguration, ContextKeys, GlyphChars, Schemes, setContext, WorkspaceState } from '../constants';
import { BuiltInGitConfiguration, ContextKeys, GlyphChars, Schemes, setContext } from '../constants';
import type { Container } from '../container';
import { ProviderNotFoundError } from '../errors';
import { Logger } from '../logger';
import { asRepoComparisonKey, RepoComparisionKey, Repositories } from '../repositories';
import { WorkspaceState } from '../storage';
import { groupByFilterMap, groupByMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
@ -493,7 +494,7 @@ export class GitProviderService implements Disposable {
// If we think we should be disabled during startup, check if we have a saved value from the last time this repo was loaded
if (!enabled && this._initializing) {
disabled = !(
this.container.context.workspaceState.get<boolean>(WorkspaceState.AssumeRepositoriesOnStartup) ?? true
this.container.storage.getWorkspace<boolean>(WorkspaceState.AssumeRepositoriesOnStartup) ?? true
);
}
@ -514,7 +515,7 @@ export class GitProviderService implements Disposable {
await Promise.all(promises);
if (!this._initializing) {
void this.container.context.workspaceState.update(WorkspaceState.AssumeRepositoriesOnStartup, enabled);
void this.container.storage.storeWorkspace(WorkspaceState.AssumeRepositoriesOnStartup, enabled);
}
}

+ 2
- 2
src/git/models/branch.ts Переглянути файл

@ -1,6 +1,6 @@
import { BranchSorting, configuration, DateStyle } from '../../configuration';
import { Starred, WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { Starred, WorkspaceState } from '../../storage';
import { formatDate, fromNow } from '../../system/date';
import { debug } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
@ -234,7 +234,7 @@ export class GitBranch implements GitBranchReference {
}
get starred() {
const starred = Container.instance.context.workspaceState.get<Starred>(WorkspaceState.StarredBranches);
const starred = Container.instance.storage.getWorkspace<Starred>(WorkspaceState.StarredBranches);
return starred !== undefined && starred[this.id] === true;
}

+ 3
- 3
src/git/models/remote.ts Переглянути файл

@ -1,5 +1,5 @@
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { WorkspaceState } from '../../storage';
import { sortCompare } from '../../system/string';
import { RemoteProvider, RichRemoteProvider } from '../remotes/provider';
@ -59,7 +59,7 @@ export class GitRemote
) {}
get default() {
const defaultRemote = Container.instance.context.workspaceState.get<string>(WorkspaceState.DefaultRemote);
const defaultRemote = Container.instance.storage.getWorkspace<string>(WorkspaceState.DefaultRemote);
return this.id === defaultRemote;
}
@ -83,7 +83,7 @@ export class GitRemote
}
async setAsDefault(state: boolean = true, updateViews: boolean = true) {
void (await Container.instance.context.workspaceState.update(
void (await Container.instance.storage.storeWorkspace(
WorkspaceState.DefaultRemote,
state ? this.id : undefined,
));

+ 5
- 4
src/git/models/repository.ts Переглянути файл

@ -14,11 +14,12 @@ import {
import type { CreatePullRequestActionContext } from '../../api/gitlens';
import { executeActionCommand } from '../../commands';
import { configuration } from '../../configuration';
import { BuiltInGitCommands, BuiltInGitConfiguration, Schemes, Starred, WorkspaceState } from '../../constants';
import { BuiltInGitCommands, BuiltInGitConfiguration, Schemes } from '../../constants';
import { Container } from '../../container';
import { Logger } from '../../logger';
import { Messages } from '../../messages';
import { asRepoComparisonKey } from '../../repositories';
import { Starred, WorkspaceState } from '../../storage';
import { filterMap, groupByMap } from '../../system/array';
import { formatDate, fromNow } from '../../system/date';
import { gate } from '../../system/decorators/gate';
@ -821,7 +822,7 @@ export class Repository implements Disposable {
}
get starred() {
const starred = this.container.context.workspaceState.get<Starred>(WorkspaceState.StarredRepositories);
const starred = this.container.storage.getWorkspace<Starred>(WorkspaceState.StarredRepositories);
return starred != null && starred[this.id] === true;
}
@ -900,7 +901,7 @@ export class Repository implements Disposable {
}
private async updateStarredCore(key: WorkspaceState, id: string, star: boolean) {
let starred = this.container.context.workspaceState.get<Starred>(key);
let starred = this.container.storage.getWorkspace<Starred>(key);
if (starred === undefined) {
starred = Object.create(null) as Starred;
}
@ -911,7 +912,7 @@ export class Repository implements Disposable {
const { [id]: _, ...rest } = starred;
starred = rest;
}
await this.container.context.workspaceState.update(key, starred);
await this.container.storage.storeWorkspace(key, starred);
this.fireChange(RepositoryChange.Starred);
}

+ 8
- 8
src/git/remotes/provider.ts Переглянути файл

@ -10,10 +10,10 @@ import {
} from 'vscode';
import { DynamicAutolinkReference } from '../../annotations/autolinks';
import { AutolinkReference } from '../../config';
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { AuthenticationError, ProviderRequestClientError } from '../../errors';
import { Logger } from '../../logger';
import { WorkspaceState } from '../../storage';
import { gate } from '../../system/decorators/gate';
import { debug, log } from '../../system/decorators/log';
import { encodeUrl } from '../../system/encoding';
@ -303,7 +303,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
return this.custom ? `${this.name}:${this.domain}` : this.name;
}
private get connectedKey() {
private get connectedKey() class="o">: `${WorkspaceState.ConnectedPrefix}${string}` {
return `${WorkspaceState.ConnectedPrefix}${this.key}`;
}
@ -346,7 +346,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
this._session = null;
if (connected) {
void Container.instance.context.workspaceState.update(this.connectedKey, false);
void Container.instance.storage.storeWorkspace(this.connectedKey, false);
this._onDidChange.fire();
if (!silent) {
@ -573,8 +573,8 @@ export abstract class RichRemoteProvider extends RemoteProvider {
if (!Container.instance.config.integrations.enabled) return undefined;
if (createIfNeeded) {
await Container.instance.context.workspaceState.update(this.connectedKey, undefined);
} else if (Container.instance.context.workspaceState.get<boolean>(this.connectedKey) === false) {
await Container.instance.storage.deleteWorkspace(this.connectedKey);
} else if (Container.instance.storage.getWorkspace<boolean>(this.connectedKey) === false) {
return undefined;
}
@ -585,7 +585,7 @@ export abstract class RichRemoteProvider extends RemoteProvider {
silent: !createIfNeeded,
});
} catch (ex) {
await Container.instance.context.workspaceState.update(this.connectedKey, undefined);
await Container.instance.storage.deleteWorkspace(this.connectedKey);
if (ex instanceof Error && ex.message.includes('User did not consent')) {
return undefined;
@ -595,14 +595,14 @@ export abstract class RichRemoteProvider extends RemoteProvider {
}
if (session === undefined && !createIfNeeded) {
await Container.instance.context.workspaceState.update(this.connectedKey, undefined);
await Container.instance.storage.deleteWorkspace(this.connectedKey);
}
this._session = session ?? null;
this.invalidClientExceptionCount = 0;
if (session != null) {
await Container.instance.context.workspaceState.update(this.connectedKey, true);
await Container.instance.storage.storeWorkspace(this.connectedKey, true);
queueMicrotask(() => {
this._onDidChange.fire();

+ 129
- 0
src/storage.ts Переглянути файл

@ -0,0 +1,129 @@
import { ExtensionContext } from 'vscode';
import { ViewShowBranchComparison } from './config';
import { SearchPattern } from './git/search';
export class Storage {
constructor(private readonly context: ExtensionContext) {}
get<T>(key: GlobalState | SyncedState): T | undefined;
get<T>(key: GlobalState | SyncedState, defaultValue: T): T;
get<T>(key: GlobalState | SyncedState, defaultValue?: T): T | undefined {
return this.context.globalState.get(key, defaultValue);
}
async delete(key: GlobalState | SyncedState): Promise<void> {
return this.context.globalState.update(key, undefined);
}
async store(key: GlobalState | SyncedState, value: unknown): Promise<void> {
return this.context.globalState.update(key, value);
}
getWorkspace<T>(key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`): T | undefined;
getWorkspace<T>(key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`, defaultValue: T): T;
getWorkspace<T>(
key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`,
defaultValue?: T,
): T | undefined {
return this.context.workspaceState.get(key, defaultValue);
}
async deleteWorkspace(key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`): Promise<void> {
return this.context.workspaceState.update(key, undefined);
}
async storeWorkspace(
key: WorkspaceState | `${WorkspaceState.ConnectedPrefix}${string}`,
value: unknown,
): Promise<void> {
return this.context.workspaceState.update(key, value);
}
}
export const enum GlobalState {
Avatars = 'gitlens:avatars',
PendingWelcomeOnFocus = 'gitlens:pendingWelcomeOnFocus',
PendingWhatsNewOnFocus = 'gitlens:pendingWhatsNewOnFocus',
Version = 'gitlens:version',
Deprecated_Version = 'gitlensVersion',
}
export const enum SyncedState {
Version = 'gitlens:synced:version',
WelcomeViewVisible = 'gitlens:views:welcome:visible',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
}
export const enum WorkspaceState {
AssumeRepositoriesOnStartup = 'gitlens:assumeRepositoriesOnStartup',
GitPath = 'gitlens:gitPath',
BranchComparisons = 'gitlens:branch:comparisons',
ConnectedPrefix = 'gitlens:connected:',
DefaultRemote = 'gitlens:remote:default',
GitCommandPaletteUsage = 'gitlens:gitComandPalette:usage',
StarredBranches = 'gitlens:starred:branches',
StarredRepositories = 'gitlens:starred:repositories',
ViewsRepositoriesAutoRefresh = 'gitlens:views:repositories:autoRefresh',
ViewsSearchAndCompareKeepResults = 'gitlens:views:searchAndCompare:keepResults',
ViewsSearchAndComparePinnedItems = 'gitlens:views:searchAndCompare:pinned',
Deprecated_DisallowConnectionPrefix = 'gitlens:disallow:connection:',
Deprecated_PinnedComparisons = 'gitlens:pinned:comparisons',
}
export interface BranchComparison {
ref: string;
notation: '..' | '...' | undefined;
type: Exclude<ViewShowBranchComparison, false> | undefined;
}
export interface BranchComparisons {
[id: string]: string | BranchComparison;
}
export interface NamedRef {
label?: string;
ref: string;
}
export interface PinnedComparison {
type: 'comparison';
timestamp: number;
path: string;
ref1: NamedRef;
ref2: NamedRef;
notation?: '..' | '...';
}
export interface PinnedSearch {
type: 'search';
timestamp: number;
path: string;
labels: {
label: string;
queryLabel:
| string
| {
label: string;
resultsType?: { singular: string; plural: string };
};
};
search: SearchPattern;
}
export type PinnedItem = PinnedComparison | PinnedSearch;
export interface PinnedItems {
[id: string]: PinnedItem;
}
export interface Starred {
[id: string]: boolean;
}
export interface Usage {
[id: string]: number;
}

+ 8
- 9
src/views/nodes/compareBranchNode.ts Переглянути файл

@ -1,9 +1,10 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { ViewShowBranchComparison } from '../../configuration';
import { BranchComparison, BranchComparisons, GlyphChars, WorkspaceState } from '../../constants';
import { GlyphChars } from '../../constants';
import { GitUri } from '../../git/gitUri';
import { GitBranch, GitRevision } from '../../git/models';
import { CommandQuickPickItem, ReferencePicker } from '../../quickpicks';
import { BranchComparison, BranchComparisons, WorkspaceState } from '../../storage';
import { debug, gate, log, Strings } from '../../system';
import { BranchesView } from '../branchesView';
import { CommitsView } from '../commitsView';
@ -310,12 +311,12 @@ export class CompareBranchNode extends ViewNode
private async getFilesQuery(): Promise<FilesQueryResults> {
let comparison;
if (this._compareWith!.ref === '') {
if (!this._compareWith?.ref) {
comparison = this.branch.ref;
} else if (this.compareWithWorkingTree) {
comparison = this._compareWith!.ref;
comparison = this._compareWith.ref;
} else {
comparison = `${this._compareWith!.ref}..${this.branch.ref}`;
comparison = `${this._compareWith.ref}..${this.branch.ref}`;
}
const files = await this.view.container.git.getDiffStatus(this.uri.repoPath!, comparison);
@ -327,7 +328,7 @@ export class CompareBranchNode extends ViewNode
}
private loadCompareWith() {
const comparisons = this.view.container.context.workspaceState.get<BranchComparisons>(
const comparisons = this.view.container.storage.getWorkspace<BranchComparisons>(
WorkspaceState.BranchComparisons,
);
@ -347,9 +348,7 @@ export class CompareBranchNode extends ViewNode
private async updateCompareWith(compareWith: BranchComparison | undefined) {
this._compareWith = compareWith;
let comparisons = this.view.container.context.workspaceState.get<BranchComparisons>(
WorkspaceState.BranchComparisons,
);
let comparisons = this.view.container.storage.getWorkspace<BranchComparisons>(WorkspaceState.BranchComparisons);
if (comparisons == null) {
if (compareWith == null) return;
@ -366,6 +365,6 @@ export class CompareBranchNode extends ViewNode
const { [id]: _, ...rest } = comparisons;
comparisons = rest;
}
await this.view.container.context.workspaceState.update(WorkspaceState.BranchComparisons, comparisons);
await this.view.container.storage.storeWorkspace(WorkspaceState.BranchComparisons, comparisons);
}
}

+ 2
- 1
src/views/nodes/comparePickerNode.ts Переглянути файл

@ -1,6 +1,7 @@
import { TreeItem, TreeItemCollapsibleState } from 'vscode';
import { GlyphChars, NamedRef } from '../../constants';
import { GlyphChars } from '../../constants';
import { GitUri } from '../../git/gitUri';
import { NamedRef } from '../../storage';
import { SearchAndCompareView, SearchAndCompareViewNode } from '../searchAndCompareView';
import { ContextValues, ViewNode } from './viewNode';

+ 1
- 1
src/views/nodes/compareResultsNode.ts Переглянути файл

@ -1,7 +1,7 @@
import { ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { NamedRef } from '../../constants';
import { GitUri } from '../../git/gitUri';
import { GitRevision } from '../../git/models';
import { NamedRef } from '../../storage';
import { debug, gate, log, Strings } from '../../system';
import { SearchAndCompareView } from '../searchAndCompareView';
import { RepositoryNode } from './repositoryNode';

+ 5
- 4
src/views/repositoriesView.ts Переглянути файл

@ -15,7 +15,7 @@ import {
ViewFilesLayout,
ViewShowBranchComparison,
} from '../configuration';
import { ContextKeys, setContext, WorkspaceState } from '../constants';
import { ContextKeys, setContext } from '../constants';
import { Container } from '../container';
import {
GitBranch,
@ -28,6 +28,7 @@ import {
GitStashReference,
GitTagReference,
} from '../git/models';
import { WorkspaceState } from '../storage';
import { gate } from '../system';
import {
BranchesNode,
@ -273,7 +274,7 @@ export class RepositoriesView extends ViewBase
get autoRefresh() {
return (
this.config.autoRefresh &&
this.container.context.workspaceState.get<boolean>(WorkspaceState.ViewsRepositoriesAutoRefresh, true)
this.container.storage.getWorkspace<boolean>(WorkspaceState.ViewsRepositoriesAutoRefresh, true)
);
}
@ -770,12 +771,12 @@ export class RepositoriesView extends ViewBase
private async setAutoRefresh(enabled: boolean, workspaceEnabled?: boolean) {
if (enabled) {
if (workspaceEnabled === undefined) {
workspaceEnabled = this.container.context.workspaceState.get<boolean>(
workspaceEnabled = this.container.storage.getWorkspace<boolean>(
WorkspaceState.ViewsRepositoriesAutoRefresh,
true,
);
} else {
await this.container.context.workspaceState.update(
await this.container.storage.storeWorkspace(
WorkspaceState.ViewsRepositoriesAutoRefresh,
workspaceEnabled,
);

+ 10
- 17
src/views/searchAndCompareView.ts Переглянути файл

@ -1,12 +1,13 @@
import { commands, ConfigurationChangeEvent, Disposable, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { getRepoPathOrPrompt } from '../commands';
import { configuration, SearchAndCompareViewConfig, ViewFilesLayout } from '../configuration';
import { ContextKeys, NamedRef, PinnedItem, PinnedItems, setContext, WorkspaceState } from '../constants';
import { ContextKeys, setContext } from '../constants';
import { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { GitLog, GitRevision } from '../git/models';
import { SearchPattern } from '../git/search';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import { NamedRef, PinnedItem, PinnedItems, WorkspaceState } from '../storage';
import { filterMap } from '../system/array';
import { gate } from '../system/decorators/gate';
import { debug, log } from '../system/decorators/log';
@ -355,10 +356,7 @@ export class SearchAndCompareView extends ViewBase
}
get keepResults(): boolean {
return this.container.context.workspaceState.get<boolean>(
WorkspaceState.ViewsSearchAndCompareKeepResults,
true,
);
return this.container.storage.getWorkspace<boolean>(WorkspaceState.ViewsSearchAndCompareKeepResults, true);
}
clear() {
@ -436,12 +434,12 @@ export class SearchAndCompareView extends ViewBase
}
getPinned() {
let savedPins = this.container.context.workspaceState.get<PinnedItems>(
let savedPins = this.container.storage.getWorkspace<PinnedItems>(
WorkspaceState.ViewsSearchAndComparePinnedItems,
);
if (savedPins == null) {
// Migrate any deprecated pinned items
const deprecatedPins = this.container.context.workspaceState.get<DeprecatedPinnedComparisons>(
const deprecatedPins = this.container.storage.getWorkspace<DeprecatedPinnedComparisons>(
WorkspaceState.Deprecated_PinnedComparisons,
);
if (deprecatedPins == null) return [];
@ -457,11 +455,8 @@ export class SearchAndCompareView extends ViewBase
};
}
void this.container.context.workspaceState.update(
WorkspaceState.ViewsSearchAndComparePinnedItems,
savedPins,
);
void this.container.context.workspaceState.update(WorkspaceState.Deprecated_PinnedComparisons, undefined);
void this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndComparePinnedItems, savedPins);
void this.container.storage.deleteWorkspace(WorkspaceState.Deprecated_PinnedComparisons);
}
const root = this.ensureRoot();
@ -482,9 +477,7 @@ export class SearchAndCompareView extends ViewBase
}
async updatePinned(id: string, pin?: PinnedItem) {
let pinned = this.container.context.workspaceState.get<PinnedItems>(
WorkspaceState.ViewsSearchAndComparePinnedItems,
);
let pinned = this.container.storage.getWorkspace<PinnedItems>(WorkspaceState.ViewsSearchAndComparePinnedItems);
if (pinned == null) {
pinned = Object.create(null) as PinnedItems;
}
@ -496,7 +489,7 @@ export class SearchAndCompareView extends ViewBase
pinned = rest;
}
await this.container.context.workspaceState.update(WorkspaceState.ViewsSearchAndComparePinnedItems, pinned);
await this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndComparePinnedItems, pinned);
this.triggerNodeChange(this.ensureRoot());
}
@ -541,7 +534,7 @@ export class SearchAndCompareView extends ViewBase
}
private setKeepResults(enabled: boolean) {
void this.container.context.workspaceState.update(WorkspaceState.ViewsSearchAndCompareKeepResults, enabled);
void this.container.storage.storeWorkspace(WorkspaceState.ViewsSearchAndCompareKeepResults, enabled);
void setContext(ContextKeys.ViewsSearchAndCompareKeepResults, enabled);
}

Завантаження…
Відмінити
Зберегти