From cc0d73c2c1351a08c95654f7792f56c1d3d0ab54 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 12 Jun 2023 21:30:49 -0700 Subject: slash commands dropdown! --- extension/react-app/src/components/ComboBox.tsx | 146 ++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 extension/react-app/src/components/ComboBox.tsx (limited to 'extension/react-app/src/components/ComboBox.tsx') diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx new file mode 100644 index 00000000..1b7c60e6 --- /dev/null +++ b/extension/react-app/src/components/ComboBox.tsx @@ -0,0 +1,146 @@ +import React, { useCallback } from "react"; +import { useCombobox } from "downshift"; +import styled from "styled-components"; +import { + buttonColor, + defaultBorderRadius, + secondaryDark, + vscBackground, +} from "."; + +const mainInputFontSize = 16; +const MainTextInput = styled.input` + padding: 8px; + font-size: ${mainInputFontSize}px; + border-radius: ${defaultBorderRadius}; + border: 1px solid #ccc; + margin: 8px auto; + width: 100%; + background-color: ${vscBackground}; + color: white; + outline: 1px solid orange; +`; + +const UlMaxHeight = 200; +const Ul = styled.ul<{ + hidden: boolean; + showAbove: boolean; + ulHeightPixels: number; +}>` + ${(props) => + props.showAbove + ? `transform: translateY(-${props.ulHeightPixels + 8}px);` + : `transform: translateY(${2 * mainInputFontSize}px);`} + position: absolute; + background: ${vscBackground}; + background-color: ${secondaryDark}; + color: white; + font-family: "Fira Code", monospace; + max-height: ${UlMaxHeight}px; + overflow: scroll; + padding: 0; + ${({ hidden }) => hidden && "display: none;"} + border-radius: ${defaultBorderRadius}; + overflow: hidden; + border: 0.5px solid gray; +`; + +const Li = styled.li<{ + highlighted: boolean; + selected: boolean; + isLastItem: boolean; +}>` + ${({ highlighted }) => highlighted && "background: #aa0000;"} + ${({ selected }) => selected && "font-weight: bold;"} + padding: 0.5rem 0.75rem; + display: flex; + flex-direction: column; + ${({ isLastItem }) => isLastItem && "border-bottom: 1px solid gray;"} + border-top: 1px solid gray; + cursor: pointer; +`; + +interface ComboBoxProps { + items: { name: string; description: string }[]; + onInputValueChange: (inputValue: string) => void; + disabled?: boolean; + onEnter?: (e: React.KeyboardEvent) => void; +} + +const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { + const [items, setItems] = React.useState(props.items); + const { + isOpen, + getToggleButtonProps, + getLabelProps, + getMenuProps, + getInputProps, + highlightedIndex, + getItemProps, + selectedItem, + setInputValue, + } = useCombobox({ + onInputValueChange({ inputValue }) { + if (!inputValue) return; + props.onInputValueChange(inputValue); + setItems( + props.items.filter((item) => + item.name.toLowerCase().startsWith(inputValue.toLowerCase()) + ) + ); + }, + items, + itemToString(item) { + return item ? item.name : ""; + }, + }); + + const divRef = React.useRef(null); + const ulRef = React.useRef(null); + const showAbove = () => { + return (divRef.current?.getBoundingClientRect().top || 0) > UlMaxHeight; + }; + + return ( + + ); +}); + +export default ComboBox; -- cgit v1.2.3-70-g09d2 From 276a7ab42a6cbeea931b6eeb7a27f56f60b3fb86 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 13 Jun 2023 12:00:35 -0700 Subject: env to .env to be caught by .gitignore --- continuedev/src/continuedev/core/policy.py | 2 +- .../continuedev/recipes/AddTransformRecipe/steps.py | 8 ++++---- .../recipes/CreatePipelineRecipe/steps.py | 10 +++++----- .../src/continuedev/recipes/DDtoBQRecipe/steps.py | 10 +++++----- .../recipes/DeployPipelineAirflowRecipe/steps.py | 8 ++++---- .../continuedev/recipes/WritePytestsRecipe/main.py | 3 +++ docs/docs/walkthroughs/create-a-recipe.md | 2 +- extension/react-app/src/components/ComboBox.tsx | 2 +- extension/react-app/src/components/StepContainer.tsx | 20 +++++++++++--------- 9 files changed, 35 insertions(+), 30 deletions(-) (limited to 'extension/react-app/src/components/ComboBox.tsx') diff --git a/continuedev/src/continuedev/core/policy.py b/continuedev/src/continuedev/core/policy.py index 51135f70..2b50307a 100644 --- a/continuedev/src/continuedev/core/policy.py +++ b/continuedev/src/continuedev/core/policy.py @@ -58,7 +58,7 @@ class DemoPolicy(Policy): # AnswerQuestionChroma(question=user_input), # EditFileChroma(request=user_input), (SimpleChatStep(user_input=user_input), - "Respond to the user with a chat message"), + "Respond to the user with a chat message. Can answer questions about code or anything else."), ], default_step=EditHighlightedCodeStep(user_input=user_input)) state = history.get_current() diff --git a/continuedev/src/continuedev/recipes/AddTransformRecipe/steps.py b/continuedev/src/continuedev/recipes/AddTransformRecipe/steps.py index f042424c..6a743fb5 100644 --- a/continuedev/src/continuedev/recipes/AddTransformRecipe/steps.py +++ b/continuedev/src/continuedev/recipes/AddTransformRecipe/steps.py @@ -24,15 +24,15 @@ class SetUpChessPipelineStep(Step): # running commands to get started when creating a new dlt pipeline await sdk.run([ - 'python3 -m venv env', - 'source env/bin/activate', + 'python3 -m venv .env', + 'source .env/bin/activate', 'pip install dlt', 'dlt --non-interactive init chess duckdb', 'pip install -r requirements.txt', 'pip install pandas streamlit' # Needed for the pipeline show step later ], name="Set up Python environment", description=dedent(f"""\ - - Create a Python virtual environment: `python3 -m venv env` - - Activate the virtual environment: `source env/bin/activate` + - Create a Python virtual environment: `python3 -m venv .env` + - Activate the virtual environment: `source .env/bin/activate` - Install dlt: `pip install dlt` - Create a new dlt pipeline called "chess" that loads data into a local DuckDB instance: `dlt init chess duckdb` - Install the Python dependencies for the pipeline: `pip install -r requirements.txt`""")) diff --git a/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py b/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py index ea4607da..88e27d2a 100644 --- a/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py +++ b/continuedev/src/continuedev/recipes/CreatePipelineRecipe/steps.py @@ -35,15 +35,15 @@ class SetupPipelineStep(Step): # running commands to get started when creating a new dlt pipeline await sdk.run([ - 'python3 -m venv env', - 'source env/bin/activate', + 'python3 -m venv .env', + 'source .env/bin/activate', 'pip install dlt', f'dlt --non-interactive init {source_name} duckdb', 'pip install -r requirements.txt' ], description=dedent(f"""\ Running the following commands: - - `python3 -m venv env`: Create a Python virtual environment - - `source env/bin/activate`: Activate the virtual environment + - `python3 -m venv .env`: Create a Python virtual environment + - `source .env/bin/activate`: Activate the virtual environment - `pip install dlt`: Install dlt - `dlt init {source_name} duckdb`: Create a new dlt pipeline called {source_name} that loads data into a local DuckDB instance - `pip install -r requirements.txt`: Install the Python dependencies for the pipeline"""), name="Setup Python environment") @@ -156,7 +156,7 @@ class RunQueryStep(Step): hide: bool = True async def run(self, sdk: ContinueSDK): - output = await sdk.run('env/bin/python3 query.py', name="Run test query", description="Running `env/bin/python3 query.py` to test that the data was loaded into DuckDB as expected", handle_error=False) + output = await sdk.run('.env/bin/python3 query.py', name="Run test query", description="Running `.env/bin/python3 query.py` to test that the data was loaded into DuckDB as expected", handle_error=False) if "Traceback" in output or "SyntaxError" in output: suggestion = sdk.models.gpt35.complete(dedent(f"""\ diff --git a/continuedev/src/continuedev/recipes/DDtoBQRecipe/steps.py b/continuedev/src/continuedev/recipes/DDtoBQRecipe/steps.py index 5cf89ccf..4b8971c2 100644 --- a/continuedev/src/continuedev/recipes/DDtoBQRecipe/steps.py +++ b/continuedev/src/continuedev/recipes/DDtoBQRecipe/steps.py @@ -27,15 +27,15 @@ class SetUpChessPipelineStep(Step): # running commands to get started when creating a new dlt pipeline await sdk.run([ - 'python3 -m venv env', - 'source env/bin/activate', + 'python3 -m venv .env', + 'source .env/bin/activate', 'pip install dlt', 'dlt --non-interactive init chess duckdb', 'pip install -r requirements.txt', ], name="Set up Python environment", description=dedent(f"""\ Running the following commands: - - `python3 -m venv env`: Create a Python virtual environment - - `source env/bin/activate`: Activate the virtual environment + - `python3 -m venv .env`: Create a Python virtual environment + - `source .env/bin/activate`: Activate the virtual environment - `pip install dlt`: Install dlt - `dlt init chess duckdb`: Create a new dlt pipeline called "chess" that loads data into a local DuckDB instance - `pip install -r requirements.txt`: Install the Python dependencies for the pipeline""")) @@ -75,7 +75,7 @@ class LoadDataStep(Step): async def run(self, sdk: ContinueSDK): # Run the pipeline again to load data to BigQuery - output = await sdk.run('env/bin/python3 chess_pipeline.py', name="Load data to BigQuery", description="Running `env/bin/python3 chess_pipeline.py` to load data to Google BigQuery") + output = await sdk.run('.env/bin/python3 chess_pipeline.py', name="Load data to BigQuery", description="Running `.env/bin/python3 chess_pipeline.py` to load data to Google BigQuery") if "Traceback" in output or "SyntaxError" in output: with open(os.path.join(os.path.dirname(__file__), "dlt_duckdb_to_bigquery_docs.md"), "r") as f: diff --git a/continuedev/src/continuedev/recipes/DeployPipelineAirflowRecipe/steps.py b/continuedev/src/continuedev/recipes/DeployPipelineAirflowRecipe/steps.py index ee3275e7..c9749348 100644 --- a/continuedev/src/continuedev/recipes/DeployPipelineAirflowRecipe/steps.py +++ b/continuedev/src/continuedev/recipes/DeployPipelineAirflowRecipe/steps.py @@ -28,15 +28,15 @@ class SetupPipelineStep(Step): async def run(self, sdk: ContinueSDK): await sdk.run([ - 'python3 -m venv env', - 'source env/bin/activate', + 'python3 -m venv .env', + 'source .env/bin/activate', 'pip install dlt', f'dlt --non-interactive init {self.source_name} duckdb', 'pip install -r requirements.txt' ], description=dedent(f"""\ Running the following commands: - - `python3 -m venv env`: Create a Python virtual environment - - `source env/bin/activate`: Activate the virtual environment + - `python3 -m venv .env`: Create a Python virtual environment + - `source .env/bin/activate`: Activate the virtual environment - `pip install dlt`: Install dlt - `dlt init {self.source_name} duckdb`: Create a new dlt pipeline called {self.source_name} that loads data into a local DuckDB instance - `pip install -r requirements.txt`: Install the Python dependencies for the pipeline"""), name="Setup Python environment") diff --git a/continuedev/src/continuedev/recipes/WritePytestsRecipe/main.py b/continuedev/src/continuedev/recipes/WritePytestsRecipe/main.py index a19caf8b..688f44c3 100644 --- a/continuedev/src/continuedev/recipes/WritePytestsRecipe/main.py +++ b/continuedev/src/continuedev/recipes/WritePytestsRecipe/main.py @@ -9,6 +9,9 @@ class WritePytestsRecipe(Step): for_filepath: Union[str, None] = None user_input: str = "Write unit tests for this file." + async def describe(self, models): + return f"Writing unit tests for {self.for_filepath}" + async def run(self, sdk: ContinueSDK): if self.for_filepath is None: self.for_filepath = (await sdk.ide.getOpenFiles())[0] diff --git a/docs/docs/walkthroughs/create-a-recipe.md b/docs/docs/walkthroughs/create-a-recipe.md index 3b80df8a..5d80d083 100644 --- a/docs/docs/walkthroughs/create-a-recipe.md +++ b/docs/docs/walkthroughs/create-a-recipe.md @@ -93,5 +93,5 @@ class SetUpVenvStep(Step): if os == "Windows": await sdk.run("python -m venv env; .\\env\\Scripts\\activate") else: - await sdk.run("python3 -m venv env && source env/bin/activate") # MacOS and Linux + await sdk.run("python3 -m venv .env && source .env/bin/activate") # MacOS and Linux ``` diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx index 1b7c60e6..46d8c4d3 100644 --- a/extension/react-app/src/components/ComboBox.tsx +++ b/extension/react-app/src/components/ComboBox.tsx @@ -105,7 +105,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {