fix(mongodb): skip SQL semantic diagnostics for MongoDB connections

MongoDB shell syntax like db.collection.find({}) was incorrectly
parsed as SQL, causing a "sql parser error" diagnostic in the editor.
Added MongoDB guards in shouldRunSqlSemanticDiagnostics and
refreshSemanticDiagnostics, matching existing Elasticsearch logic.

Also fix a pre-existing TiDB cloud URL param ordering test failure.
This commit is contained in:
t8y2 2026-06-09 16:20:50 +08:00
parent 7798f2231e
commit 6a14b11efc
4 changed files with 24 additions and 3 deletions

View File

@ -741,7 +741,7 @@ async function refreshSemanticDiagnostics() {
setSemanticDiagnostics([]);
return;
}
if (props.databaseType === "elasticsearch") {
if (props.databaseType === "mongodb" || props.databaseType === "elasticsearch") {
setSemanticDiagnostics([]);
return;
}

View File

@ -104,7 +104,7 @@ export function shouldRunSqlSemanticDiagnostics(
cursor: number,
options: { databaseType?: DatabaseType } = {},
): boolean {
if (options.databaseType === "elasticsearch") return false;
if (options.databaseType === "mongodb" || options.databaseType === "elasticsearch") return false;
const context = getSqlCompletionContext(sql, cursor);
if (context.suggestTables || context.exclusiveTableSuggestions || context.exclusiveColumnSuggestions) return false;
if (context.qualifier) return false;

View File

@ -1685,7 +1685,7 @@ mod tests {
assert_eq!(
config.connection_url(),
"mysql://root:secret@gateway01.us-west-2.prod.aws.tidbcloud.com:4000/test?require_ssl=true&verify_ca=false&verify_identity=false&charset=utf8mb4"
"mysql://root:secret@gateway01.us-west-2.prod.aws.tidbcloud.com:4000/test?require_ssl=true&charset=utf8mb4&verify_ca=false&verify_identity=false"
);
}

View File

@ -93,3 +93,24 @@ test("defers diagnostics while the cursor is in table completion context", () =>
assert.equal(shouldRunSqlSemanticDiagnostics("select u.", "select u.".length), false);
assert.equal(shouldRunSqlSemanticDiagnostics("select * from users where missing = 1", 42), true);
});
test("skips diagnostics for MongoDB connections", () => {
assert.equal(
shouldRunSqlSemanticDiagnostics("db.my_collection.find({})", 0, { databaseType: "mongodb" }),
false,
);
});
test("skips diagnostics for Elasticsearch connections", () => {
assert.equal(
shouldRunSqlSemanticDiagnostics("db.my_collection.find({})", 0, { databaseType: "elasticsearch" }),
false,
);
});
test("still runs diagnostics for SQL connections", () => {
assert.equal(
shouldRunSqlSemanticDiagnostics("SELECT * FROM users WHERE id = 1", 42, { databaseType: "mysql" }),
true,
);
});