Add SQL Support for gr.Code (#7328)

* add sql language support, Fixes https://github.com/gradio-app/gradio/issues/7316

* format

* add missing languages

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Freddy Boulton <alfonsoboulton@gmail.com>
This commit is contained in:
Adrian Ehrsam 2024-02-09 13:28:12 +01:00 committed by GitHub
parent 2244059cdb
commit c1a7ea7c0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 65 additions and 2 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/code": minor
"gradio": minor
---
feat:Add SQL Support for gr.Code

View File

@ -29,6 +29,19 @@ class Code(Component):
"dockerfile",
"shell",
"r",
"sql",
"sql-msSQL",
"sql-mySQL",
"sql-mariaDB",
"sql-sqlite",
"sql-cassandra",
"sql-plSQL",
"sql-hive",
"sql-pgSQL",
"sql-gql",
"sql-gpSQL",
"sql-sparkSQL",
"sql-esper",
None,
]
@ -54,6 +67,19 @@ class Code(Component):
"dockerfile",
"shell",
"r",
"sql",
"sql-msSQL",
"sql-mySQL",
"sql-mariaDB",
"sql-sqlite",
"sql-cassandra",
"sql-plSQL",
"sql-hive",
"sql-pgSQL",
"sql-gql",
"sql-gpSQL",
"sql-sparkSQL",
"sql-esper",
]
| None = None,
*,

View File

@ -1,5 +1,6 @@
import type { Extension } from "@codemirror/state";
import { StreamLanguage } from "@codemirror/language";
import { sql } from "@codemirror/legacy-modes/mode/sql";
const possible_langs = [
"python",
@ -12,9 +13,26 @@ const possible_langs = [
"yaml",
"dockerfile",
"shell",
"r"
"r",
"sql"
];
const sql_dialects = [
"standardSQL",
"msSQL",
"mySQL",
"mariaDB",
"sqlite",
"cassandra",
"plSQL",
"hive",
"pgSQL",
"gql",
"gpSQL",
"sparkSQL",
"esper"
] as const;
const lang_map: Record<string, (() => Promise<Extension>) | undefined> = {
python: () => import("@codemirror/lang-python").then((m) => m.python()),
markdown: async () => {
@ -48,7 +66,20 @@ const lang_map: Record<string, (() => Promise<Extension>) | undefined> = {
r: () =>
import("@codemirror/legacy-modes/mode/r").then((m) =>
StreamLanguage.define(m.r)
)
),
sql: () =>
import("@codemirror/legacy-modes/mode/sql").then((m) =>
StreamLanguage.define(m.standardSQL)
),
...Object.fromEntries(
sql_dialects.map((dialect) => [
"sql-" + dialect,
() =>
import("@codemirror/legacy-modes/mode/sql").then((m) =>
StreamLanguage.define(m[dialect])
)
])
)
} as const;
const alias_map: Record<string, string> = {