From cd24ecf686071e8a2257d875eb0e76b9bcb8a1ba Mon Sep 17 00:00:00 2001 From: Jason Jacobs Date: Thu, 14 Mar 2024 13:20:47 -0700 Subject: [PATCH 1/3] Changing the subMenuTitle in the context provider has led to an inability to add new documentation sources. (#959) --- gui/src/components/mainInput/MentionList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/mainInput/MentionList.tsx b/gui/src/components/mainInput/MentionList.tsx index a8528f224..2b4de321a 100644 --- a/gui/src/components/mainInput/MentionList.tsx +++ b/gui/src/components/mainInput/MentionList.tsx @@ -175,7 +175,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => { useEffect(() => { const items = [...props.items]; - if (subMenuTitle === "Search documentation") { + if (subMenuTitle === "Type to search docs") { items.push({ title: "Add Docs", type: "action", From caa7aa9459b997e564a087193094083919115397 Mon Sep 17 00:00:00 2001 From: Riccardo Schirone <562321+ret2libc@users.noreply.github.com> Date: Thu, 14 Mar 2024 21:23:16 +0100 Subject: [PATCH 2/3] Add autocomplete support for Solidity (#964) --- core/autocomplete/languages.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/autocomplete/languages.ts b/core/autocomplete/languages.ts index 865f7b09d..1f9e7dac2 100644 --- a/core/autocomplete/languages.ts +++ b/core/autocomplete/languages.ts @@ -184,6 +184,28 @@ export const Dart = { endOfLine: [";"], }; +// Solidity +export const Solidity = { + stopWords: [ + "contract", + "event", + "modifier", + "function", + "constructor", + "for", + "require", + "emit", + "interface", + "error", + "library", + "struct", + "enum", + "type", + ], + comment: "//", + endOfLine: [";"], +}; + export const LANGUAGES: { [extension: string]: AutocompleteLanguageInfo } = { ts: Typescript, js: Typescript, @@ -219,4 +241,5 @@ export const LANGUAGES: { [extension: string]: AutocompleteLanguageInfo } = { r: R, R: R, dart: Dart, + sol: Solidity, }; From 9c290e9db8a105729ea7d0eaa2dcccbd736094ae Mon Sep 17 00:00:00 2001 From: Jason Jacobs Date: Thu, 14 Mar 2024 13:24:12 -0700 Subject: [PATCH 3/3] Refactor DB (#960) * Refactor table creation and SQLite connection initialization. Previously, attempts to create the 'docs' table were made on every interaction with it. Now, table creation is attempted only upon the first interaction. Additionally, the SQLite connection is now initialized just once, enhancing performance. * no longer need createDocsTable * library no longer used --- core/indexing/docs/db.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/core/indexing/docs/db.ts b/core/indexing/docs/db.ts index a59c1c934..73651452e 100644 --- a/core/indexing/docs/db.ts +++ b/core/indexing/docs/db.ts @@ -2,7 +2,6 @@ import { Database, open } from "sqlite"; import sqlite3 from "sqlite3"; import { Chunk } from "../.."; import { getDocsSqlitePath, getLanceDbPath } from "../../util/paths"; -import { SqliteDb } from "../refreshIndex"; import { downloadPreIndexedDocs } from "./preIndexed"; import { default as configs } from "./preIndexedDocs"; @@ -21,12 +20,23 @@ interface LanceDbDocsRow { [key: string]: any; } -async function createDocsTable(db: Database) { - db.exec(`CREATE TABLE IF NOT EXISTS docs ( +let dbDocs:Database; + +async function getDBDocs() { + if (!dbDocs) { + dbDocs = await open({ + filename: getDocsSqlitePath(), + driver: sqlite3.Database, + }); + + dbDocs.exec(`CREATE TABLE IF NOT EXISTS docs ( id INTEGER PRIMARY KEY AUTOINCREMENT, title STRING NOT NULL, baseUrl STRING NOT NULL UNIQUE )`); + } + + return dbDocs; } export async function retrieveDocs( @@ -37,8 +47,7 @@ export async function retrieveDocs( nested: boolean = false, ): Promise { const lancedb = await import("vectordb"); - const db = await SqliteDb.get(); - await createDocsTable(db); + const db = await getDBDocs(); const lance = await lancedb.connect(getLanceDbPath()); const downloadDocs = async () => { @@ -116,11 +125,7 @@ export async function addDocs( } // Only after add it to SQLite - const db = await open({ - filename: getDocsSqlitePath(), - driver: sqlite3.Database, - }); - await createDocsTable(db); + const db = await getDBDocs(); await db.run( `INSERT INTO docs (title, baseUrl) VALUES (?, ?)`, title, @@ -131,11 +136,7 @@ export async function addDocs( export async function listDocs(): Promise< { title: string; baseUrl: string }[] > { - const db = await open({ - filename: getDocsSqlitePath(), - driver: sqlite3.Database, - }); - await createDocsTable(db); - const docs = await db.all(`SELECT title, baseUrl FROM docs`); + const db = await getDBDocs(); + const docs = db.all(`SELECT title, baseUrl FROM docs`); return docs; }