Skip to content

Commit 843cac9

Browse files
committed
restore most of old setup so it can run in parallell
1 parent faf3864 commit 843cac9

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
@@ -966,5 +966,17 @@ Path ReactDOM.Client.Root.
966966
}]
967967

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

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

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

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ Hover src/Fragment.res 6:19
22
{"contents": {"kind": "markdown", "value": "```rescript\nReact.component<SectionHeader.props<React.element>>\n```\n\n---\n\n```\n \n```\n```rescript\ntype React.component<'props> = Jsx.component<'props>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C12%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype SectionHeader.props<'children> = {children: 'children}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Fragment.res%22%2C1%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype React.element = Jsx.element\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22React.res%22%2C0%2C0%5D)\n"}}
33

44
Hover src/Fragment.res 9:56
5-
{"contents": {"kind": "markdown", "value": "```rescript\nReact.element\n```"}}
5+
Nothing at that position. Now trying to use completion.
6+
posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:9->9:70]
7+
posCursor:[9:56] posNoWhite:[9:55] Found expr:[9:12->9:66]
8+
JSX <SectionHeader:[9:13->9:26] > _children:9:29
9+
null
610

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

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ Hover src/Hover.res 77:7
4949
{"contents": {"kind": "markdown", "value": "```rescript\nmodule A: {\n let x: int\n}\n```"}}
5050

5151
Hover src/Hover.res 91:10
52+
Nothing at that position. Now trying to use completion.
53+
posCursor:[91:10] posNoWhite:[91:8] Found expr:[88:2->91:9]
54+
JSX <Comp:[88:3->88:7] > _children:89:4
5255
null
5356

5457
Hover src/Hover.res 98:10
55-
{"contents": {"kind": "markdown", "value": "```rescript\nReact.element\n```"}}
58+
Nothing at that position. Now trying to use completion.
59+
posCursor:[98:10] posNoWhite:[98:9] Found expr:[95:2->98:10]
60+
JSX <Comp1:[95:3->95:8] > _children:96:4
61+
null
5662

5763
Hover src/Hover.res 103:25
5864
{"contents": {"kind": "markdown", "value": "```rescript\nfloat\n```"}}
@@ -67,7 +73,12 @@ Hover src/Hover.res 119:25
6773
{"contents": {"kind": "markdown", "value": "```rescript\nAA.cond<([< #str(string)] as 'a)> => AA.cond<'a>\n```\n\n---\n\n```\n \n```\n```rescript\ntype AA.cond<'a> = 'a\n constraint 'a = [< #str(string)]\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C110%2C2%5D)\n"}}
6874

6975
Hover src/Hover.res 122:3
70-
null
76+
Nothing at that position. Now trying to use completion.
77+
Attribute id:live:[122:0->122:5] label:live
78+
Completable: Cdecorator(live)
79+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
80+
Resolved opens 1 Stdlib
81+
{"contents": {"kind": "markdown", "value": "The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.\n\n`@live` tells the dead code analysis that the value should be considered live, even though it might appear to be dead. This is typically used in case of FFI where there are indirect ways to access values. It can be added to everything that could otherwise be considered unused by the dead code analysis - values, functions, arguments, records, individual record fields, and so on.\n\n[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#live-decorator).\n\nHint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!"}}
7182

7283
Hover src/Hover.res 125:4
7384
{"contents": {"kind": "markdown", "value": "```rescript\nunit => unit => int\n```"}}
@@ -88,10 +99,10 @@ Hover src/Hover.res 148:6
8899
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n doc comment 2 "}}
89100

90101
Hover src/Hover.res 165:23
91-
{"contents": {"kind": "markdown", "value": "```rescript\nfoo<bar>\n```\n\n---\n\n```\n \n```\n```rescript\ntype foo<'a> = {content: 'a, zzz: string}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C161%2C2%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype bar = {age: int}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C162%2C2%5D)\n"}}
102+
{"contents": {"kind": "markdown", "value": "```rescript\nfoo<bar>\n```"}}
92103

93104
Hover src/Hover.res 167:22
94-
{"contents": {"kind": "markdown", "value": "```rescript\nfoobar\n```\n\n---\n\n```\n \n```\n```rescript\ntype foobar = foo<bar>\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C163%2C2%5D)\n"}}
105+
{"contents": {"kind": "markdown", "value": "```rescript\nfoobar\n```"}}
95106

96107
Complete src/Hover.res 170:16
97108
posCursor:[170:16] posNoWhite:[170:15] Found expr:[170:5->170:16]
@@ -236,7 +247,17 @@ Hover src/Hover.res 202:16
236247
{"contents": {"kind": "markdown", "value": "```rescript\nuseR\n```"}}
237248

238249
Hover src/Hover.res 210:13
239-
null
250+
Nothing at that position. Now trying to use completion.
251+
posCursor:[210:13] posNoWhite:[210:12] Found expr:[210:11->210:14]
252+
Pexp_ident usr:[210:11->210:14]
253+
Completable: Cpath Value[usr]
254+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
255+
Resolved opens 1 Stdlib
256+
ContextPath Value[usr]
257+
Path usr
258+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
259+
Resolved opens 1 Stdlib
260+
{"contents": {"kind": "markdown", "value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n"}}
240261

241262
Hover src/Hover.res 230:20
242263
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n More Stuff "}}
@@ -245,7 +266,23 @@ Hover src/Hover.res 233:17
245266
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n---\n More Stuff "}}
246267

247268
Hover src/Hover.res 245:6
248-
null
269+
Nothing at that position. Now trying to use completion.
270+
posCursor:[245:6] posNoWhite:[245:5] Found expr:[245:3->245:14]
271+
Pexp_field [245:3->245:4] someField:[245:5->245:14]
272+
Completable: Cpath Value[x].someField
273+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
274+
Resolved opens 1 Stdlib
275+
ContextPath Value[x].someField
276+
ContextPath Value[x]
277+
Path x
278+
ContextPath Value[x]->someField
279+
ContextPath Value[x]
280+
Path x
281+
CPPipe pathFromEnv: found:true
282+
Path Hover.someField
283+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
284+
Resolved opens 1 Stdlib
285+
{"contents": {"kind": "markdown", "value": " Mighty fine field here. \n\n```rescript\nbool\n```"}}
249286

250287
Hover src/Hover.res 248:19
251288
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n---\n Mighty fine field here. "}}
@@ -254,10 +291,34 @@ Hover src/Hover.res 253:20
254291
{"contents": {"kind": "markdown", "value": "```rescript\nvariant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C251%2C0%5D)\n\n---\n```rescript\nCoolVariant\n```\n---\n Cool variant! "}}
255292

256293
Hover src/Hover.res 257:23
257-
null
294+
Nothing at that position. Now trying to use completion.
295+
posCursor:[257:23] posNoWhite:[257:22] Found expr:[257:22->257:25]
296+
Pexp_ident fff:[257:22->257:25]
297+
Completable: Cpath Value[fff]
298+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
299+
Resolved opens 1 Stdlib
300+
ContextPath Value[fff]
301+
Path fff
302+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
303+
Resolved opens 1 Stdlib
304+
ContextPath string
305+
{"contents": {"kind": "markdown", "value": "```rescript\nstring\n```"}}
258306

259307
Hover src/Hover.res 260:33
260-
null
308+
Nothing at that position. Now trying to use completion.
309+
posCursor:[260:33] posNoWhite:[260:32] Found expr:[260:31->260:40]
310+
Pexp_ident someField:[260:31->260:40]
311+
Completable: Cpath Value[someField]
312+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
313+
Resolved opens 1 Stdlib
314+
ContextPath Value[someField]
315+
Path someField
316+
Package opens Stdlib.place holder Pervasives.JsxModules.place holder
317+
Resolved opens 1 Stdlib
318+
ContextPath CPatternPath(Value[x])->recordField(someField)
319+
ContextPath Value[x]
320+
Path x
321+
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```"}}
261322

262323
Hover src/Hover.res 263:8
263324
{"contents": {"kind": "markdown", "value": "\n [`Belt.Array`]()\n\n **mutable array**: Utilities functions\n\n```rescript\nmodule Array: {\n module Id\n module Array\n module SortArray\n module MutableQueue\n module MutableStack\n module List\n module Range\n module Set\n module Map\n module MutableSet\n module MutableMap\n module HashSet\n module HashMap\n module Option\n module Result\n module Int\n module Float\n}\n```"}}

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
Inlay Hint src/InlayHint.res 1:34
22
[{
3-
"position": {"line": 33, "character": 14},
4-
"label": ": int",
5-
"kind": 1,
6-
"paddingLeft": true,
7-
"paddingRight": false
8-
}, {
9-
"position": {"line": 33, "character": 9},
10-
"label": ": string",
11-
"kind": 1,
12-
"paddingLeft": true,
13-
"paddingRight": false
14-
}, {
153
"position": {"line": 28, "character": 9},
164
"label": ": foo",
175
"kind": 1,

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,7 @@ Package opens Stdlib.place holder Pervasives.JsxModules.place holder
373373
Resolved opens 1 Stdlib
374374
ContextPath Type[ReactDOMR]
375375
Path ReactDOMR
376-
[{
377-
"label": "ReactDOMRe",
378-
"kind": 9,
379-
"tags": [],
380-
"detail": "module ReactDOMRe",
381-
"documentation": null,
382-
"data": {
383-
"modulePath": "ReactDOMRe",
384-
"filePath": "src/Jsx2.res"
385-
}
386-
}]
376+
[]
387377

388378
Complete src/Jsx2.res 102:21
389379
posCursor:[102:21] posNoWhite:[102:20] Found expr:[102:13->102:21]
@@ -527,8 +517,8 @@ Path Nested.
527517
}]
528518

529519
Hover src/Jsx2.res 162:12
530-
{"contents": {"kind": "markdown", "value": "```rescript\nReact.element\n```"}}
520+
{"contents": {"kind": "markdown", "value": "```rescript\nComp.props<int>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Jsx2.res%22%2C157%2C2%5D)\n"}}
531521

532522
Hover src/Jsx2.res 167:16
533-
{"contents": {"kind": "markdown", "value": "```rescript\nReact.element\n```"}}
523+
{"contents": {"kind": "markdown", "value": "```rescript\nComp.props<int>\n```\n\n---\n\n```\n \n```\n```rescript\ntype Comp.props<'age> = {age: 'age}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Jsx2.res%22%2C157%2C2%5D)\n"}}
534524

0 commit comments

Comments
 (0)