Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Ada language support (after stale) #9908

Merged
merged 7 commits into from
Mar 19, 2024
Merged
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP |
| --- | --- | --- | --- | --- |
| ada | ✓ | ✓ | | `ada_language_server`, `ada_language_server` |
| agda | ✓ | | | |
| astro | ✓ | | | |
| awk | ✓ | ✓ | | `awk-language-server` |
Expand Down
17 changes: 17 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use-grammars = { except = [ "hare", "wren", "gemini" ] }
[language-server]

als = { command = "als" }
ada-language-server = { command = "ada_language_server" }
ada-gpr-language-server = {command = "ada_language_server", args = ["--language-gpr"]}
awk-language-server = { command = "awk-language-server" }
bash-language-server = { command = "bash-language-server", args = ["start"] }
bass = { command = "bass", args = ["--lsp"] }
Expand Down Expand Up @@ -2336,6 +2338,21 @@ language-servers = [ "jsonnet-language-server" ]
name = "jsonnet"
source = { git = "https://github.com/sourcegraph/tree-sitter-jsonnet", rev = "0475a5017ad7dc84845d1d33187f2321abcb261d" }

[[language]]
name = "ada"
scope = "source.ada"
injection-regex = "ada"
file-types = ["adb", "ads", "gpr"]
roots = ["alire.toml", "*.gpr"]
KhazAkar marked this conversation as resolved.
Show resolved Hide resolved
comment-token = "--"
indent = { tab-width = 3, unit = " " }
KhazAkar marked this conversation as resolved.
Show resolved Hide resolved
language-servers = ["ada-language-server", "ada-gpr-language-server"]


[[grammar]]
name = "ada"
source = { git = "https://github.com/briot/tree-sitter-ada", rev = "ba0894efa03beb70780156b91e28c716b7a4764d" }

[[language]]
name = "astro"
scope = "source.astro"
Expand Down
15 changes: 15 additions & 0 deletions runtime/queries/ada/folds.scm
Original file line number Diff line number Diff line change
@@ -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
178 changes: 178 additions & 0 deletions runtime/queries/ada/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
;; 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
(comment) @spell ;; spell-check comments
(string_literal) @string
(string_literal) @spell ;; spell-check strings
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
(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) @preproc
(gnatprep_if_statement) @preproc
(gnatprep_identifier) @preproc
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved

(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
; )


33 changes: 33 additions & 0 deletions runtime/queries/ada/locals.scm
KhazAkar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
;; Better highlighting by referencing to the definition, for variable
;; references. However, this is not yet supported by neovim
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
;; See https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables

(compilation) @scope
(package_declaration) @scope
(package_body) @scope
(subprogram_declaration) @scope
(subprogram_body) @scope
(block_statement) @scope

(with_clause (_) @definition.import)
(procedure_specification name: (_) @definition.function)
(function_specification name: (_) @definition.function)
(package_declaration name: (_) @definition.var)
(package_body name: (_) @definition.var)
(generic_instantiation . name: (_) @definition.var)
(component_declaration . (identifier) @definition.var)
(exception_declaration . (identifier) @definition.var)
(formal_object_declaration . (identifier) @definition.var)
(object_declaration . (identifier) @definition.var)
(parameter_specification . (identifier) @definition.var)
(full_type_declaration . (identifier) @definition.type)
(private_type_declaration . (identifier) @definition.type)
(private_extension_declaration . (identifier) @definition.type)
(incomplete_type_declaration . (identifier) @definition.type)
(protected_type_declaration . (identifier) @definition.type)
(formal_complete_type_declaration . (identifier) @definition.type)
(formal_incomplete_type_declaration . (identifier) @definition.type)
(task_type_declaration . (identifier) @definition.type)
(subtype_declaration . (identifier) @definition.type)

(identifier) @reference
23 changes: 23 additions & 0 deletions runtime/queries/ada/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
;; Support for high-level text objects selections.
;; For instance:
;; vaf (v)isually select (a) (f)unction or subprogram
;; vif (v)isually select (i)nside a (f)unction or subprogram
;; vai (v)isually select (a) (i)f statement (or loop)
;; vii (v)isually select (i)nside an (i)f statement (or loop)
;;
;; https://github.com/nvim-treesitter/nvim-treesitter-textobjects/blob/master/README.md
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved

(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
(if_statement) @object.around
(if_statement statements: (_) @object.inside)
(if_statement else_statements: (_) @object.inside)
(elsif_statement_item statements: (_) @object.inside)
(loop_statement) @object.around
(loop_statement statements: (_) @object.inside)
the-mikedavis marked this conversation as resolved.
Show resolved Hide resolved
Loading