@cloudcare/codemirror-dql 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @cloudcare/codemirror-dql
|
|
2
|
+
|
|
3
|
+
> 基于 [CodeMirror 6](https://codemirror.net/6/) 构建的 DQL 编辑器插件,提供完整的语法高亮、自动补全、函数提示、字段查询、语法检查能力,适用于指标查询、日志检索、埋点分析等场景。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ✨ 功能特点
|
|
8
|
+
|
|
9
|
+
- ✅ 支持 DQL 语法的高亮渲染(亮色/暗色主题)
|
|
10
|
+
- ✅ 自动补全字段、函数、数据源、指标索引等
|
|
11
|
+
- ✅ 实时语法校验(linter)
|
|
12
|
+
- ✅ 可扩展的远程补全接口(继承 `DQLClient`)
|
|
13
|
+
- ✅ 与 CodeMirror 插件生态完全兼容
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 📦 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @cloudcare/codemirror-dql
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
依赖 CodeMirror 6 相关核心模块(如果尚未安装):
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @codemirror/state @codemirror/view @codemirror/language
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 🚀 快速上手
|
|
32
|
+
|
|
33
|
+
### 初始化编辑器(基础语法高亮)
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { EditorView, basicSetup } from 'codemirror';
|
|
37
|
+
import { EditorState } from '@codemirror/state';
|
|
38
|
+
import { DQLExtension, baseTheme, dqlHighlighter } from '@cloudcare/codemirror-dql';
|
|
39
|
+
import { syntaxHighlighting } from '@codemirror/language';
|
|
40
|
+
|
|
41
|
+
const dql = new DQLExtension();
|
|
42
|
+
|
|
43
|
+
const state = EditorState.create({
|
|
44
|
+
doc: 'L::re(`.*`):(*)',
|
|
45
|
+
extensions: [basicSetup, baseTheme, dql.asExtension(), syntaxHighlighting(dqlHighlighter)],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
new EditorView({
|
|
49
|
+
state,
|
|
50
|
+
parent: document.getElementById('editor')!,
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## ⚙️ 启用自动补全 & linter
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
const dql = new DQLExtension().activateCompletion(true).activateLinter(true).setComplete(new MyCustomDQLClient());
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🧩 自定义补全:实现 `DQLClient`
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { DQLClient, Matcher } from '@cloudcare/codemirror-dql';
|
|
68
|
+
|
|
69
|
+
class MyCustomDQLClient extends DQLClient {
|
|
70
|
+
getIndexs(): Promise<string[]> {
|
|
71
|
+
return Promise.resolve(['default', 'index-a']);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getSourceList(namespace: string): Promise<string[]> {
|
|
75
|
+
return Promise.resolve(['source1', 'source2']);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getFields(namespace: string): Promise<any[]> {
|
|
79
|
+
return Promise.resolve([
|
|
80
|
+
{ name: 'host', type: 'string', info: '主机名' },
|
|
81
|
+
{ name: 'status', type: 'number', info: '状态码' },
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
showFunctions(): Promise<any[]> {
|
|
86
|
+
return Promise.resolve([
|
|
87
|
+
{ name: 'show_field_key()', info: '展示字段列表' },
|
|
88
|
+
{ name: 'show_measurement()', info: '展示指标名称' },
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 🎨 支持主题
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
import { dqlHighlighter, darkDqlHighlighter, lightTheme, darkTheme } from '@cloudcare/codemirror-dql';
|
|
100
|
+
|
|
101
|
+
const themeExtensions = [syntaxHighlighting(darkDqlHighlighter), darkTheme];
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## 📦 TypeScript 类型支持
|
|
107
|
+
|
|
108
|
+
插件提供完整类型定义:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
interface FieldNameData {
|
|
112
|
+
name: string;
|
|
113
|
+
type: string;
|
|
114
|
+
info: string;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface Matcher {
|
|
118
|
+
name: string;
|
|
119
|
+
type: string;
|
|
120
|
+
value?: string;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## 📚 示例:Vue 中使用
|
|
127
|
+
|
|
128
|
+
```vue
|
|
129
|
+
<template>
|
|
130
|
+
<div ref="editor" style="height: 200px; border: 1px solid #ccc;"></div>
|
|
131
|
+
</template>
|
|
132
|
+
|
|
133
|
+
<script lang="ts">
|
|
134
|
+
import { defineComponent, onMounted, ref } from 'vue';
|
|
135
|
+
import { EditorView } from '@codemirror/view';
|
|
136
|
+
import { EditorState } from '@codemirror/state';
|
|
137
|
+
import { DQLExtension, baseTheme, dqlHighlighter } from '@cloudcare/codemirror-dql';
|
|
138
|
+
import { syntaxHighlighting } from '@codemirror/language';
|
|
139
|
+
|
|
140
|
+
export default defineComponent({
|
|
141
|
+
setup() {
|
|
142
|
+
const editor = ref();
|
|
143
|
+
|
|
144
|
+
onMounted(() => {
|
|
145
|
+
const dql = new DQLExtension().activateCompletion(true).activateLinter(true);
|
|
146
|
+
|
|
147
|
+
const state = EditorState.create({
|
|
148
|
+
doc: '',
|
|
149
|
+
extensions: [baseTheme, dql.asExtension(), syntaxHighlighting(dqlHighlighter)],
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
new EditorView({
|
|
153
|
+
state,
|
|
154
|
+
parent: editor.value,
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
return { editor };
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
</script>
|
|
162
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudcare/codemirror-dql",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "a CodeMirror mode for the DQL language",
|
|
5
5
|
"types": "dist/esm/index.d.ts",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@cloudcare/lezer-dql": "0.0.
|
|
26
|
+
"@cloudcare/lezer-dql": "0.0.19"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@codemirror/autocomplete": "^6.18.6",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=12.0.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "13e7cb0f49683e6f381d1fa1e78e8ee91b645818"
|
|
58
58
|
}
|