feat: add combobox for edit file selection
This commit is contained in:
parent
a78cbbb0a9
commit
7c6295feeb
14 changed files with 224 additions and 70 deletions
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
|
|
@ -12,8 +12,8 @@
|
|||
"cwd": "${workspaceFolder}/extensions/vscode",
|
||||
"args": [
|
||||
// Pass a directory to manually test in
|
||||
"${workspaceFolder}/manual-testing-sandbox",
|
||||
"${workspaceFolder}/manual-testing-sandbox/test.js",
|
||||
"${workspaceFolder}/gui",
|
||||
"${workspaceFolder}/gui/src/App.tsx",
|
||||
"--extensionDevelopmentPath=${workspaceFolder}/extensions/vscode"
|
||||
],
|
||||
"pauseForSourceMap": false,
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ export class ChromiumInstaller {
|
|||
|
||||
private async proposeInstall(site: string) {
|
||||
const msg =
|
||||
`Unable to crawl documentation site: ${site}\n` +
|
||||
`Unable to crawl documentation site: "${site}".` +
|
||||
"We recommend installing Chromium. " +
|
||||
"Download progress can be viewed in the developer console.";
|
||||
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.9.233",
|
||||
"version": "0.9.234",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.9.233",
|
||||
"version": "0.9.234",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
|
|||
|
|
@ -508,10 +508,6 @@ const getCommandsMap: (
|
|||
editor.selection.anchor,
|
||||
);
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
}, 30);
|
||||
},
|
||||
"continue.focusEditWithoutClear": async () => {
|
||||
captureCommandTelemetry("focusEditWithoutClear");
|
||||
|
|
@ -553,10 +549,6 @@ const getCommandsMap: (
|
|||
contents,
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
}, 30);
|
||||
},
|
||||
"continue.exitEditMode": async () => {
|
||||
captureCommandTelemetry("exitEditMode");
|
||||
|
|
|
|||
|
|
@ -382,7 +382,6 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
) : (
|
||||
<>
|
||||
{subMenuTitle && <ItemDiv className="mb-2">{subMenuTitle}</ItemDiv>}
|
||||
{/* <CustomScrollbarDiv className="overflow-y-scroll max-h-96"> */}
|
||||
{allItems.length ? (
|
||||
allItems.map((item, index) => (
|
||||
<ItemDiv
|
||||
|
|
@ -402,7 +401,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
height="20px"
|
||||
width="20px"
|
||||
filename={item.description}
|
||||
></FileIcon>
|
||||
/>
|
||||
)}
|
||||
{!showFileIconForItem(item) && (
|
||||
<>
|
||||
|
|
@ -414,7 +413,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
</div>
|
||||
<span
|
||||
style={{
|
||||
color: vscListActiveForeground,
|
||||
color: lightGray,
|
||||
float: "right",
|
||||
textAlign: "right",
|
||||
opacity: index !== selectedIndex ? 0 : 1,
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ import {
|
|||
} from "./handleMetaKeyIssues";
|
||||
import { ComboBoxItem } from "./types";
|
||||
import useIsOSREnabled from "../../hooks/useIsOSREnabled";
|
||||
import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice";
|
||||
import { AddCodeToEdit } from "./AddCodeToEditExtension";
|
||||
import {
|
||||
addCodeToEdit,
|
||||
|
|
@ -827,13 +826,6 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const [activeKey, setActiveKey] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldAddFileForEditing && props.isMainInput) {
|
||||
insertCharacterWithWhitespace("#");
|
||||
dispatch(setShouldAddFileForEditing(false));
|
||||
}
|
||||
}, [shouldAddFileForEditing]);
|
||||
|
||||
const insertCharacterWithWhitespace = useCallback(
|
||||
(char: string) => {
|
||||
const text = editor.getText();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export default function GeneratingCodeLoader({
|
|||
|
||||
return (
|
||||
<span className="inline-flex items-center gap-2 text-gray-400">
|
||||
{showLineCount ? linesGeneratedText : "Generating..."}
|
||||
{showLineCount ? linesGeneratedText : "Generating"}
|
||||
<Spinner />
|
||||
</span>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
import { ContextSubmenuItem } from "core";
|
||||
import { createContext } from "react";
|
||||
|
||||
export interface ContextSubmenuItemWithProvider extends ContextSubmenuItem {
|
||||
providerTitle: string;
|
||||
}
|
||||
|
||||
export const SubmenuContextProvidersContext = createContext<{
|
||||
getSubmenuContextItems: (
|
||||
providerTitle: string | undefined,
|
||||
query: string,
|
||||
) => (ContextSubmenuItem & { providerTitle: string })[];
|
||||
) => ContextSubmenuItemWithProvider[];
|
||||
addItem: (providerTitle: string, item: ContextSubmenuItem) => void;
|
||||
}>({
|
||||
getSubmenuContextItems: () => [],
|
||||
|
|
|
|||
|
|
@ -258,11 +258,12 @@ function useChatHandler(dispatch: Dispatch, ideMessenger: IIdeMessenger) {
|
|||
ideMessenger,
|
||||
dispatch,
|
||||
);
|
||||
|
||||
if (promptPreamble) {
|
||||
typeof content === "string"
|
||||
? (content += promptPreamble)
|
||||
: (content.at(-1).text += promptPreamble);
|
||||
if (typeof content === "string") {
|
||||
content = promptPreamble + content;
|
||||
} else {
|
||||
content[0].text = promptPreamble + content[0].text;
|
||||
}
|
||||
}
|
||||
|
||||
const message: ChatMessage = {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,29 @@
|
|||
import { useContext, useState, useRef, useEffect } from "react";
|
||||
import { useContext, useRef } from "react";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { setShouldAddFileForEditing } from "../../redux/slices/uiStateSlice";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline";
|
||||
import { addCodeToEdit } from "../../redux/slices/editModeState";
|
||||
import { Listbox } from "@headlessui/react";
|
||||
|
||||
export default function AddFileButton() {
|
||||
export interface AddFileButtonProps {
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
export default function AddFileButton({ onClick }: AddFileButtonProps) {
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
function onClickAddFileToCodeToEdit() {
|
||||
dispatch(setShouldAddFileForEditing(true));
|
||||
}
|
||||
|
||||
async function handleAddAllOpenFiles() {
|
||||
const openFiles = await ideMessenger.ide.getOpenFiles();
|
||||
const filesData = await Promise.all(
|
||||
openFiles.map(async (filepath) => {
|
||||
const contents = await ideMessenger.ide.readFile(filepath);
|
||||
return { filepath, contents };
|
||||
}),
|
||||
);
|
||||
|
||||
for (const filepath of openFiles) {
|
||||
const contents = await ideMessenger.ide.readFile(filepath);
|
||||
dispatch(addCodeToEdit({ filepath, contents }));
|
||||
}
|
||||
dispatch(addCodeToEdit(filesData));
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -29,14 +31,14 @@ export default function AddFileButton() {
|
|||
<div className="relative">
|
||||
<Listbox.Button
|
||||
ref={buttonRef}
|
||||
className="bg-vsc-editor-background border-lightgray/50 flex cursor-pointer items-center justify-between rounded-md border border-solid px-0 shadow-sm transition-colors"
|
||||
className="bg-vsc-editor-background border-lightgray/50 flex h-5 cursor-pointer items-center justify-between rounded-md border border-solid px-0 shadow-sm transition-colors"
|
||||
>
|
||||
<div
|
||||
className="flex items-center gap-1 px-1.5 hover:brightness-125"
|
||||
className="flex h-5 w-14 items-center justify-center gap-1 hover:brightness-125"
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onClickAddFileToCodeToEdit();
|
||||
onClick();
|
||||
}}
|
||||
>
|
||||
<PlusIcon className="text-vsc-foreground inline h-2.5 w-2.5 brightness-75" />
|
||||
|
|
|
|||
130
gui/src/pages/Edit/AddFileCombobox.tsx
Normal file
130
gui/src/pages/Edit/AddFileCombobox.tsx
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
import { useState, useContext, useEffect, useRef } from "react";
|
||||
import {
|
||||
ContextSubmenuItemWithProvider,
|
||||
SubmenuContextProvidersContext,
|
||||
} from "../../context/SubmenuContextProviders";
|
||||
import { Combobox } from "@headlessui/react";
|
||||
import FileIcon from "../../components/FileIcon";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "../../redux/store";
|
||||
|
||||
export interface AddFileComboboxProps {
|
||||
onSelect: (filepaths: string[]) => void;
|
||||
onEscape: () => void;
|
||||
}
|
||||
|
||||
export default function AddFileCombobox({
|
||||
onSelect,
|
||||
onEscape,
|
||||
}: AddFileComboboxProps) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [selectedFiles, setSelectedFiles] = useState<
|
||||
ContextSubmenuItemWithProvider[]
|
||||
>([]);
|
||||
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const buttonRef = useRef<HTMLButtonElement>(null);
|
||||
const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext);
|
||||
const allFiles = getSubmenuContextItems("file", "");
|
||||
const codeToEdit = useSelector(
|
||||
(state: RootState) => state.editModeState.codeToEdit,
|
||||
);
|
||||
const remainingFiles = allFiles.filter(
|
||||
(file) => !codeToEdit.find((code) => code.filepath === file.id),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (inputRef.current) {
|
||||
inputRef.current.focus();
|
||||
}
|
||||
}, []);
|
||||
|
||||
const filteredFiles =
|
||||
query === ""
|
||||
? remainingFiles
|
||||
: remainingFiles.filter((file) =>
|
||||
file.title.toLowerCase().includes(query.toLowerCase()),
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="pb-2 pl-3.5 pr-2">
|
||||
<Combobox
|
||||
multiple
|
||||
value={selectedFiles}
|
||||
onChange={(files) => {
|
||||
setSelectedFiles(files);
|
||||
onSelect(files.map((file) => file.id));
|
||||
buttonRef.current?.click();
|
||||
}}
|
||||
>
|
||||
{({ open }) => (
|
||||
<div className="relative">
|
||||
<Combobox.Button className="hidden" ref={buttonRef} />
|
||||
<Combobox.Input
|
||||
ref={inputRef}
|
||||
onClick={() => {
|
||||
if (!open) {
|
||||
buttonRef.current?.click();
|
||||
}
|
||||
}}
|
||||
onFocus={() => {
|
||||
buttonRef.current?.click();
|
||||
}}
|
||||
className="bg-vsc-background border-lightgray text-vsc-foreground box-border w-full rounded border border-solid py-0.5 pl-2 focus:outline-none"
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
placeholder="Type to search files..."
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape" && !open) {
|
||||
onEscape();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<Combobox.Options className="no-scrollbar bg-vsc-editor-background border-lightgray/50 absolute left-0 right-0 z-50 mt-1 max-h-60 overflow-y-auto overflow-x-hidden rounded-md border border-solid px-1 py-0 pl-0 pr-5 shadow-lg focus:outline-none">
|
||||
{filteredFiles.length > 0 ? (
|
||||
filteredFiles.map((file) => (
|
||||
<Combobox.Option
|
||||
key={file.id}
|
||||
value={file}
|
||||
className={({ active }) =>
|
||||
`relative flex w-full cursor-pointer px-2 py-1 text-left text-xs ${
|
||||
active
|
||||
? "bg-vsc-list-active-background text-vsc-list-active-foreground"
|
||||
: ""
|
||||
}`
|
||||
}
|
||||
>
|
||||
{({ active, selected }) => (
|
||||
<div className="group flex w-full min-w-0 items-center gap-1">
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1">
|
||||
<FileIcon
|
||||
height="20px"
|
||||
width="20px"
|
||||
filename={file.title}
|
||||
/>
|
||||
<span className="truncate">{file.title}</span>
|
||||
</div>
|
||||
|
||||
<span
|
||||
className={`text-lightgray max-w-[30%] truncate ${
|
||||
active || selected ? "visible" : "invisible"
|
||||
} group-hover:visible`}
|
||||
>
|
||||
{file.description}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</Combobox.Option>
|
||||
))
|
||||
) : (
|
||||
<div className="text-vsc-list-active-foreground0 px-2 py-1 text-xs">
|
||||
No results
|
||||
</div>
|
||||
)}
|
||||
</Combobox.Options>
|
||||
</div>
|
||||
)}
|
||||
</Combobox>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,16 +1,21 @@
|
|||
import { useContext } from "react";
|
||||
import { useContext, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { removeCodeToEdit } from "../../redux/slices/editModeState";
|
||||
import {
|
||||
removeCodeToEdit,
|
||||
addCodeToEdit,
|
||||
} from "../../redux/slices/editModeState";
|
||||
import { RootState } from "../../redux/store";
|
||||
import CodeToEditListItem from "./CodeToEditListItem";
|
||||
|
||||
import { CodeToEdit, RangeInFileWithContents } from "core";
|
||||
import AddFileButton from "./AddFileButton";
|
||||
import AddFileCombobox from "./AddFileCombobox";
|
||||
import { XMarkIcon } from "@heroicons/react/24/outline";
|
||||
|
||||
export default function WorkingSet() {
|
||||
const dispatch = useDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const [showAddFileCombobox, setShowAddFileCombobox] = useState(false);
|
||||
const codeToEdit = useSelector(
|
||||
(state: RootState) => state.editModeState.codeToEdit,
|
||||
);
|
||||
|
|
@ -38,22 +43,33 @@ export default function WorkingSet() {
|
|||
}
|
||||
}
|
||||
|
||||
const codeToEditItems = [...codeToEdit]
|
||||
.reverse()
|
||||
.map((code, i) => (
|
||||
<CodeToEditListItem
|
||||
key={code.filepath + i}
|
||||
code={code}
|
||||
onDelete={onDelete}
|
||||
onClickFilename={onClickFilename}
|
||||
/>
|
||||
));
|
||||
async function onSelectFilesToAdd(filepaths: string[]) {
|
||||
const filePromises = filepaths.map(async (filepath) => {
|
||||
const contents = await ideMessenger.ide.readFile(filepath);
|
||||
return { contents, filepath };
|
||||
});
|
||||
|
||||
const fileResults = await Promise.all(filePromises);
|
||||
|
||||
for (const file of fileResults) {
|
||||
dispatch(addCodeToEdit(file));
|
||||
}
|
||||
}
|
||||
|
||||
const codeToEditItems = codeToEdit.map((code, i) => (
|
||||
<CodeToEditListItem
|
||||
key={code.filepath + i}
|
||||
code={code}
|
||||
onDelete={onDelete}
|
||||
onClickFilename={onClickFilename}
|
||||
/>
|
||||
));
|
||||
|
||||
return (
|
||||
<div className="bg-vsc-editor-background border-vsc-input-border mx-1 flex flex-col rounded-t-lg border border-b-0 border-solid px-1">
|
||||
<div className="text-lightgray flex items-center justify-between gap-1.5 py-1.5 pl-3 pr-2 text-xs">
|
||||
<span>{title}</span>
|
||||
<AddFileButton />
|
||||
<AddFileButton onClick={() => setShowAddFileCombobox(true)} />
|
||||
</div>
|
||||
|
||||
{codeToEdit.length > 0 && (
|
||||
|
|
@ -61,6 +77,23 @@ export default function WorkingSet() {
|
|||
{codeToEditItems}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{showAddFileCombobox && (
|
||||
<div className="mr-2 flex items-center py-1">
|
||||
<div className="flex-grow">
|
||||
<AddFileCombobox
|
||||
onSelect={onSelectFilesToAdd}
|
||||
onEscape={() => setShowAddFileCombobox(false)}
|
||||
/>
|
||||
</div>
|
||||
<XMarkIcon
|
||||
onClick={(e) => {
|
||||
setShowAddFileCombobox(false);
|
||||
}}
|
||||
className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground mb-2 h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,13 +24,21 @@ export const editModeStateSlice = createSlice({
|
|||
name: "editModeState",
|
||||
initialState,
|
||||
reducers: {
|
||||
addCodeToEdit: (state, { payload }: PayloadAction<CodeToEdit>) => {
|
||||
const entryExists = state.codeToEdit.some((entry) =>
|
||||
isCodeToEditEqual(entry, payload),
|
||||
addCodeToEdit: (
|
||||
state,
|
||||
{ payload }: PayloadAction<CodeToEdit | CodeToEdit[]>,
|
||||
) => {
|
||||
const entries = Array.isArray(payload) ? payload : [payload];
|
||||
|
||||
const newEntries = entries.filter(
|
||||
(entry) =>
|
||||
!state.codeToEdit.some((existingEntry) =>
|
||||
isCodeToEditEqual(existingEntry, entry),
|
||||
),
|
||||
);
|
||||
|
||||
if (!entryExists) {
|
||||
state.codeToEdit.push(payload);
|
||||
if (newEntries.length > 0) {
|
||||
state.codeToEdit.push(...newEntries);
|
||||
}
|
||||
},
|
||||
focusEdit: (state) => {
|
||||
|
|
|
|||
|
|
@ -43,12 +43,6 @@ export const uiStateSlice = createSlice({
|
|||
setShowDialog: (state, action: PayloadAction<UiState["showDialog"]>) => {
|
||||
state.showDialog = action.payload;
|
||||
},
|
||||
setShouldAddFileForEditing: (
|
||||
state,
|
||||
action: PayloadAction<UiState["shouldAddFileForEditing"]>,
|
||||
) => {
|
||||
state.shouldAddFileForEditing = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -57,7 +51,6 @@ export const {
|
|||
setDialogMessage,
|
||||
setDialogEntryOn,
|
||||
setShowDialog,
|
||||
setShouldAddFileForEditing,
|
||||
} = uiStateSlice.actions;
|
||||
|
||||
export default uiStateSlice.reducer;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue