Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(sql-editor): override some auto-complete popup icons (#13233)

Liu Ji511611f39476
diff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.go
index 39cf475af5..6a3d97fad0 100644
--- a/backend/api/lsp/completion.go
+++ b/backend/api/lsp/completion.go
@@ -147,6 +147,8 @@ func generateSortText(_ lsp.CompletionParams, engine storepb.Engine, candidate b
func convertLSPCompletionItemKind(tp base.CandidateType) lsp.CompletionItemKind {
switch tp {
+ case base.CandidateTypeSchema:
+ return lsp.CIKModule
case base.CandidateTypeDatabase:
return lsp.CIKClass
case base.CandidateTypeTable, base.CandidateTypeForeignTable:
diff --git a/frontend/package.json b/frontend/package.json
index be9da75db6..47e7b0ada5 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -43,6 +43,7 @@
"js-yaml": "4.1.0",
"jszip": "^3.10.1",
"lodash-es": "4.17.21",
+ "lucide-static": "^0.424.0",
"lucide-vue-next": "^0.408.0",
"markdown-it": "^14.0.0",
"match-sorter": "6.3.4",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index d74c767568..7da1538bfe 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -77,6 +77,9 @@ importers:
lodash-es:
specifier: 4.17.21
version: 4.17.21
+ lucide-static:
+ specifier: ^0.424.0
+ version: 0.424.0
lucide-vue-next:
specifier: ^0.408.0
@@ -2756,6 +2759,9 @@ packages:
resolution: {integrity: sha512-AI2r85+4MquTw9ZYqabu4nMwy9Oftlfa/e/52t9IjtfG+mGBbTNdAoZ3RQKLHR6r0wQnwZnPIEh/Ya6XTWAKNA==}
+ resolution: {integrity: sha512-KUsIoKeIZF/rc5dttI/bZmd3+zQ/V9YA/G/NsGALA3QWqVncuZsyJ+IrM+jI0BTHiARwVZfp7zOEhc7gqn5x7A==}
+
resolution: {integrity: sha512-X2w4IDKs6O/R+vPdyMl5VvXS0mhuTqXtw6/NQOOIfCHvMz6vWa1Q2XvYT3oQGzyU94uVZw16jcdC1LwI5XbOdg==}
peerDependencies:
@@ -6577,6 +6583,8 @@ snapshots:
+
dependencies:
vue: 3.4.31([email protected])
diff --git a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
index e79cc38acd..f9cc027e53 100644
--- a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
@@ -64,6 +64,7 @@ import {
useSuggestOptionByLanguage,
useLineHighlights,
useLSPConnectionState,
+ useOverrideSuggestIcons,
} from "./composables";
import monaco, { createMonacoEditor } from "./editor";
import type {
@@ -168,6 +169,7 @@ onMounted(async () => {
useLineHighlights(monaco, editor, toRef(props, "lineHighlights"));
useAutoHeight(monaco, editor, containerRef, toRef(props, "autoHeight"));
useAutoComplete(monaco, editor, toRef(props, "autoCompleteContext"));
+ useOverrideSuggestIcons(monaco, editor);
ready.value = true;
diff --git a/frontend/src/components/MonacoEditor/composables/index.ts b/frontend/src/components/MonacoEditor/composables/index.ts
index 7f9ccf11dd..1c75a24bd7 100644
--- a/frontend/src/components/MonacoEditor/composables/index.ts
+++ b/frontend/src/components/MonacoEditor/composables/index.ts
@@ -9,3 +9,4 @@ export * from "./useLineHighlights";
export * from "./useAutoHeight";
export * from "./useAutoComplete";
export * from "./useLSPConnectionState";
+export * from "./useOverrideSuggestIcons";
diff --git a/frontend/src/components/MonacoEditor/composables/useOverrideSuggestIcons.ts b/frontend/src/components/MonacoEditor/composables/useOverrideSuggestIcons.ts
new file mode 100644
index 0000000000..41037bdd3b
--- /dev/null
+++ b/frontend/src/components/MonacoEditor/composables/useOverrideSuggestIcons.ts
@@ -0,0 +1,108 @@
+import { useStyleTag } from "@vueuse/core";
+import SchemaIconSVG from "lucide-static/icons/box.svg?raw";
+import FunctionIconSVG from "lucide-static/icons/square-function.svg?raw";
+import TableIconSVG from "lucide-static/icons/table.svg?raw";
+import type monaco from "monaco-editor";
+import type { MonacoModule } from "../types";
+
+// Base on heroicons-outline:circle-stack
+const DatabaseIconSVG = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
+ <path stroke-linecap="round" stroke-linejoin="round" d="M20.25 6.375c0 2.278-3.694 4.125-8.25 4.125S3.75 8.653 3.75 6.375m16.5 0c0-2.278-3.694-4.125-8.25-4.125S3.75 4.097 3.75 6.375m16.5 0v11.25c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125V6.375m16.5 0v3.75m-16.5-3.75v3.75m16.5 0v3.75C20.25 16.153 16.556 18 12 18s-8.25-1.847-8.25-4.125v-3.75m16.5 0c0 2.278-3.694 4.125-8.25 4.125s-8.25-1.847-8.25-4.125" />
+</svg>
+`;
+
+// Based on lucide:columns-3 and removing the second gap line
+const ColumnIconSVG = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-columns-3">
+ <rect width="18" height="18" x="3" y="3" rx="2"/><path d="M9 3v18"/>
+</svg>`;
+
+// Combine lucide:table and lucide:glasses
+// See <ViewIcon /> for more details
+const ViewIconSVG = {
+ normal: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke-linecap="round" stroke-linejoin="round">
+ <g stroke="rgb(156 163 175)" stroke-width="2" >
+ <path d="M12 3v18"/>
+ <rect width="18" height="18" x="3" y="3" rx="2"/>
+ <path d="M3 9h18M3 15h18"/>
+ </g>
+ <g transform="scale(.75)" transform-origin="100% 100%" stroke="rgb(79 70 229)" stroke-width="3.5">
+ <circle cx="6" cy="15" r="4"/>
+ <circle cx="18" cy="15" r="4"/>
+ <path d="M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2m-7.5-2L5 7c.7-1.3 1.4-2 3-2m13.5 8L19 7c-.7-1.3-1.5-2-3-2"/>
+ </g>
+</svg>`,
+ active: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" stroke-linecap="round" stroke-linejoin="round">
+ <g stroke="#fff" stroke-width="2" >
+ <path d="M12 3v18"/>
+ <rect width="18" height="18" x="3" y="3" rx="2"/>
+ <path d="M3 9h18M3 15h18"/>
+ </g>
+ <g transform="scale(.75)" transform-origin="100% 100%" stroke="rgb(79 70 229)" stroke-width="3.5">
+ <circle cx="6" cy="15" r="4"/>
+ <circle cx="18" cy="15" r="4"/>
+ <path d="M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2m-7.5-2L5 7c.7-1.3 1.4-2 3-2m13.5 8L19 7c-.7-1.3-1.5-2-3-2"/>
+ </g>
+</svg>`,
+};
+
+type MonochromeIconOverride = { css: string; url: string };
+type ColoredIconOverride = {
+ css: string;
+ url: { normal: string; active: string };
+};
+
+const content2DataURL = (content: string, mimeType = "image/svg+xml") => {
+ return `data:${mimeType};base64,${btoa(content)}`;
+};
+
+const MonochromeIconOverrides: MonochromeIconOverride[] = [
+ { css: "module", url: content2DataURL(SchemaIconSVG) },
+ { css: "class", url: content2DataURL(DatabaseIconSVG) },
+ { css: "field", url: content2DataURL(TableIconSVG) },
+ { css: "interface", url: content2DataURL(ColumnIconSVG) },
+ { css: "function", url: content2DataURL(FunctionIconSVG) },
+];
+const ColoredIconOverrides: ColoredIconOverride[] = [
+ {
+ css: "variable",
+ url: {
+ normal: content2DataURL(ViewIconSVG.normal),
+ active: content2DataURL(ViewIconSVG.active),
+ },
+ },
+];
+
+const createMonochromeCSS = (icon: MonochromeIconOverride) => {
+ return `.monaco-editor .suggest-widget .monaco-list .monaco-list-row .suggest-icon.codicon.codicon-symbol-${icon.css}:before {
+ content: " " !important;
+ width: 16px;
+ height: 16px;
+ background-color: currentColor;
+ mask-image: url(${icon.url});
+ mask-size: 100% 100%;
+}`;
+};
+
+const createColoredCSS = (icon: ColoredIconOverride) => {
+ return `.monaco-editor .suggest-widget .monaco-list .monaco-list-row .suggest-icon.codicon.codicon-symbol-${icon.css}:before {
+ content: " " !important;
+ width: 16px;
+ height: 16px;
+ background-image: url(${icon.url.normal});
+ background-size: 100% 100%;
+}
+.monaco-editor .suggest-widget .monaco-list .monaco-list-row.focused .suggest-icon.codicon.codicon-symbol-${icon.css}:before {
+ background-image: url(${icon.url.active});
+}`;
+};
+
+export const useOverrideSuggestIcons = (
+ monaco: MonacoModule,
+ editor: monaco.editor.IStandaloneCodeEditor
+) => {
+ const style = [
+ ...MonochromeIconOverrides.map(createMonochromeCSS),
+ ...ColoredIconOverrides.map(createColoredCSS),
+ ].join("\n");
+ useStyleTag(style);
+};