aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorDamian Zaręba2024-03-19 12:28:15 +0000
committerGitHub2024-03-19 12:28:15 +0000
commit485c5cf0b81ed1f189c5bb06263667449d5684d6 (patch)
treea5da5324e53af5a6595045f4ad87f5a790feb518 /runtime
parent0b6dea6dc2f78376890beeb31b591987f7f5249b (diff)
Initial Ada language support (after stale) (#9908)
* Adding initial support for ada language, based off #7790 PR from tomekw * More translation to helix-specific tree-sitter scm labels, add ada gpr switch to ada LSP * Generate ada in lang-support.md using cargo xtask docgen * Update tree-sitter definitions according to comments * Remove .gpr glob from languages.toml * Fix unit in languages.toml for ada, update locals.scm to helix needs
Diffstat (limited to 'runtime')
-rw-r--r--runtime/queries/ada/folds.scm15
-rw-r--r--runtime/queries/ada/highlights.scm176
-rw-r--r--runtime/queries/ada/locals.scm32
-rw-r--r--runtime/queries/ada/textobjects.scm21
4 files changed, 244 insertions, 0 deletions
diff --git a/runtime/queries/ada/folds.scm b/runtime/queries/ada/folds.scm
new file mode 100644
index 00000000..819d92cc
--- /dev/null
+++ b/runtime/queries/ada/folds.scm
@@ -0,0 +1,15 @@
+; Support for folding in Ada
+;; za toggles folding a package, subprogram, if statement or loop
+
+[
+ (package_declaration)
+ (generic_package_declaration)
+ (package_body)
+ (subprogram_declaration)
+ (subprogram_body)
+ (block_statement)
+ (if_statement)
+ (loop_statement)
+ (gnatprep_declarative_if_statement)
+ (gnatprep_if_statement)
+] @fold
diff --git a/runtime/queries/ada/highlights.scm b/runtime/queries/ada/highlights.scm
new file mode 100644
index 00000000..643fbd66
--- /dev/null
+++ b/runtime/queries/ada/highlights.scm
@@ -0,0 +1,176 @@
+;; highlight queries.
+;; See the syntax at https://tree-sitter.github.io/tree-sitter/using-parsers#pattern-matching-with-queries
+;; See also https://github.com/nvim-treesitter/nvim-treesitter/blob/master/CONTRIBUTING.md#parser-configurations
+;; for a list of recommended @ tags, though not all of them have matching
+;; highlights in neovim.
+
+[
+ "abort"
+ "abs"
+ "abstract"
+ "accept"
+ "access"
+ "all"
+ "array"
+ "at"
+ "begin"
+ "declare"
+ "delay"
+ "delta"
+ "digits"
+ "do"
+ "end"
+ "entry"
+ "exit"
+ "generic"
+ "interface"
+ "is"
+ "limited"
+ "of"
+ "others"
+ "out"
+ "pragma"
+ "private"
+ "range"
+ "synchronized"
+ "tagged"
+ "task"
+ "terminate"
+ "until"
+ "when"
+] @keyword
+[
+ "null"
+] @constant.builtin
+[
+ "aliased"
+ "constant"
+ "renames"
+] @keyword.storage
+[
+ "mod"
+ "new"
+ "protected"
+ "record"
+ "subtype"
+ "type"
+] @type.builtin
+[
+ "with"
+ "use"
+] @keyword.control.import
+[
+ "body"
+ "function"
+ "overriding"
+ "procedure"
+ "package"
+ "separate"
+] @keyword.function
+[
+ "and"
+ "in"
+ "not"
+ "or"
+ "xor"
+] @operator
+[
+ "while"
+ "loop"
+ "for"
+ "parallel"
+ "reverse"
+ "some"
+] @kewyord.control.repeat
+[
+ "return"
+] @keyword.control.return
+[
+ "case"
+ "if"
+ "else"
+ "then"
+ "elsif"
+ "select"
+] @keyword.control.conditional
+[
+ "exception"
+ "raise"
+] @keyword.control.exception
+(comment) @comment
+(string_literal) @string
+(character_literal) @string
+(numeric_literal) @constant.numeric
+
+;; Highlight the name of subprograms
+(procedure_specification name: (_) @function.builtin)
+(function_specification name: (_) @function.builtin)
+(package_declaration name: (_) @function.builtin)
+(package_body name: (_) @function.builtin)
+(generic_instantiation name: (_) @function.builtin)
+(entry_declaration . (identifier) @function.builtin)
+
+;; Some keywords should take different categories depending on the context
+(use_clause "use" @keyword.control.import "type" @keyword.control.import)
+(with_clause "private" @keyword.control.import)
+(with_clause "limited" @keyword.control.import)
+(use_clause (_) @namespace)
+(with_clause (_) @namespace)
+
+(loop_statement "end" @keyword.control.repeat)
+(if_statement "end" @keyword.control.conditional)
+(loop_parameter_specification "in" @keyword.control.repeat)
+(loop_parameter_specification "in" @keyword.control.repeat)
+(iterator_specification ["in" "of"] @keyword.control.repeat)
+(range_attribute_designator "range" @keyword.control.repeat)
+
+(raise_statement "with" @keyword.control.exception)
+
+(gnatprep_declarative_if_statement) @keyword.directive
+(gnatprep_if_statement) @keyword.directive
+(gnatprep_identifier) @keyword.directive
+
+(subprogram_declaration "is" @keyword.function "abstract" @keyword.function)
+(aspect_specification "with" @keyword.function)
+
+(full_type_declaration "is" @type.builtin)
+(subtype_declaration "is" @type.builtin)
+(record_definition "end" @type.builtin)
+(full_type_declaration (_ "access" @type.builtin))
+(array_type_definition "array" @type.builtin "of" @type.builtin)
+(access_to_object_definition "access" @type.builtin)
+(access_to_object_definition "access" @type.builtin
+ [
+ (general_access_modifier "constant" @type.builtin)
+ (general_access_modifier "all" @type.builtin)
+ ]
+)
+(range_constraint "range" @type.builtin)
+(signed_integer_type_definition "range" @type.builtin)
+(index_subtype_definition "range" @type.builtin)
+(record_type_definition "abstract" @type.builtin)
+(record_type_definition "tagged" @type.builtin)
+(record_type_definition "limited" @type.builtin)
+(record_type_definition (record_definition "null" @type.builtin))
+(private_type_declaration "is" @type.builtin "private" @type.builtin)
+(private_type_declaration "tagged" @type.builtin)
+(private_type_declaration "limited" @type.builtin)
+(task_type_declaration "task" @type.builtin "is" @type.builtin)
+
+;; Gray the body of expression functions
+(expression_function_declaration
+ (function_specification)
+ "is"
+ (_) @attribute
+)
+(subprogram_declaration (aspect_specification) @attribute)
+
+;; Highlight full subprogram specifications
+; (subprogram_body
+; [
+; (procedure_specification)
+; (function_specification)
+; ] @function.builtin.spec
+; )
+
+
diff --git a/runtime/queries/ada/locals.scm b/runtime/queries/ada/locals.scm
new file mode 100644
index 00000000..e532a2f1
--- /dev/null
+++ b/runtime/queries/ada/locals.scm
@@ -0,0 +1,32 @@
+;; Better highlighting by referencing to the definition, for variable references.
+;; See https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables
+
+(compilation) @local.scope
+(package_declaration) @local.scope
+(package_body) @local.scope
+(subprogram_declaration) @local.scope
+(subprogram_body) @local.scope
+(block_statement) @local.scope
+
+(with_clause (_) @local.definition)
+(procedure_specification name: (_) @local.definition)
+(function_specification name: (_) @local.definition)
+(package_declaration name: (_) @local.definition)
+(package_body name: (_) @local.definition)
+(generic_instantiation . name: (_) @local.definition)
+(component_declaration . (identifier) @local.definition)
+(exception_declaration . (identifier) @local.definition)
+(formal_object_declaration . (identifier) @local.definition)
+(object_declaration . (identifier) @local.definition)
+(parameter_specification . (identifier) @local.definition)
+(full_type_declaration . (identifier) @local.definition)
+(private_type_declaration . (identifier) @local.definition)
+(private_extension_declaration . (identifier) @local.definition)
+(incomplete_type_declaration . (identifier) @local.definition)
+(protected_type_declaration . (identifier) @local.definition)
+(formal_complete_type_declaration . (identifier) @local.definition)
+(formal_incomplete_type_declaration . (identifier) @local.definition)
+(task_type_declaration . (identifier) @local.definition)
+(subtype_declaration . (identifier) @local.definition)
+
+(identifier) @local.reference
diff --git a/runtime/queries/ada/textobjects.scm b/runtime/queries/ada/textobjects.scm
new file mode 100644
index 00000000..284b4125
--- /dev/null
+++ b/runtime/queries/ada/textobjects.scm
@@ -0,0 +1,21 @@
+;; Support for high-level text objects selections.
+;; For instance:
+;; maf (v)isually select (a) (f)unction or subprogram
+;; mif (v)isually select (i)nside a (f)unction or subprogram
+;; mai (v)isually select (a) (i)f statement (or loop)
+;; mii (v)isually select (i)nside an (i)f statement (or loop)
+;;
+;; For navigations using textobjects, check link below:
+;; https://docs.helix-editor.com/master/usage.html#navigating-using-tree-sitter-textobjects
+;;
+;; For Textobject queries explaination, check out link below:
+;; https://docs.helix-editor.com/master/guides/textobject.html
+
+(subprogram_body) @function.around
+(subprogram_body (non_empty_declarative_part) @function.inside)
+(subprogram_body (handled_sequence_of_statements) @function.inside)
+(function_specification) @function.around
+(procedure_specification) @function.around
+(package_declaration) @function.around
+(generic_package_declaration) @function.around
+(package_body) @function.around