fix(editor): Format SQL uppercases words inside string literals, quoted identifiers and comments
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
Read lib/core/actions/sql_script_format.dart and the existing scanner in lib/core/database/destructive_sql_detector.dart, then review test/core/actions/sql_script_format_test.dart and SqlQueryTabSession.formatSql in lib/features/workspace/sql_query_tab_session.dart. Coordinate with issue #1511 because it touches the same detector. Done means formatting changes SQL keywords only in code segments, preserves the caret position, and the listed literal, identifier, comment, escape, and unterminated-literal cases are covered by tests.
由索引模型根據 Issue 內容生成。
描述
Problem
Format SQL Query (command palette, Shift+Alt+F) calls formatSqlScript (lib/core/actions/sql_script_format.dart:64), which runs one regex over the whole text and uppercases every word found in _kSqlKeywords. It does not know about string literals, quoted identifiers or comments:
| Before | After | Effect |
|---|---|---|
WHERE status = 'not null' |
WHERE status = 'NOT NULL' |
query now matches different rows |
SELECT "order", "desc" FROM t |
SELECT "ORDER", "DESC" FROM t |
PostgreSQL: quoted identifiers are case-sensitive, the query fails (column does not exist) |
SELECT `limit` FROM t (MySQL) |
SELECT `LIMIT` FROM t |
changes the identifier on case-sensitive table names |
$$ ... begin ... end $$ (function body) |
body rewritten | changes stored code |
-- set in prod |
-- SET IN prod |
cosmetic |
The only test (test/core/actions/sql_script_format_test.dart) checks a literal with no keywords inside.
Also in SqlQueryTabSession.formatSql (lib/features/workspace/sql_query_tab_session.dart:102-108) the caret always jumps to the end of the document after formatting.
Fix
- Format only code segments. Scanning logic already exists in
DestructiveSqlDetector.stripCommentsAndStrings(lib/core/database/destructive_sql_detector.dart:213:--,/* */,$tag$,'...'), but it drops the segments and does not know"..."/`...`. Extract one lexical scanner that yields segments (code, string, quoted identifier, comment, dollar-quoted body) and use it in the formatter (and later in the stripper / splitter; coordinate with #1511 which touches the same detector). - Keep the caret where it was, mapped onto the new text. Keywords keep their length, so the offset is unchanged.
- Tests: each row of the table above, plus nested
''escapes and an unterminated literal.
- 主要語言
- Dart
- 星號
- 23
- 分支
- 1
- 平均合併
- 49 分鐘
- 30 天內合併 PR
- 496
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
QueryaHub/Querya-Desktop 的其他 Issue
-
bug P3 ux
難度 2/5 1-3 小時 新手友好度 79/100
QueryaHub/Querya-Desktop#1837 ·
維護者通常 1 天內回覆
-
enhancement P3
難度 4/5 3-5 天 新手友好度 50/100
QueryaHub/Querya-Desktop#1838 ·
維護者通常 1 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 45/100
QueryaHub/Querya-Desktop#1690 ·
維護者通常 1 天內回覆
-
enhancement
難度 4/5 1-2 天 新手友好度 55/100
QueryaHub/Querya-Desktop#1683 ·
維護者通常 1 天內回覆
-
enhancement
難度 5/5 一週以上 新手友好度 20/100
QueryaHub/Querya-Desktop#1625 · 2 則留言 ·
維護者通常 1 天內回覆
查看 QueryaHub/Querya-Desktop 的全部 Issue
相似的 Issue
-
bot-found bug priority: P3
難度 2/5 1-3 小時 新手友好度 72/100
madenvel/KalinkaPlayer#498 ·
-
難度 2/5 1-3 小時 新手友好度 70/100
libnativeapi/nativeapi#21 ·
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
chriskelly/wish-together#102 ·
維護者通常 1 天內回覆
-
area/adaptivity kind/task priority/p1
難度 2/5 1-3 小時 新手友好度 85/100
-
bug
難度 2/5 1-3 小時 新手友好度 60/100
spotiflacapp/SpotiFLAC-Mobile#783 ·