Merge branch 'dev' into pe/indexing-progress-bar
This commit is contained in:
commit
100b6a0ce5
25 changed files with 456 additions and 155 deletions
4
.changes/unreleased/Added-20240927-142940.yaml
Normal file
4
.changes/unreleased/Added-20240927-142940.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
project: extensions/vscode
|
||||
kind: Added
|
||||
body: Improved loading/accept/reject UI for apply
|
||||
time: 2024-09-27T14:29:40.283176-07:00
|
||||
4
.changes/unreleased/Added-20240927-143005.yaml
Normal file
4
.changes/unreleased/Added-20240927-143005.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
project: extensions/vscode
|
||||
kind: Added
|
||||
body: Polished chat sidebar, especially context dropdown
|
||||
time: 2024-09-27T14:30:05.576347-07:00
|
||||
4
.changes/unreleased/Fixed-20240927-142924.yaml
Normal file
4
.changes/unreleased/Fixed-20240927-142924.yaml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
project: extensions/vscode
|
||||
kind: Fixed
|
||||
body: Fixed a number of apply bugs
|
||||
time: 2024-09-27T14:29:24.69568-07:00
|
||||
|
|
@ -154,4 +154,8 @@ describe("deterministicApplyLazyEdit(", () => {
|
|||
test("no lazy blocks in single top level class", async () => {
|
||||
await expectDiff("no-lazy-single-class.js");
|
||||
});
|
||||
|
||||
test("should acknowledge jsx_expression lazy comments", async () => {
|
||||
await expectDiff("migration-page.tsx");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -135,10 +135,10 @@ export async function deterministicApplyLazyEdit(
|
|||
}
|
||||
}
|
||||
|
||||
const acc: AstReplacements = [];
|
||||
findLazyBlockReplacements(oldTree.rootNode, newTree.rootNode, acc);
|
||||
const replacements: AstReplacements = [];
|
||||
findLazyBlockReplacements(oldTree.rootNode, newTree.rootNode, replacements);
|
||||
|
||||
const newFullFile = reconstructNewFile(oldFile, newLazyFile, acc);
|
||||
const newFullFile = reconstructNewFile(oldFile, newLazyFile, replacements);
|
||||
const diff = myersDiff(oldFile, newFullFile);
|
||||
|
||||
// If the diff is too messy and seems likely borked, we fall back to LLM strategy
|
||||
|
|
@ -155,9 +155,27 @@ export function isLazyLine(text: string): boolean {
|
|||
}
|
||||
|
||||
function isLazyBlock(node: Parser.SyntaxNode): boolean {
|
||||
// Special case for "{/* ... existing code ... */}"
|
||||
if (
|
||||
node.type === "jsx_expression" &&
|
||||
node.namedChildCount === 1 &&
|
||||
isLazyBlock(node.namedChildren[0])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return node.type.includes("comment") && isLazyLine(node.text);
|
||||
}
|
||||
|
||||
function stringsWithinLevDistThreshold(
|
||||
a: string,
|
||||
b: string,
|
||||
threshold: number,
|
||||
) {
|
||||
const dist = distance(a, b);
|
||||
return dist / Math.min(a.length, b.length) <= threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether two nodes are similar
|
||||
* @param a
|
||||
|
|
@ -184,11 +202,23 @@ function nodesAreSimilar(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Matching jsx_elements needs to be different because they have such a minimal first line
|
||||
if (
|
||||
a.type === "jsx_element" &&
|
||||
b.type === "jsx_element" &&
|
||||
// Check that the tag names match
|
||||
a.namedChildren[0]?.children[1]?.text ===
|
||||
b.namedChildren[0]?.children[1]?.text
|
||||
) {
|
||||
if (stringsWithinLevDistThreshold(a.text, b.text, 0.3)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const lineOneA = a.text.split("\n")[0];
|
||||
const lineOneB = b.text.split("\n")[0];
|
||||
|
||||
const levDist = distance(lineOneA, lineOneB);
|
||||
return levDist / Math.min(lineOneA.length, lineOneB.length) <= 0.2;
|
||||
return stringsWithinLevDistThreshold(lineOneA, lineOneB, 0.2);
|
||||
}
|
||||
|
||||
function nodesAreExact(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean {
|
||||
|
|
@ -204,7 +234,7 @@ function nodesAreExact(a: Parser.SyntaxNode, b: Parser.SyntaxNode): boolean {
|
|||
function findLazyBlockReplacements(
|
||||
oldNode: Parser.SyntaxNode,
|
||||
newNode: Parser.SyntaxNode,
|
||||
acc: AstReplacements,
|
||||
replacements: AstReplacements,
|
||||
): void {
|
||||
// Base case
|
||||
if (nodesAreExact(oldNode, newNode)) {
|
||||
|
|
@ -254,7 +284,7 @@ function findLazyBlockReplacements(
|
|||
}
|
||||
|
||||
// then recurse at the match
|
||||
findLazyBlockReplacements(L, rightChildren[0], acc);
|
||||
findLazyBlockReplacements(L, rightChildren[0], replacements);
|
||||
|
||||
// then consume L and R
|
||||
leftChildren.shift();
|
||||
|
|
@ -263,7 +293,7 @@ function findLazyBlockReplacements(
|
|||
// Exit "lazy mode"
|
||||
if (isLazy) {
|
||||
// Record the replacement lines
|
||||
acc.push({
|
||||
replacements.push({
|
||||
nodeToReplace: currentLazyBlockNode!,
|
||||
replacementNodes: [...currentLazyBlockReplacementNodes],
|
||||
});
|
||||
|
|
@ -275,7 +305,7 @@ function findLazyBlockReplacements(
|
|||
}
|
||||
|
||||
if (isLazy) {
|
||||
acc.push({
|
||||
replacements.push({
|
||||
nodeToReplace: currentLazyBlockNode!,
|
||||
replacementNodes: [...currentLazyBlockReplacementNodes, ...leftChildren],
|
||||
});
|
||||
|
|
@ -284,7 +314,7 @@ function findLazyBlockReplacements(
|
|||
// Cut out any extraneous lazy blocks
|
||||
for (const R of rightChildren) {
|
||||
if (isLazyBlock(R)) {
|
||||
acc.push({
|
||||
replacements.push({
|
||||
nodeToReplace: R,
|
||||
replacementNodes: [],
|
||||
});
|
||||
|
|
|
|||
166
core/edit/lazy/test-examples/migration-page.tsx.diff
Normal file
166
core/edit/lazy/test-examples/migration-page.tsx.diff
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
import { useNavigate } from "react-router-dom";
|
||||
import ContinueButton from "../components/mainInput/ContinueButton";
|
||||
|
||||
function MigrationPage() {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<div className="p-8">
|
||||
<h1>
|
||||
Migration to <code>config.json</code>
|
||||
</h1>
|
||||
|
||||
<p>
|
||||
Continue now uses a .json config file. We hope that this takes the
|
||||
guesswork out of setting up.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Your configuration should have been automatically migrated, but we
|
||||
recommend double-checking that everything looks correct.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
For a summary of what changed and examples of <code>config.json</code>,
|
||||
please see the{" "}
|
||||
<a
|
||||
href="https://docs.continue.dev/walkthroughs/config-file-migration"
|
||||
target="_blank"
|
||||
>
|
||||
migration walkthrough
|
||||
</a>
|
||||
, and if you have any questions please reach out to us on{" "}
|
||||
<a href="https://discord.gg/Y83xkG3uUW" target="_blank">
|
||||
Discord
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
|
||||
<i>
|
||||
Note: If you are running the server manually and have not updated the
|
||||
server, this message does not apply.
|
||||
</i>
|
||||
|
||||
<ContinueButton
|
||||
showStop={false}
|
||||
onClick={() => {
|
||||
navigate("/");
|
||||
}}
|
||||
disabled={false}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MigrationPage;
|
||||
|
||||
---
|
||||
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import ContinueButton from "../components/mainInput/ContinueButton";
|
||||
|
||||
function MigrationPage() {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<div className="p-8">
|
||||
<h1>
|
||||
Migration to <code>config.json</code>
|
||||
</h1>
|
||||
|
||||
<p className="text-sm">
|
||||
Continue now uses a .json config file. We hope that this takes the
|
||||
guesswork out of setting up.
|
||||
</p>
|
||||
|
||||
<p className="text-sm">
|
||||
Your configuration should have been automatically migrated, but we
|
||||
recommend double-checking that everything looks correct.
|
||||
</p>
|
||||
|
||||
<p className="text-sm">
|
||||
For a summary of what changed and examples of <code>config.json</code>,
|
||||
please see the{" "}
|
||||
<a
|
||||
href="https://docs.continue.dev/walkthroughs/config-file-migration"
|
||||
target="_blank"
|
||||
>
|
||||
migration walkthrough
|
||||
</a>
|
||||
, and if you have any questions please reach out to us on{" "}
|
||||
<a href="https://discord.gg/Y83xkG3uUW" target="_blank">
|
||||
Discord
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
|
||||
<i className="text-sm">
|
||||
Note: If you are running the server manually and have not updated the
|
||||
server, this message does not apply.
|
||||
</i>
|
||||
|
||||
{/* ... existing code ... */}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MigrationPage;
|
||||
|
||||
---
|
||||
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import ContinueButton from "../components/mainInput/ContinueButton";
|
||||
|
||||
function MigrationPage() {
|
||||
const navigate = useNavigate();
|
||||
return (
|
||||
<div className="p-8">
|
||||
<h1>
|
||||
Migration to <code>config.json</code>
|
||||
</h1>
|
||||
|
||||
- <p>
|
||||
+ <p className="text-sm">
|
||||
Continue now uses a .json config file. We hope that this takes the
|
||||
guesswork out of setting up.
|
||||
</p>
|
||||
|
||||
- <p>
|
||||
+ <p className="text-sm">
|
||||
Your configuration should have been automatically migrated, but we
|
||||
recommend double-checking that everything looks correct.
|
||||
</p>
|
||||
|
||||
- <p>
|
||||
+ <p className="text-sm">
|
||||
For a summary of what changed and examples of <code>config.json</code>,
|
||||
please see the{" "}
|
||||
<a
|
||||
href="https://docs.continue.dev/walkthroughs/config-file-migration"
|
||||
target="_blank"
|
||||
>
|
||||
migration walkthrough
|
||||
</a>
|
||||
, and if you have any questions please reach out to us on{" "}
|
||||
<a href="https://discord.gg/Y83xkG3uUW" target="_blank">
|
||||
Discord
|
||||
</a>
|
||||
.
|
||||
</p>
|
||||
|
||||
- <i>
|
||||
+ <i className="text-sm">
|
||||
Note: If you are running the server manually and have not updated the
|
||||
server, this message does not apply.
|
||||
</i>
|
||||
|
||||
<ContinueButton
|
||||
showStop={false}
|
||||
onClick={() => {
|
||||
navigate("/");
|
||||
}}
|
||||
disabled={false}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MigrationPage;
|
||||
|
|
@ -5,9 +5,10 @@ const SYSTEM_MESSAGE = `When generating new code:
|
|||
1. Always produce a single code block.
|
||||
2. Never separate the code into multiple code blocks.
|
||||
3. Only include the code that is being added.
|
||||
4. Replace existing code with a "lazy" block like this: "// ... existing code ..."
|
||||
5. You must always provide 1-2 lines of context above and below a "lazy" block
|
||||
6. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block.
|
||||
4. Replace existing code with a "lazy" comment like this: "// ... existing code ..."
|
||||
5. The "lazy" comment must always be a valid comment in the current context (e.g. "<!-- ... existing code ... -->" for HTML, "// ... existing code ..." for JavaScript, "{/* ... existing code */}" for TSX, etc.)
|
||||
6. You must always provide 1-2 lines of context above and below a "lazy" comment
|
||||
7. If the user submits a code block that contains a filename in the language specifier, always include the filename in any code block you generate based on that file. The filename should be on the same line as the language specifier in your code block.
|
||||
|
||||
Example 1:
|
||||
Input:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
},
|
||||
];
|
||||
openUrl: [string, void];
|
||||
applyToCurrentFile: [{ text: string }, void];
|
||||
applyToCurrentFile: [{ text: string; streamId: string }, void];
|
||||
showTutorial: [undefined, void];
|
||||
showFile: [{ filepath: string }, void];
|
||||
openConfigJson: [undefined, void];
|
||||
|
|
@ -32,6 +32,11 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
rejectDiff: [{ filepath: string }, void];
|
||||
};
|
||||
|
||||
export interface ApplyState {
|
||||
streamId: string;
|
||||
status: "streaming" | "done" | "closed";
|
||||
}
|
||||
|
||||
export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
||||
setInactive: [undefined, void];
|
||||
setTTSActive: [boolean, void];
|
||||
|
|
@ -65,4 +70,5 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
incrementFtc: [undefined, void];
|
||||
openOnboardingCard: [undefined, void];
|
||||
applyCodeFromChat: [undefined, void];
|
||||
updateApplyState: [ApplyState, void];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ If there is information from the codebase, documentation, IDE, or other tools th
|
|||
|
||||
## Apply generated code to your file
|
||||
|
||||
When the LLM replies with code, you can hover over the top right of the code block and select “Apply to current file” to update the existing code in the editor to this new version.
|
||||
When the LLM replies with edits to a file, you can click the “Apply” button. This will update the existing code in the editor to reflect the suggested changes.
|
||||
|
||||
## Start a fresh session for a new task
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pluginGroup = com.github.continuedev.continueintellijextension
|
|||
pluginName = continue-intellij-extension
|
||||
pluginRepositoryUrl = https://github.com/continuedev/continue
|
||||
# SemVer format -> https://semver.org
|
||||
pluginVersion = 0.0.69
|
||||
pluginVersion = 0.0.70
|
||||
|
||||
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
|
||||
pluginSinceBuild = 223
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ and is generated by [Changie](https://github.com/miniscruff/changie).
|
|||
|
||||
|
||||
Pre-release Changes
|
||||
### Added
|
||||
* Improved loading/accept/reject UI for apply
|
||||
* Polished chat sidebar, especially context dropdown
|
||||
### Changed
|
||||
* Updated tutorial file
|
||||
### Fixed
|
||||
* Continue for teams auth bug fix
|
||||
* Fixed a number of apply bugs
|
||||
|
||||
## 0.9.210 - 2024-09-15
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "0.9.212",
|
||||
"version": "0.9.213",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
|
|
@ -223,6 +223,7 @@ const commandsMap: (
|
|||
await verticalDiffManager.streamEdit(
|
||||
config.experimental?.contextMenuPrompts?.[promptName] ?? fallbackPrompt,
|
||||
modelTitle,
|
||||
undefined,
|
||||
onlyOneInsertion,
|
||||
undefined,
|
||||
range,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import type { DiffLine } from "core";
|
||||
import { ApplyState } from "core/protocol/ideWebview";
|
||||
import * as vscode from "vscode";
|
||||
import {
|
||||
DecorationTypeRangeManager,
|
||||
|
|
@ -12,6 +13,7 @@ import type { VerticalDiffCodeLens } from "./manager";
|
|||
export interface VerticalDiffHandlerOptions {
|
||||
input?: string;
|
||||
instant?: boolean;
|
||||
onStatusUpdate: (status: ApplyState["status"]) => void;
|
||||
}
|
||||
|
||||
export class VerticalDiffHandler implements vscode.Disposable {
|
||||
|
|
@ -268,6 +270,8 @@ export class VerticalDiffHandler implements vscode.Disposable {
|
|||
},
|
||||
);
|
||||
|
||||
this.options.onStatusUpdate("closed");
|
||||
|
||||
this.cancelled = true;
|
||||
this.refreshCodeLens();
|
||||
this.dispose();
|
||||
|
|
@ -352,6 +356,8 @@ export class VerticalDiffHandler implements vscode.Disposable {
|
|||
|
||||
this.refreshCodeLens();
|
||||
|
||||
this.options.onStatusUpdate("done");
|
||||
|
||||
// Reject on user typing
|
||||
// const listener = vscode.workspace.onDidChangeTextDocument((e) => {
|
||||
// if (e.document.uri.fsPath === this.filepath) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { getMarkdownLanguageTagForFile } from "core/util";
|
|||
import { DiffLine } from "core";
|
||||
import { streamDiffLines } from "core/edit/streamDiffLines";
|
||||
import * as vscode from "vscode";
|
||||
import { VsCodeWebviewProtocol } from "../../webviewProtocol";
|
||||
import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler";
|
||||
|
||||
export interface VerticalDiffCodeLens {
|
||||
|
|
@ -22,7 +23,10 @@ export class VerticalDiffManager {
|
|||
|
||||
private userChangeListener: vscode.Disposable | undefined;
|
||||
|
||||
constructor(private readonly configHandler: ConfigHandler) {
|
||||
constructor(
|
||||
private readonly configHandler: ConfigHandler,
|
||||
private readonly webviewProtocol: VsCodeWebviewProtocol,
|
||||
) {
|
||||
this.userChangeListener = undefined;
|
||||
}
|
||||
|
||||
|
|
@ -176,6 +180,7 @@ export class VerticalDiffManager {
|
|||
async streamDiffLines(
|
||||
diffStream: AsyncGenerator<DiffLine>,
|
||||
instant: boolean,
|
||||
streamId: string,
|
||||
) {
|
||||
vscode.commands.executeCommand("setContext", "continue.diffVisible", true);
|
||||
|
||||
|
|
@ -205,6 +210,11 @@ export class VerticalDiffManager {
|
|||
endLine,
|
||||
{
|
||||
instant,
|
||||
onStatusUpdate: (status) =>
|
||||
this.webviewProtocol.request("updateApplyState", {
|
||||
streamId,
|
||||
status,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
@ -271,6 +281,7 @@ export class VerticalDiffManager {
|
|||
async streamEdit(
|
||||
input: string,
|
||||
modelTitle: string | undefined,
|
||||
streamId?: string,
|
||||
onlyOneInsertion?: boolean,
|
||||
quickEdit?: string,
|
||||
range?: vscode.Range,
|
||||
|
|
@ -339,7 +350,15 @@ export class VerticalDiffManager {
|
|||
filepath,
|
||||
startLine,
|
||||
endLine,
|
||||
{ input },
|
||||
{
|
||||
input,
|
||||
onStatusUpdate: (status) =>
|
||||
streamId &&
|
||||
this.webviewProtocol.request("updateApplyState", {
|
||||
streamId,
|
||||
status,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
if (!diffHandler) {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,10 @@ export class VsCodeExtension {
|
|||
resolveConfigHandler?.(this.configHandler);
|
||||
|
||||
this.configHandler.reloadConfig();
|
||||
this.verticalDiffManager = new VerticalDiffManager(this.configHandler);
|
||||
this.verticalDiffManager = new VerticalDiffManager(
|
||||
this.configHandler,
|
||||
this.sidebar.webviewProtocol,
|
||||
);
|
||||
resolveVerticalDiffManager?.(this.verticalDiffManager);
|
||||
this.tabAutocompleteModel = new TabAutocompleteModel(this.configHandler);
|
||||
|
||||
|
|
|
|||
|
|
@ -191,10 +191,30 @@ export class VsCodeMessenger {
|
|||
);
|
||||
const verticalDiffManager = await this.verticalDiffManagerPromise;
|
||||
if (instant) {
|
||||
verticalDiffManager.streamDiffLines(diffLines, instant);
|
||||
verticalDiffManager.streamDiffLines(
|
||||
diffLines,
|
||||
instant,
|
||||
msg.data.streamId,
|
||||
);
|
||||
} else {
|
||||
const prompt = `The following code was suggested as an edit:\n\`\`\`\n${msg.data.text}\n\`\`\`\nPlease apply it to the previous code.`;
|
||||
verticalDiffManager.streamEdit(prompt, llm.title);
|
||||
const fullEditorRange = new vscode.Range(
|
||||
0,
|
||||
0,
|
||||
editor.document.lineCount - 1,
|
||||
editor.document.lineAt(editor.document.lineCount - 1).text.length,
|
||||
);
|
||||
const rangeToApplyTo = editor.selection.isEmpty
|
||||
? fullEditorRange
|
||||
: editor.selection;
|
||||
verticalDiffManager.streamEdit(
|
||||
prompt,
|
||||
llm.title,
|
||||
msg.data.streamId,
|
||||
undefined,
|
||||
undefined,
|
||||
rangeToApplyTo,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as vscode from "vscode";
|
||||
import { VerticalDiffCodeLens } from "../../../diff/vertical/manager";
|
||||
import { getAltOrOption, getMetaKeyLabel } from "../../../util/util";
|
||||
import { getMetaKeyLabel } from "../../../util/util";
|
||||
|
||||
export class VerticalDiffCodeLensProvider implements vscode.CodeLensProvider {
|
||||
private _eventEmitter: vscode.EventEmitter<void> =
|
||||
|
|
@ -33,9 +33,6 @@ export class VerticalDiffCodeLensProvider implements vscode.CodeLensProvider {
|
|||
const codeLenses: vscode.CodeLens[] = [];
|
||||
|
||||
for (let i = 0; i < blocks.length; i++) {
|
||||
const isFirstBlockInMultiBlockDocument =
|
||||
codeLenses.length === 0 && blocks.length > 1;
|
||||
|
||||
const block = blocks[i];
|
||||
const start = new vscode.Position(block.start, 0);
|
||||
const range = new vscode.Range(
|
||||
|
|
@ -43,43 +40,20 @@ export class VerticalDiffCodeLensProvider implements vscode.CodeLensProvider {
|
|||
start.translate(block.numGreen + block.numRed),
|
||||
);
|
||||
|
||||
if (isFirstBlockInMultiBlockDocument) {
|
||||
codeLenses.push(
|
||||
new vscode.CodeLens(range, {
|
||||
title: `Accept All (${getMetaKeyLabel()}⇧↩)`,
|
||||
command: "continue.acceptDiff",
|
||||
arguments: [filepath, i],
|
||||
}),
|
||||
new vscode.CodeLens(range, {
|
||||
title: `Reject All (${getMetaKeyLabel()}⇧⌫)`,
|
||||
command: "continue.rejectDiff",
|
||||
arguments: [filepath, i],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
codeLenses.push(
|
||||
new vscode.CodeLens(range, {
|
||||
title: `Accept${
|
||||
codeLenses.length === 2
|
||||
? ` (${getAltOrOption()}${getMetaKeyLabel()}Y)`
|
||||
: ""
|
||||
}`,
|
||||
title: `Accept`,
|
||||
command: "continue.acceptVerticalDiffBlock",
|
||||
arguments: [filepath, i],
|
||||
}),
|
||||
new vscode.CodeLens(range, {
|
||||
title: `Reject${
|
||||
codeLenses.length === 2
|
||||
? ` (${getAltOrOption()}${getMetaKeyLabel()}N)`
|
||||
: ""
|
||||
}`,
|
||||
title: `Reject`,
|
||||
command: "continue.rejectVerticalDiffBlock",
|
||||
arguments: [filepath, i],
|
||||
}),
|
||||
);
|
||||
|
||||
if (codeLenses.length === 4) {
|
||||
if (codeLenses.length === 2) {
|
||||
codeLenses.push(
|
||||
new vscode.CodeLens(range, {
|
||||
title: `${getMetaKeyLabel()}I to add instructions`,
|
||||
|
|
|
|||
|
|
@ -296,6 +296,7 @@ export class QuickEdit {
|
|||
prompt,
|
||||
modelTitle,
|
||||
undefined,
|
||||
undefined,
|
||||
this.previousInput,
|
||||
this.range,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -136,10 +136,30 @@ export class VsCodeIdeUtils {
|
|||
);
|
||||
}
|
||||
|
||||
openFile(filepath: string, range?: vscode.Range) {
|
||||
private async resolveAbsFilepathInWorkspace(
|
||||
filepath: string,
|
||||
): Promise<string> {
|
||||
// If the filepath is already absolute, return it as is
|
||||
if (this.path.isAbsolute(filepath)) {
|
||||
return filepath;
|
||||
}
|
||||
|
||||
// Try to resolve for each workspace directory
|
||||
const workspaceDirectories = this.getWorkspaceDirectories();
|
||||
for (const dir of workspaceDirectories) {
|
||||
const resolvedPath = this.path.resolve(dir, filepath);
|
||||
if (await this.fileExists(resolvedPath)) {
|
||||
return resolvedPath;
|
||||
}
|
||||
}
|
||||
|
||||
return filepath;
|
||||
}
|
||||
|
||||
async openFile(filepath: string, range?: vscode.Range) {
|
||||
// vscode has a builtin open/get open files
|
||||
return openEditorAndRevealRange(
|
||||
filepath,
|
||||
await this.resolveAbsFilepathInWorkspace(filepath),
|
||||
range,
|
||||
vscode.ViewColumn.One,
|
||||
false,
|
||||
|
|
|
|||
|
|
@ -2,19 +2,21 @@ import { useContext, useEffect } from "react";
|
|||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
CustomScrollbarDiv,
|
||||
defaultBorderRadius,
|
||||
vscForeground,
|
||||
vscInputBackground,
|
||||
} from ".";
|
||||
import { CustomScrollbarDiv, defaultBorderRadius, vscInputBackground } from ".";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
import { setShowDialog, updateApplyState } from "../redux/slices/uiStateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../util";
|
||||
import { getLocalStorage, setLocalStorage } from "../util/localStorage";
|
||||
import ButtonWithTooltip from "./ButtonWithTooltip";
|
||||
import TextDialog from "./dialogs";
|
||||
import ProgressBar from "./loaders/ProgressBar";
|
||||
import { useOnboardingCard } from "./OnboardingCard";
|
||||
import { isNewUserOnboarding } from "./OnboardingCard/utils";
|
||||
import PostHogPageView from "./PosthogPageView";
|
||||
import ProfileSwitcher from "./ProfileSwitcher";
|
||||
import { isNewUserOnboarding } from "./OnboardingCard/utils";
|
||||
import { useOnboardingCard } from "./OnboardingCard";
|
||||
import {
|
||||
|
|
@ -22,7 +24,9 @@ import {
|
|||
setBottomMessageCloseTimeout,
|
||||
setShowDialog,
|
||||
} from "../redux/slices/uiStateSlice";
|
||||
import Footer from "./Footer";
|
||||
import ButtonWithTooltip from "./ButtonWithTooltip";
|
||||
|
||||
const FOOTER_HEIGHT = "1.8em";
|
||||
|
||||
const LayoutTopDiv = styled(CustomScrollbarDiv)`
|
||||
height: 100%;
|
||||
|
|
@ -41,21 +45,20 @@ const LayoutTopDiv = styled(CustomScrollbarDiv)`
|
|||
}
|
||||
`;
|
||||
|
||||
const BottomMessageDiv = styled.div<{ displayOnBottom: boolean }>`
|
||||
position: fixed;
|
||||
bottom: ${(props) => (props.displayOnBottom ? "50px" : undefined)};
|
||||
top: ${(props) => (props.displayOnBottom ? undefined : "50px")};
|
||||
left: 0;
|
||||
right: 0;
|
||||
margin: 8px;
|
||||
margin-top: 0;
|
||||
background-color: ${vscInputBackground};
|
||||
color: ${vscForeground};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
padding: 12px;
|
||||
z-index: 100;
|
||||
box-shadow: 0px 0px 2px 0px ${vscForeground};
|
||||
max-height: 35vh;
|
||||
const Footer = styled.footer`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
justify-content: right;
|
||||
padding: 8px;
|
||||
align-items: center;
|
||||
width: calc(100% - 16px);
|
||||
height: ${FOOTER_HEIGHT};
|
||||
background-color: transparent;
|
||||
backdrop-filter: blur(12px);
|
||||
border-top: 1px solid rgba(136, 136, 136, 0.3);
|
||||
border-bottom: 1px solid rgba(136, 136, 136, 0.3);
|
||||
overflow: hidden;
|
||||
`;
|
||||
|
||||
const GridDiv = styled.div`
|
||||
|
|
@ -95,12 +98,7 @@ const Layout = () => {
|
|||
(state: RootState) => state.uiState.showDialog,
|
||||
);
|
||||
|
||||
const bottomMessage = useSelector(
|
||||
(state: RootState) => state.uiState.bottomMessage,
|
||||
);
|
||||
const displayBottomMessageOnBottom = useSelector(
|
||||
(state: RootState) => state.uiState.displayBottomMessageOnBottom,
|
||||
);
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
const timeline = useSelector((state: RootState) => state.state.history);
|
||||
|
||||
|
|
@ -162,6 +160,14 @@ const Layout = () => {
|
|||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"updateApplyState",
|
||||
async (state) => {
|
||||
dispatch(updateApplyState(state));
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"openOnboardingCard",
|
||||
async () => {
|
||||
|
|
@ -215,21 +221,6 @@ const Layout = () => {
|
|||
<ProfileDropdownPortalDiv id="profile-select-top-div"></ProfileDropdownPortalDiv>
|
||||
<Footer />
|
||||
</GridDiv>
|
||||
|
||||
<BottomMessageDiv
|
||||
displayOnBottom={displayBottomMessageOnBottom}
|
||||
onMouseEnter={() => {
|
||||
dispatch(setBottomMessageCloseTimeout(undefined));
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
if (!e.buttons) {
|
||||
dispatch(setBottomMessage(undefined));
|
||||
}
|
||||
}}
|
||||
hidden={!bottomMessage}
|
||||
>
|
||||
{bottomMessage}
|
||||
</BottomMessageDiv>
|
||||
</div>
|
||||
<div
|
||||
style={{ fontSize: `${getFontSize() - 4}px` }}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,15 @@ import {
|
|||
ArrowLeftEndOnRectangleIcon,
|
||||
CheckIcon,
|
||||
ClipboardIcon,
|
||||
PlayIcon,
|
||||
CommandLineIcon,
|
||||
PlayIcon,
|
||||
XMarkIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { useContext, useState } from "react";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { getBasename } from "core/util";
|
||||
import { useContext, useRef, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
|
|
@ -17,13 +19,16 @@ import {
|
|||
} from "..";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useWebviewListener } from "../../hooks/useWebviewListener";
|
||||
import { incrementNextCodeBlockToApplyIndex } from "../../redux/slices/uiStateSlice";
|
||||
import {
|
||||
incrementNextCodeBlockToApplyIndex,
|
||||
updateApplyState,
|
||||
} from "../../redux/slices/uiStateSlice";
|
||||
import { RootState } from "../../redux/store";
|
||||
import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util";
|
||||
import FileIcon from "../FileIcon";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import FileIcon from "../FileIcon";
|
||||
import { CopyButton as CopyButtonHeader } from "./CopyButton";
|
||||
import { ToolbarButtonWithTooltip } from "./ToolbarButtonWithTooltip";
|
||||
import { getBasename } from "core/util";
|
||||
|
||||
const ToolbarDiv = styled.div`
|
||||
display: flex;
|
||||
|
|
@ -123,16 +128,28 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useDispatch();
|
||||
const isTerminal = isTerminalCodeBlock(props.language, props.text);
|
||||
const [showAcceptReject, setShowAcceptReject] = useState(false);
|
||||
const [isCopied, setIsCopied] = useState(false);
|
||||
const [isApplying, setIsApplying] = useState(false);
|
||||
|
||||
const streamIdRef = useRef<string | null>(null);
|
||||
if (streamIdRef.current === null) {
|
||||
streamIdRef.current = uuidv4();
|
||||
}
|
||||
|
||||
const applyState = useSelector(
|
||||
(store: RootState) =>
|
||||
store.uiState.applyStates.find(
|
||||
(state) => state.streamId === streamIdRef.current,
|
||||
)?.status ?? "closed",
|
||||
);
|
||||
|
||||
// Handle apply keyboard shortcut
|
||||
useWebviewListener(
|
||||
"applyCodeFromChat",
|
||||
async () => {
|
||||
await ideMessenger.request("applyToCurrentFile", {
|
||||
text: props.text,
|
||||
streamId: streamIdRef.current,
|
||||
});
|
||||
dispatch(incrementNextCodeBlockToApplyIndex({}));
|
||||
},
|
||||
|
|
@ -157,10 +174,16 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
if (isTerminal) {
|
||||
ideMessenger.ide.runCommand(getTerminalCommand(props.text));
|
||||
} else {
|
||||
ideMessenger.post("applyToCurrentFile", { text: props.text });
|
||||
setIsApplying(true);
|
||||
setTimeout(() => setIsApplying(false), 2000);
|
||||
setShowAcceptReject(true);
|
||||
ideMessenger.post("applyToCurrentFile", {
|
||||
text: props.text,
|
||||
streamId: streamIdRef.current,
|
||||
});
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId: streamIdRef.current,
|
||||
status: "streaming",
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,12 +196,22 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
|
||||
function onClickAccept() {
|
||||
ideMessenger.post("acceptDiff", { filepath: props.filepath });
|
||||
setShowAcceptReject(false);
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId: streamIdRef.current,
|
||||
status: "closed",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function onClickReject() {
|
||||
ideMessenger.post("rejectDiff", { filepath: props.filepath });
|
||||
setShowAcceptReject(false);
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId: streamIdRef.current,
|
||||
status: "closed",
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (!props.filepath) {
|
||||
|
|
@ -239,7 +272,7 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
|
||||
{!isJetBrains() && (
|
||||
<div className="flex">
|
||||
{!showAcceptReject ? (
|
||||
{applyState === "closed" ? (
|
||||
<ToolbarButton
|
||||
onClick={onClickApply}
|
||||
style={{ color: lightGray }}
|
||||
|
|
@ -252,7 +285,7 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
<span className="hidden xs:inline">Apply</span>
|
||||
</div>
|
||||
</ToolbarButton>
|
||||
) : (
|
||||
) : applyState === "done" ? (
|
||||
<>
|
||||
<ToolbarButtonWithTooltip
|
||||
onClick={onClickReject}
|
||||
|
|
@ -274,6 +307,29 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
</div>
|
||||
</ToolbarButtonWithTooltip>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex items-center mr-2">
|
||||
<svg
|
||||
className="animate-spin h-4 w-4 text-gray-400"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
className="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
></circle>
|
||||
<path
|
||||
className="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
></path>
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { debounce } from "lodash";
|
|||
import { useEffect, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { defaultBorderRadius, lightGray } from "..";
|
||||
import { defaultBorderRadius } from "..";
|
||||
import useUIConfig from "../../hooks/useUIConfig";
|
||||
import { RootState } from "../../redux/store";
|
||||
import CodeBlockToolBar from "./CodeBlockToolbar";
|
||||
|
|
@ -47,16 +47,20 @@ function PreWithToolbar(props: {
|
|||
);
|
||||
|
||||
useEffect(() => {
|
||||
const debouncedEffect = debounce(() => {
|
||||
if (copyValue === "") {
|
||||
setCopyValue(childrenToText(props.children.props.children));
|
||||
}, 100);
|
||||
} else {
|
||||
const debouncedEffect = debounce(() => {
|
||||
setCopyValue(childrenToText(props.children.props.children));
|
||||
}, 100);
|
||||
|
||||
debouncedEffect();
|
||||
debouncedEffect();
|
||||
|
||||
return () => {
|
||||
debouncedEffect.cancel();
|
||||
};
|
||||
}, [props.children]);
|
||||
return () => {
|
||||
debouncedEffect.cancel();
|
||||
};
|
||||
}
|
||||
}, [props.children, copyValue]);
|
||||
|
||||
return (
|
||||
<TopDiv
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
import { RootState } from "../store";
|
||||
|
||||
const selectBottomMessage = (state: RootState) => state.uiState.bottomMessage;
|
||||
|
||||
export { selectBottomMessage };
|
||||
|
|
@ -1,31 +1,28 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { ApplyState } from "core/protocol/ideWebview";
|
||||
import {
|
||||
defaultOnboardingCardState,
|
||||
OnboardingCardState,
|
||||
} from "../../components/OnboardingCard";
|
||||
|
||||
type UiState = {
|
||||
bottomMessage: JSX.Element | undefined;
|
||||
bottomMessageCloseTimeout: NodeJS.Timeout | undefined;
|
||||
displayBottomMessageOnBottom: boolean;
|
||||
showDialog: boolean;
|
||||
dialogMessage: string | JSX.Element | undefined;
|
||||
dialogEntryOn: boolean;
|
||||
nextCodeBlockToApplyIndex: number;
|
||||
onboardingCard: OnboardingCardState;
|
||||
applyStates: ApplyState[];
|
||||
};
|
||||
|
||||
export const uiStateSlice = createSlice({
|
||||
name: "uiState",
|
||||
initialState: {
|
||||
bottomMessage: undefined,
|
||||
bottomMessageCloseTimeout: undefined,
|
||||
showDialog: false,
|
||||
dialogMessage: "",
|
||||
dialogEntryOn: false,
|
||||
displayBottomMessageOnBottom: true,
|
||||
nextCodeBlockToApplyIndex: 0,
|
||||
onboardingCard: defaultOnboardingCardState,
|
||||
applyStates: [],
|
||||
} as UiState,
|
||||
reducers: {
|
||||
setOnboardingCard: (
|
||||
|
|
@ -34,21 +31,6 @@ export const uiStateSlice = createSlice({
|
|||
) => {
|
||||
state.onboardingCard = { ...state.onboardingCard, ...action.payload };
|
||||
},
|
||||
setBottomMessage: (
|
||||
state,
|
||||
action: PayloadAction<UiState["bottomMessage"]>,
|
||||
) => {
|
||||
state.bottomMessage = action.payload;
|
||||
},
|
||||
setBottomMessageCloseTimeout: (
|
||||
state,
|
||||
action: PayloadAction<UiState["bottomMessageCloseTimeout"]>,
|
||||
) => {
|
||||
if (state.bottomMessageCloseTimeout) {
|
||||
clearTimeout(state.bottomMessageCloseTimeout);
|
||||
}
|
||||
state.bottomMessageCloseTimeout = action.payload;
|
||||
},
|
||||
setDialogMessage: (
|
||||
state,
|
||||
action: PayloadAction<UiState["dialogMessage"]>,
|
||||
|
|
@ -64,18 +46,26 @@ export const uiStateSlice = createSlice({
|
|||
setShowDialog: (state, action: PayloadAction<UiState["showDialog"]>) => {
|
||||
state.showDialog = action.payload;
|
||||
},
|
||||
setDisplayBottomMessageOnBottom: (
|
||||
state,
|
||||
action: PayloadAction<UiState["displayBottomMessageOnBottom"]>,
|
||||
) => {
|
||||
state.displayBottomMessageOnBottom = action.payload;
|
||||
},
|
||||
|
||||
resetNextCodeBlockToApplyIndex: (state) => {
|
||||
state.nextCodeBlockToApplyIndex = 0;
|
||||
},
|
||||
incrementNextCodeBlockToApplyIndex: (state, action) => {
|
||||
state.nextCodeBlockToApplyIndex++;
|
||||
},
|
||||
updateApplyState: (state, action: PayloadAction<ApplyState>) => {
|
||||
const { streamId, status } = action.payload;
|
||||
const index = state.applyStates.findIndex(
|
||||
(applyState) => applyState.streamId === streamId,
|
||||
);
|
||||
if (status === "closed" && index !== -1) {
|
||||
state.applyStates.splice(index, 1);
|
||||
} else if (index === -1) {
|
||||
state.applyStates.push(action.payload);
|
||||
} else {
|
||||
state.applyStates[index].status = status;
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -86,9 +76,7 @@ export const {
|
|||
setShowDialog,
|
||||
resetNextCodeBlockToApplyIndex,
|
||||
incrementNextCodeBlockToApplyIndex,
|
||||
setBottomMessage,
|
||||
setBottomMessageCloseTimeout,
|
||||
setDisplayBottomMessageOnBottom,
|
||||
updateApplyState,
|
||||
} = uiStateSlice.actions;
|
||||
|
||||
export default uiStateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue