docs servie updates

This commit is contained in:
Dallin Romney 2024-11-15 14:34:03 -08:00
parent ba16799dd3
commit d2decdb80e
5 changed files with 56 additions and 64 deletions

View file

@ -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) => {

View file

@ -95,6 +95,6 @@ export default DocsCrawler;
export {
CheerioCrawler,
ChromiumCrawler,
ChromiumInstaller as ChromiumInstaller,
ChromiumInstaller,
GitHubCrawler,
};

View file

@ -103,26 +103,6 @@ export default class DocsService {
return docsService;
}
async isJetBrainsAndPreIndexedDocsProvider(): Promise<boolean> {
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<boolean> {
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(

View file

@ -37,7 +37,6 @@ function useSetup(dispatch: Dispatch<any>) {
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<any>) {
}
};
// 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());

View file

@ -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(