feat(oracle): Ctrl/Cmd+click 打开存储过程源码

* feat(oracle): open procedure source via Ctrl/Cmd+click in SQL editor

Allow navigating from SQL identifiers to routine source like DataGrip/DBeaver.
Call sites open immediately without a global ALL_OBJECTS scan, and query-tab
views wrap bare Oracle ALL_SOURCE as CREATE OR REPLACE for editable DDL.

Close #5290

* fix(oracle): harden Ctrl/Cmd+click navigation identity model

Address review feedback on routine navigation correctness:
- Distinguish relation column lists (INSERT INTO t(...)) from routine calls
- Resolve schema.routine vs package.member before optimistic open
- Preserve quoted mixed-case identities for Oracle ALL_SOURCE lookup
- Try exact then uppercase name candidates in the Oracle Go agent
This commit is contained in:
Yy-702 authored and GitHub committed 2026-08-05 23:57:50 +08:00
1 parent 44e0eff76e
commit e749bdd42c
11 files changed
+1005 -46

No files matched your search

@@ -61,7 +61,21 @@ import {
type SqlCompletionScope,
} from "@/lib/sql/sqlCompletionLookupTarget";
import { usesOracleSessionCompletionColumns as shouldUseOracleSessionCompletionColumns } from "@/lib/sql/oracleCompletionSession";
import { extractIdentifierDetailsAt, isSqlKeyword, matchTable, mergeSqlObjectNavigationType, splitQualifiedIdentifier, sqlObjectHoverDetail, sqlObjectNavigationSourceKind, sqlObjectNavigationTarget, type SqlObjectNavigationTarget } from "@/lib/sql/sqlNavigation";
import {
extractIdentifierDetailsAt,
isSqlKeyword,
matchSqlObject,
matchTable,
mergeSqlObjectNavigationType,
resolveSqlObjectNavigationIdentity,
splitQualifiedIdentifier,
sqlObjectHoverDetail,
sqlObjectNavigationSourceKind,
sqlObjectNavigationTarget,
sqlObjectNavigationTargetFromIdentity,
sqlObjectNavigationTypeFromCompletionObjectType,
type SqlObjectNavigationTarget,
} from "@/lib/sql/sqlNavigation";
import { buildHoverTableSql, ddlForHoverPreview, hoverTableMatchesScope, quoteQualifiedName, reformatHoverDdl, scopeHoverTables, type HoverTableScope } from "@/lib/editor/hoverTableSql";
import { lineColumnToOffset, parseSqlErrorLocation } from "@/lib/sql/sqlDiagnostics";
import {
@@ -4312,24 +4326,115 @@ onMounted(async () => {
event.preventDefault();
setTimeout(async () => {
try {
const identifierParts = splitQualifiedIdentifier(identifier);
const tableLookupFilter = identifierParts[identifierParts.length - 1] ?? identifier;
// Single identity model: quote flags + role (relation column list vs routine call vs unknown).
const identity = resolveSqlObjectNavigationIdentity(doc, pos);
if (!identity) return;
// Ensure table cache is populated
const identifierParts = identity.parts.map((part) => part.value);
const tableLookupFilter = identity.name;
const objectNameFilter = identity.name;
// 3-part schema.package.member; 2-part stays ambiguous until metadata resolves it.
const objectParentHint = identity.parts.length >= 3 ? identity.qualifier : undefined;
const objectSchemaHint = identity.parts.length >= 3 ? identity.schema : identity.parts.length === 1 ? props.schema : undefined;
const isRoutineCall = identity.role === "routine_call";
const isRelationColumnList = identity.role === "relation_column_list";
// 1. Local table cache (sync). Relation column lists always prefer tables over routines.
if (cachedTables.length === 0) {
// Some metadata providers only accept table-name masks, not schema.table masks.
cachedTables = usesLocalOnlyCompletionMetadata()
? connectionStore.lookupLocalCompletionTables(props.connectionId!, props.database!, tableLookupFilter, MAX_COMPLETION_TABLES, props.schema, props.catalog)
: await connectionStore.listCompletionTables(props.connectionId!, props.database!, tableLookupFilter, MAX_COMPLETION_TABLES, props.schema, false, props.schema, props.catalog);
cachedTables = connectionStore.lookupLocalCompletionTables(props.connectionId!, props.database!, tableLookupFilter, MAX_COMPLETION_TABLES, props.schema, props.catalog);
}
// 1. Check if it's a table name
const matchedTable = matchTable(identifier, cachedTables);
let matchedTable = matchTable(identifier, cachedTables);
if (matchedTable) {
emit("clickTable", sqlObjectNavigationTarget(matchedTable));
return;
}
const preserveOracleStoreCase = (value?: string) => !!value && value !== value.toUpperCase();
const openMatchedObject = (matchedObject: { name: string; schema?: string; type: string; signature?: string; parentName?: string; parentSchema?: string }) => {
const navigationType = sqlObjectNavigationTypeFromCompletionObjectType(matchedObject.type);
if (!navigationType) return false;
// Metadata names are store-correct; mark mixed-case (or click-quoted) so Oracle normalize won't force UPPER.
emit(
"openObjectSource",
sqlObjectNavigationTarget({
name: matchedObject.name,
schema: matchedObject.schema,
type: navigationType,
signature: matchedObject.signature,
parentName: matchedObject.parentName,
parentSchema: matchedObject.parentSchema,
nameQuoted: identity.nameQuoted || preserveOracleStoreCase(matchedObject.name),
schemaQuoted: matchedObject.schema ? identity.schemaQuoted || identity.qualifierQuoted || preserveOracleStoreCase(matchedObject.schema) : undefined,
parentNameQuoted: matchedObject.parentName ? identity.qualifierQuoted || preserveOracleStoreCase(matchedObject.parentName) : undefined,
parentSchemaQuoted: matchedObject.parentSchema ? identity.schemaQuoted || preserveOracleStoreCase(matchedObject.parentSchema) : undefined,
}),
false,
);
return true;
};
// 1b. Local routine cache — skip for pure relation column lists (INSERT INTO t(...)).
if (!isRelationColumnList) {
const localObjects = connectionStore.lookupLocalCompletionObjects(props.connectionId!, props.database!, objectNameFilter, MAX_COMPLETION_TABLES, props.schema);
let matchedObject = matchSqlObject(identifier, localObjects);
if (matchedObject && openMatchedObject(matchedObject)) return;
if (!usesLocalOnlyCompletionMetadata()) {
// Disambiguate schema.routine vs package.member with small scoped lookups (no global scan).
if (identity.parts.length === 2 && identity.qualifier) {
// Prefer package.member under session schema (Oracle common: PKG.MEMBER()).
const packageObjects = await connectionStore.listCompletionObjects(props.connectionId!, props.database!, objectNameFilter, 20, props.schema, identity.qualifier, false, props.schema, ["routine"]);
matchedObject = matchSqlObject(identifier, packageObjects);
if (matchedObject && openMatchedObject(matchedObject)) return;
// Then schema.routine with qualifier as owner.
const schemaObjects = await connectionStore.listCompletionObjects(props.connectionId!, props.database!, objectNameFilter, 20, identity.qualifier, undefined, false, props.schema, ["routine"]);
matchedObject = matchSqlObject(identifier, schemaObjects);
if (matchedObject && openMatchedObject(matchedObject)) return;
} else {
const scopedObjects = await connectionStore.listCompletionObjects(props.connectionId!, props.database!, objectNameFilter, 20, objectSchemaHint, objectParentHint, false, props.schema, ["routine"]);
matchedObject = matchSqlObject(identifier, scopedObjects);
if (matchedObject && openMatchedObject(matchedObject)) return;
}
}
}
// 1c. Remote table metadata — never skip for relation column lists or unknown identifiers.
// Routine-call sites may still hit this when a table and procedure share a name and
// local caches were empty; table wins only if listed as a relation.
if (!usesLocalOnlyCompletionMetadata() && (!isRoutineCall || isRelationColumnList || identity.role === "unknown")) {
cachedTables = await connectionStore.listCompletionTables(props.connectionId!, props.database!, tableLookupFilter, MAX_COMPLETION_TABLES, props.schema, false, props.schema, props.catalog);
matchedTable = matchTable(identifier, cachedTables);
if (matchedTable) {
emit("clickTable", sqlObjectNavigationTarget(matchedTable));
return;
}
} else if (!usesLocalOnlyCompletionMetadata() && isRoutineCall) {
// Lightweight table check so INSERT INTO ORDERS(…) is not the only guarded path —
// still avoid global scans: only session-scoped prefix lookup.
cachedTables = await connectionStore.listCompletionTables(props.connectionId!, props.database!, tableLookupFilter, 20, props.schema, false, props.schema, props.catalog);
matchedTable = matchTable(identifier, cachedTables);
if (matchedTable) {
emit("clickTable", sqlObjectNavigationTarget(matchedTable));
return;
}
}
// 1d. Optimistic routine open only for confirmed call sites after metadata + table checks.
if (isRoutineCall) {
const optimistic = sqlObjectNavigationTargetFromIdentity(identity, {
fallbackSchema: props.schema,
preferType: "procedure",
// 2-part: package.member under session schema (not schema.routine).
asPackageMember: identity.twoPartAmbiguous,
});
if (optimistic) {
emit("openObjectSource", optimistic, false);
return;
}
}
// 2. Parse SQL at click position to get referenced tables
const context = getSqlCompletionContext(doc, pos);
let referencedTables: Array<SqlCompletionReferencedTable & Pick<SqlCompletionTable, "type">> = context.referencedTables;
@@ -8,6 +8,7 @@ import { useSettingsStore } from "@/stores/settingsStore";
import { copyToClipboard } from "@/lib/common/clipboard";
import { formatSqlForDisplay, type SqlFormatDialect } from "@/lib/sql/sqlFormatter";
import { buildEditableObjectSource, buildExecutableObjectSourceStatements, executeObjectSourceSave, formatObjectSourceSaveError } from "@/lib/table/objectSourceEditor";
import { loadObjectSourceWithRoutineFallback } from "@/lib/table/objectSourceLoad";
import { executeWithProductionSqlGuard } from "@/lib/database/productionExecutionGuard";
import * as api from "@/lib/backend/api";
import QueryEditor from "@/components/editor/QueryEditor.vue";
@@ -54,6 +55,8 @@ const editing = ref(false);
const sourceEditable = ref(true);
const error = ref("");
const saveError = ref("");
/** May differ from props.objectType after PROCEDURE/FUNCTION/PACKAGE fallback resolution. */
const resolvedObjectType = ref<ObjectSourceKind>(props.objectType);
let loadSerial = 0;
const canEdit = computed(() => sourceEditable.value && props.objectType !== "SEQUENCE");
@@ -80,16 +83,17 @@ async function loadSource(nextEditing = props.initialEditing && canEdit.value) {
try {
if (!props.databaseType) throw new Error("Connection type is unavailable.");
const schema = props.schema || props.database;
const result = await api.getObjectSource(props.connectionId, props.database, schema, props.name, props.objectType, props.signature, props.relationName);
const { source: result, objectType: resolvedType } = await loadObjectSourceWithRoutineFallback(api.getObjectSource, props.connectionId, props.database, schema, props.name, props.objectType, props.signature, props.relationName);
const editableAllowed = result.editable !== false;
const editable = await buildEditableObjectSource({
databaseType: props.databaseType,
objectType: props.objectType,
objectType: resolvedType,
schema,
name: props.name,
source: result.source,
});
if (serial !== loadSerial) return;
resolvedObjectType.value = resolvedType;
sourceEditable.value = editableAllowed;
const formatted = await formatSqlForDisplay(editable, props.formatDialect ?? props.dialect, settingsStore.editorSettings.sqlFormatter);
editableText.value = editable;
@@ -145,7 +149,7 @@ async function saveSource() {
try {
const statements = await buildExecutableObjectSourceStatements({
databaseType,
objectType: props.objectType,
objectType: resolvedObjectType.value,
schema,
name: props.name,
source: draft.value,
@@ -125,7 +125,8 @@ import {
type TableChildObjectType,
} from "@/lib/database/dbAdminSql";
import { buildRenameObjectSql, supportsObjectRename, type RenameableObjectType } from "@/lib/table/objectRenameSql";
import { buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";
import { buildEditableObjectSource, buildRoutineRenameObjectSourceStatements, supportsSourceBackedRoutineRename } from "@/lib/table/objectSourceEditor";
import { loadEditableObjectSourceForEditor } from "@/lib/table/objectSourceLoad";
import { buildViewDdl } from "@/lib/table/viewDdl";
import { formatSqlForDisplay, sqlFormatDialectForDbType } from "@/lib/sql/sqlFormatter";
import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";
@@ -1626,14 +1627,29 @@ function openObjectSourceDialog(initialEditing: boolean) {
.then(async () => {
connectionStore.activeConnectionId = connectionId;
const schema = node.schema || database;
const result = await api.getObjectSource(connectionId, database, schema, node.objectName || node.label, objectType as any, node.signature);
const tabId = queryStore.createTab(connectionId, database, `Source - ${node.label}`, "query", schema, result.source, node.catalog, { forceNew: true });
const sourceIsEditable = result.editable !== false && !["SEQUENCE", "TRIGGER", "TYPE", "TYPE_BODY"].includes(objectType);
const databaseType = effectiveDatabaseTypeForConnection(connectionStore.getConfig(connectionId));
if (!databaseType) throw new Error("Connection type is unavailable.");
const objectName = node.objectName || node.label;
const {
raw,
editableSource,
objectType: resolvedType,
} = await loadEditableObjectSourceForEditor(api.getObjectSource, buildEditableObjectSource, {
connectionId,
database,
schema,
name: objectName,
objectType: objectType as any,
databaseType,
signature: node.signature,
});
const tabId = queryStore.createTab(connectionId, database, `Source - ${node.label}`, "query", schema, editableSource, node.catalog, { forceNew: true });
const sourceIsEditable = raw.editable !== false && !["SEQUENCE", "TRIGGER", "TYPE", "TYPE_BODY"].includes(resolvedType);
if (sourceIsEditable) {
queryStore.setObjectSource(tabId, {
schema,
name: node.objectName || node.label,
objectType,
name: objectName,
objectType: resolvedType,
signature: node.signature,
});
}