Browse Source

Moves context key handling out of constants

main
Eric Amodio 2 years ago
parent
commit
7381857a9c
22 changed files with 74 additions and 53 deletions
  1. +1
    -1
      src/annotations/annotationProvider.ts
  2. +2
    -1
      src/annotations/fileAnnotationController.ts
  3. +1
    -1
      src/api/actionRunners.ts
  4. +1
    -1
      src/codelens/codeLensController.ts
  5. +1
    -1
      src/commands/closeView.ts
  6. +1
    -1
      src/commands/showView.ts
  7. +1
    -30
      src/constants.ts
  8. +42
    -0
      src/context.ts
  9. +1
    -1
      src/extension.ts
  10. +2
    -1
      src/git/gitProviderService.ts
  11. +4
    -4
      src/keyboard.ts
  12. +2
    -1
      src/trackers/documentTracker.ts
  13. +2
    -1
      src/trackers/trackedDocument.ts
  14. +2
    -1
      src/views/commitsView.ts
  15. +1
    -1
      src/views/fileHistoryView.ts
  16. +1
    -1
      src/views/lineHistoryView.ts
  17. +2
    -1
      src/views/nodes/fileHistoryTrackerNode.ts
  18. +1
    -1
      src/views/nodes/lineHistoryTrackerNode.ts
  19. +1
    -1
      src/views/repositoriesView.ts
  20. +1
    -1
      src/views/searchAndCompareView.ts
  21. +2
    -1
      src/views/viewCommands.ts
  22. +2
    -1
      src/vsls/vsls.ts

+ 1
- 1
src/annotations/annotationProvider.ts View File

@ -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';

+ 2
- 1
src/annotations/fileAnnotationController.ts View File

@ -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';

+ 1
- 1
src/api/actionRunners.ts View File

@ -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';

+ 1
- 1
src/codelens/codeLensController.ts View File

@ -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 {

+ 1
- 1
src/commands/closeView.ts View File

@ -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';

+ 1
- 1
src/commands/showView.ts View File

@ -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';

+ 1
- 30
src/constants.ts View File

@ -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<string, string> = {
@ -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',

+ 42
- 0
src/context.ts View File

@ -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<string, unknown>();
// 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<void> {
// contextStorage.set(key, value);
void (await commands.executeCommand(BuiltInCommands.SetContext, key, value));
}

+ 1
- 1
src/extension.ts View File

@ -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';

+ 2
- 1
src/git/gitProviderService.ts View File

@ -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';

+ 4
- 4
src/keyboard.ts View File

@ -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]))));
}
}

+ 2
- 1
src/trackers/documentTracker.ts View File

@ -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';

+ 2
- 1
src/trackers/trackedDocument.ts View File

@ -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';

+ 2
- 1
src/views/commitsView.ts View File

@ -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,

+ 1
- 1
src/views/fileHistoryView.ts View File

@ -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';

+ 1
- 1
src/views/lineHistoryView.ts View File

@ -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';

+ 2
- 1
src/views/nodes/fileHistoryTrackerNode.ts View File

@ -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';

+ 1
- 1
src/views/nodes/lineHistoryTrackerNode.ts View File

@ -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';

+ 1
- 1
src/views/repositoriesView.ts View File

@ -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,

+ 1
- 1
src/views/searchAndCompareView.ts View File

@ -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';

+ 2
- 1
src/views/viewCommands.ts View File

@ -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';

+ 2
- 1
src/vsls/vsls.ts View File

@ -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';

Loading…
Cancel
Save