Skip to content

Commit f725fbf

Browse files
committed
Completion debug
start having a single entry point for completions
1 parent 1fe913b commit f725fbf

File tree

3 files changed

+57
-69
lines changed

3 files changed

+57
-69
lines changed

analysis/src/Commands.ml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
let getCompletions ~debug ~path ~pos ~currentFile ~forHover =
2-
let textOpt = Files.readFile currentFile in
3-
match textOpt with
4-
| None | Some "" -> []
5-
| Some text -> (
1+
let completion ~debug ~path ~pos ~currentFile =
2+
let completions =
63
match
7-
CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos
8-
~currentFile ~text
4+
Completions.getCompletions ~debug ~path ~pos ~currentFile ~forHover:false
95
with
106
| None -> []
11-
| Some (completable, scope) -> (
12-
if debug then
13-
Printf.printf "Completable: %s\n"
14-
(SharedTypes.Completable.toString completable);
15-
(* Only perform expensive ast operations if there are completables *)
16-
match Cmt.loadFullCmtFromPath ~path with
17-
| None -> []
18-
| Some full ->
19-
let env = SharedTypes.QueryEnv.fromFile full.file in
20-
completable
21-
|> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env
22-
~forHover))
23-
24-
let completion ~debug ~path ~pos ~currentFile =
7+
| Some (completions, _) -> completions
8+
in
259
print_endline
26-
(getCompletions ~debug ~path ~pos ~currentFile ~forHover:false
10+
(completions
2711
|> List.map CompletionBackEnd.completionToItem
2812
|> List.map Protocol.stringifyCompletionItem
2913
|> Protocol.array)

analysis/src/Completions.ml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
let getCompletions ~debug ~path ~pos ~currentFile ~forHover =
2+
let textOpt = Files.readFile currentFile in
3+
match textOpt with
4+
| None | Some "" -> None
5+
| Some text -> (
6+
match
7+
CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos
8+
~currentFile ~text
9+
with
10+
| None -> None
11+
| Some (completable, scope) -> (
12+
if debug then
13+
Printf.printf "Completable: %s\n"
14+
(SharedTypes.Completable.toString completable);
15+
(* Only perform expensive ast operations if there are completables *)
16+
match Cmt.loadFullCmtFromPath ~path with
17+
| None -> None
18+
| Some full ->
19+
let env = SharedTypes.QueryEnv.fromFile full.file in
20+
let completables =
21+
completable
22+
|> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env
23+
~forHover
24+
in
25+
Some (completables, full)))

analysis/src/Hover.ml

Lines changed: 26 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -123,54 +123,33 @@ let hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ =
123123
makes it (most often) work with unsaved content. *)
124124
let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
125125
~supportsMarkdownLinks =
126-
let textOpt = Files.readFile currentFile in
127-
match textOpt with
128-
| None | Some "" -> None
129-
| Some text -> (
130-
match
131-
CompletionFrontEnd.completionWithParser ~debug ~path ~posCursor:pos
132-
~currentFile ~text
133-
with
134-
| None -> None
135-
| Some (completable, scope) -> (
136-
if debug then
137-
Printf.printf "Completable: %s\n"
138-
(SharedTypes.Completable.toString completable);
139-
(* Only perform expensive ast operations if there are completables *)
140-
match Cmt.loadFullCmtFromPath ~path with
141-
| None -> None
142-
| Some full -> (
143-
let {file; package} = full in
144-
let env = SharedTypes.QueryEnv.fromFile file in
145-
let completions =
146-
completable
147-
|> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env
148-
~forHover
126+
match Completions.getCompletions ~debug ~path ~pos ~currentFile ~forHover with
127+
| None -> None
128+
| Some (completions, {file; package}) -> (
129+
match completions with
130+
| {kind = Label typString; docstring} :: _ ->
131+
let parts =
132+
(if typString = "" then [] else [Markdown.codeBlock typString])
133+
@ docstring
134+
in
135+
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
136+
| {kind = Field _; docstring} :: _ -> (
137+
match CompletionBackEnd.completionsGetTypeEnv completions with
138+
| Some (typ, _env) ->
139+
let typeString =
140+
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
149141
in
150-
match completions with
151-
| {kind = Label typString; docstring} :: _ ->
152-
let parts =
153-
(if typString = "" then [] else [Markdown.codeBlock typString])
154-
@ docstring
155-
in
156-
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
157-
| {kind = Field _; docstring} :: _ -> (
158-
match CompletionBackEnd.completionsGetTypeEnv completions with
159-
| Some (typ, _env) ->
160-
let typeString =
161-
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
162-
in
163-
let parts = typeString :: docstring in
164-
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
165-
| None -> None)
166-
| _ -> (
167-
match CompletionBackEnd.completionsGetTypeEnv completions with
168-
| Some (typ, _env) ->
169-
let typeString =
170-
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
171-
in
172-
Some (Protocol.stringifyHover typeString)
173-
| None -> None))))
142+
let parts = typeString :: docstring in
143+
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
144+
| None -> None)
145+
| _ -> (
146+
match CompletionBackEnd.completionsGetTypeEnv completions with
147+
| Some (typ, _env) ->
148+
let typeString =
149+
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
150+
in
151+
Some (Protocol.stringifyHover typeString)
152+
| None -> None))
174153

175154
let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
176155
match locItem.locType with

0 commit comments

Comments
 (0)