diff --git a/src/commands/addAuthors.ts b/src/commands/addAuthors.ts index fa00112fa97ec..a997b41a4d161 100644 --- a/src/commands/addAuthors.ts +++ b/src/commands/addAuthors.ts @@ -1,19 +1,19 @@ 'use strict'; import { SourceControl } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; import { executeGitCommand } from './gitCommands'; @command() export class AddAuthorsCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.AddAuthors); } async execute(sourceControl: SourceControl) { let repo; if (sourceControl?.rootUri != null) { - repo = await Container.instance.git.getRepository(sourceControl.rootUri); + repo = await this.container.git.getRepository(sourceControl.rootUri); } return executeGitCommand({ diff --git a/src/commands/browseRepoAtRevision.ts b/src/commands/browseRepoAtRevision.ts index 3001882c1fa68..8d8087f1fb07e 100644 --- a/src/commands/browseRepoAtRevision.ts +++ b/src/commands/browseRepoAtRevision.ts @@ -1,7 +1,7 @@ 'use strict'; import { commands, TextEditor, Uri } from 'vscode'; import { BuiltInCommands } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { toGitLensFSUri } from '../git/fsProvider'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; @@ -26,7 +26,7 @@ export interface BrowseRepoAtRevisionCommandArgs { @command() export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.BrowseRepoAtRevision, Commands.BrowseRepoAtRevisionInNewWindow, @@ -66,7 +66,7 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand { if (gitUri.sha == null) return; const sha = args?.before - ? await Container.instance.git.resolveReference(gitUri.repoPath!, `${gitUri.sha}^`) + ? await this.container.git.resolveReference(gitUri.repoPath!, `${gitUri.sha}^`) : gitUri.sha; uri = toGitLensFSUri(sha, gitUri.repoPath!); gitUri = GitUri.fromRevisionUri(uri); diff --git a/src/commands/closeUnchangedFiles.ts b/src/commands/closeUnchangedFiles.ts index 499bb518d6e16..362a2f6aa887d 100644 --- a/src/commands/closeUnchangedFiles.ts +++ b/src/commands/closeUnchangedFiles.ts @@ -2,7 +2,7 @@ import { commands, TextEditor, Uri, window } from 'vscode'; import { TextEditorComparer, UriComparer } from '../comparers'; import { BuiltInCommands } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { Functions } from '../system'; @@ -16,7 +16,7 @@ export interface CloseUnchangedFilesCommandArgs { export class CloseUnchangedFilesCommand extends Command { private _onEditorChangedFn: ((editor: TextEditor | undefined) => void) | undefined; - constructor() { + constructor(private readonly container: Container) { super(Commands.CloseUnchangedFiles); } @@ -28,7 +28,7 @@ export class CloseUnchangedFilesCommand extends Command { const repoPath = await getRepoPathOrPrompt('Close All Unchanged Files'); if (!repoPath) return; - const status = await Container.instance.git.getStatusForRepo(repoPath); + const status = await this.container.git.getStatusForRepo(repoPath); if (status == null) { void window.showWarningMessage('Unable to close unchanged files'); diff --git a/src/commands/closeView.ts b/src/commands/closeView.ts index fa7a0a95478e8..61db612feb769 100644 --- a/src/commands/closeView.ts +++ b/src/commands/closeView.ts @@ -1,11 +1,11 @@ 'use strict'; import { ContextKeys, setContext, SyncedState } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, CommandContext, Commands } from './common'; @command() export class CloseViewCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.CloseWelcomeView]); } @@ -16,7 +16,7 @@ export class CloseViewCommand extends Command { async execute(command: Commands) { switch (command) { case Commands.CloseWelcomeView: - await Container.instance.context.globalState.update(SyncedState.WelcomeViewVisible, false); + await this.container.context.globalState.update(SyncedState.WelcomeViewVisible, false); await setContext(ContextKeys.ViewsWelcomeVisible, false); break; } diff --git a/src/commands/common.ts b/src/commands/common.ts index b6a17d17eeeb7..3b37146408c2c 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -2,7 +2,6 @@ import { commands, Disposable, - ExtensionContext, GitTimelineItem, SourceControlResourceGroup, SourceControlResourceState, @@ -218,7 +217,7 @@ export function executeEditorCommand(command: Commands, uri: Uri | undefined, } interface CommandConstructor { - new (): Command; + new (container: Container): Command; } const registrableCommands: CommandConstructor[] = []; @@ -229,10 +228,8 @@ export function command(): ClassDecorator { }; } -export function registerCommands(context: ExtensionContext): void { - for (const c of registrableCommands) { - context.subscriptions.push(new c()); - } +export function registerCommands(container: Container): Disposable[] { + return registrableCommands.map(c => new c(container)); } export function getCommandUri(uri?: Uri, editor?: TextEditor): Uri | undefined { diff --git a/src/commands/compareWith.ts b/src/commands/compareWith.ts index a48e97f5b6e9f..714d0d6038dc0 100644 --- a/src/commands/compareWith.ts +++ b/src/commands/compareWith.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { @@ -19,7 +19,7 @@ export interface CompareWithCommandArgs { @command() export class CompareWithCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.CompareWith, Commands.CompareHeadWith, @@ -76,9 +76,9 @@ export class CompareWithCommand extends ActiveEditorCommand { if (!repoPath) return; if (args.ref1 != null && args.ref2 != null) { - void (await Container.instance.searchAndCompareView.compare(repoPath, args.ref1, args.ref2)); + void (await this.container.searchAndCompareView.compare(repoPath, args.ref1, args.ref2)); } else { - Container.instance.searchAndCompareView.selectForCompare(repoPath, args.ref1, { prompt: true }); + this.container.searchAndCompareView.selectForCompare(repoPath, args.ref1, { prompt: true }); } } catch (ex) { Logger.error(ex, 'CompareWithCommmand'); diff --git a/src/commands/copyCurrentBranch.ts b/src/commands/copyCurrentBranch.ts index 667e552ce694b..6283f5d3a921c 100644 --- a/src/commands/copyCurrentBranch.ts +++ b/src/commands/copyCurrentBranch.ts @@ -1,13 +1,13 @@ 'use strict'; import { env, TextEditor, Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { ActiveEditorCommand, command, Commands, getCommandUri, getRepoPathOrActiveOrPrompt } from './common'; @command() export class CopyCurrentBranchCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.CopyCurrentBranch); } @@ -20,7 +20,7 @@ export class CopyCurrentBranchCommand extends ActiveEditorCommand { if (!repoPath) return; try { - const branch = await Container.instance.git.getBranch(repoPath); + const branch = await this.container.git.getBranch(repoPath); if (branch?.name) { await env.clipboard.writeText(branch.name); } diff --git a/src/commands/copyMessageToClipboard.ts b/src/commands/copyMessageToClipboard.ts index 41bd670dd4736..11ea37926c886 100644 --- a/src/commands/copyMessageToClipboard.ts +++ b/src/commands/copyMessageToClipboard.ts @@ -1,6 +1,6 @@ 'use strict'; import { env, TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { Messages } from '../messages'; @@ -23,7 +23,7 @@ export interface CopyMessageToClipboardCommandArgs { @command() export class CopyMessageToClipboardCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.CopyMessageToClipboard); } @@ -53,10 +53,10 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { let repoPath; // If we don't have an editor then get the message of the last commit to the branch if (uri == null) { - repoPath = await Container.instance.git.getActiveRepoPath(editor); + repoPath = await this.container.git.getActiveRepoPath(editor); if (!repoPath) return; - const log = await Container.instance.git.getLog(repoPath, { limit: 1 }); + const log = await this.container.git.getLog(repoPath, { limit: 1 }); if (log == null) return; args.message = Iterables.first(log.commits.values()).message; @@ -70,12 +70,12 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { try { const blame = editor?.document.isDirty - ? await Container.instance.git.getBlameForLineContents( + ? await this.container.git.getBlameForLineContents( gitUri, blameline, editor.document.getText(), ) - : await Container.instance.git.getBlameForLine(gitUri, blameline); + : await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) return; if (blame.commit.isUncommitted) return; @@ -93,7 +93,7 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand { } // Get the full commit message -- since blame only returns the summary - const commit = await Container.instance.git.getCommit(repoPath!, args.sha); + const commit = await this.container.git.getCommit(repoPath!, args.sha); if (commit == null) return; args.message = commit.message; diff --git a/src/commands/copyShaToClipboard.ts b/src/commands/copyShaToClipboard.ts index 1d277c573279c..88f310e84d310 100644 --- a/src/commands/copyShaToClipboard.ts +++ b/src/commands/copyShaToClipboard.ts @@ -1,6 +1,6 @@ 'use strict'; import { env, TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { Messages } from '../messages'; @@ -22,14 +22,14 @@ export interface CopyShaToClipboardCommandArgs { @command() export class CopyShaToClipboardCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.CopyShaToClipboard); } protected override preExecute(context: CommandContext, args?: CopyShaToClipboardCommandArgs) { if (isCommandContextViewNodeHasCommit(context)) { args = { ...args }; - args.sha = Container.instance.config.advanced.abbreviateShaOnCopy + args.sha = this.container.config.advanced.abbreviateShaOnCopy ? context.node.commit.shortSha : context.node.commit.sha; return this.execute(context.editor, context.node.commit.uri, args); @@ -53,10 +53,10 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand { try { // If we don't have an editor then get the sha of the last commit to the branch if (uri == null) { - const repoPath = await Container.instance.git.getActiveRepoPath(editor); + const repoPath = await this.container.git.getActiveRepoPath(editor); if (!repoPath) return; - const log = await Container.instance.git.getLog(repoPath, { limit: 1 }); + const log = await this.container.git.getLog(repoPath, { limit: 1 }); if (log == null) return; args.sha = Iterables.first(log.commits.values()).sha; @@ -67,12 +67,8 @@ export class CopyShaToClipboardCommand extends ActiveEditorCommand { try { const gitUri = await GitUri.fromUri(uri); const blame = editor?.document.isDirty - ? await Container.instance.git.getBlameForLineContents( - gitUri, - blameline, - editor.document.getText(), - ) - : await Container.instance.git.getBlameForLine(gitUri, blameline); + ? await this.container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText()) + : await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) return; args.sha = blame.commit.sha; diff --git a/src/commands/createPullRequestOnRemote.ts b/src/commands/createPullRequestOnRemote.ts index 4cfda0a082125..a2b4b9e849bc1 100644 --- a/src/commands/createPullRequestOnRemote.ts +++ b/src/commands/createPullRequestOnRemote.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitRemote } from '../git/models'; import { RemoteProvider, RemoteResource, RemoteResourceType } from '../git/remotes/provider'; import { Command, command, Commands, executeCommand } from './common'; @@ -16,14 +16,14 @@ export interface CreatePullRequestOnRemoteCommandArgs { @command() export class CreatePullRequestOnRemoteCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.CreatePullRequestOnRemote); } async execute(args?: CreatePullRequestOnRemoteCommandArgs) { if (args?.repoPath == null) return; - const repo = await Container.instance.git.getRepository(args.repoPath); + const repo = await this.container.git.getRepository(args.repoPath); if (repo == null) return; const compareRemote = await repo.getRemote(args.remote); diff --git a/src/commands/diffLineWithPrevious.ts b/src/commands/diffLineWithPrevious.ts index 52f5e36068a13..d13d07d493d55 100644 --- a/src/commands/diffLineWithPrevious.ts +++ b/src/commands/diffLineWithPrevious.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitCommit } from '../git/models'; import { Logger } from '../logger'; @@ -17,7 +17,7 @@ export interface DiffLineWithPreviousCommandArgs { @command() export class DiffLineWithPreviousCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.DiffLineWithPrevious); } @@ -33,7 +33,7 @@ export class DiffLineWithPreviousCommand extends ActiveEditorCommand { const gitUri = args.commit != null ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri); try { - const diffUris = await Container.instance.git.getPreviousLineDiffUris( + const diffUris = await this.container.git.getPreviousLineDiffUris( gitUri.repoPath!, gitUri, args.line, diff --git a/src/commands/diffLineWithWorking.ts b/src/commands/diffLineWithWorking.ts index a81e155f79db1..15350719cda18 100644 --- a/src/commands/diffLineWithWorking.ts +++ b/src/commands/diffLineWithWorking.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitCommit, GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -17,7 +17,7 @@ export interface DiffLineWithWorkingCommandArgs { @command() export class DiffLineWithWorkingCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.DiffLineWithWorking); } @@ -38,8 +38,8 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand { try { const blame = editor?.document.isDirty - ? await Container.instance.git.getBlameForLineContents(gitUri, blameline, editor.document.getText()) - : await Container.instance.git.getBlameForLine(gitUri, blameline); + ? await this.container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText()) + : await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) { void Messages.showFileNotUnderSourceControlWarningMessage('Unable to open compare'); @@ -50,7 +50,7 @@ export class DiffLineWithWorkingCommand extends ActiveEditorCommand { // If the line is uncommitted, change the previous commit if (args.commit.isUncommitted) { - const status = await Container.instance.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath); + const status = await this.container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath); args.commit = args.commit.with({ sha: status?.indexStatus != null ? GitRevision.uncommittedStaged : args.commit.previousSha!, fileName: args.commit.previousFileName!, diff --git a/src/commands/diffWith.ts b/src/commands/diffWith.ts index e7ffdd6d9eaab..6879822d908d0 100644 --- a/src/commands/diffWith.ts +++ b/src/commands/diffWith.ts @@ -1,7 +1,7 @@ 'use strict'; import { commands, Range, TextDocumentShowOptions, Uri, ViewColumn } from 'vscode'; import { BuiltInCommands, GlyphChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitCommit, GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -67,7 +67,7 @@ export class DiffWithCommand extends Command { return super.getMarkdownCommandArgsCore(Commands.DiffWith, args); } - constructor() { + constructor(private readonly container: Container) { super(Commands.DiffWith); } @@ -88,10 +88,10 @@ export class DiffWithCommand extends Command { let rhsSha = args.rhs.sha; [args.lhs.sha, args.rhs.sha] = await Promise.all([ - await Container.instance.git.resolveReference(args.repoPath, args.lhs.sha, args.lhs.uri, { + await this.container.git.resolveReference(args.repoPath, args.lhs.sha, args.lhs.uri, { timeout: 100, }), - await Container.instance.git.resolveReference(args.repoPath, args.rhs.sha, args.rhs.uri, { + await this.container.git.resolveReference(args.repoPath, args.rhs.sha, args.rhs.uri, { timeout: 100, }), ]); @@ -102,7 +102,7 @@ export class DiffWithCommand extends Command { if (args.rhs.sha && args.rhs.sha !== GitRevision.deletedOrMissing) { // Ensure that the file still exists in this commit - const status = await Container.instance.git.getFileStatusForCommit( + const status = await this.container.git.getFileStatusForCommit( args.repoPath, args.rhs.uri, args.rhs.sha, @@ -119,8 +119,8 @@ export class DiffWithCommand extends Command { } const [lhs, rhs] = await Promise.all([ - Container.instance.git.getVersionedUri(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha), - Container.instance.git.getVersionedUri(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha), + this.container.git.getVersionedUri(args.repoPath, args.lhs.uri.fsPath, args.lhs.sha), + this.container.git.getVersionedUri(args.repoPath, args.rhs.uri.fsPath, args.rhs.sha), ]); let rhsSuffix = GitRevision.shorten(rhsSha, { strings: { uncommitted: 'Working Tree' } }); diff --git a/src/commands/diffWithNext.ts b/src/commands/diffWithNext.ts index 1fdd82b23a99a..f045f59def0c6 100644 --- a/src/commands/diffWithNext.ts +++ b/src/commands/diffWithNext.ts @@ -1,6 +1,6 @@ 'use strict'; import { Range, TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitLogCommit } from '../git/models'; import { Logger } from '../logger'; @@ -19,7 +19,7 @@ export interface DiffWithNextCommandArgs { @command() export class DiffWithNextCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.DiffWithNext, Commands.DiffWithNextInDiffLeft, Commands.DiffWithNextInDiffRight]); } @@ -42,7 +42,7 @@ export class DiffWithNextCommand extends ActiveEditorCommand { const gitUri = args.commit != null ? GitUri.fromCommit(args.commit) : await GitUri.fromUri(uri); try { - const diffUris = await Container.instance.git.getNextDiffUris( + const diffUris = await this.container.git.getNextDiffUris( gitUri.repoPath!, gitUri, gitUri.sha, diff --git a/src/commands/diffWithPrevious.ts b/src/commands/diffWithPrevious.ts index 71a187a0f91d7..12d50201756e6 100644 --- a/src/commands/diffWithPrevious.ts +++ b/src/commands/diffWithPrevious.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitCommit, GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -27,7 +27,7 @@ export interface DiffWithPreviousCommandArgs { @command() export class DiffWithPreviousCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.DiffWithPrevious, Commands.DiffWithPreviousInDiffLeft, Commands.DiffWithPreviousInDiffRight]); } @@ -83,7 +83,7 @@ export class DiffWithPreviousCommand extends ActiveEditorCommand { // } try { - const diffUris = await Container.instance.git.getPreviousDiffUris( + const diffUris = await this.container.git.getPreviousDiffUris( gitUri.repoPath!, gitUri, gitUri.sha, diff --git a/src/commands/diffWithRevision.ts b/src/commands/diffWithRevision.ts index 2bf8e88511f8f..c7c5429719f22 100644 --- a/src/commands/diffWithRevision.ts +++ b/src/commands/diffWithRevision.ts @@ -1,7 +1,7 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { GlyphChars, quickPickTitleMaxChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -19,7 +19,7 @@ export interface DiffWithRevisionCommandArgs { @command() export class DiffWithRevisionCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.DiffWithRevision); } @@ -35,13 +35,13 @@ export class DiffWithRevisionCommand extends ActiveEditorCommand { } try { - const log = Container.instance.git + const log = this.container.git .getLogForFile(gitUri.repoPath, gitUri.fsPath) .then( log => log ?? (gitUri.sha - ? Container.instance.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha }) + ? this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha }) : undefined), ); diff --git a/src/commands/diffWithRevisionFrom.ts b/src/commands/diffWithRevisionFrom.ts index 63026efcfdd99..16836ae172a1b 100644 --- a/src/commands/diffWithRevisionFrom.ts +++ b/src/commands/diffWithRevisionFrom.ts @@ -1,7 +1,7 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { GlyphChars, quickPickTitleMaxChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitReference, GitRevision } from '../git/models'; import { Messages } from '../messages'; @@ -19,7 +19,7 @@ export interface DiffWithRevisionFromCommandArgs { @command() export class DiffWithRevisionFromCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.DiffWithRevisionFrom); } @@ -46,7 +46,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand { const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`; const pick = await StashPicker.show( - Container.instance.git.getStash(gitUri.repoPath), + this.container.git.getStash(gitUri.repoPath), `${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`, 'Choose a stash to compare with', { @@ -81,7 +81,7 @@ export class DiffWithRevisionFromCommand extends ActiveEditorCommand { let renamedTitle: string | undefined; // Check to see if this file has been renamed - const files = await Container.instance.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] }); + const files = await this.container.git.getDiffStatus(gitUri.repoPath, 'HEAD', ref, { filters: ['R', 'C'] }); if (files != null) { const fileName = normalizePath(relative(gitUri.repoPath, gitUri.fsPath)); const rename = files.find(s => s.fileName === fileName); diff --git a/src/commands/diffWithWorking.ts b/src/commands/diffWithWorking.ts index ebe5e8579b927..712bf93bd6f82 100644 --- a/src/commands/diffWithWorking.ts +++ b/src/commands/diffWithWorking.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -17,7 +17,7 @@ export interface DiffWithWorkingCommandArgs { @command() export class DiffWithWorkingCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.DiffWithWorking, Commands.DiffWithWorkingInDiffLeft, Commands.DiffWithWorkingInDiffRight]); } @@ -38,12 +38,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { if (args.inDiffRightEditor) { try { - const diffUris = await Container.instance.git.getPreviousDiffUris( - gitUri.repoPath!, - gitUri, - gitUri.sha, - 0, - ); + const diffUris = await this.container.git.getPreviousDiffUris(gitUri.repoPath!, gitUri, gitUri.sha, 0); gitUri = diffUris?.previous ?? gitUri; } catch (ex) { Logger.error( @@ -71,7 +66,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { // If we are a fake "staged" sha, check the status if (gitUri.isUncommittedStaged) { - const status = await Container.instance.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath); + const status = await this.container.git.getStatusForFile(gitUri.repoPath!, gitUri.fsPath); if (status?.indexStatus != null) { void (await executeCommand(Commands.DiffWith, { repoPath: gitUri.repoPath, @@ -93,7 +88,7 @@ export class DiffWithWorkingCommand extends ActiveEditorCommand { uri = gitUri.toFileUri(); - const workingUri = await Container.instance.git.getWorkingUri(gitUri.repoPath!, uri); + const workingUri = await this.container.git.getWorkingUri(gitUri.repoPath!, uri); if (workingUri == null) { void window.showWarningMessage('Unable to open compare. File has been deleted from the working tree'); diff --git a/src/commands/externalDiff.ts b/src/commands/externalDiff.ts index ace9cab6d9b50..b7a3aea347369 100644 --- a/src/commands/externalDiff.ts +++ b/src/commands/externalDiff.ts @@ -2,7 +2,7 @@ import { env, SourceControlResourceState, Uri, window } from 'vscode'; import { ScmResource } from '../@types/vscode.git.resources'; import { ScmResourceGroupType, ScmStatus } from '../@types/vscode.git.resources.enums'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -31,7 +31,7 @@ export interface ExternalDiffCommandArgs { @command() export class ExternalDiffCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.ExternalDiff, Commands.ExternalDiffAll]); } @@ -92,7 +92,7 @@ export class ExternalDiffCommand extends Command { const repoPath = await getRepoPathOrPrompt('Open All Changes (difftool)'); if (!repoPath) return undefined; - const status = await Container.instance.git.getStatusForRepo(repoPath); + const status = await this.container.git.getStatusForRepo(repoPath); if (status == null) { return window.showInformationMessage("The repository doesn't have any changes"); } @@ -130,11 +130,11 @@ export class ExternalDiffCommand extends Command { const editor = window.activeTextEditor; if (editor == null) return; - repoPath = await Container.instance.git.getRepoPathOrActive(undefined, editor); + repoPath = await this.container.git.getRepoPathOrActive(undefined, editor); if (!repoPath) return; const uri = editor.document.uri; - const status = await Container.instance.git.getStatusForFile(repoPath, uri.fsPath); + const status = await this.container.git.getStatusForFile(repoPath, uri.fsPath); if (status == null) { void window.showInformationMessage("The current file doesn't have any changes"); @@ -150,13 +150,12 @@ export class ExternalDiffCommand extends Command { args.files.push({ uri: status.uri, staged: false }); } } else { - repoPath = await Container.instance.git.getRepoPath(args.files[0].uri.fsPath); + repoPath = await this.container.git.getRepoPath(args.files[0].uri.fsPath); if (!repoPath) return; } const tool = - Container.instance.config.advanced.externalDiffTool || - (await Container.instance.git.getDiffTool(repoPath)); + this.container.config.advanced.externalDiffTool || (await this.container.git.getDiffTool(repoPath)); if (!tool) { const viewDocs = 'View Git Docs'; const result = await window.showWarningMessage( @@ -173,7 +172,7 @@ export class ExternalDiffCommand extends Command { } for (const file of args.files) { - void Container.instance.git.openDiffTool(repoPath, file.uri, { + void this.container.git.openDiffTool(repoPath, file.uri, { ref1: file.ref1, ref2: file.ref2, staged: file.staged, diff --git a/src/commands/git/branch.ts b/src/commands/git/branch.ts index b16d64d5fe53c..43cefe7b49b8e 100644 --- a/src/commands/git/branch.ts +++ b/src/commands/git/branch.ts @@ -83,8 +83,8 @@ export interface BranchGitCommandArgs { export class BranchGitCommand extends QuickCommand { private subcommand: State['subcommand'] | undefined; - constructor(args?: BranchGitCommandArgs) { - super('branch', 'branch', 'Branch', { + constructor(container: Container, args?: BranchGitCommandArgs) { + super(container, 'branch', 'branch', 'Branch', { description: 'create, rename, or delete branches', }); @@ -150,8 +150,8 @@ export class BranchGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - associatedView: Container.instance.branchesView, - repos: Container.instance.git.openRepositories, + associatedView: this.container.branchesView, + repos: this.container.git.openRepositories, showTags: false, title: this.title, }; diff --git a/src/commands/git/cherry-pick.ts b/src/commands/git/cherry-pick.ts index 6db2f35b7588e..18b927306587c 100644 --- a/src/commands/git/cherry-pick.ts +++ b/src/commands/git/cherry-pick.ts @@ -44,8 +44,8 @@ export interface CherryPickGitCommandArgs { type CherryPickStepState = ExcludeSome, 'repo', string>; export class CherryPickGitCommand extends QuickCommand { - constructor(args?: CherryPickGitCommandArgs) { - super('cherry-pick', 'cherry-pick', 'Cherry Pick', { + constructor(container: Container, args?: CherryPickGitCommandArgs) { + super(container, 'cherry-pick', 'cherry-pick', 'Cherry Pick', { description: 'integrates changes from specified commits into the current branch', }); @@ -82,8 +82,8 @@ export class CherryPickGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, cache: new Map>(), destination: undefined!, selectedBranchOrTag: undefined, @@ -165,7 +165,7 @@ export class CherryPickGitCommand extends QuickCommand { let log = context.cache.get(ref); if (log == null) { - log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false }); + log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false }); context.cache.set(ref, log); } diff --git a/src/commands/git/coauthors.ts b/src/commands/git/coauthors.ts index fd6224a0d9c32..4b1973e7f4670 100644 --- a/src/commands/git/coauthors.ts +++ b/src/commands/git/coauthors.ts @@ -34,8 +34,10 @@ export interface CoAuthorsGitCommandArgs { type CoAuthorStepState = ExcludeSome, 'repo', string>; export class CoAuthorsGitCommand extends QuickCommand { - constructor(args?: CoAuthorsGitCommandArgs) { - super('co-authors', 'co-authors', 'Add Co-Authors', { description: 'adds co-authors to a commit message' }); + constructor(container: Container, args?: CoAuthorsGitCommandArgs) { + super(container, 'co-authors', 'co-authors', 'Add Co-Authors', { + description: 'adds co-authors to a commit message', + }); let counter = 0; if (args?.state?.repo != null) { @@ -61,7 +63,7 @@ export class CoAuthorsGitCommand extends QuickCommand { } async execute(state: CoAuthorStepState) { - const repo = await Container.instance.git.getOrOpenScmRepository(state.repo.path); + const repo = await this.container.git.getOrOpenScmRepository(state.repo.path); if (repo == null) return; let message = repo.inputBox.value; @@ -94,13 +96,13 @@ export class CoAuthorsGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, + repos: this.container.git.openRepositories, activeRepo: undefined, - associatedView: Container.instance.contributorsView, + associatedView: this.container.contributorsView, title: this.title, }; - const scmRepositories = await Container.instance.git.getOpenScmRepositories(); + const scmRepositories = await this.container.git.getOpenScmRepositories(); if (scmRepositories.length) { // Filter out any repo's that are not known to the built-in git context.repos = context.repos.filter(repo => @@ -108,7 +110,7 @@ export class CoAuthorsGitCommand extends QuickCommand { ); // Ensure that the active repo is known to the built-in git - context.activeRepo = await Container.instance.git.getActiveRepository(); + context.activeRepo = await this.container.git.getActiveRepository(); if ( context.activeRepo != null && !scmRepositories.some(r => r.rootUri.fsPath === context.activeRepo!.path) diff --git a/src/commands/git/fetch.ts b/src/commands/git/fetch.ts index b967a4d692528..039b70366d241 100644 --- a/src/commands/git/fetch.ts +++ b/src/commands/git/fetch.ts @@ -41,8 +41,8 @@ export interface FetchGitCommandArgs { type FetchStepState = ExcludeSome, 'repos', string | string[] | Repository>; export class FetchGitCommand extends QuickCommand { - constructor(args?: FetchGitCommandArgs) { - super('fetch', 'fetch', 'Fetch', { description: 'fetches changes from one or more remotes' }); + constructor(container: Container, args?: FetchGitCommandArgs) { + super(container, 'fetch', 'fetch', 'Fetch', { description: 'fetches changes from one or more remotes' }); let counter = 0; if (args?.state?.repos != null && (!Array.isArray(args.state.repos) || args.state.repos.length !== 0)) { @@ -61,7 +61,7 @@ export class FetchGitCommand extends QuickCommand { return state.repos[0].fetch({ branch: state.reference }); } - return Container.instance.git.fetchAll(state.repos, { + return this.container.git.fetchAll(state.repos, { all: state.flags.includes('--all'), prune: state.flags.includes('--prune'), }); @@ -69,8 +69,8 @@ export class FetchGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, title: this.title, }; diff --git a/src/commands/git/log.ts b/src/commands/git/log.ts index 58178afe3924e..12790fba405ba 100644 --- a/src/commands/git/log.ts +++ b/src/commands/git/log.ts @@ -40,8 +40,8 @@ export interface LogGitCommandArgs { } export class LogGitCommand extends QuickCommand { - constructor(args?: LogGitCommandArgs) { - super('log', 'history', 'Commits', { + constructor(container: Container, args?: LogGitCommandArgs) { + super(container, 'log', 'history', 'Commits', { description: 'aka log, shows commit history', }); @@ -78,8 +78,8 @@ export class LogGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, cache: new Map>(), selectedBranchOrTag: undefined, title: this.title, @@ -155,8 +155,8 @@ export class LogGitCommand extends QuickCommand { if (log == null) { log = state.fileName != null - ? Container.instance.git.getLogForFile(state.repo.path, state.fileName, { ref: ref }) - : Container.instance.git.getLog(state.repo.path, { ref: ref }); + ? this.container.git.getLogForFile(state.repo.path, state.fileName, { ref: ref }) + : this.container.git.getLog(state.repo.path, { ref: ref }); context.cache.set(ref, log); } @@ -178,10 +178,11 @@ export class LogGitCommand extends QuickCommand { } if (!(state.reference instanceof GitLogCommit) || state.reference.isFile) { - state.reference = await Container.instance.git.getCommit(state.repo.path, state.reference.ref); + state.reference = await this.container.git.getCommit(state.repo.path, state.reference.ref); } const result = yield* GitCommandsCommand.getSteps( + this.container, { command: 'show', state: { diff --git a/src/commands/git/merge.ts b/src/commands/git/merge.ts index 06a411d57abbb..f1042a82ad095 100644 --- a/src/commands/git/merge.ts +++ b/src/commands/git/merge.ts @@ -48,8 +48,8 @@ export interface MergeGitCommandArgs { type MergeStepState = ExcludeSome, 'repo', string>; export class MergeGitCommand extends QuickCommand { - constructor(args?: MergeGitCommandArgs) { - super('merge', 'merge', 'Merge', { + constructor(container: Container, args?: MergeGitCommandArgs) { + super(container, 'merge', 'merge', 'Merge', { description: 'integrates changes from a specified branch into the current branch', }); @@ -79,8 +79,8 @@ export class MergeGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, cache: new Map>(), destination: undefined!, pickCommit: false, @@ -165,7 +165,7 @@ export class MergeGitCommand extends QuickCommand { let log = context.cache.get(ref); if (log == null) { - log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false }); + log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false }); context.cache.set(ref, log); } @@ -201,7 +201,7 @@ export class MergeGitCommand extends QuickCommand { } private async *confirmStep(state: MergeStepState, context: Context): AsyncStepResultGenerator { - const aheadBehind = await Container.instance.git.getAheadBehindCommitCount(state.repo.path, [ + const aheadBehind = await this.container.git.getAheadBehindCommitCount(state.repo.path, [ GitRevision.createRange(context.destination.name, state.reference.name), ]); const count = aheadBehind != null ? aheadBehind.ahead + aheadBehind.behind : 0; diff --git a/src/commands/git/pull.ts b/src/commands/git/pull.ts index 059ed62d38f35..139cd83fc82b4 100644 --- a/src/commands/git/pull.ts +++ b/src/commands/git/pull.ts @@ -42,8 +42,8 @@ export interface PullGitCommandArgs { type PullStepState = ExcludeSome, 'repos', string | string[] | Repository>; export class PullGitCommand extends QuickCommand { - constructor(args?: PullGitCommandArgs) { - super('pull', 'pull', 'Pull', { + constructor(container: Container, args?: PullGitCommandArgs) { + super(container, 'pull', 'pull', 'Pull', { description: 'fetches and integrates changes from a remote into the current branch', }); @@ -70,13 +70,13 @@ export class PullGitCommand extends QuickCommand { } } - return Container.instance.git.pullAll(state.repos, { rebase: state.flags.includes('--rebase') }); + return this.container.git.pullAll(state.repos, { rebase: state.flags.includes('--rebase') }); } protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, title: this.title, }; diff --git a/src/commands/git/push.ts b/src/commands/git/push.ts index 17f6b010c767b..49cd404437be2 100644 --- a/src/commands/git/push.ts +++ b/src/commands/git/push.ts @@ -44,8 +44,8 @@ export interface PushGitCommandArgs { type PushStepState = ExcludeSome, 'repos', string | string[] | Repository>; export class PushGitCommand extends QuickCommand { - constructor(args?: PushGitCommandArgs) { - super('push', 'push', 'Push', { + constructor(container: Container, args?: PushGitCommandArgs) { + super(container, 'push', 'push', 'Push', { description: 'pushes changes from the current branch to a remote', }); @@ -66,14 +66,14 @@ export class PushGitCommand extends QuickCommand { if (index !== -1) { if (!GitReference.isBranch(state.reference)) return Promise.resolve(); - return Container.instance.git.pushAll(state.repos, { + return this.container.git.pushAll(state.repos, { force: false, publish: { remote: state.flags[index + 1] }, reference: state.reference, }); } - return Container.instance.git.pushAll(state.repos, { + return this.container.git.pushAll(state.repos, { force: state.flags.includes('--force'), reference: state.reference, }); @@ -81,8 +81,8 @@ export class PushGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, title: this.title, }; diff --git a/src/commands/git/rebase.ts b/src/commands/git/rebase.ts index c07be2cf5d304..96bbdb6a31f4f 100644 --- a/src/commands/git/rebase.ts +++ b/src/commands/git/rebase.ts @@ -49,8 +49,8 @@ export interface RebaseGitCommandArgs { type RebaseStepState = ExcludeSome, 'repo', string>; export class RebaseGitCommand extends QuickCommand { - constructor(args?: RebaseGitCommandArgs) { - super('rebase', 'rebase', 'Rebase', { + constructor(container: Container, args?: RebaseGitCommandArgs) { + super(container, 'rebase', 'rebase', 'Rebase', { description: 'integrates changes from a specified branch into the current branch, by changing the base of the branch and reapplying the commits on top', }); @@ -78,7 +78,7 @@ export class RebaseGitCommand extends QuickCommand { async execute(state: RebaseStepState) { let configs: string[] | undefined; if (state.flags.includes('--interactive')) { - await Container.instance.rebaseEditor.enableForNextUse(); + await this.container.rebaseEditor.enableForNextUse(); let editor; switch (env.appName) { @@ -103,8 +103,8 @@ export class RebaseGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, cache: new Map>(), destination: undefined!, pickCommit: false, @@ -189,7 +189,7 @@ export class RebaseGitCommand extends QuickCommand { let log = context.cache.get(ref); if (log == null) { - log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false }); + log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false }); context.cache.set(ref, log); } @@ -225,7 +225,7 @@ export class RebaseGitCommand extends QuickCommand { } private async *confirmStep(state: RebaseStepState, context: Context): AsyncStepResultGenerator { - const aheadBehind = await Container.instance.git.getAheadBehindCommitCount(state.repo.path, [ + const aheadBehind = await this.container.git.getAheadBehindCommitCount(state.repo.path, [ state.reference.refType === 'revision' ? GitRevision.createRange(state.reference.ref, context.destination.ref) : GitRevision.createRange(context.destination.name, state.reference.name), diff --git a/src/commands/git/reset.ts b/src/commands/git/reset.ts index 7ea4f98976ff1..40f34031e5839 100644 --- a/src/commands/git/reset.ts +++ b/src/commands/git/reset.ts @@ -42,8 +42,8 @@ export interface ResetGitCommandArgs { type ResetStepState = ExcludeSome, 'repo', string>; export class ResetGitCommand extends QuickCommand { - constructor(args?: ResetGitCommandArgs) { - super('reset', 'reset', 'Reset', { description: 'resets the current branch to a specified commit' }); + constructor(container: Container, args?: ResetGitCommandArgs) { + super(container, 'reset', 'reset', 'Reset', { description: 'resets the current branch to a specified commit' }); let counter = 0; if (args?.state?.repo != null) { @@ -73,8 +73,8 @@ export class ResetGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, cache: new Map>(), destination: undefined!, title: this.title, @@ -121,7 +121,7 @@ export class ResetGitCommand extends QuickCommand { let log = context.cache.get(ref); if (log == null) { - log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false }); + log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false }); context.cache.set(ref, log); } diff --git a/src/commands/git/revert.ts b/src/commands/git/revert.ts index a3476b529afd7..a82ee6d3767ab 100644 --- a/src/commands/git/revert.ts +++ b/src/commands/git/revert.ts @@ -41,8 +41,8 @@ export interface RevertGitCommandArgs { type RevertStepState = ExcludeSome, 'repo', string>; export class RevertGitCommand extends QuickCommand { - constructor(args?: RevertGitCommandArgs) { - super('revert', 'revert', 'Revert', { + constructor(container: Container, args?: RevertGitCommandArgs) { + super(container, 'revert', 'revert', 'Revert', { description: 'undoes the changes of specified commits, by creating new commits with inverted changes', }); @@ -75,8 +75,8 @@ export class RevertGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, cache: new Map>(), destination: undefined!, title: this.title, @@ -125,7 +125,7 @@ export class RevertGitCommand extends QuickCommand { let log = context.cache.get(ref); if (log == null) { - log = Container.instance.git.getLog(state.repo.path, { ref: ref, merges: false }); + log = this.container.git.getLog(state.repo.path, { ref: ref, merges: false }); context.cache.set(ref, log); } diff --git a/src/commands/git/search.ts b/src/commands/git/search.ts index 7b2b22fd1c445..0e42de003887a 100644 --- a/src/commands/git/search.ts +++ b/src/commands/git/search.ts @@ -59,8 +59,8 @@ const searchOperatorToTitleMap = new Map([ type SearchStepState = ExcludeSome, 'repo', string>; export class SearchGitCommand extends QuickCommand { - constructor(args?: SearchGitCommandArgs) { - super('search', 'search', 'Commit Search', { + constructor(container: Container, args?: SearchGitCommandArgs) { + super(container, 'search', 'search', 'Commit Search', { description: 'aka grep, searches for commits', }); @@ -94,15 +94,15 @@ export class SearchGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.searchAndCompareView, + repos: this.container.git.openRepositories, + associatedView: this.container.searchAndCompareView, commit: undefined, resultsKey: undefined, resultsPromise: undefined, title: this.title, }; - const cfg = Container.instance.config.gitCommands.search; + const cfg = this.container.config.gitCommands.search; if (state.matchAll == null) { state.matchAll = cfg.matchAll; } @@ -170,7 +170,7 @@ export class SearchGitCommand extends QuickCommand { // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions if (state.showResultsInSideBar) { - void Container.instance.searchAndCompareView.search( + void this.container.searchAndCompareView.search( state.repo.path, search, { @@ -199,7 +199,7 @@ export class SearchGitCommand extends QuickCommand { showInSideBarCommand: new ActionQuickPickItem( '$(link-external) Show Results in Side Bar', () => - void Container.instance.searchAndCompareView.search( + void this.container.searchAndCompareView.search( repoPath, search, { @@ -216,7 +216,7 @@ export class SearchGitCommand extends QuickCommand { showInSideBarButton: { button: QuickCommandButtons.ShowResultsInSideBar, onDidClick: () => - void Container.instance.searchAndCompareView.search( + void this.container.searchAndCompareView.search( repoPath, search, { @@ -240,6 +240,7 @@ export class SearchGitCommand extends QuickCommand { } const result = yield* GitCommandsCommand.getSteps( + this.container, { command: 'show', state: { diff --git a/src/commands/git/show.ts b/src/commands/git/show.ts index be45f9b2d5417..f841ff95b9ebb 100644 --- a/src/commands/git/show.ts +++ b/src/commands/git/show.ts @@ -36,8 +36,8 @@ export interface ShowGitCommandArgs { type ShowStepState = ExcludeSome, 'repo', string>; export class ShowGitCommand extends QuickCommand { - constructor(args?: ShowGitCommandArgs) { - super('show', 'show', 'Show', { + constructor(container: Container, args?: ShowGitCommandArgs) { + super(container, 'show', 'show', 'Show', { description: 'shows information about a git reference', }); @@ -78,8 +78,8 @@ export class ShowGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, title: this.title, }; @@ -113,10 +113,7 @@ export class ShowGitCommand extends QuickCommand { state.reference.isFile ) { if (state.reference != null && (!GitLogCommit.is(state.reference) || state.reference.isFile)) { - state.reference = await Container.instance.git.getCommit( - state.reference.repoPath, - state.reference.ref, - ); + state.reference = await this.container.git.getCommit(state.reference.repoPath, state.reference.ref); } if (state.counter < 2 || state.reference == null) { diff --git a/src/commands/git/stash.ts b/src/commands/git/stash.ts index 0c3f054d6d74e..64b964da5b85e 100644 --- a/src/commands/git/stash.ts +++ b/src/commands/git/stash.ts @@ -95,8 +95,8 @@ export interface StashGitCommandArgs { export class StashGitCommand extends QuickCommand { private subcommand: State['subcommand'] | undefined; - constructor(args?: StashGitCommandArgs) { - super('stash', 'stash', 'Stash', { + constructor(container: Container, args?: StashGitCommandArgs) { + super(container, 'stash', 'stash', 'Stash', { description: 'shelves (stashes) local changes to be reapplied later', }); @@ -147,8 +147,8 @@ export class StashGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.stashesView, + repos: this.container.git.openRepositories, + associatedView: this.container.stashesView, title: this.title, }; @@ -262,7 +262,7 @@ export class StashGitCommand extends QuickCommand { while (this.canStepsContinue(state)) { if (state.counter < 3 || state.reference == null) { const result: StepResult = yield* pickStashStep(state, context, { - stash: await Container.instance.git.getStash(state.repo.path), + stash: await this.container.git.getStash(state.repo.path), placeholder: (context, stash) => stash == null ? `No stashes found in ${state.repo.formattedName}` @@ -360,7 +360,7 @@ export class StashGitCommand extends QuickCommand { while (this.canStepsContinue(state)) { if (state.counter < 3 || state.reference == null) { const result: StepResult = yield* pickStashStep(state, context, { - stash: await Container.instance.git.getStash(state.repo.path), + stash: await this.container.git.getStash(state.repo.path), placeholder: (context, stash) => stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose a stash to delete', picked: state.reference?.ref, @@ -421,7 +421,7 @@ export class StashGitCommand extends QuickCommand { while (this.canStepsContinue(state)) { if (state.counter < 3 || state.reference == null) { const result: StepResult = yield* pickStashStep(state, context, { - stash: await Container.instance.git.getStash(state.repo.path), + stash: await this.container.git.getStash(state.repo.path), placeholder: (context, stash) => stash == null ? `No stashes found in ${state.repo.formattedName}` : 'Choose a stash', picked: state.reference?.ref, @@ -433,10 +433,11 @@ export class StashGitCommand extends QuickCommand { } // if (!(state.reference instanceof GitStashCommit)) { - // state.reference = await Container.instance.git.getCommit(state.repo.path, state.reference.ref); + // state.reference = await this.container.git.getCommit(state.repo.path, state.reference.ref); // } const result = yield* GitCommandsCommand.getSteps( + this.container, { command: 'show', state: { diff --git a/src/commands/git/status.ts b/src/commands/git/status.ts index c21b51f8d1cc3..7a317b6c60472 100644 --- a/src/commands/git/status.ts +++ b/src/commands/git/status.ts @@ -34,8 +34,8 @@ export interface StatusGitCommandArgs { type StatusStepState = ExcludeSome, 'repo', string>; export class StatusGitCommand extends QuickCommand { - constructor(args?: StatusGitCommandArgs) { - super('status', 'status', 'Status', { + constructor(container: Container, args?: StatusGitCommandArgs) { + super(container, 'status', 'status', 'Status', { description: 'shows status information about a repository', }); @@ -57,8 +57,8 @@ export class StatusGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, status: undefined!, title: this.title, }; diff --git a/src/commands/git/switch.ts b/src/commands/git/switch.ts index be46d2fdb12cf..43a53be7b5ae7 100644 --- a/src/commands/git/switch.ts +++ b/src/commands/git/switch.ts @@ -42,8 +42,8 @@ export interface SwitchGitCommandArgs { } export class SwitchGitCommand extends QuickCommand { - constructor(args?: SwitchGitCommandArgs) { - super('switch', 'switch', 'Switch', { + constructor(container: Container, args?: SwitchGitCommandArgs) { + super(container, 'switch', 'switch', 'Switch', { description: 'aka checkout, switches the current branch to a specified branch', }); @@ -90,8 +90,8 @@ export class SwitchGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.commitsView, + repos: this.container.git.openRepositories, + associatedView: this.container.commitsView, showTags: false, title: this.title, }; @@ -149,7 +149,7 @@ export class SwitchGitCommand extends QuickCommand { if (GitReference.isBranch(state.reference) && state.reference.remote) { context.title = `Create Branch and ${this.title}`; - const { values: branches } = await Container.instance.git.getBranches(state.reference.repoPath, { + const { values: branches } = await this.container.git.getBranches(state.reference.repoPath, { filter: b => b.upstream?.name === state.reference!.name, sort: { orderBy: BranchSorting.DateDesc }, }); diff --git a/src/commands/git/tag.ts b/src/commands/git/tag.ts index f04c8167ebff7..871861f65530d 100644 --- a/src/commands/git/tag.ts +++ b/src/commands/git/tag.ts @@ -68,8 +68,8 @@ export interface TagGitCommandArgs { export class TagGitCommand extends QuickCommand { private subcommand: State['subcommand'] | undefined; - constructor(args?: TagGitCommandArgs) { - super('tag', 'tag', 'Tag', { + constructor(container: Container, args?: TagGitCommandArgs) { + super(container, 'tag', 'tag', 'Tag', { description: 'create, or delete tags', }); @@ -129,8 +129,8 @@ export class TagGitCommand extends QuickCommand { protected async *steps(state: PartialStepState): StepGenerator { const context: Context = { - repos: Container.instance.git.openRepositories, - associatedView: Container.instance.tagsView, + repos: this.container.git.openRepositories, + associatedView: this.container.tagsView, showTags: false, title: this.title, }; diff --git a/src/commands/gitCommands.ts b/src/commands/gitCommands.ts index d69055f633693..80d5717dd767f 100644 --- a/src/commands/gitCommands.ts +++ b/src/commands/gitCommands.ts @@ -2,7 +2,7 @@ import { Disposable, InputBox, QuickInputButton, QuickInputButtons, QuickPick, QuickPickItem, window } from 'vscode'; import { configuration, GitCommandSorting } from '../configuration'; import { Usage, WorkspaceState } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { KeyMapping } from '../keyboard'; import { Directive, DirectiveQuickPickItem } from '../quickpicks'; import { log, Promises } from '../system'; @@ -65,8 +65,8 @@ function* nullSteps(): StepGenerator { @command() export class GitCommandsCommand extends Command { - static getSteps(args: GitCommandsCommandArgs, pickedVia: 'menu' | 'command'): StepGenerator { - const commandsStep = new PickCommandStep(args); + static getSteps(container: Container, args: GitCommandsCommandArgs, pickedVia: 'menu' | 'command'): StepGenerator { + const commandsStep = new PickCommandStep(container, args); const command = commandsStep.find(args.command); if (command == null) return nullSteps(); @@ -78,7 +78,7 @@ export class GitCommandsCommand extends Command { private startedWith: 'menu' | 'command' = 'menu'; - constructor() { + constructor(private readonly container: Container) { super([ Commands.GitCommands, Commands.GitCommandsBranch, @@ -125,7 +125,7 @@ export class GitCommandsCommand extends Command { @log({ args: false, correlate: true, singleLine: true, timed: false }) async execute(args?: GitCommandsCommandArgs) { - const commandsStep = new PickCommandStep(args); + const commandsStep = new PickCommandStep(this.container, args); const command = args?.command != null ? commandsStep.find(args.command) : undefined; this.startedWith = command != null ? 'command' : 'menu'; @@ -310,7 +310,7 @@ export class GitCommandsCommand extends Command { } } - const scope = Container.instance.keyboard.createScope(mapping); + const scope = this.container.keyboard.createScope(mapping); void scope.start(); disposables.push( @@ -459,7 +459,7 @@ export class GitCommandsCommand extends Command { } } - const scope = Container.instance.keyboard.createScope(mapping); + const scope = this.container.keyboard.createScope(mapping); void scope.start(); let overrideItems = false; @@ -747,29 +747,32 @@ class PickCommandStep implements QuickPickStep { readonly placeholder = 'Choose a git command'; readonly title = 'GitLens'; - constructor(args?: GitCommandsCommandArgs) { + constructor(private readonly container: Container, args?: GitCommandsCommandArgs) { this.items = [ - new BranchGitCommand(args?.command === 'branch' ? args : undefined), - new CherryPickGitCommand(args?.command === 'cherry-pick' ? args : undefined), - new CoAuthorsGitCommand(args?.command === 'co-authors' ? args : undefined), - new FetchGitCommand(args?.command === 'fetch' ? args : undefined), - new LogGitCommand(args?.command === 'log' ? args : undefined), - new MergeGitCommand(args?.command === 'merge' ? args : undefined), - new PullGitCommand(args?.command === 'pull' ? args : undefined), - new PushGitCommand(args?.command === 'push' ? args : undefined), - new RebaseGitCommand(args?.command === 'rebase' ? args : undefined), - new ResetGitCommand(args?.command === 'reset' ? args : undefined), - new RevertGitCommand(args?.command === 'revert' ? args : undefined), - new SearchGitCommand(args?.command === 'search' || args?.command === 'grep' ? args : undefined), - new ShowGitCommand(args?.command === 'show' ? args : undefined), - new StashGitCommand(args?.command === 'stash' ? args : undefined), - new StatusGitCommand(args?.command === 'status' ? args : undefined), - new SwitchGitCommand(args?.command === 'switch' || args?.command === 'checkout' ? args : undefined), - new TagGitCommand(args?.command === 'tag' ? args : undefined), + new BranchGitCommand(container, args?.command === 'branch' ? args : undefined), + new CherryPickGitCommand(container, args?.command === 'cherry-pick' ? args : undefined), + new CoAuthorsGitCommand(container, args?.command === 'co-authors' ? args : undefined), + new FetchGitCommand(container, args?.command === 'fetch' ? args : undefined), + new LogGitCommand(container, args?.command === 'log' ? args : undefined), + new MergeGitCommand(container, args?.command === 'merge' ? args : undefined), + new PullGitCommand(container, args?.command === 'pull' ? args : undefined), + new PushGitCommand(container, args?.command === 'push' ? args : undefined), + new RebaseGitCommand(container, args?.command === 'rebase' ? args : undefined), + new ResetGitCommand(container, args?.command === 'reset' ? args : undefined), + new RevertGitCommand(container, args?.command === 'revert' ? args : undefined), + new SearchGitCommand(container, args?.command === 'search' || args?.command === 'grep' ? args : undefined), + new ShowGitCommand(container, args?.command === 'show' ? args : undefined), + new StashGitCommand(container, args?.command === 'stash' ? args : undefined), + new StatusGitCommand(container, args?.command === 'status' ? args : undefined), + new SwitchGitCommand( + container, + args?.command === 'switch' || args?.command === 'checkout' ? args : undefined, + ), + new TagGitCommand(container, args?.command === 'tag' ? args : undefined), ]; - if (Container.instance.config.gitCommands.sortBy === GitCommandSorting.Usage) { - const usage = Container.instance.context.workspaceState.get(WorkspaceState.GitCommandPaletteUsage); + if (this.container.config.gitCommands.sortBy === GitCommandSorting.Usage) { + const usage = this.container.context.workspaceState.get(WorkspaceState.GitCommandPaletteUsage); if (usage != null) { this.items.sort((a, b) => (usage[b.key] ?? 0) - (usage[a.key] ?? 0)); } @@ -809,12 +812,12 @@ class PickCommandStep implements QuickPickStep { } private async updateCommandUsage(id: string, timestamp: number) { - let usage = Container.instance.context.workspaceState.get(WorkspaceState.GitCommandPaletteUsage); + let usage = this.container.context.workspaceState.get(WorkspaceState.GitCommandPaletteUsage); if (usage === undefined) { usage = Object.create(null) as Usage; } usage[id] = timestamp; - await Container.instance.context.workspaceState.update(WorkspaceState.GitCommandPaletteUsage, usage); + await this.container.context.workspaceState.update(WorkspaceState.GitCommandPaletteUsage, usage); } } diff --git a/src/commands/inviteToLiveShare.ts b/src/commands/inviteToLiveShare.ts index 0fd85192e54d4..674a3578ec2ff 100644 --- a/src/commands/inviteToLiveShare.ts +++ b/src/commands/inviteToLiveShare.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, CommandContext, Commands, isCommandContextViewNodeHasContributor } from './common'; export interface InviteToLiveShareCommandArgs { @@ -16,7 +16,7 @@ export class InviteToLiveShareCommand extends Command { return super.getMarkdownCommandArgsCore(Commands.InviteToLiveShare, args); } - constructor() { + constructor(private readonly container: Container) { super(Commands.InviteToLiveShare); } @@ -32,12 +32,12 @@ export class InviteToLiveShareCommand extends Command { async execute(args?: InviteToLiveShareCommandArgs) { if (args?.email) { - const contact = await Container.instance.vsls.getContact(args.email); + const contact = await this.container.vsls.getContact(args.email); if (contact != null) { return contact.invite(); } } - return Container.instance.vsls.startSession(); + return this.container.vsls.startSession(); } } diff --git a/src/commands/logging.ts b/src/commands/logging.ts index 252d1497127e6..211f7ae1eb3a4 100644 --- a/src/commands/logging.ts +++ b/src/commands/logging.ts @@ -1,10 +1,11 @@ 'use strict'; import { configuration, OutputLevel } from '../configuration'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class EnableDebugLoggingCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.EnableDebugLogging); } @@ -15,7 +16,7 @@ export class EnableDebugLoggingCommand extends Command { @command() export class DisableDebugLoggingCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.DisableDebugLogging); } diff --git a/src/commands/openAssociatedPullRequestOnRemote.ts b/src/commands/openAssociatedPullRequestOnRemote.ts index 1218a91a6f587..2550a36053e19 100644 --- a/src/commands/openAssociatedPullRequestOnRemote.ts +++ b/src/commands/openAssociatedPullRequestOnRemote.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { ActiveEditorCommand, command, Commands, executeCommand, getCommandUri } from './common'; @@ -8,7 +8,7 @@ import { OpenPullRequestOnRemoteCommandArgs } from './openPullRequestOnRemote'; @command() export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.OpenAssociatedPullRequestOnRemote); } @@ -24,7 +24,7 @@ export class OpenAssociatedPullRequestOnRemoteCommand extends ActiveEditorComman if (blameline < 0) return; try { - const blame = await Container.instance.git.getBlameForLine(gitUri, blameline); + const blame = await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) return; await executeCommand(Commands.OpenPullRequestOnRemote, { diff --git a/src/commands/openBranchOnRemote.ts b/src/commands/openBranchOnRemote.ts index b49879e7faf04..a32b592de9ae3 100644 --- a/src/commands/openBranchOnRemote.ts +++ b/src/commands/openBranchOnRemote.ts @@ -1,5 +1,6 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/remotes/provider'; import { Logger } from '../logger'; @@ -24,7 +25,7 @@ export interface OpenBranchOnRemoteCommandArgs { @command() export class OpenBranchOnRemoteCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenBranchOnRemote, Commands.Deprecated_OpenBranchInRemote, Commands.CopyRemoteBranchUrl]); } diff --git a/src/commands/openBranchesOnRemote.ts b/src/commands/openBranchesOnRemote.ts index 77a523f6ddcb9..3739b91be2a77 100644 --- a/src/commands/openBranchesOnRemote.ts +++ b/src/commands/openBranchesOnRemote.ts @@ -1,5 +1,6 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/remotes/provider'; import { Logger } from '../logger'; @@ -22,7 +23,7 @@ export interface OpenBranchesOnRemoteCommandArgs { @command() export class OpenBranchesOnRemoteCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.OpenBranchesOnRemote, Commands.Deprecated_OpenBranchesInRemote, diff --git a/src/commands/openChangedFiles.ts b/src/commands/openChangedFiles.ts index ea265315e790f..27f4fd514428f 100644 --- a/src/commands/openChangedFiles.ts +++ b/src/commands/openChangedFiles.ts @@ -1,6 +1,6 @@ 'use strict'; import { Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { Arrays } from '../system'; @@ -12,7 +12,7 @@ export interface OpenChangedFilesCommandArgs { @command() export class OpenChangedFilesCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.OpenChangedFiles); } @@ -24,7 +24,7 @@ export class OpenChangedFilesCommand extends Command { const repoPath = await getRepoPathOrPrompt('Open All Changed Files'); if (!repoPath) return; - const status = await Container.instance.git.getStatusForRepo(repoPath); + const status = await this.container.git.getStatusForRepo(repoPath); if (status == null) { void window.showWarningMessage('Unable to open changed files'); diff --git a/src/commands/openCommitOnRemote.ts b/src/commands/openCommitOnRemote.ts index 1b158314ab63c..0d862ce6a31f3 100644 --- a/src/commands/openCommitOnRemote.ts +++ b/src/commands/openCommitOnRemote.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/remotes/provider'; import { Logger } from '../logger'; @@ -31,7 +31,7 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand { return super.getMarkdownCommandArgsCore(Commands.OpenCommitOnRemote, args); } - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenCommitOnRemote, Commands.Deprecated_OpenCommitInRemote, Commands.CopyRemoteCommitUrl]); } @@ -72,8 +72,8 @@ export class OpenCommitOnRemoteCommand extends ActiveEditorCommand { if (blameline < 0) return; const blame = editor?.document.isDirty - ? await Container.instance.git.getBlameForLineContents(gitUri, blameline, editor.document.getText()) - : await Container.instance.git.getBlameForLine(gitUri, blameline); + ? await this.container.git.getBlameForLineContents(gitUri, blameline, editor.document.getText()) + : await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) { void Messages.showFileNotUnderSourceControlWarningMessage( 'Unable to open commit on remote provider', diff --git a/src/commands/openComparisonOnRemote.ts b/src/commands/openComparisonOnRemote.ts index 094a581407dd2..b81d094169913 100644 --- a/src/commands/openComparisonOnRemote.ts +++ b/src/commands/openComparisonOnRemote.ts @@ -1,5 +1,6 @@ 'use strict'; import { window } from 'vscode'; +import type { Container } from '../container'; import { RemoteResourceType } from '../git/remotes/provider'; import { Logger } from '../logger'; import { ResultsCommitsNode } from '../views/nodes'; @@ -16,7 +17,7 @@ export interface OpenComparisonOnRemoteCommandArgs { @command() export class OpenComparisonOnRemoteCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenComparisonOnRemote, Commands.CopyRemoteComparisonUrl]); } diff --git a/src/commands/openDirectoryCompare.ts b/src/commands/openDirectoryCompare.ts index 92482443cbd41..509aff4864e80 100644 --- a/src/commands/openDirectoryCompare.ts +++ b/src/commands/openDirectoryCompare.ts @@ -1,6 +1,7 @@ 'use strict'; import { TextEditor, Uri } from 'vscode'; import { GitActions } from '../commands'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { ReferencePicker } from '../quickpicks'; @@ -22,7 +23,7 @@ export interface OpenDirectoryCompareCommandArgs { @command() export class OpenDirectoryCompareCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.DiffDirectory, Commands.DiffDirectoryWithHead, diff --git a/src/commands/openFileAtRevision.ts b/src/commands/openFileAtRevision.ts index 41d12b0246ad4..4008970abc22d 100644 --- a/src/commands/openFileAtRevision.ts +++ b/src/commands/openFileAtRevision.ts @@ -2,7 +2,7 @@ import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { FileAnnotationType } from '../configuration'; import { GlyphChars, quickPickTitleMaxChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitRevision } from '../git/models'; import { Logger } from '../logger'; @@ -46,7 +46,7 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand { return super.getMarkdownCommandArgsCore(Commands.OpenFileAtRevision, args); } - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenFileAtRevision, Commands.OpenBlamePriorToChange]); } @@ -58,7 +58,7 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand { if (editorLine >= 0) { try { const gitUri = await GitUri.fromUri(context.editor.document.uri); - const blame = await Container.instance.git.getBlameForLine(gitUri, editorLine); + const blame = await this.container.git.getBlameForLine(gitUri, editorLine); if (blame != null) { if (blame.commit.isUncommitted) { const diffUris = await blame.commit.getPreviousLineDiffUris( @@ -107,11 +107,11 @@ export class OpenFileAtRevisionCommand extends ActiveEditorCommand { try { if (args.revisionUri == null) { - const log = Container.instance.git.getLogForFile(gitUri.repoPath, gitUri.fsPath).then( + const log = this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath).then( log => log ?? (gitUri.sha - ? Container.instance.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { + ? this.container.git.getLogForFile(gitUri.repoPath, gitUri.fsPath, { ref: gitUri.sha, }) : undefined), diff --git a/src/commands/openFileAtRevisionFrom.ts b/src/commands/openFileAtRevisionFrom.ts index 469d3c68af4dd..7bd5c365b997f 100644 --- a/src/commands/openFileAtRevisionFrom.ts +++ b/src/commands/openFileAtRevisionFrom.ts @@ -2,7 +2,7 @@ import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { FileAnnotationType } from '../configuration'; import { GlyphChars, quickPickTitleMaxChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitReference } from '../git/models'; import { Messages } from '../messages'; @@ -23,7 +23,7 @@ export interface OpenFileAtRevisionFromCommandArgs { @command() export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.OpenFileAtRevisionFrom); } @@ -48,7 +48,7 @@ export class OpenFileAtRevisionFromCommand extends ActiveEditorCommand { const title = `Open Changes with Stash${Strings.pad(GlyphChars.Dot, 2, 2)}`; const pick = await StashPicker.show( - Container.instance.git.getStash(gitUri.repoPath), + this.container.git.getStash(gitUri.repoPath), `${title}${gitUri.getFormattedFileName({ truncateTo: quickPickTitleMaxChars - title.length })}`, 'Choose a stash to compare with', { filter: c => c.files.some(f => f.fileName === fileName || f.originalFileName === fileName) }, diff --git a/src/commands/openFileFromRemote.ts b/src/commands/openFileFromRemote.ts index 1644e93574846..4994986e4ddc1 100644 --- a/src/commands/openFileFromRemote.ts +++ b/src/commands/openFileFromRemote.ts @@ -1,11 +1,11 @@ 'use strict'; import { env, Range, Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, Commands, openEditor } from './common'; @command() export class OpenFileFromRemoteCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.OpenFileFromRemote); } @@ -25,9 +25,9 @@ export class OpenFileFromRemoteCommand extends Command { }); if (url == null || url.length === 0) return; - let local = await Container.instance.git.getLocalInfoFromRemoteUri(Uri.parse(url)); + let local = await this.container.git.getLocalInfoFromRemoteUri(Uri.parse(url)); if (local == null) { - local = await Container.instance.git.getLocalInfoFromRemoteUri(Uri.parse(url), { validate: false }); + local = await this.container.git.getLocalInfoFromRemoteUri(Uri.parse(url), { validate: false }); if (local == null) { void window.showWarningMessage('Unable to parse the provided remote url.'); diff --git a/src/commands/openFileOnRemote.ts b/src/commands/openFileOnRemote.ts index 19d53b4f5ce33..61aeee3ed6e23 100644 --- a/src/commands/openFileOnRemote.ts +++ b/src/commands/openFileOnRemote.ts @@ -3,7 +3,7 @@ import { Range, TextEditor, Uri, window } from 'vscode'; import { UriComparer } from '../comparers'; import { BranchSorting, TagSorting } from '../configuration'; import { GlyphChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitBranch, GitRevision } from '../git/models'; import { RemoteResourceType } from '../git/remotes/provider'; @@ -33,7 +33,7 @@ export interface OpenFileOnRemoteCommandArgs { @command() export class OpenFileOnRemoteCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.OpenFileOnRemote, Commands.Deprecated_OpenFileInRemote, @@ -84,7 +84,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand { const gitUri = await GitUri.fromUri(uri); if (gitUri.repoPath) { if (gitUri.sha == null) { - const commit = await Container.instance.git.getCommitForFile(gitUri.repoPath, gitUri, { + const commit = await this.container.git.getCommitForFile(gitUri.repoPath, gitUri, { firstIfNotFound: true, }); @@ -116,7 +116,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand { args = { range: true, ...args }; try { - let remotes = await Container.instance.git.getRemotes(gitUri.repoPath); + let remotes = await this.container.git.getRemotes(gitUri.repoPath); const range = args.range && editor != null && UriComparer.equals(editor.document.uri, uri) ? new Range( @@ -144,7 +144,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand { if ((args.sha == null && args.branchOrTag == null) || args.pickBranchOrTag) { let branch; if (!args.pickBranchOrTag) { - branch = await Container.instance.git.getBranch(gitUri.repoPath); + branch = await this.container.git.getBranch(gitUri.repoPath); } if (branch?.upstream == null) { diff --git a/src/commands/openIssueOnRemote.ts b/src/commands/openIssueOnRemote.ts index f9f0eb3a7b150..4edc3ab2fe87a 100644 --- a/src/commands/openIssueOnRemote.ts +++ b/src/commands/openIssueOnRemote.ts @@ -1,5 +1,6 @@ 'use strict'; import { env, Uri } from 'vscode'; +import type { Container } from '../container'; import { AutolinkedItemNode } from '../views/nodes/autolinkedItemNode'; import { Command, command, CommandContext, Commands } from './common'; @@ -10,7 +11,7 @@ export interface OpenIssueOnRemoteCommandArgs { @command() export class OpenIssueOnRemoteCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenIssueOnRemote, Commands.CopyRemoteIssueUrl]); } diff --git a/src/commands/openOnRemote.ts b/src/commands/openOnRemote.ts index b752e1479ac27..b6c27305d63c1 100644 --- a/src/commands/openOnRemote.ts +++ b/src/commands/openOnRemote.ts @@ -1,6 +1,6 @@ 'use strict'; import { GlyphChars } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitRemote, GitRevision } from '../git/models'; import { RemoteProvider, RemoteResource, RemoteResourceType } from '../git/remotes/provider'; import { Logger } from '../logger'; @@ -27,14 +27,14 @@ export type OpenOnRemoteCommandArgs = @command() export class OpenOnRemoteCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenOnRemote, Commands.Deprecated_OpenInRemote]); } async execute(args?: OpenOnRemoteCommandArgs) { if (args?.resource == null) return; - let remotes = 'remotes' in args ? args.remotes : await Container.instance.git.getRemotes(args.repoPath); + let remotes = 'remotes' in args ? args.remotes : await this.container.git.getRemotes(args.repoPath); if (args.remote != null) { const filtered = remotes.filter(r => r.name === args.remote); @@ -61,7 +61,7 @@ export class OpenOnRemoteCommand extends Command { const file = commit?.files.find(f => f.fileName === fileName); if (file?.status === 'D') { // Resolve to the previous commit to that file - args.resource.sha = await Container.instance.git.resolveReference( + args.resource.sha = await this.container.git.resolveReference( commit.repoPath, `${commit.sha}^`, fileName, diff --git a/src/commands/openPullRequestOnRemote.ts b/src/commands/openPullRequestOnRemote.ts index 87b0858f8e655..b03ae7f4ca8e9 100644 --- a/src/commands/openPullRequestOnRemote.ts +++ b/src/commands/openPullRequestOnRemote.ts @@ -1,6 +1,6 @@ 'use strict'; import { env, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { PullRequestNode } from '../views/nodes'; import { Command, command, CommandContext, Commands } from './common'; @@ -13,7 +13,7 @@ export interface OpenPullRequestOnRemoteCommandArgs { @command() export class OpenPullRequestOnRemoteCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenPullRequestOnRemote, Commands.CopyRemotePullRequestUrl]); } @@ -33,10 +33,10 @@ export class OpenPullRequestOnRemoteCommand extends Command { if (args?.pr == null) { if (args?.repoPath == null || args?.ref == null) return; - const remote = await Container.instance.git.getRichRemoteProvider(args.repoPath); + const remote = await this.container.git.getRichRemoteProvider(args.repoPath); if (remote?.provider == null) return; - const pr = await Container.instance.git.getPullRequestForCommit(args.ref, remote.provider); + const pr = await this.container.git.getPullRequestForCommit(args.ref, remote.provider); if (pr == null) return; args = { ...args }; diff --git a/src/commands/openRepoOnRemote.ts b/src/commands/openRepoOnRemote.ts index 3dd8bf5206cb3..fa5052b9acdb0 100644 --- a/src/commands/openRepoOnRemote.ts +++ b/src/commands/openRepoOnRemote.ts @@ -1,5 +1,6 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { RemoteResourceType } from '../git/remotes/provider'; import { Logger } from '../logger'; @@ -22,7 +23,7 @@ export interface OpenRepoOnRemoteCommandArgs { @command() export class OpenRepoOnRemoteCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenRepoOnRemote, Commands.Deprecated_OpenRepoInRemote, Commands.CopyRemoteRepositoryUrl]); } diff --git a/src/commands/openRevisionFile.ts b/src/commands/openRevisionFile.ts index 5efb160f2a2ee..da8a92175e3f1 100644 --- a/src/commands/openRevisionFile.ts +++ b/src/commands/openRevisionFile.ts @@ -1,7 +1,7 @@ 'use strict'; import { TextDocumentShowOptions, TextEditor, Uri } from 'vscode'; import { FileAnnotationType } from '../configuration'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { Messages } from '../messages'; @@ -18,7 +18,7 @@ export interface OpenRevisionFileCommandArgs { @command() export class OpenRevisionFileCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenRevisionFile, Commands.OpenRevisionFileInDiffLeft, Commands.OpenRevisionFileInDiffRight]); } @@ -36,7 +36,7 @@ export class OpenRevisionFileCommand extends ActiveEditorCommand { try { if (args.revisionUri == null) { if (gitUri?.sha) { - const commit = await Container.instance.git.getCommit(gitUri.repoPath!, gitUri.sha); + const commit = await this.container.git.getCommit(gitUri.repoPath!, gitUri.sha); args.revisionUri = commit != null && commit.status === 'D' diff --git a/src/commands/openWorkingFile.ts b/src/commands/openWorkingFile.ts index 0c1576a9008ad..b671446fb8ad7 100644 --- a/src/commands/openWorkingFile.ts +++ b/src/commands/openWorkingFile.ts @@ -1,7 +1,7 @@ 'use strict'; import { Range, TextDocumentShowOptions, TextEditor, Uri, window } from 'vscode'; import { FileAnnotationType } from '../configuration'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Logger } from '../logger'; import { Messages } from '../messages'; @@ -16,7 +16,7 @@ export interface OpenWorkingFileCommandArgs { @command() export class OpenWorkingFileCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.OpenWorkingFile, Commands.OpenWorkingFileInDiffLeft, Commands.OpenWorkingFileInDiffRight]); } @@ -36,7 +36,7 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand { args.uri = await GitUri.fromUri(uri); if (GitUri.is(args.uri) && args.uri.sha) { - const workingUri = await Container.instance.git.getWorkingUri(args.uri.repoPath!, args.uri); + const workingUri = await this.container.git.getWorkingUri(args.uri.repoPath!, args.uri); if (workingUri === undefined) { void window.showWarningMessage( 'Unable to open working file. File could not be found in the working tree', @@ -58,7 +58,7 @@ export class OpenWorkingFileCommand extends ActiveEditorCommand { const e = await findOrOpenEditor(args.uri, { ...args.showOptions, throwOnError: true }); if (args.annotationType === undefined) return; - void (await Container.instance.fileAnnotations.show(e, args.annotationType, { + void (await this.container.fileAnnotations.show(e, args.annotationType, { selection: { line: args.line }, })); } catch (ex) { diff --git a/src/commands/quickCommand.ts b/src/commands/quickCommand.ts index cee8f04680275..1cb0aae37f076 100644 --- a/src/commands/quickCommand.ts +++ b/src/commands/quickCommand.ts @@ -1,6 +1,6 @@ 'use strict'; import { InputBox, QuickInputButton, QuickPick, QuickPickItem } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { Keys } from '../keyboard'; import { Directive, DirectiveQuickPickItem } from '../quickpicks'; @@ -102,6 +102,7 @@ export abstract class QuickCommand implements QuickPickItem { private _stepsIterator: StepGenerator | undefined; constructor( + protected readonly container: Container, public readonly key: string, public readonly label: string, public readonly title: string, @@ -154,7 +155,7 @@ export abstract class QuickCommand implements QuickPickItem { return override != null ? override - : !Container.instance.config.gitCommands.skipConfirmations.includes(this.skipConfirmKey); + : !this.container.config.gitCommands.skipConfirmations.includes(this.skipConfirmKey); } isMatch(key: string) { diff --git a/src/commands/rebaseEditor.ts b/src/commands/rebaseEditor.ts index a6c2497e85836..19e469421282e 100644 --- a/src/commands/rebaseEditor.ts +++ b/src/commands/rebaseEditor.ts @@ -1,25 +1,25 @@ 'use strict'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class DisableRebaseEditorCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.DisableRebaseEditor); } execute() { - return Container.instance.rebaseEditor.setEnabled(false); + return this.container.rebaseEditor.setEnabled(false); } } @command() export class EnableRebaseEditorCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.EnableRebaseEditor); } execute() { - return Container.instance.rebaseEditor.setEnabled(true); + return this.container.rebaseEditor.setEnabled(true); } } diff --git a/src/commands/refreshHover.ts b/src/commands/refreshHover.ts index 65e14573a8bcd..7b485f6cc51ed 100644 --- a/src/commands/refreshHover.ts +++ b/src/commands/refreshHover.ts @@ -1,10 +1,11 @@ 'use strict'; import { commands } from 'vscode'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class RefreshHoverCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.RefreshHover); } diff --git a/src/commands/remoteProviders.ts b/src/commands/remoteProviders.ts index 629929be89a0b..1aa7c9690eaee 100644 --- a/src/commands/remoteProviders.ts +++ b/src/commands/remoteProviders.ts @@ -1,5 +1,5 @@ 'use strict'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitCommit, GitRemote, Repository } from '../git/models'; import { RichRemoteProvider } from '../git/remotes/provider'; import { RepositoryPicker } from '../quickpicks/repositoryPicker'; @@ -29,7 +29,7 @@ export class ConnectRemoteProviderCommand extends Command { return super.getMarkdownCommandArgsCore(Commands.ConnectRemoteProvider, args); } - constructor() { + constructor(private readonly container: Container) { super(Commands.ConnectRemoteProvider); } @@ -48,7 +48,7 @@ export class ConnectRemoteProviderCommand extends Command { if (args?.repoPath == null) { const repos = new Map>(); - for (const repo of Container.instance.git.openRepositories) { + for (const repo of this.container.git.openRepositories) { const remote = await repo.getRichRemote(); if (remote?.provider != null && !(await remote.provider.isConnected())) { repos.set(repo, remote); @@ -74,18 +74,18 @@ export class ConnectRemoteProviderCommand extends Command { } else if (args?.remote == null) { repoPath = args.repoPath; - remote = await Container.instance.git.getRichRemoteProvider(repoPath, { includeDisconnected: true }); + remote = await this.container.git.getRichRemoteProvider(repoPath, { includeDisconnected: true }); if (remote == null) return false; } else { repoPath = args.repoPath; - remotes = await Container.instance.git.getRemotes(repoPath); + remotes = await this.container.git.getRemotes(repoPath); remote = remotes.find(r => r.id === args.remote) as GitRemote | undefined; if (!remote?.hasRichProvider()) return false; } const connected = await remote.provider.connect(); - if (connected && !(remotes ?? (await Container.instance.git.getRemotes(repoPath))).some(r => r.default)) { + if (connected && !(remotes ?? (await this.container.git.getRemotes(repoPath))).some(r => r.default)) { await remote.setAsDefault(true); } return connected; @@ -118,7 +118,7 @@ export class DisconnectRemoteProviderCommand extends Command { ); } - constructor() { + constructor(private readonly container: Container) { super(Commands.DisconnectRemoteProvider); } @@ -136,7 +136,7 @@ export class DisconnectRemoteProviderCommand extends Command { if (args?.repoPath == null) { const repos = new Map>(); - for (const repo of Container.instance.git.openRepositories) { + for (const repo of this.container.git.openRepositories) { const remote = await repo.getRichRemote(true); if (remote != null) { repos.set(repo, remote); @@ -162,12 +162,12 @@ export class DisconnectRemoteProviderCommand extends Command { } else if (args?.remote == null) { repoPath = args.repoPath; - remote = await Container.instance.git.getRichRemoteProvider(repoPath, { includeDisconnected: false }); + remote = await this.container.git.getRichRemoteProvider(repoPath, { includeDisconnected: false }); if (remote == null) return undefined; } else { repoPath = args.repoPath; - remote = (await Container.instance.git.getRemotes(repoPath)).find(r => r.id === args.remote) as + remote = (await this.container.git.getRemotes(repoPath)).find(r => r.id === args.remote) as | GitRemote | undefined; if (!remote?.hasRichProvider()) return undefined; diff --git a/src/commands/repositories.ts b/src/commands/repositories.ts index 88e4c029af88e..84079a09a1d34 100644 --- a/src/commands/repositories.ts +++ b/src/commands/repositories.ts @@ -1,46 +1,46 @@ 'use strict'; import { executeGitCommand } from '../commands'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class FetchRepositoriesCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.FetchRepositories); } async execute() { return executeGitCommand({ command: 'fetch', - state: { repos: Container.instance.git.openRepositories }, + state: { repos: this.container.git.openRepositories }, }); } } @command() export class PullRepositoriesCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.PullRepositories); } async execute() { return executeGitCommand({ command: 'pull', - state: { repos: Container.instance.git.openRepositories }, + state: { repos: this.container.git.openRepositories }, }); } } @command() export class PushRepositoriesCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.PushRepositories); } async execute() { return executeGitCommand({ command: 'push', - state: { repos: Container.instance.git.openRepositories }, + state: { repos: this.container.git.openRepositories }, }); } } diff --git a/src/commands/resetAvatarCache.ts b/src/commands/resetAvatarCache.ts index de1be3f190743..a778fc9475784 100644 --- a/src/commands/resetAvatarCache.ts +++ b/src/commands/resetAvatarCache.ts @@ -1,10 +1,11 @@ 'use strict'; import { resetAvatarCache } from '../avatars'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class ResetAvatarCacheCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ResetAvatarCache); } diff --git a/src/commands/resetSuppressedWarnings.ts b/src/commands/resetSuppressedWarnings.ts index fffdfeb6a7a95..f903f625d72ce 100644 --- a/src/commands/resetSuppressedWarnings.ts +++ b/src/commands/resetSuppressedWarnings.ts @@ -1,11 +1,12 @@ 'use strict'; import { ConfigurationTarget } from 'vscode'; import { configuration } from '../configuration'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class ResetSuppressedWarningsCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ResetSuppressedWarnings); } diff --git a/src/commands/searchCommits.ts b/src/commands/searchCommits.ts index 7c49b908472aa..3be5e9250f586 100644 --- a/src/commands/searchCommits.ts +++ b/src/commands/searchCommits.ts @@ -1,6 +1,6 @@ 'use strict'; import { executeGitCommand } from '../commands'; -import { Container } from '../container'; +import type { Container } from '../container'; import { SearchPattern } from '../git/search'; import { SearchResultsNode } from '../views/nodes'; import { Command, command, CommandContext, Commands, isCommandContextViewNodeHasRepository } from './common'; @@ -16,7 +16,7 @@ export interface SearchCommitsCommandArgs { @command() export class SearchCommitsCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.SearchCommits, Commands.SearchCommitsInView]); } @@ -50,7 +50,7 @@ export class SearchCommitsCommand extends Command { repo: args?.repoPath, ...args?.search, showResultsInSideBar: - Container.instance.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar, + this.container.config.gitCommands.search.showResultsInSideBar ?? args?.showResultsInSideBar, }, })); } diff --git a/src/commands/setViewsLayout.ts b/src/commands/setViewsLayout.ts index 6277abc13c6dd..5fd9ee02deb4d 100644 --- a/src/commands/setViewsLayout.ts +++ b/src/commands/setViewsLayout.ts @@ -1,6 +1,7 @@ 'use strict'; import { commands, window } from 'vscode'; import { viewsConfigKeys } from '../configuration'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; enum ViewsLayout { @@ -14,7 +15,7 @@ export interface SetViewsLayoutCommandArgs { @command() export class SetViewsLayoutCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.SetViewsLayout); } diff --git a/src/commands/showCommitsInView.ts b/src/commands/showCommitsInView.ts index 0fec06fcbb862..10c0251d4810f 100644 --- a/src/commands/showCommitsInView.ts +++ b/src/commands/showCommitsInView.ts @@ -1,7 +1,7 @@ 'use strict'; import { TextEditor, Uri } from 'vscode'; import { executeGitCommand } from '../commands'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { SearchPattern } from '../git/search'; import { Logger } from '../logger'; @@ -16,7 +16,7 @@ export interface ShowCommitsInViewCommandArgs { @command() export class ShowCommitsInViewCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.ShowCommitInView, Commands.ShowCommitsInView]); } @@ -35,12 +35,12 @@ export class ShowCommitsInViewCommand extends ActiveEditorCommand { try { // Check for any uncommitted changes in the range const blame = editor.document.isDirty - ? await Container.instance.git.getBlameForRangeContents( + ? await this.container.git.getBlameForRangeContents( gitUri, editor.selection, editor.document.getText(), ) - : await Container.instance.git.getBlameForRange(gitUri, editor.selection); + : await this.container.git.getBlameForRange(gitUri, editor.selection); if (blame === undefined) { return Messages.showFileNotUnderSourceControlWarningMessage('Unable to find commits'); } diff --git a/src/commands/showLastQuickPick.ts b/src/commands/showLastQuickPick.ts index 73b07f6a83af4..56901bdc7c1fb 100644 --- a/src/commands/showLastQuickPick.ts +++ b/src/commands/showLastQuickPick.ts @@ -1,12 +1,13 @@ 'use strict'; import { commands } from 'vscode'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { command, Command, Commands, getLastCommand } from './common'; @command() export class ShowLastQuickPickCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ShowLastQuickPick); } diff --git a/src/commands/showQuickBranchHistory.ts b/src/commands/showQuickBranchHistory.ts index 0259fb14a8fc9..d66832912310f 100644 --- a/src/commands/showQuickBranchHistory.ts +++ b/src/commands/showQuickBranchHistory.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitReference } from '../git/models'; import { ActiveEditorCachedCommand, command, CommandContext, Commands, getCommandUri } from './common'; @@ -14,7 +14,7 @@ export interface ShowQuickBranchHistoryCommandArgs { @command() export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.ShowQuickBranchHistory, Commands.ShowQuickCurrentBranchHistory]); } @@ -32,7 +32,7 @@ export class ShowQuickBranchHistoryCommand extends ActiveEditorCachedCommand { const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined; - const repoPath = args?.repoPath ?? gitUri?.repoPath ?? Container.instance.git.highlanderRepoPath; + const repoPath = args?.repoPath ?? gitUri?.repoPath ?? this.container.git.highlanderRepoPath; let ref: GitReference | 'HEAD' | undefined; if (repoPath != null) { if (args?.branch != null) { diff --git a/src/commands/showQuickCommit.ts b/src/commands/showQuickCommit.ts index e0f0fb8465b32..c2765fcc0abf8 100644 --- a/src/commands/showQuickCommit.ts +++ b/src/commands/showQuickCommit.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitCommit, GitLog, GitLogCommit } from '../git/models'; import { Logger } from '../logger'; @@ -32,7 +32,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand { return super.getMarkdownCommandArgsCore(Commands.ShowQuickCommit, args); } - constructor() { + constructor(private readonly container: Container) { super([Commands.RevealCommitInView, Commands.ShowQuickCommit]); } @@ -89,7 +89,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand { if (blameline < 0) return; try { - const blame = await Container.instance.git.getBlameForLine(gitUri, blameline); + const blame = await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) { void Messages.showFileNotUnderSourceControlWarningMessage('Unable to show commit'); @@ -126,7 +126,7 @@ export class ShowQuickCommitCommand extends ActiveEditorCachedCommand { } if (args.repoLog == null) { - args.commit = await Container.instance.git.getCommit(repoPath!, args.sha); + args.commit = await this.container.git.getCommit(repoPath!, args.sha); } } diff --git a/src/commands/showQuickCommitFile.ts b/src/commands/showQuickCommitFile.ts index 4a00601ecb43a..a2a915a4ff1b5 100644 --- a/src/commands/showQuickCommitFile.ts +++ b/src/commands/showQuickCommitFile.ts @@ -1,6 +1,6 @@ 'use strict'; import { TextEditor, Uri, window } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitBlameCommit, GitCommit, GitLog, GitLogCommit } from '../git/models'; import { Logger } from '../logger'; @@ -28,7 +28,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand { return super.getMarkdownCommandArgsCore(Commands.ShowQuickCommitFile, args); } - constructor() { + constructor(private readonly container: Container) { super([ Commands.ShowQuickCommitFile, Commands.ShowQuickCommitRevision, @@ -78,7 +78,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand { if (blameline < 0) return; try { - const blame = await Container.instance.git.getBlameForLine(gitUri, blameline); + const blame = await this.container.git.getBlameForLine(gitUri, blameline); if (blame == null) { void Messages.showFileNotUnderSourceControlWarningMessage('Unable to show commit file details'); @@ -115,7 +115,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand { if (args.fileLog === undefined) { const repoPath = args.commit === undefined ? gitUri.repoPath : args.commit.repoPath; - args.commit = await Container.instance.git.getCommitForFile(repoPath, gitUri, { + args.commit = await this.container.git.getCommitForFile(repoPath, gitUri, { ref: args.sha, }); if (args.commit === undefined) { @@ -136,7 +136,7 @@ export class ShowQuickCommitFileCommand extends ActiveEditorCachedCommand { const fileName = args.commit.fileName; if (args.commit instanceof GitBlameCommit) { - args.commit = (await Container.instance.git.getCommit(args.commit.repoPath, args.commit.ref))!; + args.commit = (await this.container.git.getCommit(args.commit.repoPath, args.commit.ref))!; } void (await executeGitCommand({ diff --git a/src/commands/showQuickFileHistory.ts b/src/commands/showQuickFileHistory.ts index 339fb87dbb6fa..4c5c6c5023261 100644 --- a/src/commands/showQuickFileHistory.ts +++ b/src/commands/showQuickFileHistory.ts @@ -1,6 +1,6 @@ 'use strict'; import { Range, TextEditor, Uri } from 'vscode'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { GitBranch, GitLog, GitReference, GitTag } from '../git/models'; import { CommandQuickPickItem } from '../quickpicks'; @@ -20,7 +20,7 @@ export interface ShowQuickFileHistoryCommandArgs { @command() export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.OpenFileHistory, Commands.OpenFolderHistory, @@ -50,7 +50,7 @@ export class ShowQuickFileHistoryCommand extends ActiveEditorCachedCommand { const gitUri = await GitUri.fromUri(uri); if (args?.showInSideBar) { - await Container.instance.fileHistoryView.showHistoryForUri(gitUri); + await this.container.fileHistoryView.showHistoryForUri(gitUri); return; } diff --git a/src/commands/showQuickRepoStatus.ts b/src/commands/showQuickRepoStatus.ts index 5fdf685a2e8d3..2719a3ae532f8 100644 --- a/src/commands/showQuickRepoStatus.ts +++ b/src/commands/showQuickRepoStatus.ts @@ -1,5 +1,6 @@ 'use strict'; import { executeGitCommand } from '../commands'; +import type { Container } from '../container'; import { Command, command, Commands } from './common'; export interface ShowQuickRepoStatusCommandArgs { @@ -8,7 +9,7 @@ export interface ShowQuickRepoStatusCommandArgs { @command() export class ShowQuickRepoStatusCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ShowQuickRepoStatus); } diff --git a/src/commands/showQuickStashList.ts b/src/commands/showQuickStashList.ts index 6a27318c97f10..3a7b7594aa48b 100644 --- a/src/commands/showQuickStashList.ts +++ b/src/commands/showQuickStashList.ts @@ -1,5 +1,6 @@ 'use strict'; import { executeGitCommand } from '../commands'; +import type { Container } from '../container'; import { Command, command, Commands } from './common'; export interface ShowQuickStashListCommandArgs { @@ -8,7 +9,7 @@ export interface ShowQuickStashListCommandArgs { @command() export class ShowQuickStashListCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ShowQuickStashList); } diff --git a/src/commands/showView.ts b/src/commands/showView.ts index 661bf869182da..8e7d841018f0f 100644 --- a/src/commands/showView.ts +++ b/src/commands/showView.ts @@ -1,12 +1,12 @@ 'use strict'; import { commands } from 'vscode'; import { ContextKeys, setContext, SyncedState } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, CommandContext, Commands } from './common'; @command() export class ShowViewCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([ Commands.ShowBranchesView, Commands.ShowCommitsView, @@ -29,28 +29,28 @@ export class ShowViewCommand extends Command { async execute(command: Commands) { switch (command) { case Commands.ShowBranchesView: - return Container.instance.branchesView.show(); + return this.container.branchesView.show(); case Commands.ShowCommitsView: - return Container.instance.commitsView.show(); + return this.container.commitsView.show(); case Commands.ShowContributorsView: - return Container.instance.contributorsView.show(); + return this.container.contributorsView.show(); case Commands.ShowFileHistoryView: - return Container.instance.fileHistoryView.show(); + return this.container.fileHistoryView.show(); case Commands.ShowLineHistoryView: - return Container.instance.lineHistoryView.show(); + return this.container.lineHistoryView.show(); case Commands.ShowRemotesView: - return Container.instance.remotesView.show(); + return this.container.remotesView.show(); case Commands.ShowRepositoriesView: - return Container.instance.repositoriesView.show(); + return this.container.repositoriesView.show(); case Commands.ShowSearchAndCompareView: - return Container.instance.searchAndCompareView.show(); + return this.container.searchAndCompareView.show(); case Commands.ShowStashesView: - return Container.instance.stashesView.show(); + return this.container.stashesView.show(); case Commands.ShowTagsView: - return Container.instance.tagsView.show(); + return this.container.tagsView.show(); case Commands.ShowWelcomeView: await setContext(ContextKeys.ViewsWelcomeVisible, true); - void Container.instance.context.globalState.update(SyncedState.WelcomeViewVisible, true); + void this.container.context.globalState.update(SyncedState.WelcomeViewVisible, true); void (await commands.executeCommand('gitlens.views.welcome.focus')); } diff --git a/src/commands/stashApply.ts b/src/commands/stashApply.ts index 92fb8abc7697d..903a24965514c 100644 --- a/src/commands/stashApply.ts +++ b/src/commands/stashApply.ts @@ -1,5 +1,6 @@ 'use strict'; import { GitActions } from '../commands'; +import type { Container } from '../container'; import { GitStashCommit, GitStashReference } from '../git/models'; import { CommandQuickPickItem } from '../quickpicks'; import { @@ -21,7 +22,7 @@ export interface StashApplyCommandArgs { @command() export class StashApplyCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.StashApply); } diff --git a/src/commands/stashSave.ts b/src/commands/stashSave.ts index 6bdfc1d02f9b9..a15b981eb741c 100644 --- a/src/commands/stashSave.ts +++ b/src/commands/stashSave.ts @@ -3,7 +3,7 @@ import { Uri } from 'vscode'; import type { ScmResource } from '../@types/vscode.git.resources'; import { ScmResourceGroupType } from '../@types/vscode.git.resources.enums'; import { GitActions } from '../commands'; -import { Container } from '../container'; +import type { Container } from '../container'; import { GitUri } from '../git/gitUri'; import { Command, @@ -24,7 +24,7 @@ export interface StashSaveCommandArgs { @command() export class StashSaveCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super([Commands.StashSave, Commands.StashSaveFiles]); } @@ -42,9 +42,9 @@ export class StashSaveCommand extends Command { } else if (context.type === 'scm-states') { args = { ...args }; args.uris = context.scmResourceStates.map(s => s.resourceUri); - args.repoPath = await Container.instance.git.getRepoPath(args.uris[0].fsPath); + args.repoPath = await this.container.git.getRepoPath(args.uris[0].fsPath); - const status = await Container.instance.git.getStatusForRepo(args.repoPath); + const status = await this.container.git.getStatusForRepo(args.repoPath); if (status?.computeWorkingTreeStatus().staged) { if ( !context.scmResourceStates.some( @@ -60,9 +60,9 @@ export class StashSaveCommand extends Command { (a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)), [], ); - args.repoPath = await Container.instance.git.getRepoPath(args.uris[0].fsPath); + args.repoPath = await this.container.git.getRepoPath(args.uris[0].fsPath); - const status = await Container.instance.git.getStatusForRepo(args.repoPath); + const status = await this.container.git.getStatusForRepo(args.repoPath); if (status?.computeWorkingTreeStatus().staged) { if (!context.scmResourceGroups.some(g => g.id === 'index')) { args.keepStaged = true; diff --git a/src/commands/switchMode.ts b/src/commands/switchMode.ts index f7d6f7ffcc769..7753eab73f691 100644 --- a/src/commands/switchMode.ts +++ b/src/commands/switchMode.ts @@ -1,7 +1,7 @@ 'use strict'; import { ConfigurationTarget } from 'vscode'; import { configuration } from '../configuration'; -import { Container } from '../container'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { ModePicker } from '../quickpicks'; import { log } from '../system'; @@ -9,7 +9,7 @@ import { command, Command, Commands } from './common'; @command() export class SwitchModeCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.SwitchMode); } @@ -24,17 +24,17 @@ export class SwitchModeCommand extends Command { cc.exitDetails = ` \u2014 mode=${pick.key ?? ''}`; } - const active = Container.instance.config.mode.active; + const active = this.container.config.mode.active; if (active === pick.key) return; // Check if we have applied any annotations and clear them if we won't be applying them again if (active != null && active.length !== 0) { - const activeAnnotations = Container.instance.config.modes?.[active].annotations; + const activeAnnotations = this.container.config.modes?.[active].annotations; if (activeAnnotations != null) { const newAnnotations = - pick.key != null ? Container.instance.config.modes?.[pick.key].annotations : undefined; + pick.key != null ? this.container.config.modes?.[pick.key].annotations : undefined; if (activeAnnotations !== newAnnotations) { - await Container.instance.fileAnnotations.clearAll(); + await this.container.fileAnnotations.clearAll(); } } } @@ -45,37 +45,34 @@ export class SwitchModeCommand extends Command { @command() export class ToggleReviewModeCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ToggleReviewMode); } @log({ args: false, singleLine: true, timed: false }) async execute() { - if ( - Container.instance.config.modes == null || - !Object.keys(Container.instance.config.modes).includes('review') - ) { + if (this.container.config.modes == null || !Object.keys(this.container.config.modes).includes('review')) { return; } - const mode = Container.instance.config.mode.active === 'review' ? undefined : 'review'; + const mode = this.container.config.mode.active === 'review' ? undefined : 'review'; await configuration.update('mode.active', mode, ConfigurationTarget.Global); } } @command() export class ToggleZenModeCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ToggleZenMode); } @log({ args: false, singleLine: true, timed: false }) async execute() { - if (Container.instance.config.modes == null || !Object.keys(Container.instance.config.modes).includes('zen')) { + if (this.container.config.modes == null || !Object.keys(this.container.config.modes).includes('zen')) { return; } - const mode = Container.instance.config.mode.active === 'zen' ? undefined : 'zen'; + const mode = this.container.config.mode.active === 'zen' ? undefined : 'zen'; await configuration.update('mode.active', mode, ConfigurationTarget.Global); } } diff --git a/src/commands/toggleCodeLens.ts b/src/commands/toggleCodeLens.ts index a8f53b443c10e..ea2b79c50bf72 100644 --- a/src/commands/toggleCodeLens.ts +++ b/src/commands/toggleCodeLens.ts @@ -1,14 +1,14 @@ 'use strict'; -import { Container } from '../container'; +import type { Container } from '../container'; import { command, Command, Commands } from './common'; @command() export class ToggleCodeLensCommand extends Command { - constructor() { + constructor(private readonly container: Container) { super(Commands.ToggleCodeLens); } execute() { - return Container.instance.codeLens.toggleCodeLens(); + return this.container.codeLens.toggleCodeLens(); } } diff --git a/src/commands/toggleFileAnnotations.ts b/src/commands/toggleFileAnnotations.ts index a5394d31ede2c..2c8cccd7ecc9d 100644 --- a/src/commands/toggleFileAnnotations.ts +++ b/src/commands/toggleFileAnnotations.ts @@ -5,14 +5,14 @@ import { ChangesAnnotationContext } from '../annotations/gutterChangesAnnotation import { UriComparer } from '../comparers'; import { FileAnnotationType } from '../configuration'; import { isTextEditor } from '../constants'; -import { Container } from '../container'; +import type { Container } from '../container'; import { Logger } from '../logger'; import { Messages } from '../messages'; import { ActiveEditorCommand, command, Commands, EditorCommand } from './common'; @command() export class ClearFileAnnotationsCommand extends EditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.ClearFileAnnotations, Commands.ComputingFileAnnotations]); } @@ -28,7 +28,7 @@ export class ClearFileAnnotationsCommand extends EditorCommand { } try { - void (await Container.instance.fileAnnotations.clear(editor)); + void (await this.container.fileAnnotations.clear(editor)); } catch (ex) { Logger.error(ex, 'ClearFileAnnotationsCommand'); void Messages.showGenericErrorMessage('Unable to clear file annotations'); @@ -61,12 +61,12 @@ export type ToggleFileAnnotationCommandArgs = @command() export class ToggleFileBlameCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([Commands.ToggleFileBlame, Commands.ToggleFileBlameInDiffLeft, Commands.ToggleFileBlameInDiffRight]); } execute(editor: TextEditor, uri?: Uri, args?: ToggleFileBlameAnnotationCommandArgs): Promise { - return toggleFileAnnotations(editor, uri, { + return toggleFileAnnotations(this.container, editor, uri, { ...args, type: FileAnnotationType.Blame, }); @@ -75,12 +75,12 @@ export class ToggleFileBlameCommand extends ActiveEditorCommand { @command() export class ToggleFileChangesCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super(Commands.ToggleFileChanges); } execute(editor: TextEditor, uri?: Uri, args?: ToggleFileChangesAnnotationCommandArgs): Promise { - return toggleFileAnnotations(editor, uri, { + return toggleFileAnnotations(this.container, editor, uri, { ...args, type: FileAnnotationType.Changes, }); @@ -89,7 +89,7 @@ export class ToggleFileChangesCommand extends ActiveEditorCommand { @command() export class ToggleFileHeatmapCommand extends ActiveEditorCommand { - constructor() { + constructor(private readonly container: Container) { super([ Commands.ToggleFileHeatmap, Commands.ToggleFileHeatmapInDiffLeft, @@ -98,7 +98,7 @@ export class ToggleFileHeatmapCommand extends ActiveEditorCommand { } execute(editor: TextEditor, uri?: Uri, args?: ToggleFileHeatmapAnnotationCommandArgs): Promise { - return toggleFileAnnotations(editor, uri, { + return toggleFileAnnotations(this.container, editor, uri, { ...args, type: FileAnnotationType.Heatmap, }); @@ -106,6 +106,7 @@ export class ToggleFileHeatmapCommand extends ActiveEditorCommand { } async function toggleFileAnnotations( + container: Container, editor: TextEditor, uri: Uri | undefined, args: TArgs, @@ -123,7 +124,7 @@ async function toggleFileAnnotations { try { - void (await Container.instance.lineAnnotations.toggle(editor)); + void (await this.container.lineAnnotations.toggle(editor)); } catch (ex) { Logger.error(ex, 'ToggleLineBlameCommand'); void window.showErrorMessage( diff --git a/src/extension.ts b/src/extension.ts index 49e1aef053d17..d866ce5b8ab55 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -98,7 +98,7 @@ export function activate(context: ExtensionContext): Promise { - registerCommands(context); + context.subscriptions.push(...registerCommands(container)); registerBuiltInActionRunners(container); registerPartnerActionRunners(context); diff --git a/src/quickpicks/gitQuickPickItems.ts b/src/quickpicks/gitQuickPickItems.ts index 9ef03a42f0d54..a626077fdc717 100644 --- a/src/quickpicks/gitQuickPickItems.ts +++ b/src/quickpicks/gitQuickPickItems.ts @@ -2,6 +2,7 @@ import { QuickInputButton, QuickPickItem } from 'vscode'; import { Commands, GitCommandsCommand, GitCommandsCommandArgs } from '../commands'; import { GlyphChars } from '../constants'; +import { Container } from '../container'; import { emojify } from '../emojis'; import { GitBranch, @@ -25,7 +26,7 @@ export class GitCommandQuickPickItem extends CommandQuickPickItem<[GitCommandsCo } executeSteps(pickedVia: 'menu' | 'command') { - return GitCommandsCommand.getSteps(this.args![0], pickedVia); + return GitCommandsCommand.getSteps(Container.instance, this.args![0], pickedVia); } }