Browse Source

Switches when's to use config's when possible

Config when's can be resolved before extension activation
main
Eric Amodio 6 years ago
parent
commit
c8d42357a0
9 changed files with 50 additions and 94 deletions
  1. +44
    -44
      package.json
  2. +0
    -2
      src/commands.ts
  3. +0
    -5
      src/configuration.ts
  4. +0
    -4
      src/constants.ts
  5. +3
    -17
      src/extension.ts
  6. +1
    -5
      src/views/fileHistoryView.ts
  7. +1
    -5
      src/views/lineHistoryView.ts
  8. +0
    -7
      src/views/repositoriesView.ts
  9. +1
    -5
      src/views/resultsView.ts

+ 44
- 44
package.json View File

@ -2316,15 +2316,15 @@
"commandPalette": [
{
"command": "gitlens.showRepositoriesView",
"when": "gitlens:enabled && gitlens:views:repositories"
"when": "gitlens:enabled && config.gitlens.views.repositories.enabled"
},
{
"command": "gitlens.showFileHistoryView",
"when": "gitlens:enabled && gitlens:views:fileHistory"
"when": "gitlens:enabled && config.gitlens.views.fileHistory.enabled"
},
{
"command": "gitlens.showLineHistoryView",
"when": "gitlens:enabled && gitlens:views:lineHistory"
"when": "gitlens:enabled && config.gitlens.views.lineHistory.enabled"
},
{
"command": "gitlens.showResultsView",
@ -3683,162 +3683,162 @@
{
"command": "gitlens.toggleFileBlame",
"key": "alt+b",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /blameable/"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /blameable/"
},
{
"command": "gitlens.toggleCodeLens",
"key": "shift+alt+b",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:enabled && gitlens:canToggleCodeLens"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:enabled && gitlens:canToggleCodeLens"
},
{
"command": "gitlens.showLastQuickPick",
"key": "alt+-",
"when": "gitlens:keymap == alternate && gitlens:enabled"
"when": "config.gitlens.keymap == alternate && gitlens:enabled"
},
{
"command": "gitlens.showCommitSearch",
"key": "alt+/",
"when": "gitlens:keymap == alternate && gitlens:enabled"
"when": "config.gitlens.keymap == alternate && gitlens:enabled"
},
{
"command": "gitlens.showQuickFileHistory",
"key": "alt+h",
"when": "gitlens:keymap == alternate && gitlens:enabled"
"when": "config.gitlens.keymap == alternate && gitlens:enabled"
},
{
"command": "gitlens.showQuickRepoHistory",
"key": "shift+alt+h",
"when": "gitlens:keymap == alternate && gitlens:enabled"
"when": "config.gitlens.keymap == alternate && gitlens:enabled"
},
{
"command": "gitlens.showQuickRepoStatus",
"key": "alt+s",
"when": "gitlens:keymap == alternate && gitlens:enabled"
"when": "config.gitlens.keymap == alternate && gitlens:enabled"
},
{
"command": "gitlens.showQuickCommitFileDetails",
"key": "alt+c",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:enabled"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:enabled"
},
{
"command": "gitlens.diffWithNext",
"key": "alt+.",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffLineWithPrevious",
"key": "shift+alt+,",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffWithPrevious",
"key": "alt+,",
"when": "gitlens:keymap == alternate && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == alternate && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffWithPreviousInDiff",
"key": "alt+,",
"when": "gitlens:keymap == alternate && isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == alternate && isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffLineWithWorking",
"key": "alt+w",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffWithWorking",
"key": "shift+alt+w",
"when": "gitlens:keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == alternate && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.toggleFileBlame",
"key": "ctrl+shift+g b",
"mac": "cmd+alt+g b",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /blameable/"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /blameable/"
},
{
"command": "gitlens.toggleCodeLens",
"key": "ctrl+shift+g shift+b",
"mac": "cmd+alt+g shift+b",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:enabled && gitlens:canToggleCodeLens"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:enabled && gitlens:canToggleCodeLens"
},
{
"command": "gitlens.showLastQuickPick",
"key": "ctrl+shift+g -",
"mac": "cmd+alt+g -",
"when": "gitlens:keymap == chorded && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
},
{
"command": "gitlens.showCommitSearch",
"key": "ctrl+shift+g /",
"mac": "cmd+alt+g /",
"when": "gitlens:keymap == chorded && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
},
{
"command": "gitlens.showQuickFileHistory",
"key": "ctrl+shift+g h",
"mac": "cmd+alt+g h",
"when": "gitlens:keymap == chorded && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
},
{
"command": "gitlens.showQuickRepoHistory",
"key": "ctrl+shift+g shift+h",
"mac": "cmd+alt+g shift+h",
"when": "gitlens:keymap == chorded && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
},
{
"command": "gitlens.showQuickRepoStatus",
"key": "ctrl+shift+g s",
"mac": "cmd+alt+g s",
"when": "gitlens:keymap == chorded && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
},
{
"command": "gitlens.showQuickCommitFileDetails",
"key": "ctrl+shift+g c",
"mac": "cmd+alt+g c",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:enabled"
},
{
"command": "gitlens.diffWithNext",
"key": "ctrl+shift+g .",
"mac": "cmd+alt+g .",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffLineWithPrevious",
"key": "ctrl+shift+g shift+,",
"mac": "cmd+alt+g shift+,",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffWithPrevious",
"key": "ctrl+shift+g ,",
"mac": "cmd+alt+g ,",
"when": "gitlens:keymap == chorded && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == chorded && editorTextFocus && !isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffWithPreviousInDiff",
"key": "ctrl+shift+g ,",
"mac": "cmd+alt+g ,",
"when": "gitlens:keymap == chorded && isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == chorded && isInDiffEditor && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffLineWithWorking",
"key": "ctrl+shift+g w",
"mac": "cmd+alt+g w",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.diffWithWorking",
"key": "ctrl+shift+g shift+w",
"mac": "cmd+alt+g shift+w",
"when": "gitlens:keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
"when": "config.gitlens.keymap == chorded && editorTextFocus && gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "workbench.view.scm",
"key": "ctrl+shift+g g",
"mac": "ctrl+shift+g",
"when": "gitlens:keymap == chorded && gitlens:enabled"
"when": "config.gitlens.keymap == chorded && gitlens:enabled"
}
],
"viewsContainers": {
@ -3855,66 +3855,66 @@
{
"id": "gitlens.views.repositories:gitlens",
"name": "Repositories",
"when": "gitlens:enabled && gitlens:views:repositories == gitlens"
"when": "gitlens:enabled && config.gitlens.views.repositories.enabled && config.gitlens.views.repositories.location == gitlens"
},
{
"id": "gitlens.views.fileHistory:gitlens",
"name": "File History",
"when": "gitlens:enabled && gitlens:views:fileHistory == gitlens"
"when": "gitlens:enabled && config.gitlens.views.fileHistory.enabled && config.gitlens.views.fileHistory.location == gitlens"
},
{
"id": "gitlens.views.lineHistory:gitlens",
"name": "Line History",
"when": "gitlens:enabled && gitlens:views:lineHistory == gitlens"
"when": "gitlens:enabled && config.gitlens.views.lineHistory.enabled && config.gitlens.views.lineHistory.location == gitlens"
},
{
"id": "gitlens.views.results:gitlens",
"name": "Results",
"when": "gitlens:enabled && gitlens:views:results == gitlens"
"when": "gitlens:enabled && gitlens:views:results && config.gitlens.views.results.location == gitlens"
}
],
"explorer": [
{
"id": "gitlens.views.repositories:explorer",
"name": "GitLens: Repositories",
"when": "gitlens:enabled && gitlens:views:repositories == explorer"
"when": "gitlens:enabled && config.gitlens.views.repositories.enabled && config.gitlens.views.repositories.location == explorer"
},
{
"id": "gitlens.views.fileHistory:explorer",
"name": "GitLens: File History",
"when": "gitlens:enabled && gitlens:views:fileHistory == explorer"
"when": "gitlens:enabled && config.gitlens.views.fileHistory.enabled && config.gitlens.views.fileHistory.location == explorer"
},
{
"id": "gitlens.views.lineHistory:explorer",
"name": "GitLens: Line History",
"when": "gitlens:enabled && gitlens:views:lineHistory == explorer"
"when": "gitlens:enabled && config.gitlens.views.lineHistory.enabled && config.gitlens.views.lineHistory.location == explorer"
},
{
"id": "gitlens.views.results:explorer",
"name": "GitLens: Results",
"when": "gitlens:enabled && gitlens:views:results == explorer"
"when": "gitlens:enabled && gitlens:views:results && config.gitlens.views.results.location == explorer"
}
],
"scm": [
{
"id": "gitlens.views.repositories:scm",
"name": "GitLens: Repositories",
"when": "gitlens:enabled && gitlens:views:repositories == scm"
"when": "gitlens:enabled && config.gitlens.views.repositories.enabled && config.gitlens.views.repositories.location == scm"
},
{
"id": "gitlens.views.fileHistory:scm",
"name": "GitLens: File History",
"when": "gitlens:enabled && gitlens:views:fileHistory == scm"
"when": "gitlens:enabled && config.gitlens.views.fileHistory.enabled && config.gitlens.views.fileHistory.location == scm"
},
{
"id": "gitlens.views.lineHistory:scm",
"name": "GitLens: Line History",
"when": "gitlens:enabled && gitlens:views:lineHistory == scm"
"when": "gitlens:enabled && config.gitlens.views.lineHistory.enabled && config.gitlens.views.lineHistory.location == scm"
},
{
"id": "gitlens.views.results:scm",
"name": "GitLens: Results",
"when": "gitlens:enabled && gitlens:views:results == scm"
"when": "gitlens:enabled && gitlens:views:results && config.gitlens.views.results.location == scm"
}
]
}

+ 0
- 2
src/commands.ts View File

@ -97,8 +97,6 @@ export * from './commands/toggleFileRecentChanges';
export * from './commands/toggleLineBlame';
export function configureCommands(): void {
setCommandContext(CommandContext.KeyMap, Container.config.keymap);
Container.context.subscriptions.push(new ClearFileAnnotationsCommand());
Container.context.subscriptions.push(new CloseUnchangedFilesCommand());
Container.context.subscriptions.push(new CopyMessageToClipboardCommand());

+ 0
- 5
src/configuration.ts View File

@ -60,11 +60,6 @@ export class Configuration {
clearGravatarCache();
}
const section = configuration.name('keymap').value;
if (configuration.changed(e, section)) {
setCommandContext(CommandContext.KeyMap, this.get<KeyMap>(section));
}
if (
configuration.changed(e, configuration.name('mode').value) ||
configuration.changed(e, configuration.name('modes').value)

+ 0
- 4
src/constants.ts View File

@ -33,13 +33,9 @@ export enum CommandContext {
Enabled = 'gitlens:enabled',
HasRemotes = 'gitlens:hasRemotes',
Key = 'gitlens:key',
KeyMap = 'gitlens:keymap',
ViewsCanCompare = 'gitlens:views:canCompare',
ViewsFileHistory = 'gitlens:views:fileHistory',
ViewsFileHistoryEditorFollowing = 'gitlens:views:fileHistory:editorFollowing',
ViewsLineHistory = 'gitlens:views:lineHistory',
ViewsLineHistoryEditorFollowing = 'gitlens:views:lineHistory:editorFollowing',
ViewsRepositories = 'gitlens:views:repositories',
ViewsRepositoriesAutoRefresh = 'gitlens:views:repositories:autoRefresh',
ViewsResults = 'gitlens:views:results',
ViewsResultsKeepResults = 'gitlens:views:results:keepResults'

+ 3
- 17
src/extension.ts View File

@ -14,6 +14,9 @@ import { ModeConfig } from './ui/config';
export async function activate(context: ExtensionContext) {
const start = process.hrtime();
// Pretend we are enabled (until we know otherwise) and set the view contexts to reduce flashing on load
setCommandContext(CommandContext.Enabled, true);
Logger.configure(context);
const gitlens = extensions.getExtension(extensionQualifiedId)!;
@ -33,23 +36,6 @@ export async function activate(context: ExtensionContext) {
const cfg = configuration.get<Config>();
// Pretend we are enabled (until we know otherwise) and set the view contexts to reduce flashing on load
await Promise.all([
setCommandContext(CommandContext.Enabled, true),
setCommandContext(
CommandContext.ViewsRepositories,
cfg.views.repositories.enabled ? cfg.views.repositories.location : false
),
setCommandContext(
CommandContext.ViewsFileHistory,
cfg.views.fileHistory.enabled ? cfg.views.fileHistory.location : false
),
setCommandContext(
CommandContext.ViewsLineHistory,
cfg.views.lineHistory.enabled ? cfg.views.lineHistory.location : false
)
]);
const previousVersion = context.globalState.get<string>(GlobalState.GitLensVersion);
await migrateSettings(context, previousVersion);

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

@ -57,11 +57,7 @@ export class FileHistoryView extends ViewBase {
return;
}
if (
configuration.changed(e, configuration.name('views')('fileHistory')('enabled').value) ||
configuration.changed(e, configuration.name('views')('fileHistory')('location').value)
) {
setCommandContext(CommandContext.ViewsFileHistory, this.config.enabled ? this.config.location : false);
if (configuration.changed(e, configuration.name('views')('fileHistory')('enabled').value)) {
setCommandContext(CommandContext.ViewsFileHistoryEditorFollowing, true);
}

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

@ -56,11 +56,7 @@ export class LineHistoryView extends ViewBase {
return;
}
if (
configuration.changed(e, configuration.name('views')('lineHistory')('enabled').value) ||
configuration.changed(e, configuration.name('views')('lineHistory')('location').value)
) {
setCommandContext(CommandContext.ViewsLineHistory, this.config.enabled ? this.config.location : false);
if (configuration.changed(e, configuration.name('views')('lineHistory')('enabled').value)) {
setCommandContext(CommandContext.ViewsLineHistoryEditorFollowing, true);
}

+ 0
- 7
src/views/repositoriesView.ts View File

@ -68,13 +68,6 @@ export class RepositoriesView extends ViewBase {
return;
}
if (
configuration.changed(e, configuration.name('views')('repositories')('enabled').value) ||
configuration.changed(e, configuration.name('views')('repositories')('location').value)
) {
setCommandContext(CommandContext.ViewsRepositories, this.config.enabled ? this.config.location : false);
}
if (configuration.changed(e, configuration.name('views')('repositories')('autoRefresh').value)) {
void this.setAutoRefresh(Container.config.views.repositories.autoRefresh);
}

+ 1
- 5
src/views/resultsView.ts View File

@ -77,10 +77,6 @@ export class ResultsView extends ViewBase {
}
if (configuration.changed(e, configuration.name('views')('results')('location').value)) {
setCommandContext(CommandContext.ViewsResults, this.enabled ? this.config.location : false);
}
if (configuration.changed(e, configuration.name('views')('results')('location').value)) {
this.initialize(this.config.location);
}
@ -194,7 +190,7 @@ export class ResultsView extends ViewBase {
this._root.addOrReplace(results, !this.keepResults);
this._enabled = true;
await setCommandContext(CommandContext.ViewsResults, this.config.location);
await setCommandContext(CommandContext.ViewsResults, true);
setTimeout(() => this._tree!.reveal(results, { select: true }), 250);
}

Loading…
Cancel
Save