Skip to content

Commit

Permalink
Adds usage-based sorting to git command palette
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 20, 2020
1 parent d334ab9 commit bada358
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Added

- Adds usage-based sorting (on by default) to the _Git Command Palette_
- Adds a `gitlens.gitCommands.sortBy` setting to specify how Git commands are sorted in the _Git Command Palette_
- Adds ability to show gutter heatmap in the gutter and/or on the scroll bar — closes [#297](https://github.com/eamodio/vscode-gitlens/issues/297)
- Adds a `gitlens.heatmap.locations` setting to specify where the indicators of the gutter heatmap annotations will be shown
- Adds a `gitlens.fileAnnotations.command` setting to specify whether the file annotations button in the editor title shows a menu or immediately toggles the specified file annotations — closes [#1165](https://github.com/eamodio/vscode-gitlens/issues/1165) thanks to [PR #1171](https://github.com/eamodio/vscode-gitlens/pull/1171) by Raaj Patil ([@arrpee](https://github.com/arrpee))
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -875,14 +875,15 @@ See also [View Settings](#view-settings- 'Jump to the View settings')

## Git Command Palette Settings [#](#git-command-palette-settings- 'Git Command Palette Settings')

| Name | Description |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `gitlens.gitCommands.closeOnFocusOut` | Specifies whether to dismiss the _Git Commands Palette_ when focus is lost (if not, press `ESC` to dismiss) |
| `gitlens.gitCommands.search.matchAll` | Specifies whether to match all or any commit message search patterns |
| `gitlens.gitCommands.search.matchCase` | Specifies whether to match commit search patterns with or without regard to casing |
| `gitlens.gitCommands.search.matchRegex` | Specifies whether to match commit search patterns using regular expressions |
| `gitlens.gitCommands.search.showResultsInSideBar` | Specifies whether to show the commit search results directly in the quick pick menu, in the Side Bar, or will be based on the context |
| `gitlens.gitCommands.skipConfirmations` | Specifies which (and when) Git commands will skip the confirmation step, using the format: `git-command-name:(menu/command)` |
| Name | Description |
| ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gitlens.gitCommands.closeOnFocusOut` | Specifies whether to dismiss the _Git Commands Palette_ when focus is lost (if not, press `ESC` to dismiss) |
| `gitlens.gitCommands.search.matchAll` | Specifies whether to match all or any commit message search patterns |
| `gitlens.gitCommands.search.matchCase` | Specifies whether to match commit search patterns with or without regard to casing |
| `gitlens.gitCommands.search.matchRegex` | Specifies whether to match commit search patterns using regular expressions |
| `gitlens.gitCommands.search.showResultsInSideBar` | Specifies whether to show the commit search results directly in the quick pick menu, in the Side Bar, or will be based on the context |
| `gitlens.gitCommands.skipConfirmations` | Specifies which (and when) Git commands will skip the confirmation step, using the format: `git-command-name:(menu/command)` |
| `gitlens.gitCommands.sortBy` | Specifies how Git commands are sorted in the _Git Command Palette_<br /><br />`name` - sorts commands by name<br />`usage` - sorts commands by last used date |

## Remote Provider Integration Settings [#](#remote-provider-integration-settings- 'Remote Provider Integration Settings')

Expand Down
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,20 @@
"markdownDescription": "Specifies which (and when) Git commands will skip the confirmation step, using the format: `git-command-name:(menu|command)`",
"scope": "window"
},
"gitlens.gitCommands.sortBy": {
"type": "string",
"default": "usage",
"enum": [
"name",
"usage"
],
"enumDescriptions": [
"Sorts commands by name",
"Sorts commands by last used date"
],
"markdownDescription": "Specifies how Git commands are sorted in the _Git Command Palette_",
"scope": "window"
},
"gitlens.heatmap.ageThreshold": {
"type": "number",
"default": 90,
Expand Down
23 changes: 22 additions & 1 deletion src/commands/gitCommands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';
import { Disposable, InputBox, QuickInputButton, QuickInputButtons, QuickPick, QuickPickItem, window } from 'vscode';
import { command, Command, Commands } from './common';
import { configuration } from '../configuration';
import { configuration, GitCommandSorting } from '../configuration';
import { Usage, WorkspaceState } from '../constants';
import { Container } from '../container';
import { BranchGitCommand, BranchGitCommandArgs } from './git/branch';
import { CherryPickGitCommand, CherryPickGitCommandArgs } from './git/cherry-pick';
Expand Down Expand Up @@ -723,6 +724,13 @@ class PickCommandStep implements QuickPickStep {
new TagGitCommand(args?.command === 'tag' ? args : undefined),
];

if (Container.config.gitCommands.sortBy === GitCommandSorting.Usage) {
const usage = Container.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (usage != null) {
this.items.sort((a, b) => (usage[b.key] ?? 0) - (usage[a.key] ?? 0));
}
}

this.hiddenItems = [];
}

Expand Down Expand Up @@ -751,5 +759,18 @@ class PickCommandStep implements QuickPickStep {
}

this._command = command;
if (command != null) {
void this.updateCommandUsage(command.key, Date.now());
}
}

private async updateCommandUsage(id: string, timestamp: number) {
let usage = Container.context.workspaceState.get<Usage>(WorkspaceState.GitCommandPaletteUsage);
if (usage === undefined) {
usage = Object.create(null) as Usage;
}

usage[id] = timestamp;
await Container.context.workspaceState.update(WorkspaceState.GitCommandPaletteUsage, usage);
}
}
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface Config {
showResultsInSideBar: boolean | null;
};
skipConfirmations: string[];
sortBy: GitCommandSorting;
};
heatmap: {
ageThreshold: number;
Expand Down Expand Up @@ -210,6 +211,11 @@ export enum FileAnnotationType {
Heatmap = 'heatmap',
}

export enum GitCommandSorting {
Name = 'name',
Usage = 'usage',
}

export enum GravatarDefaultStyle {
Faces = 'wavatar',
Geometric = 'identicon',
Expand Down
5 changes: 5 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,16 @@ export interface Starred {
[id: string]: boolean;
}

export interface Usage {
[id: string]: number;
}

export enum WorkspaceState {
BranchComparisons = 'gitlens:branch:comparisons',
ConnectedPrefix = 'gitlens:connected:',
DefaultRemote = 'gitlens:remote:default',
DisallowConnectionPrefix = 'gitlens:disallow:connection:',
GitCommandPaletteUsage = 'gitlens:gitComandPalette:usage',
StarredBranches = 'gitlens:starred:branches',
StarredRepositories = 'gitlens:starred:repositories',
ViewsRepositoriesAutoRefresh = 'gitlens:views:repositories:autoRefresh',
Expand Down

0 comments on commit bada358

Please sign in to comment.