From d2decdb80e7ca2e3876b9541f91ee48c94c0586b Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 15 Nov 2024 14:34:03 -0800 Subject: [PATCH] docs servie updates --- core/core.ts | 2 +- core/indexing/docs/DocsCrawler.ts | 2 +- core/indexing/docs/DocsService.ts | 93 +++++++++++--------- gui/src/hooks/useSetup.ts | 16 +--- gui/src/hooks/useSubmenuContextProviders.tsx | 7 +- 5 files changed, 56 insertions(+), 64 deletions(-) diff --git a/core/core.ts b/core/core.ts index 6df1482ef..dc140cf3d 100644 --- a/core/core.ts +++ b/core/core.ts @@ -688,7 +688,7 @@ export class Core { await this.refreshCodebaseIndex(dirs); }); on("index/setPaused", (msg) => { - new GlobalContext().update("indexingPaused", msg.data); + this.globalContext.update("indexingPaused", msg.data); this.indexingPauseToken.paused = msg.data; }); on("index/indexingProgressBarInitialized", async (msg) => { diff --git a/core/indexing/docs/DocsCrawler.ts b/core/indexing/docs/DocsCrawler.ts index cb9146ab5..01f0efab1 100644 --- a/core/indexing/docs/DocsCrawler.ts +++ b/core/indexing/docs/DocsCrawler.ts @@ -95,6 +95,6 @@ export default DocsCrawler; export { CheerioCrawler, ChromiumCrawler, - ChromiumInstaller as ChromiumInstaller, + ChromiumInstaller, GitHubCrawler, }; diff --git a/core/indexing/docs/DocsService.ts b/core/indexing/docs/DocsService.ts index d97b92974..2c9a01e1e 100644 --- a/core/indexing/docs/DocsService.ts +++ b/core/indexing/docs/DocsService.ts @@ -103,26 +103,6 @@ export default class DocsService { return docsService; } - async isJetBrainsAndPreIndexedDocsProvider(): Promise { - const isJetBrains = await this.isJetBrains(); - - const isPreIndexedDocsProvider = - this.config.embeddingsProvider.id === - DocsService.preIndexedDocsEmbeddingsProvider.id; - - return isJetBrains && isPreIndexedDocsProvider; - } - - /* - * Currently, we generate and host embeddings for pre-indexed docs using transformers. - * However, we don't ship transformers with the JetBrains extension. - * So, we only include pre-indexed docs in the submenu for non-JetBrains IDEs. - */ - async canUsePreindexedDocs() { - const isJetBrains = await this.isJetBrains(); - return !isJetBrains; - } - async delete(startUrl: string) { await this.deleteFromLance(startUrl); await this.deleteFromSqlite(startUrl); @@ -426,36 +406,41 @@ export default class DocsService { private async init(configHandler: ConfigHandler) { this.config = await configHandler.loadConfig(); - this.docsCrawler = new DocsCrawler(this.ide, this.config); + await this.handleConfigUpdate({config: this.config}); + configHandler.onConfigUpdate(this.handleConfigUpdate); + } - const embeddingsProvider = await this.getEmbeddingsProvider(); + private async handleConfigUpdate({config: newConfig}: {config: ContinueConfig | undefined}) { + if(newConfig){ + this.config = newConfig; + this.docsCrawler = new DocsCrawler(this.ide, this.config); - this.globalContext.update("curEmbeddingsProviderId", embeddingsProvider.id); + const embeddingsProvider = await this.getEmbeddingsProvider(); + + this.globalContext.update("curEmbeddingsProviderId", embeddingsProvider.id); - configHandler.onConfigUpdate(async ({ config: newConfig }) => { - if (newConfig) { - const oldConfig = this.config; + const oldConfig = this.config; - // Need to update class property for config at the beginning of this callback - // to ensure downstream methods have access to the latest config. - this.config = newConfig; + // Need to update class property for config at the beginning of this callback + // to ensure downstream methods have access to the latest config. + this.config = newConfig; - if (oldConfig.docs !== newConfig.docs) { - await this.syncConfigAndSqlite(); - } - - const shouldReindex = - await this.shouldReindexDocsOnNewEmbeddingsProvider( - newConfig.embeddingsProvider.id, - ); - - if (shouldReindex) { - await this.reindexDocsOnNewEmbeddingsProvider( - newConfig.embeddingsProvider, - ); - } + if (oldConfig.docs !== newConfig.docs) { + await this.syncConfigAndSqlite(); } - }); + + const shouldReindex = + await this.shouldReindexDocsOnNewEmbeddingsProvider( + newConfig.embeddingsProvider.id, + ); + + if (shouldReindex) { + await this.reindexDocsOnNewEmbeddingsProvider( + newConfig.embeddingsProvider, + ); + } + } + } private async syncConfigAndSqlite() { @@ -609,6 +594,26 @@ export default class DocsService { return ideInfo.ideType === "jetbrains"; } + async isJetBrainsAndPreIndexedDocsProvider(): Promise { + const isJetBrains = await this.isJetBrains(); + + const isPreIndexedDocsProvider = + this.config.embeddingsProvider.id === + DocsService.preIndexedDocsEmbeddingsProvider.id; + + return isJetBrains && isPreIndexedDocsProvider; + } + + /* + * Currently, we generate and host embeddings for pre-indexed docs using transformers. + * However, we don't ship transformers with the JetBrains extension. + * So, we only include pre-indexed docs in the submenu for non-JetBrains IDEs. + */ + async canUsePreindexedDocs() { + const isJetBrains = await this.isJetBrains(); + return !isJetBrains; + } + private async hasIndexedDoc(startUrl: string) { const db = await this.getOrCreateSqliteDb(); const docs = await db.all( diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 2fed805da..8ece44bec 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -37,7 +37,6 @@ function useSetup(dispatch: Dispatch) { dispatch(setConfig(config)); dispatch(setSelectedProfileId(profileId)); setConfigLoaded(true); - setLocalStorage("disableIndexing", config.disableIndexing || false); // Perform any actions needed with the config if (config.ui?.fontSize) { @@ -46,20 +45,7 @@ function useSetup(dispatch: Dispatch) { } }; - // Load config from the IDE - useEffect(() => { - loadConfig(); - const interval = setInterval(() => { - if (configLoaded) { - clearInterval(interval); - return; - } - loadConfig(); - }, 2_000); - - return () => clearInterval(interval); - }, [configLoaded]); - + // ON LOAD useEffect(() => { // Override persisted state dispatch(setInactive()); diff --git a/gui/src/hooks/useSubmenuContextProviders.tsx b/gui/src/hooks/useSubmenuContextProviders.tsx index fc0b0c71a..7f9e65f73 100644 --- a/gui/src/hooks/useSubmenuContextProviders.tsx +++ b/gui/src/hooks/useSubmenuContextProviders.tsx @@ -13,6 +13,7 @@ import { IdeMessengerContext } from "../context/IdeMessenger"; import { selectContextProviderDescriptions } from "../redux/selectors"; import { getLocalStorage } from "../util/localStorage"; import { useWebviewListener } from "./useWebviewListener"; +import { RootState } from "../redux/store"; const MINISEARCH_OPTIONS = { prefix: true, @@ -38,6 +39,8 @@ function useSubmenuContextProviders() { const [isLoading, setIsLoading] = useState(false); const [autoLoadTriggered, setAutoLoadTriggered] = useState(false); + const config = useSelector((store: RootState) => store.state.config); + const ideMessenger = useContext(IdeMessengerContext); const memoizedGetOpenFileItems = useMemo(() => { @@ -213,12 +216,10 @@ function useSubmenuContextProviders() { const loadSubmenuItems = async () => { try { - const disableIndexing = getLocalStorage("disableIndexing") ?? false; - await Promise.all( contextProviderDescriptions.map(async (description) => { const shouldSkipProvider = - description.dependsOnIndexing && disableIndexing; + description.dependsOnIndexing && config.disableIndexing; if (shouldSkipProvider) { console.debug(