@@ -8,6 +8,35 @@ module Utils = struct
8
8
match content with
9
9
| None -> None
10
10
| Some content -> Some (wrapInTag content ~tag )
11
+
12
+ let print_type_with_related_types ~full t =
13
+ let {TypeUtils.ExpandType. mainTypes; relatedTypes} =
14
+ TypeUtils.ExpandType. expandTypes t ~full
15
+ in
16
+ Some
17
+ (Printf. sprintf
18
+ " <main_types>\n \
19
+ %s\n \
20
+ </main_types>\n\n \
21
+ <related_types>\n \
22
+ %s\n \
23
+ </related_types>"
24
+ (mainTypes
25
+ |> List. map (fun (input : TypeUtils.ExpandType.expandTypeInput ) ->
26
+ match input with
27
+ | TypeUtils.ExpandType. TypeExpr {typeExpr} ->
28
+ Shared. typeToString typeExpr
29
+ | TypeUtils.ExpandType. TypeDecl {name; typeDecl} ->
30
+ Shared. declToString name.txt typeDecl)
31
+ |> String. concat " \n\n " )
32
+ (relatedTypes
33
+ |> List. map (fun (input : TypeUtils.ExpandType.expandTypeInput ) ->
34
+ match input with
35
+ | TypeUtils.ExpandType. TypeExpr {typeExpr} ->
36
+ Shared. typeToString typeExpr
37
+ | TypeUtils.ExpandType. TypeDecl {name; typeDecl} ->
38
+ Shared. declToString name.txt typeDecl)
39
+ |> String. concat " \n\n " ))
11
40
end
12
41
13
42
module LocInfo = struct
@@ -99,42 +128,13 @@ module LocInfo = struct
99
128
showModule ~docstring: file.structure.docstring
100
129
~name: file.moduleName ~file ~package None )
101
130
| Typed (name , t , _ ) ->
102
- let {TypeUtils.ExpandType. mainTypes; relatedTypes} =
103
- TypeUtils.ExpandType. expandTypes
104
- (TypeUtils.ExpandType. TypeExpr
105
- {
106
- typeExpr = t;
107
- name = Some (Location. mkloc name locItem.loc);
108
- env = QueryEnv. fromFile full.file;
109
- })
110
- ~full
111
- in
112
- Some
113
- (Printf. sprintf
114
- " <main_types>\n \
115
- %s\n \
116
- </main_types>\n\n \
117
- <related_types>\n \
118
- %s\n \
119
- </related_types>"
120
- (mainTypes
121
- |> List. map
122
- (fun (input : TypeUtils.ExpandType.expandTypeInput ) ->
123
- match input with
124
- | TypeUtils.ExpandType. TypeExpr {typeExpr} ->
125
- Shared. typeToString typeExpr
126
- | TypeUtils.ExpandType. TypeDecl {name; typeDecl} ->
127
- Shared. declToString name.txt typeDecl)
128
- |> String. concat " \n\n " )
129
- (relatedTypes
130
- |> List. map
131
- (fun (input : TypeUtils.ExpandType.expandTypeInput ) ->
132
- match input with
133
- | TypeUtils.ExpandType. TypeExpr {typeExpr} ->
134
- Shared. typeToString typeExpr
135
- | TypeUtils.ExpandType. TypeDecl {name; typeDecl} ->
136
- Shared. declToString name.txt typeDecl)
137
- |> String. concat " \n\n " ))
131
+ Utils. print_type_with_related_types ~full
132
+ (TypeUtils.ExpandType. TypeExpr
133
+ {
134
+ typeExpr = t;
135
+ name = Some (Location. mkloc name locItem.loc);
136
+ env = QueryEnv. fromFile full.file;
137
+ })
138
138
| Constant t ->
139
139
Some
140
140
(match t with
@@ -150,3 +150,77 @@ module LocInfo = struct
150
150
| None -> " No result."
151
151
| Some s -> s
152
152
end
153
+
154
+ module IdentifierInfo = struct
155
+ let identifierInfo ~identifier ~path ~maybe_line ~maybe_col =
156
+ (* TODO: Pull out the right scope + opens if these are set. *)
157
+ ignore maybe_line;
158
+ ignore maybe_col;
159
+
160
+ let result =
161
+ match Cmt. loadFullCmtFromPath ~path with
162
+ | None -> None
163
+ | Some full ->
164
+ let env = QueryEnv. fromFile full.file in
165
+ let scope = Scope. create () in
166
+ let opens = [] in
167
+ let pos = (0 , 0 ) in
168
+ let path = identifier |> String. split_on_char '.' in
169
+ let hd_opt l = List. nth_opt l 0 in
170
+ let print_completion_item (item : Completion.t ) =
171
+ match item.kind with
172
+ | Value t ->
173
+ Some
174
+ (Printf. sprintf " Value %s:\n <value>\n %s\n </value>" identifier
175
+ (match
176
+ Utils. print_type_with_related_types ~full
177
+ (TypeUtils.ExpandType. TypeExpr
178
+ {
179
+ typeExpr = t;
180
+ name = Some (Location. mknoloc item.name);
181
+ env = QueryEnv. fromFile full.file;
182
+ })
183
+ with
184
+ | None -> " "
185
+ | Some s -> s))
186
+ | Type {decl; name} ->
187
+ Some
188
+ (Printf. sprintf " Type %s:\n <type>\n %s\n </type>" identifier
189
+ (Shared. declToString name decl))
190
+ (* | Module {module_} -> Some (LocInfo.showModule)*)
191
+ | _ -> None
192
+ in
193
+ let value_completions =
194
+ CompletionBackEnd. getCompletionsForPath ~exact: true ~debug: false ~full
195
+ ~completion Context:Value ~pos ~env ~scope ~opens path
196
+ |> hd_opt
197
+ in
198
+ let type_completions =
199
+ CompletionBackEnd. getCompletionsForPath ~exact: true ~debug: false ~full
200
+ ~completion Context:Type ~pos ~env ~scope ~opens path
201
+ |> hd_opt
202
+ in
203
+ let module_completions =
204
+ CompletionBackEnd. getCompletionsForPath ~exact: true ~debug: false ~full
205
+ ~completion Context:Module ~pos ~env ~scope ~opens path
206
+ |> hd_opt
207
+ in
208
+ Some
209
+ ([
210
+ (match value_completions with
211
+ | None -> None
212
+ | Some c -> print_completion_item c);
213
+ (match type_completions with
214
+ | None -> None
215
+ | Some c -> print_completion_item c);
216
+ (match module_completions with
217
+ | None -> None
218
+ | Some c -> print_completion_item c);
219
+ ]
220
+ |> List. filter_map (fun x -> x)
221
+ |> String. concat " \n\n " )
222
+ in
223
+ match result with
224
+ | None -> " No result."
225
+ | Some s -> s
226
+ end
0 commit comments