-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextension.ts
More file actions
88 lines (78 loc) · 2.48 KB
/
Copy pathextension.ts
File metadata and controls
88 lines (78 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import type { Extension } from "@codemirror/state";
import { type SqlLinterConfig, sqlLinter } from "./diagnostics.js";
import { type SqlHoverConfig, sqlHover, sqlHoverTheme } from "./hover.js";
import { SqlParser } from "./parser.js";
import { type SqlGutterConfig, sqlStructureGutter } from "./structure-extension.js";
/**
* Configuration options for the SQL extension
*/
export interface SqlExtensionConfig {
/**
* The SQL parser used for linting and gutter markers.
* If not provided, a default PostgreSQL parser is created.
* The parser instance is shared across the extension.
*/
sqlParser?: SqlParser;
/** Whether to enable SQL linting (default: true) */
enableLinting?: boolean;
/** Configuration for the SQL linter */
linterConfig?: SqlLinterConfig;
/** Whether to enable gutter markers for SQL statements (default: true) */
enableGutterMarkers?: boolean;
/** Configuration for the SQL gutter markers */
gutterConfig?: SqlGutterConfig;
/** Whether to enable hover tooltips (default: true) */
enableHover?: boolean;
/** Configuration for hover tooltips */
hoverConfig?: SqlHoverConfig;
}
/**
* Creates a comprehensive SQL extension for CodeMirror that includes:
* - SQL syntax validation and linting
* - Visual gutter indicators for SQL statements
* - Hover tooltips for keywords, tables, and columns
*
* @param config Configuration options for the extension
* @returns An array of CodeMirror extensions
*
* @example
* ```ts
* import { sqlExtension } from '@marimo-team/codemirror-sql';
*
* const editor = new EditorView({
* extensions: [
* sqlExtension({
* linterConfig: { delay: 500 },
* gutterConfig: { backgroundColor: '#3b82f6' },
* hoverConfig: { hoverTime: 300 }
* })
* ]
* });
* ```
*/
export function sqlExtension(config: SqlExtensionConfig = {}): Extension[] {
const extensions: Extension[] = [];
const {
enableLinting = true,
enableGutterMarkers = true,
enableHover = true,
sqlParser,
linterConfig,
gutterConfig,
hoverConfig,
} = config;
if (enableLinting || enableGutterMarkers) {
const parser = sqlParser ?? new SqlParser({ dialect: "PostgresQL" });
if (enableLinting) {
extensions.push(sqlLinter(parser, linterConfig));
}
if (enableGutterMarkers) {
extensions.push(sqlStructureGutter(parser, gutterConfig));
}
}
if (enableHover) {
extensions.push(sqlHover(hoverConfig));
extensions.push(sqlHoverTheme());
}
return extensions;
}