From 579e5eee9b4ea11bbf8ab8e1cc2279a5e8a6ac16 Mon Sep 17 00:00:00 2001
From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
Date: Thu, 12 Nov 2026 20:00:13 +0800
Subject: [PATCH] feat(languages): add Prisma (#2955)
Prisma schema files get highlighting, structure view and folding from the bundled tree-sitter-prisma-io grammar, a file icon, and code insight from @prisma/language-server (installable from the IDE). The language definition provides the `prisma` settings section the server reads before each validation; without it the server crashed.
Closes #2926
---
Cargo.lock | 11 +++++
crates/ide-language/Cargo.toml | 1 +
.../queries/prisma/highlights.scm | 40 +++++++++++++++++++
.../ide-language/queries/prisma/outline.scm | 8 ++++
crates/ide-language/src/registry.rs | 2 +
crates/ide-language/src/syntax/grammars.rs | 10 +++++
crates/ide-language/src/syntax/highlight.rs | 22 ++++++++++
crates/ide-language/src/syntax/tests.rs | 11 +++++
crates/ide-tools/src/registry.rs | 11 +++++
docs/en/languages/adding.mdx | 2 +-
docs/en/languages/index.mdx | 1 +
docs/zh/languages/adding.mdx | 2 +-
docs/zh/languages/index.mdx | 1 +
languages/prisma.toml | 17 ++++++++
src/ui/icons.tsx | 2 +
src/ui/openidea/fileTypes/prisma.svg | 3 ++
src/ui/openidea/fileTypes/prisma_dark.svg | 3 ++
17 files changed, 145 insertions(+), 2 deletions(-)
create mode 100644 crates/ide-language/queries/prisma/highlights.scm
create mode 100644 crates/ide-language/queries/prisma/outline.scm
create mode 100644 languages/prisma.toml
create mode 100644 src/ui/openidea/fileTypes/prisma.svg
create mode 100644 src/ui/openidea/fileTypes/prisma_dark.svg
diff --git a/Cargo.lock b/Cargo.lock
index 5572f0d1a..8b02c2e27 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4601,6 +4601,7 @@ dependencies = [
"tree-sitter-nix",
"tree-sitter-ocaml",
"tree-sitter-php",
+ "tree-sitter-prisma-io",
"tree-sitter-proto",
"tree-sitter-python",
"tree-sitter-ruby",
@@ -10437,6 +10438,16 @@ dependencies = [
"tree-sitter-language",
]
+[[package]]
+name = "tree-sitter-prisma-io"
+version = "1.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c35912d65a6adb07f781db46d843bf0464935e267da6ed192705516adafc7c24"
+dependencies = [
+ "cc",
+ "tree-sitter-language",
+]
+
[[package]]
name = "tree-sitter-proto"
version = "0.6.0"
diff --git a/crates/ide-language/Cargo.toml b/crates/ide-language/Cargo.toml
index 560d5a5f5..e793d04d6 100644
--- a/crates/ide-language/Cargo.toml
+++ b/crates/ide-language/Cargo.toml
@@ -55,6 +55,7 @@ tree-sitter-xml = "0.7.0"
tree-sitter-haskell = "0.24.1"
tree-sitter-dart = "0.2.0"
tree-sitter-graphql = "0.3.0"
+tree-sitter-prisma-io = "1.6.0"
tree-sitter-gdscript = "6.1.0"
[dev-dependencies]
diff --git a/crates/ide-language/queries/prisma/highlights.scm b/crates/ide-language/queries/prisma/highlights.scm
new file mode 100644
index 000000000..29aa7667e
--- /dev/null
+++ b/crates/ide-language/queries/prisma/highlights.scm
@@ -0,0 +1,40 @@
+; Prisma schema highlighting (our captures, not the grammar crate's). Later patterns win.
+
+(identifier) @variable
+(developer_comment) @comment
+(comment) @comment.doc
+(number) @number
+(string) @string
+[(true) (false) (null)] @keyword
+
+(variable) @property
+(column_declaration . (identifier) @property)
+(type_expression . (identifier) @variable.parameter)
+(enumeral (identifier) @constant)
+
+(column_type (identifier) @type)
+(column_type (call_expression (identifier) @type))
+(call_expression (identifier) @function)
+
+(model_declaration (identifier) @type)
+(view_declaration (identifier) @type)
+(type_declaration (identifier) @type)
+(type_declaration (type_declaration_type) @type)
+(enum_declaration (identifier) @type)
+(datasource_declaration (identifier) @type)
+(generator_declaration (identifier) @type)
+
+(attribute (identifier) @attribute)
+(attribute (call_expression (identifier) @attribute))
+(attribute (member_expression (identifier) @attribute (property_identifier) @attribute))
+(attribute (call_expression (member_expression (identifier) @attribute (property_identifier) @attribute)))
+(block_attribute_declaration (identifier) @attribute)
+(block_attribute_declaration (call_expression (identifier) @attribute))
+["@" "@@"] @attribute
+
+["datasource" "enum" "generator" "model" "type" "view"] @keyword
+
+["(" ")" "[" "]" "{" "}"] @punctuation.bracket
+["," ":" "."] @punctuation.delimiter
+(maybe) @operator
+"=" @operator
diff --git a/crates/ide-language/queries/prisma/outline.scm b/crates/ide-language/queries/prisma/outline.scm
new file mode 100644
index 000000000..09f855067
--- /dev/null
+++ b/crates/ide-language/queries/prisma/outline.scm
@@ -0,0 +1,8 @@
+(model_declaration (identifier) @name) @def.class
+(view_declaration (identifier) @name) @def.class
+(type_declaration . (identifier) @name (statement_block)) @def.struct
+(enum_declaration (identifier) @name) @def.enum
+(enumeral (identifier) @name) @def.enum_member
+(datasource_declaration (identifier) @name) @outline.module
+(generator_declaration (identifier) @name) @outline.module
+(column_declaration . (identifier) @name) @def.field
diff --git a/crates/ide-language/src/registry.rs b/crates/ide-language/src/registry.rs
index a79944bde..b40e2487d 100644
--- a/crates/ide-language/src/registry.rs
+++ b/crates/ide-language/src/registry.rs
@@ -67,6 +67,7 @@ const BUILTIN: &[(&str, &str)] = &[
("php", include_str!("../../../languages/php.toml")),
("plaintext", include_str!("../../../languages/plaintext.toml")),
("powershell", include_str!("../../../languages/powershell.toml")),
+ ("prisma", include_str!("../../../languages/prisma.toml")),
("properties", include_str!("../../../languages/properties.toml")),
("proto", include_str!("../../../languages/proto.toml")),
("python", include_str!("../../../languages/python.toml")),
@@ -1026,6 +1027,7 @@ mod tests {
("CMakeLists.txt", "cmake"),
("api.proto", "proto"),
("schema.graphql", "graphql"),
+ ("schema.prisma", "prisma"),
("main.tf", "terraform"),
("prod.tfvars", "terraform-vars"),
("job.nomad", "hcl"),
diff --git a/crates/ide-language/src/syntax/grammars.rs b/crates/ide-language/src/syntax/grammars.rs
index af8b96807..cd27f0df8 100644
--- a/crates/ide-language/src/syntax/grammars.rs
+++ b/crates/ide-language/src/syntax/grammars.rs
@@ -430,6 +430,16 @@ pub(crate) static SPECS: &[Spec] = &[
imports: NONE,
constructors: NONE,
},
+ Spec {
+ name: "prisma",
+ language: tree_sitter_prisma_io::LANGUAGE,
+ outline: outline!("prisma"),
+ highlights: Some(Highlights { query: highlights!("prisma"), first_wins: false }),
+ fold_nodes: NONE,
+ fold_bodies: NONE,
+ imports: NONE,
+ constructors: NONE,
+ },
Spec {
name: "make",
language: tree_sitter_make::LANGUAGE,
diff --git a/crates/ide-language/src/syntax/highlight.rs b/crates/ide-language/src/syntax/highlight.rs
index f8a894104..3a9249edc 100644
--- a/crates/ide-language/src/syntax/highlight.rs
+++ b/crates/ide-language/src/syntax/highlight.rs
@@ -501,6 +501,28 @@ mod tests {
("NEWHOPE", K::Constant),
],
),
+ (
+ "prisma",
+ "// hi\n/// Doc\nmodel User {\n id Int @id @default(autoincrement())\n email String? @db.VarChar(255)\n role Role\n @@index([email])\n}\nenum Role { ADMIN }\ndatasource db {\n provider = \"postgresql\"\n}\n",
+ &[
+ ("// hi", K::Comment),
+ ("/// Doc", K::DocComment),
+ ("model", K::Keyword),
+ ("User", K::Type),
+ ("id", K::Property),
+ ("Int", K::Type),
+ ("@id", K::Attribute),
+ ("@default", K::Attribute),
+ ("autoincrement", K::FunctionCall),
+ ("VarChar", K::Attribute),
+ ("255", K::Number),
+ ("Role", K::Type),
+ ("@@index", K::Attribute),
+ ("ADMIN", K::Constant),
+ ("provider", K::Property),
+ ("\"postgresql\"", K::String),
+ ],
+ ),
(
"hcl",
"# hi\nresource \"aws_instance\" \"web\" {\n ami = var.ami\n count = 2\n tags = { Name = \"web-${var.env}\" }\n name = upper(\"x\")\n}\n",
diff --git a/crates/ide-language/src/syntax/tests.rs b/crates/ide-language/src/syntax/tests.rs
index 23158c731..989e2fab9 100644
--- a/crates/ide-language/src/syntax/tests.rs
+++ b/crates/ide-language/src/syntax/tests.rs
@@ -886,6 +886,17 @@ fn outline_more_languages() {
Function GetUser
",
);
+ check_outline(
+ "prisma",
+ "datasource db {\n provider = \"sqlite\"\n}\nmodel User {\n id Int @id\n @@map(\"users\")\n}\nenum Role {\n ADMIN\n}\n",
+ "
+ Module db
+ Class User
+ Field id
+ Enum Role
+ EnumMember ADMIN
+ ",
+ );
check_outline(
"nix",
"{ pkgs, ... }:\nlet\n foo = 1;\n bar = x: x;\nin { inherit foo; }\n",
diff --git a/crates/ide-tools/src/registry.rs b/crates/ide-tools/src/registry.rs
index 89ad15de3..710ae0fb9 100644
--- a/crates/ide-tools/src/registry.rs
+++ b/crates/ide-tools/src/registry.rs
@@ -407,6 +407,17 @@ pub static TOOLS: &[ToolSpec] = &[
homepage: "https://github.com/graphql/graphiql",
needs: &[],
},
+ ToolSpec {
+ name: "prisma-language-server",
+ display: "Prisma Language Server",
+ kind: LanguageServer,
+ commands: &["prisma-language-server"],
+ method: Method::Npm { packages: &["@prisma/language-server"] },
+ fallback: None,
+ version: V,
+ homepage: "https://github.com/prisma/language-tools",
+ needs: &[],
+ },
ToolSpec {
name: "intelephense",
display: "Intelephense (PHP)",
diff --git a/docs/en/languages/adding.mdx b/docs/en/languages/adding.mdx
index 2d5b1e550..757a32226 100644
--- a/docs/en/languages/adding.mdx
+++ b/docs/en/languages/adding.mdx
@@ -67,7 +67,7 @@ All keys are kebab-case. Only `id` and `name` are required; a definition with no
| `formatter` | table | External formatter; see below. |
| `scratch-template` | string | Content of a new scratch file of this language. `$END$` marks where the caret goes. |
-Bundled tree-sitter grammars: `bash`, `c`, `cmake`, `cpp`, `csharp`, `css`, `dart`, `elixir`, `gdscript`, `go`, `graphql`, `haskell`, `hcl`, `html`, `java`, `javascript`, `json`, `kotlin`, `lua`, `make`, `markdown`, `nix`, `ocaml`, `ocaml_interface`, `php`, `proto`, `python`, `ruby`, `rust`, `scala`, `swift`, `toml`, `tsx`, `typescript`, `xml`, `yaml`, `zig`. A new grammar has to be compiled into the IDE; a plugin can provide highlighting and structure for a language without a grammar instead (see [Language features](/en/plugins/guides/language-features)).
+Bundled tree-sitter grammars: `bash`, `c`, `cmake`, `cpp`, `csharp`, `css`, `dart`, `elixir`, `gdscript`, `go`, `graphql`, `haskell`, `hcl`, `html`, `java`, `javascript`, `json`, `kotlin`, `lua`, `make`, `markdown`, `nix`, `ocaml`, `ocaml_interface`, `php`, `prisma`, `proto`, `python`, `ruby`, `rust`, `scala`, `swift`, `toml`, `tsx`, `typescript`, `xml`, `yaml`, `zig`. A new grammar has to be compiled into the IDE; a plugin can provide highlighting and structure for a language without a grammar instead (see [Language features](/en/plugins/guides/language-features)).
### `[[framework-ui-modes]]`
diff --git a/docs/en/languages/index.mdx b/docs/en/languages/index.mdx
index 96e55cae2..67c90c62e 100644
--- a/docs/en/languages/index.mdx
+++ b/docs/en/languages/index.mdx
@@ -151,6 +151,7 @@ The table lists every built-in language definition. Server and debugger names in
| PHP | `php` | `.php`, `.phtml`, `.php3`, `.php4`, `.php5`, … | Yes | Yes | **intelephense** → phpactor + **laravel-lsp** | **php-debug** |
| Plain Text | `plaintext` | `.txt`, `.text` | — | — | — | — |
| PowerShell | `powershell` | `.ps1`, `.psm1`, `.psd1`, `.pssc`, `.psrc` | Yes | — | powershell-editor-services | — |
+| Prisma | `prisma` | `.prisma` | Yes | Yes | **prisma-language-server** | — |
| Properties | `properties` | `.properties`, `.prefs` | Yes | — | — | — |
| Protocol Buffers | `proto` | `.proto` | Yes | Yes | **buf** | — |
| Python | `python` | `.py`, `.pyi`, `.pyw` | Yes | Yes | **basedpyright** → **pyright** → **ty** → **pyrefly** + **ruff** | **debugpy** |
diff --git a/docs/zh/languages/adding.mdx b/docs/zh/languages/adding.mdx
index a08f1db50..02edaff3e 100644
--- a/docs/zh/languages/adding.mdx
+++ b/docs/zh/languages/adding.mdx
@@ -67,7 +67,7 @@ install-hint = "Install CodeLLDB in Settings › Languages & Frameworks › Lang
| `formatter` | 表 | 外部格式化工具,见下文。 |
| `scratch-template` | 字符串 | 新建该语言草稿文件时的内容,`$END$` 表示光标位置。 |
-内置的 tree-sitter 语法:`bash`、`c`、`cmake`、`cpp`、`csharp`、`css`、`dart`、`elixir`、`gdscript`、`go`、`graphql`、`haskell`、`hcl`、`html`、`java`、`javascript`、`json`、`kotlin`、`lua`、`make`、`markdown`、`nix`、`ocaml`、`ocaml_interface`、`php`、`proto`、`python`、`ruby`、`rust`、`scala`、`swift`、`toml`、`tsx`、`typescript`、`xml`、`yaml`、`zig`。新的语法需要编译进 IDE;没有语法的语言可以改由插件提供高亮和结构(见 [语言功能](/zh/plugins/guides/language-features))。
+内置的 tree-sitter 语法:`bash`、`c`、`cmake`、`cpp`、`csharp`、`css`、`dart`、`elixir`、`gdscript`、`go`、`graphql`、`haskell`、`hcl`、`html`、`java`、`javascript`、`json`、`kotlin`、`lua`、`make`、`markdown`、`nix`、`ocaml`、`ocaml_interface`、`php`、`prisma`、`proto`、`python`、`ruby`、`rust`、`scala`、`swift`、`toml`、`tsx`、`typescript`、`xml`、`yaml`、`zig`。新的语法需要编译进 IDE;没有语法的语言可以改由插件提供高亮和结构(见 [语言功能](/zh/plugins/guides/language-features))。
### `[[framework-ui-modes]]`
diff --git a/docs/zh/languages/index.mdx b/docs/zh/languages/index.mdx
index 72320d09b..b103610df 100644
--- a/docs/zh/languages/index.mdx
+++ b/docs/zh/languages/index.mdx
@@ -146,6 +146,7 @@ IDE 安装工具从不需要 `sudo`。工具装在本地数据目录下 IDE 自
| PHP | `php` | `.php`, `.phtml`, `.php3`, `.php4`, `.php5`, … | 是 | 是 | **intelephense** → phpactor + **laravel-lsp** | **php-debug** |
| Plain Text | `plaintext` | `.txt`, `.text` | — | — | — | — |
| PowerShell | `powershell` | `.ps1`, `.psm1`, `.psd1`, `.pssc`, `.psrc` | 是 | — | powershell-editor-services | — |
+| Prisma | `prisma` | `.prisma` | 是 | 是 | **prisma-language-server** | — |
| Properties | `properties` | `.properties`, `.prefs` | 是 | — | — | — |
| Protocol Buffers | `proto` | `.proto` | 是 | 是 | **buf** | — |
| Python | `python` | `.py`, `.pyi`, `.pyw` | 是 | 是 | **basedpyright** → **pyright** → **ty** → **pyrefly** + **ruff** | **debugpy** |
diff --git a/languages/prisma.toml b/languages/prisma.toml
new file mode 100644
index 000000000..b8772603b
--- /dev/null
+++ b/languages/prisma.toml
@@ -0,0 +1,17 @@
+id = "prisma"
+name = "Prisma"
+extensions = ["prisma"]
+line-comment = "//"
+indent = { tab-size = 2, insert-spaces = true }
+tree-sitter = "prisma"
+
+[[language-servers]]
+name = "prisma-language-server"
+command = "prisma-language-server"
+args = ["--stdio"]
+root-markers = ["package.json", "schema.prisma"]
+install-hint = "npm i -g @prisma/language-server"
+
+# Asked for as section `prisma` before every validation; a missing section crashes the server.
+[language-servers.settings.prisma]
+enableDiagnostics = true
diff --git a/src/ui/icons.tsx b/src/ui/icons.tsx
index 2f3ef842a..8cbe952c3 100644
--- a/src/ui/icons.tsx
+++ b/src/ui/icons.tsx
@@ -178,6 +178,7 @@ const ICONS = {
"file-gdshader": "openidea/fileTypes/gdshader",
"file-asciidoc": "openidea/fileTypes/asciidoc",
"file-d": "openidea/fileTypes/d",
+ "file-prisma": "openidea/fileTypes/prisma",
"file-dart": "openidea/fileTypes/dart",
"file-elixir": "openidea/fileTypes/elixir",
"file-erlang": "openidea/fileTypes/erlang",
@@ -1098,6 +1099,7 @@ const EXT_ICONS = table({
"file-gdshader": "gdshader gdshaderinc",
"file-asciidoc": "adoc asciidoc",
"file-d": "d di",
+ "file-prisma": "prisma",
"file-dart": "dart",
"file-elixir": "ex exs",
"file-erlang": "erl hrl escript app.src",
diff --git a/src/ui/openidea/fileTypes/prisma.svg b/src/ui/openidea/fileTypes/prisma.svg
new file mode 100644
index 000000000..ccbb30c8c
--- /dev/null
+++ b/src/ui/openidea/fileTypes/prisma.svg
@@ -0,0 +1,3 @@
+
diff --git a/src/ui/openidea/fileTypes/prisma_dark.svg b/src/ui/openidea/fileTypes/prisma_dark.svg
new file mode 100644
index 000000000..2bd987578
--- /dev/null
+++ b/src/ui/openidea/fileTypes/prisma_dark.svg
@@ -0,0 +1,3 @@
+