From c96a659e9e2cf048606ce282f7567e11a48f20e6 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 26 Jun 2017 03:14:17 -0400 Subject: [PATCH] Fixes uris on nodes --- src/views/branchHistoryNode.ts | 4 ++-- src/views/commitFileNode.ts | 8 ++++---- src/views/commitNode.ts | 7 ++++--- src/views/explorerNode.ts | 2 +- src/views/fileHistoryNode.ts | 2 +- src/views/gitExplorer.ts | 11 ++++++----- src/views/stashCommitNode.ts | 6 +++--- src/views/stashExplorer.ts | 11 ++++++----- src/views/stashNode.ts | 2 +- 9 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/views/branchHistoryNode.ts b/src/views/branchHistoryNode.ts index 02924e1..1900317 100644 --- a/src/views/branchHistoryNode.ts +++ b/src/views/branchHistoryNode.ts @@ -10,7 +10,7 @@ export class BranchHistoryNode extends ExplorerNode { readonly resourceType: ResourceType = 'branch-history'; - constructor(public branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) { + constructor(public readonly branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) { super(uri, context, git); } @@ -18,7 +18,7 @@ export class BranchHistoryNode extends ExplorerNode { const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name); if (log === undefined) return []; - return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.uri, this.context, this.git))]; + return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.context, this.git))]; } getTreeItem(): TreeItem { diff --git a/src/views/commitFileNode.ts b/src/views/commitFileNode.ts index c74cc6a..aa3aaf2 100644 --- a/src/views/commitFileNode.ts +++ b/src/views/commitFileNode.ts @@ -1,5 +1,5 @@ 'use strict'; -import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode'; +import { ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode'; import { Commands, DiffWithPreviousCommandArgs } from '../commands'; import { ExplorerNode, ResourceType } from './explorerNode'; import { getGitStatusIcon, GitCommit, GitService, GitUri, IGitStatusFile, StatusFileFormatter } from '../gitService'; @@ -9,8 +9,8 @@ export class CommitFileNode extends ExplorerNode { readonly resourceType: ResourceType = 'commit-file'; - constructor(public status: IGitStatusFile, public commit: GitCommit, private template: string, uri: GitUri, context: ExtensionContext, git: GitService) { - super(uri, context, git); + constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, context: ExtensionContext, git: GitService) { + super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }), context, git); } getChildren(): Promise { @@ -49,7 +49,7 @@ export class CommitFileNode extends ExplorerNode { } as DiffWithPreviousCommandArgs ] }; - + return item; } } \ No newline at end of file diff --git a/src/views/commitNode.ts b/src/views/commitNode.ts index 6306231..d970c89 100644 --- a/src/views/commitNode.ts +++ b/src/views/commitNode.ts @@ -9,8 +9,9 @@ export class CommitNode extends ExplorerNode { readonly resourceType: ResourceType = 'commit'; - constructor(public commit: GitCommit, uri: GitUri, context: ExtensionContext, git: GitService) { - super(uri, context, git); + constructor(public readonly commit: GitCommit, context: ExtensionContext, git: GitService) { + super(new GitUri(commit.uri, commit), context, git); + this.commit = commit; } async getChildren(): Promise { @@ -20,7 +21,7 @@ export class CommitNode extends ExplorerNode { const commit = Iterables.first(log.commits.values()); if (commit === undefined) return []; - return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.git.config.gitExplorer.commitFileFormat, this.uri, this.context, this.git))]; + return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.git.config.gitExplorer.commitFileFormat, this.context, this.git))]; } getTreeItem(): TreeItem { diff --git a/src/views/explorerNode.ts b/src/views/explorerNode.ts index e2f1230..bc0488a 100644 --- a/src/views/explorerNode.ts +++ b/src/views/explorerNode.ts @@ -8,7 +8,7 @@ export abstract class ExplorerNode { abstract readonly resourceType: ResourceType; - constructor(public uri: GitUri, protected context: ExtensionContext, protected git: GitService) { } + constructor(public readonly uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) { } abstract getChildren(): ExplorerNode[] | Promise; abstract getTreeItem(): TreeItem | Promise; diff --git a/src/views/fileHistoryNode.ts b/src/views/fileHistoryNode.ts index a45a03c..40a74ba 100644 --- a/src/views/fileHistoryNode.ts +++ b/src/views/fileHistoryNode.ts @@ -18,7 +18,7 @@ export class FileHistoryNode extends ExplorerNode { const log = await this.git.getLogForFile(this.uri.repoPath, this.uri.fsPath, this.uri.sha); if (log === undefined) return []; - return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.uri, this.context, this.git))]; + return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.context, this.git))]; } getTreeItem(): TreeItem { diff --git a/src/views/gitExplorer.ts b/src/views/gitExplorer.ts index 43ed5ca..29e4a60 100644 --- a/src/views/gitExplorer.ts +++ b/src/views/gitExplorer.ts @@ -1,5 +1,5 @@ 'use strict'; -import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri, window } from 'vscode'; +import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode'; import { UriComparer } from '../comparers'; import { ExplorerNode, FileHistoryNode, RepositoryNode, ResourceType, StashNode } from './explorerNodes'; import { GitService, GitUri } from '../gitService'; @@ -18,12 +18,13 @@ export class GitExplorer implements TreeDataProvider { constructor(private context: ExtensionContext, private git: GitService) { commands.registerCommand('gitlens.gitExplorer.refresh', () => this.refresh()); - const editor = window.activeTextEditor; + // 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 = (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._roots.push(new RepositoryNode(uri, context, git)); } diff --git a/src/views/stashCommitNode.ts b/src/views/stashCommitNode.ts index c145d20..356e2df 100644 --- a/src/views/stashCommitNode.ts +++ b/src/views/stashCommitNode.ts @@ -8,12 +8,12 @@ export class StashCommitNode extends ExplorerNode { readonly resourceType: ResourceType = 'stash-commit'; - constructor(public commit: GitStashCommit, uri: GitUri, context: ExtensionContext, git: GitService) { - super(uri, context, git); + constructor(public readonly commit: GitStashCommit, context: ExtensionContext, git: GitService) { + super(new GitUri(commit.uri, commit), context, git); } async getChildren(): Promise { - return Promise.resolve((this.commit as GitStashCommit).fileStatuses.map(_ => new CommitFileNode(_, this.commit, this.git.config.stashExplorer.stashFileFormat, this.uri, this.context, this.git))); + return Promise.resolve((this.commit as GitStashCommit).fileStatuses.map(_ => new CommitFileNode(_, this.commit, this.git.config.stashExplorer.stashFileFormat, this.context, this.git))); } getTreeItem(): TreeItem { diff --git a/src/views/stashExplorer.ts b/src/views/stashExplorer.ts index 653441a..489dc9f 100644 --- a/src/views/stashExplorer.ts +++ b/src/views/stashExplorer.ts @@ -1,5 +1,5 @@ 'use strict'; -import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri, window } from 'vscode'; +import { commands, Event, EventEmitter, ExtensionContext, TreeDataProvider, TreeItem, Uri } from 'vscode'; import { ExplorerNode, StashNode } from './explorerNodes'; import { GitService, GitUri } from '../gitService'; import { StashCommitNode } from './stashCommitNode'; @@ -17,12 +17,13 @@ export class StashExplorer implements TreeDataProvider { constructor(private context: ExtensionContext, private git: GitService) { commands.registerCommand('gitlens.stashExplorer.refresh', () => this.refresh()); - const editor = window.activeTextEditor; + // 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 = (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); } diff --git a/src/views/stashNode.ts b/src/views/stashNode.ts index c1891a2..4a9aac4 100644 --- a/src/views/stashNode.ts +++ b/src/views/stashNode.ts @@ -18,7 +18,7 @@ export class StashNode extends ExplorerNode { const stash = await this.git.getStashList(this.uri.repoPath!); if (stash === undefined) return []; - return [...Iterables.map(stash.commits.values(), c => new StashCommitNode(c, this.uri, this.context, this.git))]; + return [...Iterables.map(stash.commits.values(), c => new StashCommitNode(c, this.context, this.git))]; } getTreeItem(): TreeItem {