refactor: clean up code
This commit is contained in:
parent
cdc9600e68
commit
db88b285fe
2 changed files with 1 additions and 51 deletions
|
|
@ -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<string> {
|
||||
async getDiff(includeUnstaged: boolean): Promise<string[]> {
|
||||
return await this.ideUtils.getDiff(includeUnstaged);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Repository[]> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue