Merge pull request #2945 from continuedev/pe/bugfix-vsc-diff-line-count

bugfix: incorrect # diff lines in VSC
This commit is contained in:
Dallin Romney 2024-11-15 16:09:49 -08:00 • committed by GitHub
commit 435a0b2139
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 21 deletions

View file

@ -25,9 +25,12 @@ export class VerticalDiffHandler implements vscode.Disposable {
private currentLineIndex: number;
private cancelled = false;
private newLinesAdded = 0;
private get diffBlocks() {
return this.editorToVerticalDiffCodeLens.get(this.filepath) || [];
private deletionBuffer: string[] = [];
private redDecorationManager: DecorationTypeRangeManager;
private get filepath() {
return this.editor.document.uri.fsPath;
}
public insertedInCurrentBlock = 0;
public get range(): vscode.Range {
const startLine = Math.min(this.startLine, this.endLine);
const endLine = Math.max(this.startLine, this.endLine);
@ -77,14 +80,6 @@ export class VerticalDiffHandler implements vscode.Disposable {
this.disposables.push(disposable);
}
private get filepath() {
return this.editor.document.uri.fsPath;
}
private deletionBuffer: string[] = [];
private redDecorationManager: DecorationTypeRangeManager;
insertedInCurrentBlock = 0;
private async insertDeletionBuffer() {
// Don't remove trailing whitespace line
const totalDeletedContent = this.deletionBuffer.join("\n");
@ -98,13 +93,15 @@ export class VerticalDiffHandler implements vscode.Disposable {
}
if (this.deletionBuffer.length || this.insertedInCurrentBlock > 0) {
this.diffBlocks.push({
const blocks = this.editorToVerticalDiffCodeLens.get(this.filepath) || [];
blocks.push({
start: this.currentLineIndex - this.insertedInCurrentBlock,
numRed: this.deletionBuffer.length,
numGreen: this.insertedInCurrentBlock,
});
this.editorToVerticalDiffCodeLens.set(this.filepath, this.diffBlocks);
this.editorToVerticalDiffCodeLens.set(this.filepath, blocks);
}
if (this.deletionBuffer.length === 0) {
@ -271,7 +268,10 @@ export class VerticalDiffHandler implements vscode.Disposable {
},
);
this.options.onStatusUpdate("closed", this.diffBlocks.length);
this.options.onStatusUpdate(
"closed",
this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0,
);
this.cancelled = true;
this.refreshCodeLens();
@ -359,7 +359,10 @@ export class VerticalDiffHandler implements vscode.Disposable {
this.refreshCodeLens();
this.options.onStatusUpdate("done", this.diffBlocks.length);
this.options.onStatusUpdate(
"done",
this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0,
);
// Reject on user typing
// const listener = vscode.workspace.onDidChangeTextDocument((e) => {
@ -409,8 +412,11 @@ export class VerticalDiffHandler implements vscode.Disposable {
// Shift the codelens objects
this.shiftCodeLensObjects(startLine, offset);
const status = this.diffBlocks.length === 0 ? "closed" : undefined;
this.options.onStatusUpdate(status, this.diffBlocks.length);
const numDiffs =
this.editorToVerticalDiffCodeLens.get(this.filepath)?.length ?? 0;
const status = numDiffs === 0 ? "closed" : undefined;
this.options.onStatusUpdate(status, numDiffs);
}
private shiftCodeLensObjects(startLine: number, offset: number) {
@ -450,6 +456,7 @@ export class VerticalDiffHandler implements vscode.Disposable {
}
public hasDiffForCurrentFile(): boolean {
return this.diffBlocks.length > 0;
const diffBlocks = this.editorToVerticalDiffCodeLens.get(this.filepath);
return diffBlocks !== undefined && diffBlocks.length > 0;
}
}

View file

@ -2,7 +2,7 @@ import { ChevronDownIcon } from "@heroicons/react/24/outline";
import { debounce } from "lodash";
import { useContext, useEffect, useRef, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import styled, { keyframes } from "styled-components";
import styled, { css, keyframes } from "styled-components";
import { v4 as uuidv4 } from "uuid";
import { defaultBorderRadius, lightGray, vscEditorBackground } from "../..";
import { IdeMessengerContext } from "../../../context/IdeMessenger";
@ -26,13 +26,18 @@ const fadeInAnimation = keyframes`
}
`;
const TopDiv = styled.div`
const TopDiv = styled.div<{ active?: boolean }>`
outline: 1px solid rgba(153, 153, 152);
outline-offset: -0.5px;
border-radius: ${defaultBorderRadius};
margin-bottom: 8px !important;
background-color: ${vscEditorBackground};
animation: ${fadeInAnimation} 300ms ease-out forwards;
${(props) =>
props.active
? "animation: none;"
: css`
animation: ${fadeInAnimation} 300ms ease-out forwards;
`}
`;
const ToolbarDiv = styled.div<{ isExpanded: boolean }>`
@ -67,6 +72,7 @@ export default function StepContainerPreToolbar(
const isMultifileEdit = useSelector(
(state: RootState) => state.state.isInMultifileEdit,
);
const active = useSelector((state: RootState) => state.state.active);
const [isExpanded, setIsExpanded] = useState(isMultifileEdit ? false : true);
const [codeBlockContent, setCodeBlockContent] = useState("");
const isChatActive = useSelector((state: RootState) => state.state.active);
@ -168,7 +174,7 @@ export default function StepContainerPreToolbar(
}
return (
<TopDiv>
<TopDiv active={active}>
<ToolbarDiv isExpanded={isExpanded} className="find-widget-skip">
<div className="flex items-center">
<ChevronDownIcon