From db88b285fed0e8c0d25bb417be1dc635c0d5d3e1 Mon Sep 17 00:00:00 2001 From: tomasz-io Date: Tue, 26 Nov 2024 14:26:59 -0800 Subject: [PATCH] refactor: clean up code --- extensions/vscode/src/VsCodeIde.ts | 3 +- extensions/vscode/src/util/diffUtils.ts | 49 ------------------------- 2 files changed, 1 insertion(+), 51 deletions(-) delete mode 100644 extensions/vscode/src/util/diffUtils.ts diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 7d9536f5a..cc0d8c343 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -36,7 +36,6 @@ import type { RangeInFile, Thread, } from "core"; -import { text } from "stream/consumers"; class VsCodeIde implements IDE { ideUtils: VsCodeIdeUtils; @@ -312,7 +311,7 @@ class VsCodeIde implements IDE { return Promise.resolve(vscode.env.machineId); } - async getDiff(includeUnstaged: boolean): Promise { + async getDiff(includeUnstaged: boolean): Promise { return await this.ideUtils.getDiff(includeUnstaged); } diff --git a/extensions/vscode/src/util/diffUtils.ts b/extensions/vscode/src/util/diffUtils.ts deleted file mode 100644 index b84a5cccb..000000000 --- a/extensions/vscode/src/util/diffUtils.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Repository } from "../otherExtensions/git"; -import { VsCodeIdeUtils } from "./ideUtils"; -import * as vscode from "vscode"; - -export class DiffUtils extends VsCodeIdeUtils { - private async getRepos(): Promise { - const workspaceDirs = this.getWorkspaceDirectories(); - - const repos: (Repository | undefined)[] = await Promise.all( - workspaceDirs.map((dir) => { - return this.getRepo(vscode.Uri.file(dir)); - }), - ); - - return repos.filter((repo) => !!repo); - } - - private splitDiff(diffString: string): string[] { - const fileDiffHeaderRegex = /(?=diff --git a\/.* b\/.*)/; - - const diffs = diffString.split(fileDiffHeaderRegex); - - if (diffs[0].trim() === "") { - diffs.shift(); - } - - return diffs; - } - - private async getRepoDiff(repo: Repository) { - const staged = await repo.diff(true); - const unstaged = await repo.diff(false); - - return [staged, unstaged].map((diff) => this.splitDiff(diff)).flat(); - } - - public async getLatestChanges() { - const repos = await this.getRepos(); - - const latestChanges: string[] = []; - - for (const repo of repos) { - const changes = await this.getRepoDiff(repo); - latestChanges.push(...changes); - } - - return latestChanges; - } -}