Skip to content

Commit 59c6275

Browse files
committed
restore most of old setup so it can run in parallell
1 parent 671e261 commit 59c6275

17 files changed

+301
-111
lines changed

analysis/bin/main.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ let main () =
132132
Commands.completion ~debug ~path
133133
~pos:(int_of_string line, int_of_string col)
134134
~currentFile
135+
| [_; "completion-revamped"; path; line; col; currentFile] ->
136+
printHeaderInfo path line col;
137+
Commands.completionRevamped ~debug ~path
138+
~pos:(int_of_string line, int_of_string col)
139+
~currentFile
135140
| [_; "completionResolve"; path; modulePath] ->
136141
Commands.completionResolve ~path ~modulePath
137142
| [_; "definition"; path; line; col] ->
@@ -143,10 +148,10 @@ let main () =
143148
~pos:(int_of_string line, int_of_string col)
144149
~debug
145150
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
146-
| [_; "hover"; path; line; col; _currentFile; supportsMarkdownLinks] ->
151+
| [_; "hover"; path; line; col; currentFile; supportsMarkdownLinks] ->
147152
Commands.hover ~path
148153
~pos:(int_of_string line, int_of_string col)
149-
~debug
154+
~currentFile ~debug
150155
~supportsMarkdownLinks:
151156
(match supportsMarkdownLinks with
152157
| "true" -> true

analysis/src/Commands.ml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ let completion ~debug ~path ~pos ~currentFile =
1111
in
1212
completions |> Protocol.array |> print_endline
1313

14+
let completionRevamped ~debug ~path ~pos ~currentFile =
15+
let completions =
16+
match Completions.getCompletionsRevamped ~debug ~path ~pos ~currentFile with
17+
| None -> []
18+
| Some (completions, full, _) ->
19+
completions
20+
|> List.map (CompletionBackEnd.completionToItem ~full)
21+
|> List.map Protocol.stringifyCompletionItem
22+
in
23+
completions |> Protocol.array |> print_endline
1424
let completionResolve ~path ~modulePath =
1525
(* We ignore the internal module path as of now because there's currently
1626
no use case for it. But, if we wanted to move resolving documentation
@@ -57,13 +67,22 @@ let codeLens ~path ~debug =
5767
in
5868
print_endline result
5969

60-
let hover ~path ~pos ~debug ~supportsMarkdownLinks =
70+
let hover ~path ~pos ~currentFile ~debug ~supportsMarkdownLinks =
6171
let result =
6272
match Cmt.loadFullCmtFromPath ~path with
6373
| None -> Protocol.null
6474
| Some full -> (
6575
match References.getLocItem ~full ~pos ~debug with
66-
| None -> Protocol.null
76+
| None -> (
77+
if debug then
78+
Printf.printf
79+
"Nothing at that position. Now trying to use completion.\n";
80+
match
81+
Hover.getHoverViaCompletions ~debug ~path ~pos ~currentFile
82+
~forHover:true ~supportsMarkdownLinks
83+
with
84+
| None -> Protocol.null
85+
| Some hover -> hover)
6786
| Some locItem -> (
6887
let isModule =
6988
match locItem.locType with
@@ -364,6 +383,13 @@ let test ~path =
364383
let currentFile = createCurrentFile () in
365384
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
366385
Sys.remove currentFile
386+
| "crm" ->
387+
print_endline
388+
("Complete Revamped " ^ path ^ " " ^ string_of_int line ^ ":"
389+
^ string_of_int col);
390+
let currentFile = createCurrentFile () in
391+
completionRevamped ~debug:true ~path ~pos:(line, col) ~currentFile;
392+
Sys.remove currentFile
367393
| "cre" ->
368394
let modulePath = String.sub rest 3 (String.length rest - 3) in
369395
let modulePath = String.trim modulePath in
@@ -388,7 +414,8 @@ let test ~path =
388414
("Hover " ^ path ^ " " ^ string_of_int line ^ ":"
389415
^ string_of_int col);
390416
let currentFile = createCurrentFile () in
391-
hover ~supportsMarkdownLinks:true ~path ~pos:(line, col) ~debug:true;
417+
hover ~supportsMarkdownLinks:true ~path ~pos:(line, col)
418+
~currentFile ~debug:true;
392419
Sys.remove currentFile
393420
| "she" ->
394421
print_endline

analysis/src/CompletionBackEndRevamped.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let findRecordField ~env ~package ~fieldName typ =
1919
fields |> List.find_opt (fun (field : field) -> field.fname.txt = fieldName)
2020

2121
let completeEmptyPattern ~env ~package typ =
22+
prerr_endline (Shared.typeToString typ);
2223
match TypeUtils.extractType ~env ~package typ with
2324
| None -> []
2425
| Some (completionType, typeArgContext) -> (

analysis/src/Completions.ml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
let getCompletions ~debug ~path ~pos ~currentFile ~forHover =
2-
ignore 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+
(* Only perform expensive ast operations if there are completables *)
13+
match Cmt.loadFullCmtFromPath ~path with
14+
| None -> None
15+
| Some full ->
16+
let env = SharedTypes.QueryEnv.fromFile full.file in
17+
let completables =
18+
completable
19+
|> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env
20+
~forHover
21+
in
22+
Some (completables, full, scope)))
23+
24+
let getCompletionsRevamped ~debug ~path ~pos ~currentFile =
325
let textOpt = Files.readFile currentFile in
426
match textOpt with
527
| None | Some "" -> None

analysis/src/Hover.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
245245
~package None)
246246
| Typed (_, _, Definition (_, (Field _ | Constructor _))) -> None
247247
| OtherExpression t | OtherPattern t ->
248+
(* TODO: Just for debugging. *)
248249
Some (Markdown.codeBlock (Shared.typeToString t))
249250
| Constant t ->
250251
Some

compiler/ml/clflags.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ and only_parse = ref false (* -only-parse *)
4242

4343
and ignore_parse_errors = ref false (* -ignore-parse-errors *)
4444

45-
and editor_mode = ref true
45+
and editor_mode = ref false
4646
(* -editor-mode *)
4747
(* true for easy testing *)
4848

tests/analysis_tests/tests/src/EnhanceHover.res

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/analysis_tests/tests/src/expected/Completion.res.txt

Lines changed: 34 additions & 22 deletions
Large diffs are not rendered by default.

tests/analysis_tests/tests/src/expected/CompletionInferValues.res.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,5 +967,17 @@ Path ReactDOM.Client.Root.
967967
}]
968968

969969
Hover src/CompletionInferValues.res 160:27
970-
null
970+
Nothing at that position. Now trying to use completion.
971+
posCursor:[160:27] posNoWhite:[160:26] Found expr:[160:25->160:28]
972+
Pexp_ident res:[160:25->160:28]
973+
Completable: Cpath Value[res]
974+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
975+
Resolved opens 1 Stdlib
976+
ContextPath Value[res]
977+
Path res
978+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
979+
Resolved opens 1 Stdlib
980+
ContextPath Value[res]
981+
Path res
982+
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```"}}
971983

tests/analysis_tests/tests/src/expected/EnhanceHover.res.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)