update
Some checks failed
Deploy / build-and-deploy (push) Has been cancelled

This commit is contained in:
2026-07-05 01:17:06 -06:00
parent aaf8719943
commit 4031bbe82e

View File

@@ -6,6 +6,8 @@ import type {
} from "@codemirror/autocomplete" } from "@codemirror/autocomplete"
import type { EditorView } from "@codemirror/view" import type { EditorView } from "@codemirror/view"
import { LANGUAGE } from "../types" import { LANGUAGE } from "../types"
import { selectedTableId } from "../composables/sqlTable"
import { sqlTables } from "../data/sqlTables"
import { cpp } from "./cpp" import { cpp } from "./cpp"
import { c } from "./c" import { c } from "./c"
import { python } from "./python" import { python } from "./python"
@@ -26,6 +28,38 @@ const chineseAnnotations: Record<string, ChineseCompletion[]> = {
sql, sql,
} }
// 数据类型只取基础部分TEXT NOT NULL -> TEXT
function baseType(type: string): string {
return type.trim().split(/\s+/)[0]
}
// 根据当前选中的数据表,动态生成表名与列名补全
function buildSqlDynamicCompletions(): ChineseCompletion[] {
const tableCompletions: ChineseCompletion[] = sqlTables.map((table) => ({
label: table.tableName,
detail: table.label,
type: "type",
info: `数据表 ${table.label},包含列:${table.columns
.map((column) => column.name)
.join("、")}`,
boost: table.id === selectedTableId.value ? 95 : 40,
apply: `${table.tableName} `,
}))
const activeTable =
sqlTables.find((table) => table.id === selectedTableId.value) ??
sqlTables[0]
const columnCompletions: ChineseCompletion[] = activeTable.columns.map(
(column) => ({
label: column.name,
detail: baseType(column.type),
type: "variable",
info: `${activeTable.label} 的列,类型 ${baseType(column.type)}`,
boost: 93,
}),
)
return [...tableCompletions, ...columnCompletions]
}
export function enhanceCompletion(language: LANGUAGE): CompletionSource { export function enhanceCompletion(language: LANGUAGE): CompletionSource {
return async function ( return async function (
context: CompletionContext, context: CompletionContext,
@@ -33,7 +67,12 @@ export function enhanceCompletion(language: LANGUAGE): CompletionSource {
const word = context.matchBefore(/\w+/) const word = context.matchBefore(/\w+/)
if (!word) return null if (!word) return null
const completions: Completion[] = (chineseAnnotations[language] || []).map( const source: ChineseCompletion[] = [
...(language === "sql" ? buildSqlDynamicCompletions() : []),
...(chineseAnnotations[language] || []),
]
const completions: Completion[] = source.map(
(completion) => { (completion) => {
const insertText = const insertText =
typeof completion.apply === "string" typeof completion.apply === "string"