Skip to content

Commit

Permalink
feat: add ocaml support (#2085)
Browse files Browse the repository at this point in the history
* Add OCaml support.

* [autofix.ci] apply automated fixes

* Update programming-languages.md

* update

---------

Co-authored-by: O. Emmerson <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 1, 2024
1 parent 2defc5d commit 502b052
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changes/unreleased/Features-20240901-155914.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Features
body: Supports Ocaml
time: 2024-09-01T15:59:14.421993-07:00
52 changes: 52 additions & 0 deletions crates/tabby-common/assets/languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,55 @@ exts = ["tex"]
[[config]]
languages = ["vb"]
exts = ["vb"]

[[config]]
languages = ["ocaml"]
exts = ["ml", "mli"]
top_level_keywords = [
"and",
"as",
"assert",
"begin",
"class",
"constraint",
"do",
"done",
"downto",
"else",
"end",
"exception",
"external",
"for",
"fun",
"function",
"functor",
"if",
"in",
"include",
"inherit",
"initializer",
"lazy",
"let",
"match",
"method",
"module",
"mutable",
"new",
"nonrec",
"object",
"of",
"open",
"private",
"rec",
"sig",
"struct",
"then",
"to",
"try",
"type",
"val",
"virtual",
"when",
"while",
"with",
]
115 changes: 115 additions & 0 deletions crates/tabby-index/queries/ocaml.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
; Modules
;--------

(
(comment)? @doc .
(module_definition (module_binding (module_name) @name) @definition.module)
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

(module_path (module_name) @name) @reference.module

; Module types
;--------------

(
(comment)? @doc .
(module_type_definition (module_type_name) @name) @definition.interface
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

(module_type_path (module_type_name) @name) @reference.implementation

; Functions
;----------

(
(comment)? @doc .
(value_definition
[
(let_binding
pattern: (value_name) @name
(parameter))
(let_binding
pattern: (value_name) @name
body: [(fun_expression) (function_expression)])
] @definition.function
)
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

(
(comment)? @doc .
(external (value_name) @name) @definition.function
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

(application_expression
function: (value_path (value_name) @name)) @reference.call

(infix_expression
left: (value_path (value_name) @name)
operator: (concat_operator) @reference.call
(#eq? @reference.call "@@"))

(infix_expression
operator: (rel_operator) @reference.call
right: (value_path (value_name) @name)
(#eq? @reference.call "|>"))

; Operator
;---------

(
(comment)? @doc .
(value_definition
(let_binding
pattern: (parenthesized_operator (_) @name)) @definition.function)
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

[
(prefix_operator)
(sign_operator)
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(and_operator)
(or_operator)
(assign_operator)
(hash_operator)
(indexing_operator)
(let_operator)
(let_and_operator)
(match_operator)
] @name @reference.call

; Classes
;--------

(
(comment)? @doc .
[
(class_definition (class_binding (class_name) @name) @definition.class)
(class_type_definition (class_type_binding (class_type_name) @name) @definition.class)
]
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

[
(class_path (class_name) @name)
(class_type_path (class_type_name) @name)
] @reference.class

; Methods
;--------

(
(comment)? @doc .
(method_definition (method_name) @name) @definition.method
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
)

(method_invocation (method_name) @name) @reference.call
3 changes: 2 additions & 1 deletion website/docs/references/programming-languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ For an actual example of an issue or pull request adding the above support, plea
* [R](https://www.r-project.org/)
* [Dart](https://dart.dev/)
* [Lua](https://www.lua.org)
* [Elixir](https://elixir-lang.org): since 0.16
* [Elixir](https://elixir-lang.org)
* [OCaml](https://ocaml.org/): Since v0.17.0

## Languages Missing Certain Support

Expand Down

0 comments on commit 502b052

Please sign in to comment.