highlighted code improvements
This commit is contained in:
parent
2b8f7b079b
commit
8f080c4d24
10 changed files with 65 additions and 25 deletions
|
|
@ -69,7 +69,8 @@ class Autopilot(ContinueBaseModel):
|
|||
user_input_queue=self._main_user_input_queue,
|
||||
default_model=self.continue_sdk.config.default_model,
|
||||
highlighted_ranges=self._highlighted_ranges,
|
||||
slash_commands=self.get_available_slash_commands()
|
||||
slash_commands=self.get_available_slash_commands(),
|
||||
adding_highlighted_code=self._adding_highlighted_code,
|
||||
)
|
||||
|
||||
def get_available_slash_commands(self) -> List[Dict]:
|
||||
|
|
@ -140,8 +141,12 @@ class Autopilot(ContinueBaseModel):
|
|||
await self._run_singular_step(step)
|
||||
|
||||
_highlighted_ranges: List[RangeInFileWithContents] = []
|
||||
_adding_highlighted_code: bool = False
|
||||
|
||||
async def handle_highlighted_code(self, range_in_files: List[RangeInFileWithContents]):
|
||||
if not self._adding_highlighted_code:
|
||||
return
|
||||
|
||||
workspace_path = self.continue_sdk.ide.workspace_directory
|
||||
for rif in range_in_files:
|
||||
rif.filepath = os.path.basename(rif.filepath)
|
||||
|
|
@ -186,6 +191,10 @@ class Autopilot(ContinueBaseModel):
|
|||
self._highlighted_ranges = kept_ranges
|
||||
await self.update_subscribers()
|
||||
|
||||
async def toggle_adding_highlighted_code(self):
|
||||
self._adding_highlighted_code = not self._adding_highlighted_code
|
||||
await self.update_subscribers()
|
||||
|
||||
async def _run_singular_step(self, step: "Step", is_future_step: bool = False) -> Coroutine[Observation, None, None]:
|
||||
# Allow config to set disallowed steps
|
||||
if step.__class__.__name__ in self.continue_sdk.config.disallowed_steps:
|
||||
|
|
|
|||
|
|
@ -207,6 +207,7 @@ class FullState(ContinueBaseModel):
|
|||
default_model: str
|
||||
highlighted_ranges: List[RangeInFileWithContents]
|
||||
slash_commands: List[SlashCommandDescription]
|
||||
adding_highlighted_code: bool
|
||||
|
||||
|
||||
class ContinueSDK:
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ class GUIProtocolServer(AbstractGUIProtocolServer):
|
|||
self.on_delete_at_index(data["index"])
|
||||
elif message_type == "delete_context_at_indices":
|
||||
self.on_delete_context_at_indices(data["indices"])
|
||||
elif message_type == "toggle_adding_highlighted_code":
|
||||
self.on_toggle_adding_highlighted_code()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
|
@ -128,6 +130,11 @@ class GUIProtocolServer(AbstractGUIProtocolServer):
|
|||
self.session.autopilot.delete_context_at_indices(indices)
|
||||
)
|
||||
|
||||
def on_toggle_adding_highlighted_code(self):
|
||||
asyncio.create_task(
|
||||
self.session.autopilot.toggle_adding_highlighted_code()
|
||||
)
|
||||
|
||||
|
||||
@router.websocket("/ws")
|
||||
async def websocket_endpoint(websocket: WebSocket, session: Session = Depends(websocket_session)):
|
||||
|
|
|
|||
|
|
@ -286,6 +286,7 @@ class DefaultModelEditCodeStep(Step):
|
|||
return "```" in line or "<modified_code_to_edit>" in line or "<file_prefix>" in line or "</file_prefix>" in line or "<file_suffix>" in line or "</file_suffix>" in line or "<user_request>" in line or "</user_request>" in line or "<code_to_edit>" in line
|
||||
|
||||
async def stream_rif(self, rif: RangeInFileWithContents, sdk: ContinueSDK):
|
||||
await sdk.ide.saveFile(rif.filepath)
|
||||
full_file_contents = await sdk.ide.readFile(rif.filepath)
|
||||
|
||||
file_prefix, contents, file_suffix, model_to_use = await self.get_prompt_parts(
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@ import CodeBlock from "./CodeBlock";
|
|||
import { RangeInFile } from "../../../src/client";
|
||||
import PillButton from "./PillButton";
|
||||
import HeaderButtonWithText from "./HeaderButtonWithText";
|
||||
import { Trash, LockClosed, LockOpen } from "@styled-icons/heroicons-outline";
|
||||
import {
|
||||
Trash,
|
||||
LockClosed,
|
||||
LockOpen,
|
||||
Plus,
|
||||
} from "@styled-icons/heroicons-outline";
|
||||
|
||||
// #region styled components
|
||||
const mainInputFontSize = 16;
|
||||
|
|
@ -100,6 +105,8 @@ interface ComboBoxProps {
|
|||
highlightedCodeSections: (RangeInFile & { contents: string })[];
|
||||
deleteContextItems: (indices: number[]) => void;
|
||||
onTogglePin: () => void;
|
||||
onToggleAddContext: () => void;
|
||||
addingHighlightedCode: boolean;
|
||||
}
|
||||
|
||||
const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
||||
|
|
@ -249,6 +256,19 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
</Ul>
|
||||
</div>
|
||||
<div className="px-2 flex gap-2 items-center flex-wrap">
|
||||
{highlightedCodeSections.length === 0 && (
|
||||
<HeaderButtonWithText
|
||||
text={
|
||||
props.addingHighlightedCode ? "Adding Context" : "Add Context"
|
||||
}
|
||||
onClick={() => {
|
||||
props.onToggleAddContext();
|
||||
}}
|
||||
inverted={props.addingHighlightedCode}
|
||||
>
|
||||
<Plus size="1.6em" />
|
||||
</HeaderButtonWithText>
|
||||
)}
|
||||
{highlightedCodeSections.length > 0 && (
|
||||
<>
|
||||
<HeaderButtonWithText
|
||||
|
|
@ -305,9 +325,8 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
|
|||
))}
|
||||
|
||||
<span className="text-trueGray-400 ml-auto mr-4 text-xs">
|
||||
Highlight code to include as context.{" "}
|
||||
{highlightedCodeSections.length === 0 &&
|
||||
"Otherwise using entire currently open file."}
|
||||
Highlight code to include as context. Currently open file included by
|
||||
default. {highlightedCodeSections.length === 0 && ""}
|
||||
</span>
|
||||
</div>
|
||||
<ContextDropdown
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ const Button = styled.button`
|
|||
background-color: white;
|
||||
color: black;
|
||||
}
|
||||
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
||||
interface PillButtonProps {
|
||||
|
|
@ -39,26 +41,13 @@ const PillButton = (props: PillButtonProps) => {
|
|||
props.onHover(false);
|
||||
}
|
||||
}}
|
||||
onClick={() => {
|
||||
if (props.onDelete) {
|
||||
props.onDelete();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{ display: "grid", gridTemplateColumns: "1fr auto", gap: "4px" }}
|
||||
>
|
||||
<span
|
||||
style={{
|
||||
cursor: "pointer",
|
||||
color: "red",
|
||||
borderRight: "1px solid black",
|
||||
paddingRight: "4px",
|
||||
}}
|
||||
onClick={() => {
|
||||
props.onDelete?.();
|
||||
props.onHover?.(false);
|
||||
}}
|
||||
>
|
||||
<XMark style={{ padding: "0px" }} size="1.2em" strokeWidth="2px" />
|
||||
</span>
|
||||
<span>{props.title}</span>
|
||||
</div>
|
||||
{props.title}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ interface UserInputContainerProps {
|
|||
historyNode: HistoryNode;
|
||||
}
|
||||
|
||||
const StyledDiv = styled.div`
|
||||
const StyledDiv = styled.div<{ hidden: boolean }>`
|
||||
background-color: rgb(50 50 50);
|
||||
padding: 8px;
|
||||
padding-left: 16px;
|
||||
|
|
@ -24,6 +24,8 @@ const StyledDiv = styled.div`
|
|||
font-size: 13px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
visibility: ${(props) => (props.hidden ? "hidden" : "visible")};
|
||||
height: ${(props) => (props.hidden ? "0px" : "auto")};
|
||||
`;
|
||||
|
||||
const UserInputContainer = (props: UserInputContainerProps) => {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ abstract class AbstractContinueGUIClientProtocol {
|
|||
abstract deleteAtIndex(index: number): void;
|
||||
|
||||
abstract deleteContextAtIndices(indices: number[]): void;
|
||||
|
||||
abstract toggleAddingHighlightedCode(): void;
|
||||
}
|
||||
|
||||
export default AbstractContinueGUIClientProtocol;
|
||||
|
|
|
|||
|
|
@ -74,6 +74,10 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol {
|
|||
deleteContextAtIndices(indices: number[]) {
|
||||
this.messenger.send("delete_context_at_indices", { indices });
|
||||
}
|
||||
|
||||
toggleAddingHighlightedCode(): void {
|
||||
this.messenger.send("toggle_adding_highlighted_code", {});
|
||||
}
|
||||
}
|
||||
|
||||
export default ContinueGUIClientProtocol;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ function GUI(props: GUIProps) {
|
|||
const [waitingForSteps, setWaitingForSteps] = useState(false);
|
||||
const [userInputQueue, setUserInputQueue] = useState<string[]>([]);
|
||||
const [highlightedRanges, setHighlightedRanges] = useState([]);
|
||||
const [addingHighlightedCode, setAddingHighlightedCode] = useState(false);
|
||||
const [availableSlashCommands, setAvailableSlashCommands] = useState<
|
||||
{ name: string; description: string }[]
|
||||
>([]);
|
||||
|
|
@ -157,6 +158,7 @@ function GUI(props: GUIProps) {
|
|||
setHistory(state.history);
|
||||
setHighlightedRanges(state.highlighted_ranges);
|
||||
setUserInputQueue(state.user_input_queue);
|
||||
setAddingHighlightedCode(state.adding_highlighted_code);
|
||||
setAvailableSlashCommands(
|
||||
state.slash_commands.map((c: any) => {
|
||||
return {
|
||||
|
|
@ -361,6 +363,10 @@ function GUI(props: GUIProps) {
|
|||
onTogglePin={() => {
|
||||
setPinned((prev: boolean) => !prev);
|
||||
}}
|
||||
onToggleAddContext={() => {
|
||||
client?.toggleAddingHighlightedCode();
|
||||
}}
|
||||
addingHighlightedCode={addingHighlightedCode}
|
||||
/>
|
||||
<ContinueButton onClick={onMainTextInput} />
|
||||
</TopGUIDiv>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue