From b5705c1d5fc0103b7ab849855cd8b90041551ff1 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 9 Jan 2025 10:10:24 +0000 Subject: [PATCH 01/10] docs/getDetails --- core/core.ts | 3 + core/index.d.ts | 8 + core/indexing/docs/DocsService.ts | 108 ++++++++--- core/protocol/core.ts | 3 +- core/protocol/passThrough.ts | 1 + .../toolWindow/ContinueBrowser.kt | 1 + .../components/indexing/DocsDetailsDialog.tsx | 176 ++++++++++++++++++ .../indexing/DocsIndexingStatus.tsx | 26 ++- gui/src/index.css | 10 + 9 files changed, 305 insertions(+), 31 deletions(-) create mode 100644 gui/src/components/indexing/DocsDetailsDialog.tsx diff --git a/core/core.ts b/core/core.ts index af05f7d96..8122636dd 100644 --- a/core/core.ts +++ b/core/core.ts @@ -843,6 +843,9 @@ export class Core { on("docs/initStatuses", async (msg) => { void this.docsService.initStatuses(); }); + on("docs/getDetails", async (msg) => { + return await this.docsService.getDetails(msg.data.startUrl); + }); // on("didChangeSelectedProfile", (msg) => { diff --git a/core/index.d.ts b/core/index.d.ts index e4f3ff143..bbdc02658 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -231,6 +231,14 @@ export interface SiteIndexingConfig { maxDepth?: number; } +export interface DocsIndexingDetails { + startUrl: string; + config: SiteIndexingConfig; + indexingStatus: IndexingStatus | undefined; + chunks: Chunk[]; + isPreIndexedDoc: boolean; +} + export interface IContextProvider { get description(): ContextProviderDescription; diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 1f56de495..0bed5571e 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -5,6 +5,7 @@ import lancedb, { Connection } from "vectordb"; import { Chunk, ContinueConfig, + DocsIndexingDetails, IDE, IdeInfo, ILLM, @@ -322,7 +323,7 @@ export default class DocsService { } // Returns true if startUrl has been indexed with current embeddingsProvider - async hasMetadata(startUrl: string): Promise> { + async hasMetadata(startUrl: string): Promise { const db = await this.getOrCreateSqliteDb(); const title = await db.get( `SELECT title FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`, @@ -660,6 +661,64 @@ export default class DocsService { return await this.retrieveChunks(startUrl, vector, nRetrieve); } + private lanceDBRowToChunk(row: LanceDbDocsRow): Chunk { + return { + digest: row.path, + filepath: row.path, + startLine: row.startline, + endLine: row.endline, + index: 0, + content: row.content, + otherMetadata: { + title: row.title, + }, + }; + } + async getDetails(startUrl: string): Promise { + const db = await this.getOrCreateSqliteDb(); + + try { + const preIndexedDoc = preIndexedDocs[startUrl]; + const isPreIndexedDoc = !!preIndexedDoc; + + const embeddingsProvider = + await this.getEmbeddingsProvider(isPreIndexedDoc); + const result = await db.get( + `SELECT startUrl, title, favicon FROM ${DocsService.sqlitebTableName} WHERE startUrl = ? AND embeddingsProviderId = ?`, + startUrl, + embeddingsProvider.embeddingId, + ); + + if (!result) { + throw new Error(`${startUrl} not found in sqlite`); + } + const siteIndexingConfig: SiteIndexingConfig = { + startUrl, + faviconUrl: result.favicon, + title: result.title, + }; + + const table = await this.getOrCreateLanceTable({ + initializationVector: [], + isPreIndexedDoc, + }); + const rows = (await table + .filter(`starturl = '${startUrl}'`) + .limit(1000) + .execute()) as LanceDbDocsRow[]; + + return { + startUrl, + config: siteIndexingConfig, + indexingStatus: this.statuses.get(startUrl), + chunks: rows.map(this.lanceDBRowToChunk), + isPreIndexedDoc, + }; + } catch (e) { + console.warn("Error getting details", e); + throw e; + } + } // This is split into its own function so that it can be recursive // in the case of fetching preindexed docs from s3 async retrieveChunks( @@ -703,17 +762,7 @@ export default class DocsService { }); } - return docs.map((doc) => ({ - digest: doc.path, - filepath: doc.path, - startLine: doc.startline, - endLine: doc.endline, - index: 0, - content: doc.content, - otherMetadata: { - title: doc.title, - }, - })); + return docs.map(this.lanceDBRowToChunk); } // SQLITE DB @@ -769,7 +818,7 @@ export default class DocsService { private async syncDocs( oldConfig: ContinueConfig | undefined, newConfig: ContinueConfig, - reindex: boolean, + forceReindex: boolean, ) { try { this.isSyncing = true; @@ -812,20 +861,25 @@ export default class DocsService { ) { changedDocs.push(doc); } else { - // if get's here, not changed, no update needed, mark as complete - this.handleStatusUpdate({ - type: "docs", - id: doc.startUrl, - embeddingsProviderId: this.config.embeddingsProvider.embeddingId, - isReindexing: false, - title: doc.title, - debugInfo: "Config sync: not changed", - icon: doc.faviconUrl, - url: doc.startUrl, - progress: 1, - description: "Complete", - status: "complete", - }); + if (forceReindex) { + changedDocs.push(doc); + } else { + // if get's here, not changed, no update needed, mark as complete + this.handleStatusUpdate({ + type: "docs", + id: doc.startUrl, + embeddingsProviderId: + this.config.embeddingsProvider.embeddingId, + isReindexing: false, + title: doc.title, + debugInfo: "Config sync: not changed", + icon: doc.faviconUrl, + url: doc.startUrl, + progress: 1, + description: "Complete", + status: "complete", + }); + } } } else { newDocs.push(doc); diff --git a/core/protocol/core.ts b/core/protocol/core.ts index 9495dc3b2..63474514f 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -9,6 +9,7 @@ import type { ContextProviderWithParams, ContextSubmenuItem, DiffLine, + DocsIndexingDetails, FileSymbolMap, IdeSettings, LLMFullCompletionOptions, @@ -201,7 +202,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { "indexing/setPaused": [{ type: string; id: string; paused: boolean }, void]; "docs/getSuggestedDocs": [undefined, void]; "docs/initStatuses": [undefined, void]; - + "docs/getDetails": [{ startUrl: string }, DocsIndexingDetails]; addAutocompleteModel: [{ model: ModelDescription }, void]; "profiles/switch": [{ id: string }, undefined]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 756b3db54..c7f6822bf 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -52,6 +52,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "indexing/setPaused", "docs/getSuggestedDocs", "docs/initStatuses", + "docs/getDetails", // "completeOnboarding", "addAutocompleteModel", diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt index 5523bdeff..c670ec862 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinueBrowser.kt @@ -62,6 +62,7 @@ class ContinueBrowser(val project: Project, url: String) { "indexing/setPaused", "docs/getSuggestedDocs", "docs/initStatuses", + "docs/getDetails", // "completeOnboarding", "addAutocompleteModel", diff --git a/gui/src/components/indexing/DocsDetailsDialog.tsx b/gui/src/components/indexing/DocsDetailsDialog.tsx new file mode 100644 index 000000000..7b824291a --- /dev/null +++ b/gui/src/components/indexing/DocsDetailsDialog.tsx @@ -0,0 +1,176 @@ +import { + CheckIcon, + InformationCircleIcon, + PencilIcon, + PlusIcon, +} from "@heroicons/react/24/outline"; +import { + DocsIndexingDetails, + IndexingStatus, + PackageDocsResult, + SiteIndexingConfig, +} from "core"; +import preIndexedDocs from "core/indexing/docs/preIndexedDocs"; +import { usePostHog } from "posthog-js/react"; +import { + useCallback, + useContext, + useEffect, + useLayoutEffect, + useMemo, + useRef, + useState, +} from "react"; +import { useDispatch } from "react-redux"; +import { Input, SecondaryButton } from ".."; +import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { useAppSelector } from "../../redux/hooks"; +import { updateConfig } from "../../redux/slices/configSlice"; +import { updateIndexingStatus } from "../../redux/slices/indexingSlice"; +import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; +import FileIcon from "../FileIcon"; +import { ToolTip } from "../gui/Tooltip"; +import DocsIndexingPeeks from "../indexing/DocsIndexingPeeks"; +import { Tooltip } from "react-tooltip"; + +interface DocsDetailsDialogProps { + startUrl: string; +} +function DocsDetailsDialog({ startUrl }: DocsDetailsDialogProps) { + const config = useAppSelector((store) => store.config.config); + const posthog = usePostHog(); + const dispatch = useDispatch(); + + const ideMessenger = useContext(IdeMessengerContext); + + const closeDialog = () => { + dispatch(setShowDialog(false)); + dispatch(setDialogMessage(undefined)); + }; + + const [isLoading, setIsLoading] = useState(false); + const [isError, setIsError] = useState(false); + const [data, setData] = useState(undefined); + + const fetchData = useCallback(async () => { + setIsLoading(true); + setIsError(false); + + try { + const response = await ideMessenger.request("docs/getDetails", { + startUrl, + }); + if (response.status === "error") { + throw new Error(response.error); + } + setData(response.content); + } catch (error) { + setIsError(true); + } finally { + setIsLoading(false); + } + }, []); + + useEffect(() => { + fetchData(); + }, []); + + let comp =
Loading...
; + if (!isLoading) { + if (isError) { + comp = ( +
+
Error fetching docs details
+ Try again +
+ ); + } + if (data) { + comp = ( +
+

{`Title: ${data.config.title}`}

+

{`Pre-indexed doc: ${data.isPreIndexedDoc}`}

+ {!data.chunks?.length ? ( +
No article chunks
+ ) : ( +
+ + + + + + + + + {data.chunks.map((chunk, i) => { + const contentToolTipId = `docs-content-peek-${i}`; + const urlToolTipId = `docs-url-peek-${i}`; + return ( + <> + + + + + + {chunk.filepath} + + + {chunk.content} + + + ); + })} + +
FilepathContent
+ + {chunk.filepath} + + + + {chunk.content} + +
+
+ )} +
+ ); + } + } + + return ( +
+

Docs index

+

{ + e.stopPropagation(); + ideMessenger.post("openUrl", startUrl); + }} + > + {startUrl} +

+ {comp} +
+ Close +
+
+ ); +} + +export default DocsDetailsDialog; diff --git a/gui/src/components/indexing/DocsIndexingStatus.tsx b/gui/src/components/indexing/DocsIndexingStatus.tsx index 9fbd0f9fe..125bb202b 100644 --- a/gui/src/components/indexing/DocsIndexingStatus.tsx +++ b/gui/src/components/indexing/DocsIndexingStatus.tsx @@ -6,6 +6,7 @@ import { ArrowTopRightOnSquareIcon, CheckCircleIcon, ExclamationTriangleIcon, + EyeIcon, PauseCircleIcon, TrashIcon, } from "@heroicons/react/24/outline"; @@ -13,6 +14,7 @@ import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { updateIndexingStatus } from "../../redux/slices/indexingSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import ConfirmationDialog from "../dialogs/ConfirmationDialog"; +import DocsDetailsDialog from "./DocsDetailsDialog"; interface IndexingStatusViewerProps { docConfig: SiteIndexingConfig; @@ -173,9 +175,27 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { }[status?.status]} - - {status?.description} - +
+ + {status?.description} + + {process.env.NODE_ENV === "development" && + status?.status === "complete" ? ( + { + dispatch(setShowDialog(true)); + dispatch( + setDialogMessage( + , + ), + ); + }} + > + Add Docs + + ) : null} +
); diff --git a/gui/src/index.css b/gui/src/index.css index ba8454b7b..93ccd384f 100644 --- a/gui/src/index.css +++ b/gui/src/index.css @@ -92,3 +92,13 @@ body { -webkit-line-clamp: 1; -webkit-box-orient: vertical; } + +.truncate-start { + display: inline-block; + vertical-align: middle; + overflow: hidden; + white-space: nowrap; + text-overflow: ellipsis; + direction: rtl; + width: 100%; +} From 8a71cc603288f7badb4b82521c19fc22b2d30165 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 9 Jan 2025 11:41:52 +0000 Subject: [PATCH 02/10] docs crawler logging --- core/context/providers/DocsContextProvider.ts | 1 + core/indexing/docs/DocsCrawler.ts | 15 +++++++++------ gui/src/components/mainInput/resolveInput.ts | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index 9ee50c256..0d296c71d 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -88,6 +88,7 @@ class DocsContextProvider extends BaseContextProvider { } await docsService.isInitialized; + console.log("DOCS REQUEST", extras.fullInput, query); // Get chunks let chunks = await docsService.retrieveChunksFromQuery( extras.fullInput, // confusing: fullInput = the query, query = startUrl in this case diff --git a/core/indexing/docs/DocsCrawler.ts b/core/indexing/docs/DocsCrawler.ts index 8854d8e87..d8a13e80f 100644 --- a/core/indexing/docs/DocsCrawler.ts +++ b/core/indexing/docs/DocsCrawler.ts @@ -39,11 +39,13 @@ class DocsCrawler { maxRequestsPerCrawl: number = this.MAX_REQUESTS_PER_CRAWL, ): AsyncGenerator { if (startUrl.host === this.GITHUB_HOST) { + console.log("GITHUB DETECTED: Using Github"); yield* new GitHubCrawler(startUrl).crawl(); return; } try { + console.log(`Crawling ${startUrl.toString()}: Trying default crawler`); const pageData = await new DefaultCrawler(startUrl).crawl(); if (pageData.length > 0) { yield* pageData; @@ -54,9 +56,11 @@ class DocsCrawler { } if (this.shouldUseChromium()) { + console.log(`Crawling ${startUrl.toString()}: Trying chromium crawler`); yield* new ChromiumCrawler(startUrl, maxRequestsPerCrawl).crawl(); } else { let didCrawlSinglePage = false; + console.log(`Crawling ${startUrl.toString()}: Trying cheerio crawler`); for await (const pageData of new CheerioCrawler( startUrl, @@ -73,6 +77,10 @@ class DocsCrawler { this.chromiumInstaller.shouldProposeUseChromiumOnCrawlFailure(); if (shouldProposeUseChromium) { + console.log( + `Crawling ${startUrl.toString()}: Cheerio failed: proposing chromium crawler`, + ); + const didInstall = await this.chromiumInstaller.proposeAndAttemptInstall( startUrl.toString(), @@ -92,9 +100,4 @@ class DocsCrawler { } export default DocsCrawler; -export { - CheerioCrawler, - ChromiumCrawler, - ChromiumInstaller, - GitHubCrawler, -}; +export { CheerioCrawler, ChromiumCrawler, ChromiumInstaller, GitHubCrawler }; diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 535a3074f..1707dfe21 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -128,7 +128,9 @@ async function resolveEditorContent({ selectedCode, selectedModelTitle, }); + console.log(item, stripImages(parts)); if (result.status === "success") { + console.log("SUCCESS", result); const resolvedItems = result.content; contextItems.push(...resolvedItems); for (const resolvedItem of resolvedItems) { @@ -238,7 +240,7 @@ function resolveParagraph( export function hasSlashCommandOrContextProvider( editorState: JSONContent, ): boolean { - if (!editorState.content) { + if (!editorState?.content) { return false; } From d6051f307c07835b6e9270a09a6eb1db13a927bf Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 9 Jan 2025 16:34:37 -0800 Subject: [PATCH 03/10] minor mentionlist updates --- core/context/providers/DocsContextProvider.ts | 6 ++++-- gui/src/components/mainInput/AddCodeToEditExtension.ts | 2 +- gui/src/components/mainInput/MentionExtension.ts | 3 ++- gui/src/components/mainInput/resolveInput.ts | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index 0d296c71d..d014b4b9a 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -20,6 +20,7 @@ class DocsContextProvider extends BaseContextProvider { displayTitle: "Docs", description: "Type to search docs", type: "submenu", + renderInlineAs: "", }; constructor(options: any) { @@ -80,6 +81,8 @@ class DocsContextProvider extends BaseContextProvider { query: string, extras: ContextProviderExtras, ): Promise { + const nRetrieve = this.options?.nRetrieve ?? DocsContextProvider.nRetrieve; + // Get docs service const docsService = DocsService.getSingleton(); if (!docsService) { @@ -88,12 +91,11 @@ class DocsContextProvider extends BaseContextProvider { } await docsService.isInitialized; - console.log("DOCS REQUEST", extras.fullInput, query); // Get chunks let chunks = await docsService.retrieveChunksFromQuery( extras.fullInput, // confusing: fullInput = the query, query = startUrl in this case query, - this.options?.nRetrieve ?? DocsContextProvider.nRetrieve, + nRetrieve, ); if (!chunks?.length) { return []; diff --git a/gui/src/components/mainInput/AddCodeToEditExtension.ts b/gui/src/components/mainInput/AddCodeToEditExtension.ts index 795b7a2e4..f633c342b 100644 --- a/gui/src/components/mainInput/AddCodeToEditExtension.ts +++ b/gui/src/components/mainInput/AddCodeToEditExtension.ts @@ -89,7 +89,7 @@ export const AddCodeToEdit = Node.create({ default: null, parseHTML: (element) => element.getAttribute("data-renderInlineAs"), renderHTML: (attributes) => { - if (!attributes.renderInlineAs) { + if (typeof attributes.renderInlineAs !== "string") { return {}; } diff --git a/gui/src/components/mainInput/MentionExtension.ts b/gui/src/components/mainInput/MentionExtension.ts index 71d282d46..b17f2ee76 100644 --- a/gui/src/components/mainInput/MentionExtension.ts +++ b/gui/src/components/mainInput/MentionExtension.ts @@ -31,6 +31,7 @@ export const Mention = Node.create({ char: "@", pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { + console.log(props); // increase range.to by one when the next node is of type "text" // and starts with a space character const nodeAfter = editor.view.state.selection.$to.nodeAfter; @@ -116,7 +117,7 @@ export const Mention = Node.create({ default: null, parseHTML: (element) => element.getAttribute("data-renderInlineAs"), renderHTML: (attributes) => { - if (!attributes.renderInlineAs) { + if (typeof attributes.renderInlineAs !== "string") { return {}; } diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 1707dfe21..ae1a97cea 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -52,7 +52,7 @@ async function resolveEditorContent({ for (const p of editorState.content) { if (p.type === "paragraph") { const [text, ctxItems, foundSlashCommand] = resolveParagraph(p); - + console.log("PARAGRAPH RESOLVE", ctxItems); // Only take the first slash command\ if (foundSlashCommand && typeof slashCommand === "undefined") { slashCommand = foundSlashCommand; @@ -128,9 +128,7 @@ async function resolveEditorContent({ selectedCode, selectedModelTitle, }); - console.log(item, stripImages(parts)); if (result.status === "success") { - console.log("SUCCESS", result); const resolvedItems = result.content; contextItems.push(...resolvedItems); for (const resolvedItem of resolvedItems) { @@ -139,6 +137,7 @@ async function resolveEditorContent({ } } + console.log(stripImages(parts), contextItems); // cmd+enter to use codebase if (modifiers.useCodebase) { const result = await ideMessenger.request("context/getContextItems", { @@ -219,6 +218,7 @@ function resolveParagraph( if (child.type === "text") { text += text === "" ? child.text?.trimStart() : child.text; } else if (child.type === "mention") { + console.log("CHILD", child); text += typeof child.attrs?.renderInlineAs === "string" ? child.attrs.renderInlineAs From fe231a23a31e4d6f3f2b18f2554e17e9c21f27b2 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Tue, 14 Jan 2025 18:36:23 -0800 Subject: [PATCH 04/10] replace trash context provider icon --- gui/src/components/mainInput/MentionList.tsx | 537 +++++++++--------- gui/src/components/mainInput/getSuggestion.ts | 2 +- 2 files changed, 272 insertions(+), 267 deletions(-) diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index aae963779..194f7415e 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -71,6 +71,7 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = { debugger: BugAntIcon, os: CpuChipIcon, tree: Bars3BottomLeftIcon, + trash: TrashIcon, "prompt-files": DocumentTextIcon, "repo-map": FolderIcon, "/clear": TrashIcon, @@ -189,294 +190,298 @@ interface MentionListProps { onClose: () => void; } -const MentionList = forwardRef((props: MentionListProps, ref) => { - const dispatch = useDispatch(); +export const MentionList = forwardRef( + (props: MentionListProps, ref) => { + const dispatch = useDispatch(); - const ideMessenger = useContext(IdeMessengerContext); + const ideMessenger = useContext(IdeMessengerContext); - const [selectedIndex, setSelectedIndex] = useState(0); + const [selectedIndex, setSelectedIndex] = useState(0); - const [subMenuTitle, setSubMenuTitle] = useState( - undefined, - ); - const [querySubmenuItem, setQuerySubmenuItem] = useState< - ComboBoxItem | undefined - >(undefined); + const [subMenuTitle, setSubMenuTitle] = useState( + undefined, + ); + const [querySubmenuItem, setQuerySubmenuItem] = useState< + ComboBoxItem | undefined + >(undefined); - const [allItems, setAllItems] = useState([]); + const [allItems, setAllItems] = useState([]); - useEffect(() => { - const items = [...props.items]; - if (subMenuTitle === "Type to search docs") { - items.push({ - title: "Add Docs", - type: "action", - action: () => { - dispatch(setShowDialog(true)); - dispatch(setDialogMessage()); + useEffect(() => { + const items = [...props.items]; + if (subMenuTitle === "Type to search docs") { + items.push({ + title: "Add Docs", + type: "action", + action: () => { + dispatch(setShowDialog(true)); + dispatch(setDialogMessage()); - // Delete back to last '@' - const { tr } = props.editor.view.state; - const text = tr.doc.textBetween(0, tr.selection.from); - const start = text.lastIndexOf("@"); - props.editor.view.dispatch( - tr.delete(start, tr.selection.from).scrollIntoView(), - ); - }, - description: "Add a new documentation source", - }); - } else if (subMenuTitle === ".prompt files") { - items.push({ - title: "New .prompt file", - type: "action", - action: () => { - ideMessenger.post("config/newPromptFile", undefined); - const { tr } = props.editor.view.state; - const text = tr.doc.textBetween(0, tr.selection.from); - const start = text.lastIndexOf("@"); - if (start !== -1) { + // Delete back to last '@' + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const start = text.lastIndexOf("@"); props.editor.view.dispatch( tr.delete(start, tr.selection.from).scrollIntoView(), ); - } - props.onClose(); // Escape the mention list after creating a new prompt file - }, - description: "Create a new .prompt file", + }, + description: "Add a new documentation source", + }); + } else if (subMenuTitle === ".prompt files") { + items.push({ + title: "New .prompt file", + type: "action", + action: () => { + ideMessenger.post("config/newPromptFile", undefined); + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const start = text.lastIndexOf("@"); + if (start !== -1) { + props.editor.view.dispatch( + tr.delete(start, tr.selection.from).scrollIntoView(), + ); + } + props.onClose(); // Escape the mention list after creating a new prompt file + }, + description: "Create a new .prompt file", + }); + } + + setAllItems(items); + }, [subMenuTitle, props.items, props.editor]); + + const queryInputRef = useRef(null); + + useEffect(() => { + if (queryInputRef.current) { + queryInputRef.current.focus(); + } + }, [querySubmenuItem]); + + const selectItem = (index: number) => { + const item = allItems[index]; + + if (item.type === "action" && item.action) { + item.action(); + return; + } + + if ( + item.type === "contextProvider" && + item.contextProvider?.type === "submenu" + ) { + setSubMenuTitle(item.description); + if (item.id) { + props.enterSubmenu?.(props.editor, item.id); + } + return; + } + + if (item.contextProvider?.type === "query") { + // update editor to complete context provider title + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const partialText = text.slice(text.lastIndexOf("@") + 1); + const remainingText = item.title.slice(partialText.length); + props.editor.view.dispatch( + tr.insertText(remainingText, tr.selection.from), + ); + + setSubMenuTitle(item.description); + setQuerySubmenuItem(item); + return; + } + + if (item) { + props.command({ ...item, itemType: item.type }); + } + }; + + const totalItems = allItems.length; + + const itemRefs = useRef>([]); + + const upHandler = () => { + setSelectedIndex((prevIndex) => { + const newIndex = prevIndex - 1 >= 0 ? prevIndex - 1 : 0; + itemRefs.current[newIndex]?.scrollIntoView({ + behavior: "instant" as ScrollBehavior, + block: "nearest", + }); + return newIndex; }); - } + }; - setAllItems(items); - }, [subMenuTitle, props.items, props.editor]); - - const queryInputRef = useRef(null); - - useEffect(() => { - if (queryInputRef.current) { - queryInputRef.current.focus(); - } - }, [querySubmenuItem]); - - const selectItem = (index: number) => { - const item = allItems[index]; - - if (item.type === "action" && item.action) { - item.action(); - return; - } - - if ( - item.type === "contextProvider" && - item.contextProvider?.type === "submenu" - ) { - setSubMenuTitle(item.description); - if (item.id) { - props.enterSubmenu?.(props.editor, item.id); - } - return; - } - - if (item.contextProvider?.type === "query") { - // update editor to complete context provider title - const { tr } = props.editor.view.state; - const text = tr.doc.textBetween(0, tr.selection.from); - const partialText = text.slice(text.lastIndexOf("@") + 1); - const remainingText = item.title.slice(partialText.length); - props.editor.view.dispatch( - tr.insertText(remainingText, tr.selection.from), - ); - - setSubMenuTitle(item.description); - setQuerySubmenuItem(item); - return; - } - - if (item) { - props.command({ ...item, itemType: item.type }); - } - }; - - const totalItems = allItems.length; - - const itemRefs = useRef>([]); - - const upHandler = () => { - setSelectedIndex((prevIndex) => { - const newIndex = prevIndex - 1 >= 0 ? prevIndex - 1 : 0; - itemRefs.current[newIndex]?.scrollIntoView({ - behavior: "instant" as ScrollBehavior, - block: "nearest", + const downHandler = () => { + setSelectedIndex((prevIndex) => { + const newIndex = prevIndex + 1 < totalItems ? prevIndex + 1 : prevIndex; + itemRefs.current[newIndex]?.scrollIntoView({ + behavior: "instant" as ScrollBehavior, + block: "nearest", + }); + return newIndex; }); - return newIndex; - }); - }; + }; - const downHandler = () => { - setSelectedIndex((prevIndex) => { - const newIndex = prevIndex + 1 < totalItems ? prevIndex + 1 : prevIndex; - itemRefs.current[newIndex]?.scrollIntoView({ - behavior: "instant" as ScrollBehavior, - block: "nearest", - }); - return newIndex; - }); - }; + const enterHandler = () => { + selectItem(selectedIndex); + }; - const enterHandler = () => { - selectItem(selectedIndex); - }; + useEffect(() => setSelectedIndex(0), [allItems]); - useEffect(() => setSelectedIndex(0), [allItems]); - - useImperativeHandle(ref, () => ({ - onKeyDown: ({ event }: { event: KeyboardEvent }) => { - if (event.key === "ArrowUp") { - upHandler(); - return true; - } - - if (event.key === "ArrowDown") { - downHandler(); - return true; - } - - if (event.key === "Enter" || event.key === "Tab") { - enterHandler(); - event.stopPropagation(); - event.preventDefault(); - return true; - } - - if (event.key === "Escape") { - event.preventDefault(); - event.stopPropagation(); - return true; - } - - if (event.key === " ") { - if (allItems.length === 1) { - enterHandler(); + useImperativeHandle(ref, () => ({ + onKeyDown: ({ event }: { event: KeyboardEvent }) => { + if (event.key === "ArrowUp") { + upHandler(); return true; } - } - return false; - }, - })); + if (event.key === "ArrowDown") { + downHandler(); + return true; + } - const showFileIconForItem = (item: ComboBoxItem) => { - return ["file", "code"].includes(item.type); - }; + if (event.key === "Enter" || event.key === "Tab") { + enterHandler(); + event.stopPropagation(); + event.preventDefault(); + return true; + } - useEffect(() => { - itemRefs.current = itemRefs.current.slice(0, allItems.length); - }, [allItems]); + if (event.key === "Escape") { + event.preventDefault(); + event.stopPropagation(); + return true; + } - return ( - - {querySubmenuItem ? ( - { - if (!queryInputRef.current) { - return; - } - if (e.key === "Enter") { - if (e.shiftKey) { - queryInputRef.current.innerText += "\n"; - } else { - props.command({ - ...querySubmenuItem, - itemType: querySubmenuItem.type, - query: queryInputRef.current.value, - label: `${querySubmenuItem.label}: ${queryInputRef.current.value}`, - }); + if (event.key === " ") { + if (allItems.length === 1) { + enterHandler(); + return true; + } + } + + return false; + }, + })); + + const showFileIconForItem = (item: ComboBoxItem) => { + return ["file", "code"].includes(item.type); + }; + + useEffect(() => { + itemRefs.current = itemRefs.current.slice(0, allItems.length); + }, [allItems]); + + return ( + + {querySubmenuItem ? ( + { + if (!queryInputRef.current) { + return; } - } else if (e.key === "Escape") { - setQuerySubmenuItem(undefined); - setSubMenuTitle(undefined); - } - }} - /> - ) : ( - <> - {subMenuTitle && {subMenuTitle}} - {allItems.length ? ( - allItems.map((item, index) => ( - (itemRefs.current[index] = el)} - className={`item ${ - index === selectedIndex ? "is-selected" : "" - }`} - key={index} - onClick={() => selectItem(index)} - onMouseEnter={() => setSelectedIndex(index)} - > - -
- {showFileIconForItem(item) && ( - - )} - {!showFileIconForItem(item) && ( - <> - - - )} - {item.title} - {" "} -
- - {item.description} - {item.type === "contextProvider" && - item.contextProvider?.type === "submenu" && ( - + ) : ( + <> + {subMenuTitle && {subMenuTitle}} + {allItems.length ? ( + allItems.map((item, index) => ( + (itemRefs.current[index] = el)} + className={`item ${ + index === selectedIndex ? "is-selected" : "" + }`} + key={index} + onClick={() => selectItem(index)} + onMouseEnter={() => setSelectedIndex(index)} + > + +
+ {showFileIconForItem(item) && ( + )} - {item.subActions?.map((subAction) => { - const Icon = ICONS_FOR_DROPDOWN[subAction.icon]; - return ( - { - subAction.action(item); - e.stopPropagation(); - e.preventDefault(); - props.onClose(); - }} - text={undefined} - > - - - ); - })} + {!showFileIconForItem(item) && ( + <> + + + )} + {item.title} + {" "} +
+ + {item.description} + {item.type === "contextProvider" && + item.contextProvider?.type === "submenu" && ( + + )} + {item.subActions?.map((subAction) => { + const Icon = getIconFromDropdownItem( + subAction.icon, + "action", + ); + return ( + { + subAction.action(item); + e.stopPropagation(); + e.preventDefault(); + props.onClose(); + }} + text={undefined} + > + + + ); + })} +
-
-
- )) - ) : ( - No results - )} - {/* */} - - )} -
- ); -}); -export default MentionList; + + )) + ) : ( + No results + )} + {/* */} + + )} +
+ ); + }, +); diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index ecc7b835e..4d3590c19 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -7,7 +7,7 @@ import { import { MutableRefObject } from "react"; import tippy from "tippy.js"; import { IIdeMessenger } from "../../context/IdeMessenger"; -import MentionList from "./MentionList"; +import { MentionList } from "./MentionList"; import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types"; import { TIPPY_DIV_ID } from "./TipTapEditor"; From 8c49bd8e848fe85c72e058fa660e788c452add8d Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 15 Jan 2025 08:50:38 -0800 Subject: [PATCH 05/10] docs comment --- core/context/providers/DocsContextProvider.ts | 5 ++++- core/indexing/docs/crawlers/GithubCrawler.test.ts | 0 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 core/indexing/docs/crawlers/GithubCrawler.test.ts diff --git a/core/context/providers/DocsContextProvider.ts b/core/context/providers/DocsContextProvider.ts index dcc5000b7..5d79f989f 100644 --- a/core/context/providers/DocsContextProvider.ts +++ b/core/context/providers/DocsContextProvider.ts @@ -20,7 +20,10 @@ class DocsContextProvider extends BaseContextProvider { displayTitle: "Docs", description: "Type to search docs", type: "submenu", - renderInlineAs: "", + // Todo: consider a different renderInline so that when multiple docs are referenced in one message, + // Or the doc has an odd name unrelated to the content + // The name of the doc itself doesn't skew the embedding results + // renderInlineAs: "", }; constructor(options: any) { diff --git a/core/indexing/docs/crawlers/GithubCrawler.test.ts b/core/indexing/docs/crawlers/GithubCrawler.test.ts new file mode 100644 index 000000000..e69de29bb From c837378c2ef591cd0ef3da1b4bede3141b36d535 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 15 Jan 2025 09:07:53 -0800 Subject: [PATCH 06/10] cleanup --- core/indexing/docs/DocsCrawler.ts | 8 -------- core/indexing/docs/crawlers/GithubCrawler.test.ts | 0 gui/src/components/mainInput/MentionExtension.ts | 1 - gui/src/components/mainInput/resolveInput.ts | 3 --- 4 files changed, 12 deletions(-) delete mode 100644 core/indexing/docs/crawlers/GithubCrawler.test.ts diff --git a/core/indexing/docs/DocsCrawler.ts b/core/indexing/docs/DocsCrawler.ts index d8a13e80f..24f937019 100644 --- a/core/indexing/docs/DocsCrawler.ts +++ b/core/indexing/docs/DocsCrawler.ts @@ -39,13 +39,11 @@ class DocsCrawler { maxRequestsPerCrawl: number = this.MAX_REQUESTS_PER_CRAWL, ): AsyncGenerator { if (startUrl.host === this.GITHUB_HOST) { - console.log("GITHUB DETECTED: Using Github"); yield* new GitHubCrawler(startUrl).crawl(); return; } try { - console.log(`Crawling ${startUrl.toString()}: Trying default crawler`); const pageData = await new DefaultCrawler(startUrl).crawl(); if (pageData.length > 0) { yield* pageData; @@ -56,11 +54,9 @@ class DocsCrawler { } if (this.shouldUseChromium()) { - console.log(`Crawling ${startUrl.toString()}: Trying chromium crawler`); yield* new ChromiumCrawler(startUrl, maxRequestsPerCrawl).crawl(); } else { let didCrawlSinglePage = false; - console.log(`Crawling ${startUrl.toString()}: Trying cheerio crawler`); for await (const pageData of new CheerioCrawler( startUrl, @@ -77,10 +73,6 @@ class DocsCrawler { this.chromiumInstaller.shouldProposeUseChromiumOnCrawlFailure(); if (shouldProposeUseChromium) { - console.log( - `Crawling ${startUrl.toString()}: Cheerio failed: proposing chromium crawler`, - ); - const didInstall = await this.chromiumInstaller.proposeAndAttemptInstall( startUrl.toString(), diff --git a/core/indexing/docs/crawlers/GithubCrawler.test.ts b/core/indexing/docs/crawlers/GithubCrawler.test.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/gui/src/components/mainInput/MentionExtension.ts b/gui/src/components/mainInput/MentionExtension.ts index b17f2ee76..364b241ee 100644 --- a/gui/src/components/mainInput/MentionExtension.ts +++ b/gui/src/components/mainInput/MentionExtension.ts @@ -31,7 +31,6 @@ export const Mention = Node.create({ char: "@", pluginKey: MentionPluginKey, command: ({ editor, range, props }) => { - console.log(props); // increase range.to by one when the next node is of type "text" // and starts with a space character const nodeAfter = editor.view.state.selection.$to.nodeAfter; diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index ae1a97cea..c9e1b698a 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -52,7 +52,6 @@ async function resolveEditorContent({ for (const p of editorState.content) { if (p.type === "paragraph") { const [text, ctxItems, foundSlashCommand] = resolveParagraph(p); - console.log("PARAGRAPH RESOLVE", ctxItems); // Only take the first slash command\ if (foundSlashCommand && typeof slashCommand === "undefined") { slashCommand = foundSlashCommand; @@ -137,7 +136,6 @@ async function resolveEditorContent({ } } - console.log(stripImages(parts), contextItems); // cmd+enter to use codebase if (modifiers.useCodebase) { const result = await ideMessenger.request("context/getContextItems", { @@ -218,7 +216,6 @@ function resolveParagraph( if (child.type === "text") { text += text === "" ? child.text?.trimStart() : child.text; } else if (child.type === "mention") { - console.log("CHILD", child); text += typeof child.attrs?.renderInlineAs === "string" ? child.attrs.renderInlineAs From 6a93bd991362be2df2155873b453785f08bdef42 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 19 Jan 2025 22:08:13 -0800 Subject: [PATCH 07/10] fix import --- gui/src/components/mainInput/MentionList.tsx | 393 +++++++++--------- gui/src/components/mainInput/getSuggestion.ts | 2 +- 2 files changed, 203 insertions(+), 192 deletions(-) diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index 74c074b1a..530144e4a 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -71,7 +71,6 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = { debugger: BugAntIcon, os: CpuChipIcon, tree: Bars3BottomLeftIcon, - trash: TrashIcon, "prompt-files": DocumentTextIcon, "repo-map": FolderIcon, "/clear": TrashIcon, @@ -82,6 +81,7 @@ const ICONS_FOR_DROPDOWN: { [key: string]: any } = { google: GoogleIcon, "gitlab-mr": GitlabIcon, http: GlobeAltIcon, + trash: TrashIcon, }; export function getIconFromDropdownItem( @@ -190,199 +190,209 @@ interface MentionListProps { onClose: () => void; } -export const MentionList = forwardRef( - (props: MentionListProps, ref) => { - const dispatch = useDispatch(); +const MentionList = forwardRef((props: MentionListProps, ref) => { + const dispatch = useDispatch(); - const ideMessenger = useContext(IdeMessengerContext); + const ideMessenger = useContext(IdeMessengerContext); - const [selectedIndex, setSelectedIndex] = useState(0); + const [selectedIndex, setSelectedIndex] = useState(0); - const [subMenuTitle, setSubMenuTitle] = useState( - undefined, - ); - const [querySubmenuItem, setQuerySubmenuItem] = useState< - ComboBoxItem | undefined - >(undefined); + const [subMenuTitle, setSubMenuTitle] = useState( + undefined, + ); + const [querySubmenuItem, setQuerySubmenuItem] = useState< + ComboBoxItem | undefined + >(undefined); - const [allItems, setAllItems] = useState([]); + const [allItems, setAllItems] = useState([]); - useEffect(() => { - const items = [...props.items]; - if (subMenuTitle === "Type to search docs") { - items.push({ - title: "Add Docs", - type: "action", - action: () => { - dispatch(setShowDialog(true)); - dispatch(setDialogMessage()); + useEffect(() => { + const items = [...props.items]; + if (subMenuTitle === "Type to search docs") { + items.push({ + title: "Add Docs", + type: "action", + action: () => { + dispatch(setShowDialog(true)); + dispatch(setDialogMessage()); - // Delete back to last '@' - const { tr } = props.editor.view.state; - const text = tr.doc.textBetween(0, tr.selection.from); - const start = text.lastIndexOf("@"); + // Delete back to last '@' + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const start = text.lastIndexOf("@"); + props.editor.view.dispatch( + tr.delete(start, tr.selection.from).scrollIntoView(), + ); + }, + description: "Add a new documentation source", + }); + } else if (subMenuTitle === ".prompt files") { + items.push({ + title: "New .prompt file", + type: "action", + action: () => { + ideMessenger.post("config/newPromptFile", undefined); + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const start = text.lastIndexOf("@"); + if (start !== -1) { props.editor.view.dispatch( tr.delete(start, tr.selection.from).scrollIntoView(), ); - }, - description: "Add a new documentation source", - }); - } else if (subMenuTitle === ".prompt files") { - items.push({ - title: "New .prompt file", - type: "action", - action: () => { - ideMessenger.post("config/newPromptFile", undefined); - const { tr } = props.editor.view.state; - const text = tr.doc.textBetween(0, tr.selection.from); - const start = text.lastIndexOf("@"); - if (start !== -1) { - props.editor.view.dispatch( - tr.delete(start, tr.selection.from).scrollIntoView(), - ); - } - props.onClose(); // Escape the mention list after creating a new prompt file - }, - description: "Create a new .prompt file", - }); - } - - setAllItems(items); - }, [subMenuTitle, props.items, props.editor]); - - const queryInputRef = useRef(null); - - useEffect(() => { - if (queryInputRef.current) { - queryInputRef.current.focus(); - } - }, [querySubmenuItem]); - - const selectItem = (index: number) => { - const item = allItems[index]; - - if (item.type === "action" && item.action) { - item.action(); - return; - } - - if ( - item.type === "contextProvider" && - item.contextProvider?.type === "submenu" - ) { - setSubMenuTitle(item.description); - if (item.id) { - props.enterSubmenu?.(props.editor, item.id); - } - return; - } - - if (item.contextProvider?.type === "query") { - // update editor to complete context provider title - const { tr } = props.editor.view.state; - const text = tr.doc.textBetween(0, tr.selection.from); - const partialText = text.slice(text.lastIndexOf("@") + 1); - const remainingText = item.title.slice(partialText.length); - props.editor.view.dispatch( - tr.insertText(remainingText, tr.selection.from), - ); - - setSubMenuTitle(item.description); - setQuerySubmenuItem(item); - return; - } - - if (item) { - props.command({ ...item, itemType: item.type }); - } - }; - - const totalItems = allItems.length; - - const itemRefs = useRef>([]); - - const upHandler = () => { - setSelectedIndex((prevIndex) => { - const newIndex = prevIndex - 1 >= 0 ? prevIndex - 1 : 0; - itemRefs.current[newIndex]?.scrollIntoView({ - behavior: "instant" as ScrollBehavior, - block: "nearest", - }); - return newIndex; - }); - }; - - const downHandler = () => { - setSelectedIndex((prevIndex) => { - const newIndex = prevIndex + 1 < totalItems ? prevIndex + 1 : prevIndex; - itemRefs.current[newIndex]?.scrollIntoView({ - behavior: "instant" as ScrollBehavior, - block: "nearest", - }); - return newIndex; - }); - }; - - const enterHandler = () => { - selectItem(selectedIndex); - }; - - useEffect(() => setSelectedIndex(0), [allItems]); - - useImperativeHandle(ref, () => ({ - onKeyDown: ({ event }: { event: KeyboardEvent }) => { - if (event.key === "ArrowUp") { - upHandler(); - return true; - } - - if (event.key === "ArrowDown") { - downHandler(); - return true; - } - - if (event.key === "Enter" || event.key === "Tab") { - enterHandler(); - event.stopPropagation(); - event.preventDefault(); - return true; - } - - if (event.key === "Escape") { - event.preventDefault(); - event.stopPropagation(); - return true; - } - - if (event.key === " ") { - if (allItems.length === 1) { - enterHandler(); - return true; } + props.onClose(); // Escape the mention list after creating a new prompt file + }, + description: "Create a new .prompt file", + }); + } + + setAllItems(items); + }, [subMenuTitle, props.items, props.editor]); + + const queryInputRef = useRef(null); + + useEffect(() => { + if (queryInputRef.current) { + queryInputRef.current.focus(); + } + }, [querySubmenuItem]); + + const selectItem = (index: number) => { + const item = allItems[index]; + + if (item.type === "action" && item.action) { + item.action(); + return; + } + + if ( + item.type === "contextProvider" && + item.contextProvider?.type === "submenu" + ) { + setSubMenuTitle(item.description); + if (item.id) { + props.enterSubmenu?.(props.editor, item.id); + } + return; + } + + if (item.contextProvider?.type === "query") { + // update editor to complete context provider title + const { tr } = props.editor.view.state; + const text = tr.doc.textBetween(0, tr.selection.from); + const partialText = text.slice(text.lastIndexOf("@") + 1); + const remainingText = item.title.slice(partialText.length); + props.editor.view.dispatch( + tr.insertText(remainingText, tr.selection.from), + ); + + setSubMenuTitle(item.description); + setQuerySubmenuItem(item); + return; + } + + if (item) { + props.command({ ...item, itemType: item.type }); + } + }; + + const totalItems = allItems.length; + + const itemRefs = useRef>([]); + + const upHandler = () => { + setSelectedIndex((prevIndex) => { + const newIndex = prevIndex - 1 >= 0 ? prevIndex - 1 : 0; + itemRefs.current[newIndex]?.scrollIntoView({ + behavior: "instant" as ScrollBehavior, + block: "nearest", + }); + return newIndex; + }); + }; + + const downHandler = () => { + setSelectedIndex((prevIndex) => { + const newIndex = prevIndex + 1 < totalItems ? prevIndex + 1 : prevIndex; + itemRefs.current[newIndex]?.scrollIntoView({ + behavior: "instant" as ScrollBehavior, + block: "nearest", + }); + return newIndex; + }); + }; + + const enterHandler = () => { + selectItem(selectedIndex); + }; + + useEffect(() => setSelectedIndex(0), [allItems]); + + useImperativeHandle(ref, () => ({ + onKeyDown: ({ event }: { event: KeyboardEvent }) => { + if (event.key === "ArrowUp") { + upHandler(); + return true; + } + + if (event.key === "ArrowDown") { + downHandler(); + return true; + } + + if (event.key === "Enter" || event.key === "Tab") { + enterHandler(); + event.stopPropagation(); + event.preventDefault(); + return true; + } + + if (event.key === "Escape") { + event.preventDefault(); + event.stopPropagation(); + return true; + } + + if (event.key === " ") { + if (allItems.length === 1) { + enterHandler(); + return true; } + } - return false; - }, - })); + return false; + }, + })); - const showFileIconForItem = (item: ComboBoxItem) => { - return ["file", "code"].includes(item.type); - }; + const showFileIconForItem = (item: ComboBoxItem) => { + return ["file", "code"].includes(item.type); + }; - useEffect(() => { - itemRefs.current = itemRefs.current.slice(0, allItems.length); - }, [allItems]); + useEffect(() => { + itemRefs.current = itemRefs.current.slice(0, allItems.length); + }, [allItems]); - return ( - - {querySubmenuItem ? ( - { - if (!queryInputRef.current) { - return; + return ( + + {querySubmenuItem ? ( + { + if (!queryInputRef.current) { + return; + } + if (e.key === "Enter") { + if (e.shiftKey) { + queryInputRef.current.innerText += "\n"; + } else { + props.command({ + ...querySubmenuItem, + itemType: querySubmenuItem.type, + query: queryInputRef.current.value, + label: `${querySubmenuItem.label}: ${queryInputRef.current.value}`, + }); } } else if (e.key === "Escape") { setQuerySubmenuItem(undefined); @@ -462,15 +472,16 @@ export const MentionList = forwardRef( ); })} - - )) - ) : ( - No results - )} - {/* */} - - )} - - ); - }, -); + + + )) + ) : ( + No results + )} + {/* */} + + )} + + ); +}); +export default MentionList; diff --git a/gui/src/components/mainInput/getSuggestion.ts b/gui/src/components/mainInput/getSuggestion.ts index 4d3590c19..ecc7b835e 100644 --- a/gui/src/components/mainInput/getSuggestion.ts +++ b/gui/src/components/mainInput/getSuggestion.ts @@ -7,7 +7,7 @@ import { import { MutableRefObject } from "react"; import tippy from "tippy.js"; import { IIdeMessenger } from "../../context/IdeMessenger"; -import { MentionList } from "./MentionList"; +import MentionList from "./MentionList"; import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "./types"; import { TIPPY_DIV_ID } from "./TipTapEditor"; From c637b7ba3d9fc175052f5499623dfc7ec3d328d7 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Sun, 19 Jan 2025 22:17:59 -0800 Subject: [PATCH 08/10] don't persist indexing status --- gui/src/redux/store.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 4432b3be6..b1c74f34b 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -36,6 +36,7 @@ const saveSubsetFilters = [ createFilter("editModeState", []), createFilter("config", ["defaultModelTitle"]), createFilter("ui", ["toolSettings", "useTools"]), + createFilter("indexing", []), ]; const migrations: MigrationManifest = { From 412a0b78fb4466e5712f2bb49b60be85517b6e34 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 23 Jan 2025 10:47:10 -0800 Subject: [PATCH 09/10] show docs get details button on prod --- gui/src/components/indexing/DocsIndexingStatus.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gui/src/components/indexing/DocsIndexingStatus.tsx b/gui/src/components/indexing/DocsIndexingStatus.tsx index 361005ba5..fe64ae2dc 100644 --- a/gui/src/components/indexing/DocsIndexingStatus.tsx +++ b/gui/src/components/indexing/DocsIndexingStatus.tsx @@ -195,8 +195,7 @@ function DocsIndexingStatus({ docConfig }: IndexingStatusViewerProps) { {status?.description} )} - {process.env.NODE_ENV === "development" && - status?.status === "complete" ? ( + {status?.status === "complete" ? ( { From fbee4a8aece2d4fc956b748761c9893053f6de41 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 23 Jan 2025 11:11:20 -0800 Subject: [PATCH 10/10] import fix --- core/indexing/docs/DocsService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index 74f68af9b..f0d1e2f3c 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -40,7 +40,7 @@ import { SiteIndexingResults, } from "./preIndexed"; import preIndexedDocs from "./preIndexedDocs"; -import { ConfigResult } from "@continuedev/config-types"; +import { ConfigResult } from "@continuedev/config-yaml"; // Purposefully lowercase because lancedb converts export interface LanceDbDocsRow { @@ -713,8 +713,8 @@ export default class DocsService { const db = await this.getOrCreateSqliteDb(); try { - - const { isPreindexed, provider } = await this.getEmbeddingsProvider(startUrl); + const { isPreindexed, provider } = + await this.getEmbeddingsProvider(startUrl); const preIndexedDoc = preIndexedDocs[startUrl]; const isPreIndexedDoc = !!preIndexedDoc;