Unnamed repository; edit this file 'description' to name the repository.
feat: add `pip-requirements` language (#14161)
Kristoffer Plagborg Bak Sørensen 7 months ago
parent 155fde5 · commit 327f385
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml11
-rw-r--r--runtime/queries/pip-requirements/highlights.scm41
-rw-r--r--runtime/queries/pip-requirements/injections.scm2
4 files changed, 55 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index ee011cf5..6eebf9a7 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -185,6 +185,7 @@
| pest | ✓ | ✓ | ✓ | | | `pest-language-server` |
| php | ✓ | ✓ | ✓ | ✓ | | `intelephense` |
| php-only | ✓ | | | ✓ | | |
+| pip-requirements | ✓ | | | | | |
| pkgbuild | ✓ | ✓ | ✓ | | | `termux-language-server`, `bash-language-server` |
| pkl | ✓ | | ✓ | | | `pkl-lsp` |
| po | ✓ | ✓ | | | | |
diff --git a/languages.toml b/languages.toml
index d3dc2972..a5a92ba5 100644
--- a/languages.toml
+++ b/languages.toml
@@ -4628,3 +4628,14 @@ comment-token = "#"
[[grammar]]
name = "robots"
source = { git = "https://github.com/opa-oz/tree-sitter-robots-txt", rev = "8e3a4205b76236bb6dbebdbee5afc262ce38bb62" }
+
+[[language]]
+name = "pip-requirements"
+scope = "source.pip-requirements"
+injection-regex = "(pip-)?requirements(\\.txt)?"
+grammar = "requirements"
+file-types = [{ glob = "requirements.txt" }, { glob = "constraints.txt" }]
+
+[[grammar]]
+name = "requirements"
+source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-requirements", rev = "caeb2ba854dea55931f76034978de1fd79362939" }
diff --git a/runtime/queries/pip-requirements/highlights.scm b/runtime/queries/pip-requirements/highlights.scm
new file mode 100644
index 00000000..6036e301
--- /dev/null
+++ b/runtime/queries/pip-requirements/highlights.scm
@@ -0,0 +1,41 @@
+(comment) @comment
+
+(requirement (package) @variable)
+(extras (package) @variable.parameter)
+
+; "==" | ">" | "<" | ">=" | "<="
+(version_cmp) @operator
+
+(version) @constant.numeric
+
+(marker_var) @attribute
+
+(marker_op) @keyword.operator
+
+[
+ "[" "]"
+ "(" ")"
+] @punctuation.bracket
+
+[
+ ","
+ ";"
+ "@"
+] @punctuation.delimiter
+
+[
+ "${" "}"
+] @punctuation.special
+
+"=" @operator
+
+(path) @string.special.path
+(url) @string.special.url
+
+(option) @function
+
+(env_var) @constant
+
+(quoted_string) @string
+
+(linebreak) @constant.character.escape
diff --git a/runtime/queries/pip-requirements/injections.scm b/runtime/queries/pip-requirements/injections.scm
new file mode 100644
index 00000000..2f0e58eb
--- /dev/null
+++ b/runtime/queries/pip-requirements/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))