diff options
author | Nate Sesti <33237525+sestinj@users.noreply.github.com> | 2023-08-10 15:52:44 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-10 15:52:44 -0700 |
commit | e07dd52631b78a01402d7569dd976b2505a20f8b (patch) | |
tree | 51d20aa637a074eadd2323b30c437dbf7c04ca47 /extension/react-app | |
parent | b82e61cf8ba2be3bcda00699618a83f7c4db275e (diff) | |
parent | 7ca3bea2990d3a1c84d5a544e72827242a78361c (diff) | |
download | sncontinue-e07dd52631b78a01402d7569dd976b2505a20f8b.tar.gz sncontinue-e07dd52631b78a01402d7569dd976b2505a20f8b.tar.bz2 sncontinue-e07dd52631b78a01402d7569dd976b2505a20f8b.zip |
Merge pull request #360 from bra1nDump/fixup-search-cross-workspace-polution
Fixup search cross workspace polution
Diffstat (limited to 'extension/react-app')
-rw-r--r-- | extension/react-app/package.json | 4 | ||||
-rw-r--r-- | extension/react-app/src/App.tsx | 2 | ||||
-rw-r--r-- | extension/react-app/src/components/ComboBox.tsx | 18 | ||||
-rw-r--r-- | extension/react-app/src/redux/slices/configSlice.ts | 8 | ||||
-rw-r--r-- | extension/react-app/src/redux/store.ts | 2 |
5 files changed, 22 insertions, 12 deletions
diff --git a/extension/react-app/package.json b/extension/react-app/package.json index b4762990..38beb742 100644 --- a/extension/react-app/package.json +++ b/extension/react-app/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc && vite build --sourcemap", + "build": "tsc && vite build --sourcemap 'inline'", "preview": "vite preview" }, "dependencies": { @@ -39,4 +39,4 @@ "typescript": "^4.9.3", "vite": "^4.1.0" } -} +}
\ No newline at end of file diff --git a/extension/react-app/src/App.tsx b/extension/react-app/src/App.tsx index 879373a0..05b322ff 100644 --- a/extension/react-app/src/App.tsx +++ b/extension/react-app/src/App.tsx @@ -11,6 +11,7 @@ import { setSessionId, setVscMediaUrl, setDataSwitchOn, + setWorkspacePaths, } from "./redux/slices/configSlice"; import { setHighlightedCode } from "./redux/slices/miscSlice"; import { postVscMessage } from "./vscode"; @@ -56,6 +57,7 @@ function App() { dispatch(setSessionId(event.data.sessionId)); dispatch(setVscMediaUrl(event.data.vscMediaUrl)); dispatch(setDataSwitchOn(event.data.dataSwitchOn)); + dispatch(setWorkspacePaths(event.data.workspacePaths)); break; case "highlightedCode": dispatch(setHighlightedCode(event.data.rangeInFile)); diff --git a/extension/react-app/src/components/ComboBox.tsx b/extension/react-app/src/components/ComboBox.tsx index 472e1b14..c75f9ee6 100644 --- a/extension/react-app/src/components/ComboBox.tsx +++ b/extension/react-app/src/components/ComboBox.tsx @@ -24,7 +24,8 @@ import { setBottomMessage, setBottomMessageCloseTimeout, } from "../redux/slices/uiStateSlice"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; +import { RootStore } from "../redux/store"; const SEARCH_INDEX_NAME = "continue_context_items"; @@ -136,6 +137,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { const searchClient = new MeiliSearch({ host: "http://127.0.0.1:7700" }); const client = useContext(GUIClientContext); const dispatch = useDispatch(); + const workspacePaths = useSelector((state: RootStore) => state.config.workspacePaths); const [history, setHistory] = React.useState<string[]>([]); // The position of the current command you are typing now, so the one that will be appended to history once you press enter @@ -181,10 +183,16 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { // Get search results and return setCurrentlyInContextQuery(true); const providerAndQuery = segs[segs.length - 1] || ""; - const [provider, query] = providerAndQuery.split(" "); + // Only return context items from the current workspace - the index is currently shared between all sessions + const workspaceFilter = + workspacePaths && workspacePaths.length > 0 + ? `workspace_dir IN [ ${workspacePaths.map((path) => `"${path}"`).join(", ")} ]` + : undefined; searchClient .index(SEARCH_INDEX_NAME) - .search(providerAndQuery) + .search(providerAndQuery, { + filter: workspaceFilter, + }) .then((res) => { setItems( res.hits.map((hit) => { @@ -410,7 +418,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { // Prevent Downshift's default 'Enter' behavior. (event.nativeEvent as any).preventDownshiftDefault = true; - if (props.onEnter) props.onEnter(event); + if (props.onEnter) {props.onEnter(event);} setCurrentlyInContextQuery(false); } else if (event.key === "Tab" && items.length > 0) { downshiftProps.setInputValue(items[0].name); @@ -423,7 +431,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { ) { (event.nativeEvent as any).preventDownshiftDefault = true; } else if (event.key === "ArrowUp") { - if (positionInHistory == 0) return; + if (positionInHistory == 0) {return;} else if ( positionInHistory == history.length && (history.length === 0 || diff --git a/extension/react-app/src/redux/slices/configSlice.ts b/extension/react-app/src/redux/slices/configSlice.ts index 59c76066..9cf5402f 100644 --- a/extension/react-app/src/redux/slices/configSlice.ts +++ b/extension/react-app/src/redux/slices/configSlice.ts @@ -7,13 +7,13 @@ export const configSlice = createSlice({ apiUrl: "http://localhost:65432", } as RootStore["config"], reducers: { - setWorkspacePath: ( + setWorkspacePaths: ( state: RootStore["config"], - action: { type: string; payload: string } + action: { type: string; payload: string[] } ) => { return { ...state, - workspacePath: action.payload, + workspacePaths: action.payload, }; }, setApiUrl: ( @@ -57,7 +57,7 @@ export const configSlice = createSlice({ export const { setVscMachineId, setApiUrl, - setWorkspacePath, + setWorkspacePaths, setSessionId, setVscMediaUrl, setDataSwitchOn, diff --git a/extension/react-app/src/redux/store.ts b/extension/react-app/src/redux/store.ts index a9a45ec1..7959a067 100644 --- a/extension/react-app/src/redux/store.ts +++ b/extension/react-app/src/redux/store.ts @@ -14,7 +14,7 @@ export interface ChatMessage { export interface RootStore { config: { - workspacePath: string | undefined; + workspacePaths: string[] | undefined; apiUrl: string; vscMachineId: string | undefined; sessionId: string | undefined; |