mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-16 01:25:42 -05:00
Reworks ExplorerNode base class
Adds TextExplorerNode for messages
This commit is contained in:
@@ -10,15 +10,15 @@ export class BranchHistoryNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'branch-history';
|
||||
|
||||
constructor(public readonly branch: GitBranch, uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
super(uri, context, git);
|
||||
}
|
||||
constructor(public readonly branch: GitBranch, uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<CommitNode[]> {
|
||||
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.context, this.git))];
|
||||
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
|
||||
}
|
||||
|
||||
getTreeItem(): TreeItem {
|
||||
|
||||
@@ -9,9 +9,9 @@ export class BranchesNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'branches';
|
||||
|
||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
super(uri, context, git);
|
||||
}
|
||||
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<BranchHistoryNode[]> {
|
||||
const branches = await this.git.getBranches(this.uri.repoPath!);
|
||||
|
||||
@@ -9,8 +9,8 @@ export class CommitFileNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'commit-file';
|
||||
|
||||
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);
|
||||
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }));
|
||||
}
|
||||
|
||||
getChildren(): Promise<ExplorerNode[]> {
|
||||
|
||||
@@ -9,9 +9,8 @@ export class CommitNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'commit';
|
||||
|
||||
constructor(public readonly commit: GitCommit, context: ExtensionContext, git: GitService) {
|
||||
super(new GitUri(commit.uri, commit), context, git);
|
||||
this.commit = commit;
|
||||
constructor(public readonly commit: GitCommit, private template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(new GitUri(commit.uri, commit));
|
||||
}
|
||||
|
||||
async getChildren(): Promise<ExplorerNode[]> {
|
||||
@@ -25,7 +24,7 @@ export class CommitNode extends ExplorerNode {
|
||||
}
|
||||
|
||||
getTreeItem(): TreeItem {
|
||||
const label = CommitFormatter.fromTemplate(this.git.config.gitExplorer.commitFormat, this.commit, this.git.config.defaultDateFormat);
|
||||
const label = CommitFormatter.fromTemplate(this.template, this.commit, this.git.config.defaultDateFormat);
|
||||
|
||||
const item = new TreeItem(label, TreeItemCollapsibleState.Collapsed);
|
||||
item.contextValue = this.resourceType;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
'use strict';
|
||||
import { Command, Event, ExtensionContext, TreeItem } from 'vscode';
|
||||
import { GitService, GitUri } from '../gitService';
|
||||
import { Command, Event, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||
import { GitUri } from '../gitService';
|
||||
|
||||
export declare type ResourceType = 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
|
||||
export declare type ResourceType = 'text' | 'status' | 'branches' | 'repository' | 'branch-history' | 'file-history' | 'stash-history' | 'commit' | 'stash-commit' | 'commit-file';
|
||||
|
||||
export abstract class ExplorerNode {
|
||||
|
||||
abstract readonly resourceType: ResourceType;
|
||||
|
||||
constructor(public readonly uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) { }
|
||||
constructor(public readonly uri: GitUri) { }
|
||||
|
||||
abstract getChildren(): ExplorerNode[] | Promise<ExplorerNode[]>;
|
||||
abstract getTreeItem(): TreeItem | Promise<TreeItem>;
|
||||
@@ -20,4 +20,23 @@ export abstract class ExplorerNode {
|
||||
onDidChangeTreeData?: Event<ExplorerNode>;
|
||||
|
||||
refresh?(): void;
|
||||
}
|
||||
|
||||
export class TextExplorerNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'text';
|
||||
|
||||
constructor(private text: string) {
|
||||
super(new GitUri());
|
||||
}
|
||||
|
||||
getChildren(): ExplorerNode[] | Promise<ExplorerNode[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
getTreeItem(): TreeItem | Promise<TreeItem> {
|
||||
const item = new TreeItem(this.text, TreeItemCollapsibleState.None);
|
||||
item.contextValue = this.resourceType;
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
import { Iterables } from '../system';
|
||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||
import { CommitNode } from './commitNode';
|
||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
|
||||
import { GitService, GitUri } from '../gitService';
|
||||
|
||||
export class FileHistoryNode extends ExplorerNode {
|
||||
@@ -10,15 +10,15 @@ export class FileHistoryNode extends ExplorerNode {
|
||||
static readonly rootType: ResourceType = 'file-history';
|
||||
readonly resourceType: ResourceType = 'file-history';
|
||||
|
||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
super(uri, context, git);
|
||||
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<CommitNode[]> {
|
||||
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.context, this.git))];
|
||||
return [...Iterables.map(log.commits.values(), c => new CommitNode(c, this.git.config.gitExplorer.commitFormat, this.context, this.git))];
|
||||
}
|
||||
|
||||
getTreeItem(): TreeItem {
|
||||
|
||||
@@ -11,8 +11,8 @@ export class RepositoryNode extends ExplorerNode {
|
||||
static readonly rootType: ResourceType = 'repository';
|
||||
readonly resourceType: ResourceType = 'repository';
|
||||
|
||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
super(uri, context, git);
|
||||
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<ExplorerNode[]> {
|
||||
|
||||
@@ -13,8 +13,8 @@ export class StashCommitNode extends ExplorerNode {
|
||||
return this._onDidChangeTreeData.event;
|
||||
}
|
||||
|
||||
constructor(public readonly commit: GitStashCommit, context: ExtensionContext, git: GitService) {
|
||||
super(new GitUri(commit.uri, commit), context, git);
|
||||
constructor(public readonly commit: GitStashCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(new GitUri(commit.uri, commit));
|
||||
}
|
||||
|
||||
async getChildren(): Promise<CommitFileNode[]> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
import { Iterables } from '../system';
|
||||
import { ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'vscode';
|
||||
import { ExplorerNode, ResourceType } from './explorerNode';
|
||||
import { ExplorerNode, ResourceType, TextExplorerNode } from './explorerNode';
|
||||
import { GitService, GitUri } from '../gitService';
|
||||
import { StashCommitNode } from './stashCommitNode';
|
||||
|
||||
@@ -10,8 +10,8 @@ export class StashNode extends ExplorerNode {
|
||||
static readonly rootType: ResourceType = 'stash-history';
|
||||
readonly resourceType: ResourceType = 'stash-history';
|
||||
|
||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
super(uri, context, git);
|
||||
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<StashCommitNode[]> {
|
||||
|
||||
@@ -8,9 +8,9 @@ export class StatusNode extends ExplorerNode {
|
||||
|
||||
readonly resourceType: ResourceType = 'status';
|
||||
|
||||
constructor(uri: GitUri, context: ExtensionContext, git: GitService) {
|
||||
super(uri, context, git);
|
||||
}
|
||||
constructor(uri: GitUri, protected readonly context: ExtensionContext, protected readonly git: GitService) {
|
||||
super(uri);
|
||||
}
|
||||
|
||||
async getChildren(): Promise<ExplorerNode[]> {
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user