Skip to content

Commit 84aecb9

Browse files
committed
use config to activate new engine
1 parent c9ae2c8 commit 84aecb9

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

analysis/bin/main.ml

+9-8
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ let main () =
129129
| _ -> print_endline "\"ERR: Did not find root \"")
130130
| [_; "completion"; path; line; col; currentFile] ->
131131
printHeaderInfo path line col;
132-
Commands.completion ~debug ~path
133-
~pos:(int_of_string line, int_of_string col)
134-
~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
132+
if !Cfg.useRevampedCompletion then
133+
Commands.completionRevamped ~debug ~path
134+
~pos:(int_of_string line, int_of_string col)
135+
~currentFile
136+
else
137+
Commands.completion ~debug ~path
138+
~pos:(int_of_string line, int_of_string col)
139+
~currentFile
140140
| [_; "completionResolve"; path; modulePath] ->
141141
Commands.completionResolve ~path ~modulePath
142142
| [_; "definition"; path; line; col] ->
@@ -216,6 +216,7 @@ let main () =
216216
| [_; "test"; path] -> Commands.test ~path
217217
| [_; "test_revamped"; path; config_file_path] ->
218218
Packages.overrideConfigFilePath := Some config_file_path;
219+
Cfg.useRevampedCompletion := true;
219220
Commands.test ~path
220221
| args when List.mem "-h" args || List.mem "--help" args -> prerr_endline help
221222
| _ ->

analysis/src/Cfg.ml

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ let readProjectConfigCache =
1717
| "true" -> true
1818
| _ -> false
1919
with _ -> false)
20+
21+
let useRevampedCompletion =
22+
ref (Sys.getenv_opt "RESCRIPT_NEW_ANALYSIS_ENGINE" |> Option.is_some)

analysis/src/Commands.ml

+4-8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ let hover ~path ~pos ~currentFile ~debug ~supportsMarkdownLinks =
7373
| None -> Protocol.null
7474
| Some full -> (
7575
match References.getLocItem ~full ~pos ~debug with
76+
| None when !Cfg.useRevampedCompletion -> Protocol.null
7677
| None -> (
7778
if debug then
7879
Printf.printf
@@ -381,14 +382,9 @@ let test ~path =
381382
("Complete " ^ path ^ " " ^ string_of_int line ^ ":"
382383
^ string_of_int col);
383384
let currentFile = createCurrentFile () in
384-
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
385-
Sys.remove currentFile
386-
| "crm" ->
387-
print_endline
388-
("Complete " ^ path ^ " " ^ string_of_int line ^ ":"
389-
^ string_of_int col);
390-
let currentFile = createCurrentFile () in
391-
completionRevamped ~debug:true ~path ~pos:(line, col) ~currentFile;
385+
if !Cfg.useRevampedCompletion then
386+
completionRevamped ~debug:true ~path ~pos:(line, col) ~currentFile
387+
else completion ~debug:true ~path ~pos:(line, col) ~currentFile;
392388
Sys.remove currentFile
393389
| "cre" ->
394390
let modulePath = String.sub rest 3 (String.length rest - 3) in

analysis/src/Hover.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
246246
| Typed (_, _, Definition (_, (Field _ | Constructor _))) -> None
247247
| OtherExpression t | OtherPattern t ->
248248
(* TODO: Just for debugging. *)
249-
Some (Markdown.codeBlock (Shared.typeToString t))
249+
if !Cfg.useRevampedCompletion then
250+
Some (Markdown.codeBlock (Shared.typeToString t))
251+
else None
250252
| Constant t ->
251253
Some
252254
(Markdown.codeBlock
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// == TEST: Record field completion in nested record
22
let x = TestTypeDefs.nestedTestRecord.
3-
// ^crm
3+
// ^com
44

55
// == TEST: Record field completion in nested record, another level
66
let x = TestTypeDefs.nestedTestRecord.nested.
7-
// ^crm
7+
// ^com

tests/analysis_new_tests/tests/test_files/SwitchCaseCompletions.res

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ let someStringArr = ["hello"]
33

44
let x = switch someStringArr {
55
|
6-
// ^crm
6+
// ^com
77
}
88

99
// == TEST: Empty case, record
1010
let x = switch TestTypeDefs.nestedTestRecord {
1111
|
12-
// ^crm
12+
// ^com
1313
}
1414

1515
// == TEST: Empty case, bool
1616
let x = switch true {
1717
|
18-
// ^crm
18+
// ^com
1919
}

0 commit comments

Comments
 (0)