diff --git a/README.md b/README.md index a118626..f31f051 100644 --- a/README.md +++ b/README.md @@ -294,7 +294,7 @@ GitLens is highly customizable and provides many configuration settings to allow |Name | Description |-----|------------ |`gitlens.stashExplorer.stashFormat`|Specifies the format of stashed changes in the `Git Stashes` explorer
Available tokens
${id} - commit id
${author} - commit author
${message} - commit message
${ago} - relative commit date (e.g. 1 day ago)
${date} - formatted commit date (format specified by `gitlens.statusBar.dateFormat`)
${authorAgo} - commit author, relative commit date
See https://github.com/eamodio/vscode-gitlens/wiki/Advanced-Formatting for advanced formatting -|`gitlens.stashExplorer.stashFileFormat`|Specifies the format of a stashed file in the `Git Stashes` explorer
Available tokens
${file} - file name
${path} - file path +|`gitlens.stashExplorer.stashFileFormat`|Specifies the format of a stashed file in the `Git Stashes` explorer
Available tokens
${file} - file name
${filePath} - file name and path
${path} - file path ### Status Bar Settings diff --git a/package.json b/package.json index 58b4254..89ae502 100644 --- a/package.json +++ b/package.json @@ -420,8 +420,8 @@ }, "gitlens.stashExplorer.stashFileFormat": { "type": "string", - "default": "${file} \u00a0\u2022\u00a0 ${path}", - "description": "Specifies the format of a stashed file in the `Git Stashes` explorer\nAvailable tokens\n ${file} - file name\n ${path} - file path" + "default": "${filePath}", + "description": "Specifies the format of a stashed file in the `Git Stashes` explorer\nAvailable tokens\n ${file} - file name\n ${filePath} - file name and path\n ${path} - file path" }, "gitlens.statusBar.enabled": { "type": "boolean", @@ -1161,11 +1161,12 @@ }, { "command": "gitlens.gitExplorer.refresh", - "when": "gitlens:enabled" + "when": "false" + }, }, { "command": "gitlens.stashExplorer.refresh", - "when": "gitlens:enabled" + "when": "false" }, { "command": "gitlens.stashExplorer.openChanges", diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index 84e88c5..03624b1 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -6,13 +6,17 @@ import { GitService, GitUri } from '../gitService'; import { Logger } from '../logger'; import { OpenInRemoteCommandArgs } from './openInRemote'; +export interface OpenFileInRemoteCommandArgs { + range?: boolean; +} + export class OpenFileInRemoteCommand extends ActiveEditorCommand { constructor(private git: GitService) { super(Commands.OpenFileInRemote); } - async execute(editor?: TextEditor, uri?: Uri) { + async execute(editor?: TextEditor, uri?: Uri, args: OpenFileInRemoteCommandArgs = { range: true }) { uri = getCommandUri(uri, editor); if (uri === undefined) return undefined; @@ -23,7 +27,9 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand { try { const remotes = Arrays.uniqueBy(await this.git.getRemotes(gitUri.repoPath), _ => _.url, _ => !!_.provider); - const range = editor === undefined ? undefined : new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 })); + const range = (args.range && editor !== undefined) + ? new Range(editor.selection.start.with({ line: editor.selection.start.line + 1 }), editor.selection.end.with({ line: editor.selection.end.line + 1 })) + : undefined; return commands.executeCommand(Commands.OpenInRemote, uri, { resource: { diff --git a/src/configuration.ts b/src/configuration.ts index 3d2709e..3a4d1cb 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -297,14 +297,12 @@ export interface IConfig { defaultDateFormat: string | null; gitExplorer: { - enabled: boolean; commitFormat: string; commitFileFormat: string; // dateFormat: string | null; }; stashExplorer: { - enabled: boolean; stashFormat: string; stashFileFormat: string; // dateFormat: string | null; diff --git a/src/views/stashExplorer.ts b/src/views/stashExplorer.ts index ca8de0d..ab067ed 100644 --- a/src/views/stashExplorer.ts +++ b/src/views/stashExplorer.ts @@ -1,7 +1,7 @@ 'use strict'; // import { Functions } from '../system'; import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode'; -import { Commands, DiffWithPreviousCommandArgs, openEditor } from '../commands'; +import { Commands, DiffWithPreviousCommandArgs, openEditor, OpenFileInRemoteCommandArgs } from '../commands'; import { ExplorerNode, StashCommitNode, StashNode } from './explorerNodes'; import { GitService, GitUri } from '../gitService'; @@ -10,7 +10,6 @@ export * from './explorerNodes'; export class StashExplorer implements TreeDataProvider { private _node: ExplorerNode; - // private _refreshDebounced: () => void; private _onDidChangeTreeData = new EventEmitter(); public get onDidChangeTreeData(): Event { @@ -24,28 +23,12 @@ export class StashExplorer implements TreeDataProvider { commands.registerCommand('gitlens.stashExplorer.openStashedFile', this.openStashedFile, this); commands.registerCommand('gitlens.stashExplorer.openFileInRemote', this.openFileInRemote, this); - context.subscriptions.push(this.git.onDidChangeRepo(reasons => { - if (!reasons.includes('stash')) return; + context.subscriptions.push(this.git.onDidChangeRepo(this.onRepoChanged, this)); - this.refresh(); - }, this)); - - // this._refreshDebounced = Functions.debounce(this.refresh.bind(this), 250); - - // const editor = window.activeTextEditor; - - // const uri = (editor !== undefined && editor.document !== undefined) - // ? new GitUri(editor.document.uri, { repoPath: git.repoPath, fileName: editor.document.uri.fsPath }) - // : new GitUri(Uri.file(git.repoPath), { repoPath: git.repoPath, fileName: git.repoPath }); - - const uri = new GitUri(Uri.file(git.repoPath), { repoPath: git.repoPath, fileName: git.repoPath }); - this._node = new StashNode(uri, this.context, this.git); + this._node = this.getRootNode(); } async getTreeItem(node: ExplorerNode): Promise { - // if (node.onDidChangeTreeData !== undefined) { - // node.onDidChangeTreeData(() => setTimeout(this._refreshDebounced, 1)); - // } return node.getTreeItem(); } @@ -54,10 +37,16 @@ export class StashExplorer implements TreeDataProvider { return node.getChildren(); } - // update(uri: GitUri) { - // this._node = new StashNode(uri, this.context, this.git); - // this.refresh(); - // } + private getRootNode(): ExplorerNode { + const uri = new GitUri(Uri.file(this.git.repoPath), { repoPath: this.git.repoPath, fileName: this.git.repoPath }); + return new StashNode(uri, this.context, this.git); + } + + private onRepoChanged(reasons: ('stash' | 'unknown')[]) { + if (!reasons.includes('stash')) return; + + this.refresh(); + } refresh() { this._onDidChangeTreeData.fire(); @@ -81,6 +70,6 @@ export class StashExplorer implements TreeDataProvider { } private openFileInRemote(node: StashCommitNode) { - return commands.executeCommand(Commands.OpenFileInRemote, node.commit.previousUri); + return commands.executeCommand(Commands.OpenFileInRemote, node.commit.uri, { range: false } as OpenFileInRemoteCommandArgs); } } \ No newline at end of file diff --git a/src/views/stashNode.ts b/src/views/stashNode.ts index 5c57170..4cc83b3 100644 --- a/src/views/stashNode.ts +++ b/src/views/stashNode.ts @@ -14,9 +14,9 @@ export class StashNode extends ExplorerNode { super(uri); } - async getChildren(): Promise { + async getChildren(): Promise { const stash = await this.git.getStashList(this.uri.repoPath!); - if (stash === undefined) return []; + if (stash === undefined) return [new TextExplorerNode('No stashed changes')]; return [...Iterables.map(stash.commits.values(), c => new StashCommitNode(c, this.context, this.git))]; }