Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(blame), add a new prop previousLineContent for the IDE #9272

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions scopes/component/component-log/component-log.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type FileLog = {
export type BlameLineInfo = {
lineNumber: number;
lineContent: string;
previousLineContent?: string;
username: string;
email?: string;
date: string;
Expand Down Expand Up @@ -204,12 +205,6 @@ export class ComponentLogMain {
const blameArray: Partial<BlameLineInfo>[] = currentContentLines.map((lineContent, index) => ({
lineNumber: index + 1,
lineContent,
author: undefined,
email: undefined,
date: undefined,
message: undefined,
hash: undefined,
tag: undefined,
}));
const populateBlameArray = (lineNumber: number, log: FileLog) => {
blameArray[lineNumber].username = log.username;
Expand All @@ -223,7 +218,7 @@ export class ComponentLogMain {
// Keep track of unassigned lines
const unblamedLineIndices = new Set(blameArray.map((_, index) => index));

await pMapSeries(logs.reverse(), async (logItem) => {
await pMapSeries(logs, async (logItem) => {
if (unblamedLineIndices.size === 0) return; // All lines have been assigned

const currentHash = logItem.fileHash;
Expand All @@ -237,6 +232,9 @@ export class ComponentLogMain {

const diff = diffLines(parentContentStr, currentContentStr);

const removedLines: Record<number, string> = {};
const addedLines: number[] = [];

let currentLineNum = 0;

diff.forEach((part) => {
Expand All @@ -249,18 +247,27 @@ export class ComponentLogMain {
lines.forEach(() => {
if (unblamedLineIndices.has(currentLineNum)) {
populateBlameArray(currentLineNum, logItem);
addedLines.push(currentLineNum);
unblamedLineIndices.delete(currentLineNum);
}
currentLineNum++;
});
} else if (part.removed) {
lines.forEach((line, index) => {
removedLines[currentLineNum + index] = line;
});
// Lines removed from parent version; do not advance currentLineNum
// Since these lines are not in the current version, we ignore them
} else {
// Unchanged lines
currentLineNum += lines.length;
}
});
Object.keys(removedLines).forEach((lineNum) => {
if (addedLines.includes(parseInt(lineNum))) {
blameArray[parseInt(lineNum)].previousLineContent = removedLines[parseInt(lineNum)];
}
});
});

// Assign the oldest log info to any remaining unblamed lines
Expand Down