Skip to content

Commit 9990965

Browse files
Merge pull request #3679 from andreypopp/main
feat: add repomap support for ocaml/ocaml_interface
2 parents 5b52063 + e980973 commit 9990965

File tree

5 files changed

+332
-2
lines changed

5 files changed

+332
-2
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
; Modules
2+
;--------
3+
4+
(
5+
(comment)? @doc .
6+
(module_definition (module_binding (module_name) @name.definition.module) @definition.module)
7+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
8+
)
9+
10+
(module_path (module_name) @name.reference.module) @reference.module
11+
12+
; Module types
13+
;--------------
14+
15+
(
16+
(comment)? @doc .
17+
(module_type_definition (module_type_name) @name.definition.interface) @definition.interface
18+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
19+
)
20+
21+
(module_type_path (module_type_name) @name.reference.implementation) @reference.implementation
22+
23+
; Functions
24+
;----------
25+
26+
(
27+
(comment)? @doc .
28+
(value_definition
29+
[
30+
(let_binding
31+
pattern: (value_name) @name.definition.function
32+
(parameter))
33+
(let_binding
34+
pattern: (value_name) @name.definition.function
35+
body: [(fun_expression) (function_expression)])
36+
] @definition.function
37+
)
38+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
39+
)
40+
41+
(
42+
(comment)? @doc .
43+
(external (value_name) @name.definition.function) @definition.function
44+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
45+
)
46+
47+
(application_expression
48+
function: (value_path (value_name) @name.reference.call)) @reference.call
49+
50+
(infix_expression
51+
left: (value_path (value_name) @name.reference.call)
52+
operator: (concat_operator) @reference.call
53+
(#eq? @reference.call "@@"))
54+
55+
(infix_expression
56+
operator: (rel_operator) @reference.call
57+
right: (value_path (value_name) @name.reference.call)
58+
(#eq? @reference.call "|>"))
59+
60+
; Operator
61+
;---------
62+
63+
(
64+
(comment)? @doc .
65+
(value_definition
66+
(let_binding
67+
pattern: (parenthesized_operator (_) @name.definition.function)) @definition.function)
68+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
69+
)
70+
71+
[
72+
(prefix_operator)
73+
(sign_operator)
74+
(pow_operator)
75+
(mult_operator)
76+
(add_operator)
77+
(concat_operator)
78+
(rel_operator)
79+
(and_operator)
80+
(or_operator)
81+
(assign_operator)
82+
(hash_operator)
83+
(indexing_operator)
84+
(let_operator)
85+
(let_and_operator)
86+
(match_operator)
87+
] @name.reference.call @reference.call
88+
89+
; Classes
90+
;--------
91+
92+
(
93+
(comment)? @doc .
94+
[
95+
(class_definition (class_binding (class_name) @name.definition.class) @definition.class)
96+
(class_type_definition (class_type_binding (class_type_name) @name.definition.class) @definition.class)
97+
]
98+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
99+
)
100+
101+
[
102+
(class_path (class_name) @name.reference.class)
103+
(class_type_path (class_type_name) @name.reference.class)
104+
] @reference.class
105+
106+
; Methods
107+
;--------
108+
109+
(
110+
(comment)? @doc .
111+
(method_definition (method_name) @name.definition.method) @definition.method
112+
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
113+
)
114+
115+
(method_invocation (method_name) @name.reference.call) @reference.call
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
; Modules
2+
;--------
3+
4+
(
5+
(comment)? @doc .
6+
(module_definition
7+
(module_binding (module_name) @name) @definition.module
8+
)
9+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
10+
)
11+
12+
(module_path (module_name) @name) @reference.module
13+
(extended_module_path (module_name) @name) @reference.module
14+
15+
(
16+
(comment)? @doc .
17+
(module_type_definition (module_type_name) @name) @definition.interface
18+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
19+
)
20+
21+
(module_type_path (module_type_name) @name) @reference.implementation
22+
23+
24+
; Classes
25+
;--------
26+
27+
(
28+
(comment)? @doc .
29+
[
30+
(class_definition
31+
(class_binding (class_name) @name) @definition.class
32+
)
33+
(class_type_definition
34+
(class_type_binding (class_type_name) @name) @definition.class
35+
)
36+
]
37+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
38+
)
39+
40+
[
41+
(class_path (class_name) @name)
42+
(class_type_path (class_type_name) @name)
43+
] @reference.class
44+
45+
(
46+
(comment)? @doc .
47+
(method_definition (method_name) @name) @definition.method
48+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
49+
)
50+
51+
(method_invocation (method_name) @name) @reference.call
52+
53+
54+
; Types
55+
;------
56+
57+
(
58+
(comment)? @doc .
59+
(type_definition
60+
(type_binding
61+
name: [
62+
(type_constructor) @name
63+
(type_constructor_path (type_constructor) @name)
64+
]
65+
) @definition.type
66+
)
67+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
68+
)
69+
70+
(type_constructor_path (type_constructor) @name) @reference.type
71+
72+
[
73+
(constructor_declaration (constructor_name) @name)
74+
(tag_specification (tag) @name)
75+
] @definition.enum_variant
76+
77+
[
78+
(constructor_path (constructor_name) @name)
79+
(tag) @name
80+
] @reference.enum_variant
81+
82+
(field_declaration (field_name) @name) @definition.field
83+
84+
(field_path (field_name) @name) @reference.field
85+
86+
(
87+
(comment)? @doc .
88+
(external (value_name) @name) @definition.function
89+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
90+
)
91+
92+
(
93+
(comment)? @doc .
94+
(value_specification
95+
(value_name) @name.definition.function
96+
) @definition.function
97+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
98+
)
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
; Modules
2+
;--------
3+
4+
(
5+
(comment)? @doc .
6+
(module_definition
7+
(module_binding (module_name) @name) @definition.module
8+
)
9+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
10+
)
11+
12+
(module_path (module_name) @name) @reference.module
13+
(extended_module_path (module_name) @name) @reference.module
14+
15+
(
16+
(comment)? @doc .
17+
(module_type_definition (module_type_name) @name) @definition.interface
18+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
19+
)
20+
21+
(module_type_path (module_type_name) @name) @reference.implementation
22+
23+
24+
; Classes
25+
;--------
26+
27+
(
28+
(comment)? @doc .
29+
[
30+
(class_definition
31+
(class_binding (class_name) @name) @definition.class
32+
)
33+
(class_type_definition
34+
(class_type_binding (class_type_name) @name) @definition.class
35+
)
36+
]
37+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
38+
)
39+
40+
[
41+
(class_path (class_name) @name)
42+
(class_type_path (class_type_name) @name)
43+
] @reference.class
44+
45+
(
46+
(comment)? @doc .
47+
(method_definition (method_name) @name) @definition.method
48+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
49+
)
50+
51+
(method_invocation (method_name) @name) @reference.call
52+
53+
54+
; Types
55+
;------
56+
57+
(
58+
(comment)? @doc .
59+
(type_definition
60+
(type_binding
61+
name: [
62+
(type_constructor) @name
63+
(type_constructor_path (type_constructor) @name)
64+
]
65+
) @definition.type
66+
)
67+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
68+
)
69+
70+
(type_constructor_path (type_constructor) @name) @reference.type
71+
72+
[
73+
(constructor_declaration (constructor_name) @name)
74+
(tag_specification (tag) @name)
75+
] @definition.enum_variant
76+
77+
[
78+
(constructor_path (constructor_name) @name)
79+
(tag) @name
80+
] @reference.enum_variant
81+
82+
(field_declaration (field_name) @name) @definition.field
83+
84+
(field_path (field_name) @name) @reference.field
85+
86+
(
87+
(comment)? @doc .
88+
(external (value_name) @name) @definition.function
89+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
90+
)
91+
92+
(
93+
(comment)? @doc .
94+
(value_specification
95+
(value_name) @name.definition.function
96+
) @definition.function
97+
(#strip! @doc "^\\(\\*+\\s*|\\s*\\*+\\)$")
98+
)

tests/basic/test_repomap.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,6 @@ def test_language_kotlin(self):
314314
def test_language_lua(self):
315315
self._test_language_repo_map("lua", "lua", "greet")
316316

317-
# "ocaml": ("ml", "Greeter"), # not supported in tsl-pack (yet?)
318-
319317
def test_language_php(self):
320318
self._test_language_repo_map("php", "php", "greet")
321319

@@ -384,6 +382,12 @@ def test_language_udev(self):
384382
def test_language_scala(self):
385383
self._test_language_repo_map("scala", "scala", "Greeter")
386384

385+
def test_language_ocaml(self):
386+
self._test_language_repo_map("ocaml", "ml", "Greeter")
387+
388+
def test_language_ocaml_interface(self):
389+
self._test_language_repo_map("ocaml_interface", "mli", "Greeter")
390+
387391
def _test_language_repo_map(self, lang, key, symbol):
388392
"""Helper method to test repo map generation for a specific language."""
389393
# Get the fixture file path and name based on language
@@ -407,6 +411,7 @@ def _test_language_repo_map(self, lang, key, symbol):
407411
dump(lang)
408412
dump(result)
409413

414+
print(result)
410415
self.assertGreater(len(result.strip().splitlines()), 1)
411416

412417
# Check if the result contains all the expected files and symbols
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(* Module definition *)
2+
module Greeter : sig
3+
type person = {
4+
name: string;
5+
age: int
6+
}
7+
8+
val create_person : string -> int -> person
9+
10+
val greet : person -> unit
11+
end
12+
13+
(* Outside the module *)
14+
val main : unit -> unit

0 commit comments

Comments
 (0)