Unnamed repository; edit this file 'description' to name the repository.
feat: add thrift hightlight (#11367)
麦芽糖 2024-08-09
parent 68f495b · commit aaaafb8
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml13
-rw-r--r--runtime/queries/thrift/folds.scm12
-rw-r--r--runtime/queries/thrift/highlights.scm211
-rw-r--r--runtime/queries/thrift/injections.scm2
-rw-r--r--runtime/queries/thrift/locals.scm51
6 files changed, 290 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index d22da10d..f8513ae7 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -200,6 +200,7 @@
| tcl | ✓ | | ✓ | |
| templ | ✓ | | | `templ` |
| tfvars | ✓ | | ✓ | `terraform-ls` |
+| thrift | ✓ | | | |
| todotxt | ✓ | | | |
| toml | ✓ | ✓ | | `taplo` |
| tsq | ✓ | | | |
diff --git a/languages.toml b/languages.toml
index b1dfd0d6..d134a4a0 100644
--- a/languages.toml
+++ b/languages.toml
@@ -3762,3 +3762,16 @@ grammar = "typescript"
"{" = "}"
"(" = ")"
'"' = '"'
+
+[[language]]
+name = "thrift"
+scope = "source.thrift"
+file-types = ["thrift"]
+comment-token = "//"
+block-comment-tokens = { start = "/*", end = "*/" }
+indent = { tab-width = 2, unit = " " }
+
+[[grammar]]
+name = "thrift"
+source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-thrift" , rev = "68fd0d80943a828d9e6f49c58a74be1e9ca142cf" }
+
diff --git a/runtime/queries/thrift/folds.scm b/runtime/queries/thrift/folds.scm
new file mode 100644
index 00000000..1361be1f
--- /dev/null
+++ b/runtime/queries/thrift/folds.scm
@@ -0,0 +1,12 @@
+[
+ (annotation_definition)
+ (enum_definition)
+ (exception_definition)
+ (function_definition)
+ (senum_definition)
+ (service_definition)
+ (struct_definition)
+ (union_definition)
+
+ (comment)
+] @fold
diff --git a/runtime/queries/thrift/highlights.scm b/runtime/queries/thrift/highlights.scm
new file mode 100644
index 00000000..567c3f9d
--- /dev/null
+++ b/runtime/queries/thrift/highlights.scm
@@ -0,0 +1,211 @@
+; Variables
+
+((identifier) @variable)
+
+; Includes
+
+[
+ "include"
+ "cpp_include"
+] @keyword
+
+; Function
+
+(function_definition
+ (identifier) @function)
+
+; Fields
+
+(field (identifier) @variable.other.member)
+
+; Parameters
+
+(function_definition
+ (parameters
+ (parameter (identifier) @variable.parameter)))
+
+(throws
+ (parameters
+ (parameter (identifier) @keyword.control.exception)))
+
+; Types
+
+(typedef_identifier) @type
+(struct_definition
+ "struct" (identifier) @type)
+
+(union_definition
+ "union" (identifier) @type)
+
+(exception_definition
+ "exception" (identifier) @type)
+
+(service_definition
+ "service" (identifier) @type)
+
+(interaction_definition
+ "interaction" (identifier) @type)
+
+(type
+ type: (identifier) @type)
+
+(definition_type
+ type: (identifier) @type)
+
+; Constants
+
+(const_definition (identifier) @constant)
+
+(enum_definition "enum"
+ . (identifier) @type
+ "{" (identifier) @constant "}")
+
+; Builtin Types
+
+(primitive) @type.builtin
+
+[
+ "list"
+ "map"
+ "set"
+ "sink"
+ "stream"
+ "void"
+] @type.builtin
+
+; Namespace
+
+(namespace_declaration
+ (namespace_scope) @tag
+ [(namespace) @namespace (_ (identifier) @namespace)])
+
+; Attributes
+
+(annotation_definition
+ (annotation_identifier (identifier) @attribute))
+(fb_annotation_definition
+ "@" @attribute (annotation_identifier (identifier) @attribute)
+ (identifier)? @attribute)
+(namespace_uri (string) @attribute)
+
+; Operators
+
+[
+ "="
+ "&"
+] @operator
+
+; Exceptions
+
+[
+ "throws"
+] @keyword.control.exception
+
+; Keywords
+
+[
+ "enum"
+ "exception"
+ "extends"
+ "interaction"
+ "namespace"
+ "senum"
+ "service"
+ "struct"
+ "typedef"
+ "union"
+ "uri"
+] @keyword
+
+; Deprecated Keywords
+
+[
+ "cocoa_prefix"
+ "cpp_namespace"
+ "csharp_namespace"
+ "delphi_namespace"
+ "java_package"
+ "perl_package"
+ "php_namespace"
+ "py_module"
+ "ruby_namespace"
+ "smalltalk_category"
+ "smalltalk_prefix"
+ "xsd_all"
+ "xsd_attrs"
+ "xsd_namespace"
+ "xsd_nillable"
+ "xsd_optional"
+] @keyword
+
+; Extended Kewords
+[
+ "package"
+ "performs"
+] @keyword
+
+[
+ "async"
+ "oneway"
+] @keyword
+
+; Qualifiers
+
+[
+ "client"
+ "const"
+ "idempotent"
+ "optional"
+ "permanent"
+ "readonly"
+ "required"
+ "safe"
+ "server"
+ "stateful"
+ "transient"
+] @type.directive
+
+; Literals
+
+(string) @string
+
+(escape_sequence) @constant.character.escape
+
+(namespace_uri
+ (string) @string.special)
+
+(number) @constant.numeric.integer
+
+(double) @constant.numeric.float
+
+(boolean) @constant.builtin.boolean
+
+; Typedefs
+
+(typedef_identifier) @type.definition
+
+; Punctuation
+
+[
+ "*"
+] @punctuation.special
+
+["{" "}"] @punctuation.bracket
+
+["(" ")"] @punctuation.bracket
+
+["[" "]"] @punctuation.bracket
+
+["<" ">"] @punctuation.bracket
+
+[
+ "."
+ ","
+ ";"
+ ":"
+] @punctuation.delimiter
+
+; Comments
+
+(comment) @comment
+
diff --git a/runtime/queries/thrift/injections.scm b/runtime/queries/thrift/injections.scm
new file mode 100644
index 00000000..321c90ad
--- /dev/null
+++ b/runtime/queries/thrift/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/runtime/queries/thrift/locals.scm b/runtime/queries/thrift/locals.scm
new file mode 100644
index 00000000..538b4996
--- /dev/null
+++ b/runtime/queries/thrift/locals.scm
@@ -0,0 +1,51 @@
+; Scopes
+
+[
+ (document)
+ (definition)
+] @local.scope
+
+; References
+
+(identifier) @local.reference
+
+; Definitions
+
+(annotation_identifier) @local.definition
+
+; (const_definition (identifier) @definition.constant)
+
+; (enum_definition "enum"
+; . (identifier) @definition.enum
+; "{" (identifier) @definition.constant "}")
+
+; (senum_definition "senum"
+; . (identifier) @definition.enum)
+
+; (field (identifier) @definition.field)
+
+; (function_definition (identifier) @definition.function)
+
+; (namespace_declaration
+; "namespace" (namespace_scope)
+; . (_) @definition.namespace
+; (namespace_uri)?)
+
+; (parameter (identifier) @definition.parameter)
+
+; (struct_definition
+; "struct" . (identifier) @definition.type)
+
+; (union_definition
+; "union" . (identifier) @definition.type)
+
+; (exception_definition
+; "exception" . (identifier) @definition.type)
+
+; (service_definition
+; "service" . (identifier) @definition.type)
+
+; (interaction_definition
+; "interaction" . (identifier) @definition.type)
+
+; (typedef_identifier) @definition.type