Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(sql-editor): add "Show in Editor" button to highlight failed SQL statement (#18409)
Vincent Huang91b341af3a97
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 221f5993c0..f27453a981 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2053,6 +2053,7 @@"hex-format": "Hexadecimal format","boolean-format": "Boolean format","text-format": "Text format",+ "show-in-editor": "Show in Editor","hint-tips": {"confirm-to-close-unsaved-sheet": {"title": "Close the unsaved sheet?",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 581a24405f..f58250b978 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2053,6 +2053,7 @@"hex-format": "Formato hexadecimal","boolean-format": "Formato booleano","text-format": "Formato de texto",+ "show-in-editor": "Mostrar en el editor","hint-tips": {"confirm-to-close-unsaved-sheet": {"title": "¿Cerrar la hoja no guardada?",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex e6f09c9440..19579e3d17 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2053,6 +2053,7 @@"hex-format": "16進形式","boolean-format": "ブール形式","text-format": "テキスト形式",+ "show-in-editor": "エディタで表示","hint-tips": {"confirm-to-close-unsaved-sheet": {"title": "未保存のワークシートを閉じてもよろしいですか?",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex c50cc5393e..3840418e99 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -2053,6 +2053,7 @@"hex-format": "Định dạng thập lục phân","boolean-format": "Định dạng Boolean","text-format": "Định dạng văn bản",+ "show-in-editor": "Hiển thị trong trình soạn thảo","hint-tips": {"confirm-to-close-unsaved-sheet": {"title": "Đóng trang tính chưa lưu?",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 31d27461da..01e1427a17 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2053,6 +2053,7 @@"hex-format": "十六进制格式","boolean-format": "布尔格式","text-format": "文本格式",+ "show-in-editor": "在编辑器中显示","hint-tips": {"confirm-to-close-unsaved-sheet": {"title": "确定关闭未保存的工作表?",diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vueindex 61d2608b45..b53cddf315 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ErrorView/ErrorView.vue@@ -4,7 +4,18 @@:class="[dark ? 'text-matrix-green-hover' : 'text-control-light']"><BBAttention class="w-full" type="error">- {{ error }}+ <div class="flex items-center gap-2">+ <span class="flex-1">{{ error }}</span>+ <NButton+ v-if="canShowInEditor"+ size="tiny"+ quaternary+ type="primary"+ @click="showInEditor"+ >+ {{ positionLabel }}+ </NButton>+ </div></BBAttention><div v-if="$slots.suffix"><slot name="suffix" />@@ -14,15 +25,123 @@</template><script lang="ts" setup>+import type { IRange } from "monaco-editor";+import { Selection } from "monaco-editor";+import { NButton } from "naive-ui";+import { computed } from "vue";+import { useI18n } from "vue-i18n";import { BBAttention } from "@/bbkit";-import type { SQLResultSetV1 } from "@/types";+import { positionWithOffset } from "@/components/MonacoEditor/utils";+import type { SQLEditorQueryParams, SQLResultSetV1 } from "@/types";+import { useSQLEditorContext } from "@/views/sql-editor/context";+import { activeSQLEditorRef } from "@/views/sql-editor/EditorPanel/StandardPanel/state";import { useSQLResultViewContext } from "../context";import PostgresError from "./PostgresError.vue";-defineProps<{+const props = defineProps<{error: string | undefined;+ executeParams?: SQLEditorQueryParams;resultSet?: SQLResultSetV1;}>();+const { t } = useI18n();const { dark } = useSQLResultViewContext();+const { events: editorEvents } = useSQLEditorContext();++// Get the failing statement from the result+const failingStatement = computed(() => {+ const results = props.resultSet?.results ?? [];+ const failedResult = results.find((r) => r.error);+ return failedResult?.statement?.trim();+});++const canShowInEditor = computed(() => {+ return hasErrorPosition.value || !!failingStatement.value;+});++const hasErrorPosition = computed(() => {+ const result = props.resultSet?.results?.[0];+ if (!result) return false;++ if (result.detailedError.case === "syntaxError") {+ const pos = result.detailedError.value.startPosition;+ return (pos?.line ?? 0) > 0;+ }+ return false;+});++const errorPosition = computed(() => {+ const result = props.resultSet?.results?.[0];+ if (result?.detailedError.case === "syntaxError") {+ return result.detailedError.value.startPosition;+ }+ return undefined;+});++// Find the failing statement in the editor and return its range+const findStatementRange = (): IRange | undefined => {+ let statement = failingStatement.value;+ if (!statement) return undefined;++ const editor = activeSQLEditorRef.value;+ const model = editor?.getModel();+ if (!model) return undefined;++ // Backend may add "LIMIT N" to the statement - strip it for matching+ statement = statement.replace(/\s+LIMIT\s+\d+\s*;?\s*$/i, "").trim();++ // Try exact match first+ let matches = model.findMatches(statement, false, false, false, null, false);+ if (matches.length > 0) {+ return matches[0].range;+ }++ // Try with semicolon if not found+ matches = model.findMatches(+ statement + ";",+ false,+ false,+ false,+ null,+ false+ );+ if (matches.length > 0) {+ return matches[0].range;+ }++ return undefined;+};++const highlightRange = computed((): IRange | undefined => {+ // Priority 1: Exact error position from syntax error+ if (hasErrorPosition.value && errorPosition.value) {+ const [line, col] = positionWithOffset(+ errorPosition.value.line,+ errorPosition.value.column,+ props.executeParams?.selection+ );+ return new Selection(line, col, line, col);+ }++ // Priority 2: Find the specific failing statement in editor+ return findStatementRange();+});++const positionLabel = computed(() => {+ if (hasErrorPosition.value && errorPosition.value) {+ const [line, col] = positionWithOffset(+ errorPosition.value.line,+ errorPosition.value.column,+ props.executeParams?.selection+ );+ return `L${line}:C${col}`;+ }+ return t("sql-editor.show-in-editor");+});++const showInEditor = () => {+ if (highlightRange.value) {+ editorEvents.emit("set-editor-selection", highlightRange.value as IRange);+ }+};</script>