Skip to content

Use the vendored parser to drive autocomplete. #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 135 commits into from
Apr 23, 2022
Merged
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
ef2f7bf
Experiment with using the parser for autocomplete.
cristianoc Apr 9, 2022
b04e013
Find the location of prop labels in JSX.
cristianoc Apr 11, 2022
def4820
Show completable in tests.
cristianoc Apr 12, 2022
74e67d3
Print the component name.
cristianoc Apr 12, 2022
5e7d735
Print loc of component name and children.
cristianoc Apr 12, 2022
e854c46
Check if children exist.
cristianoc Apr 12, 2022
c9e5bda
refactor
cristianoc Apr 12, 2022
d1ea3ae
Debug.
cristianoc Apr 12, 2022
c86f7d1
Print prop range.
cristianoc Apr 12, 2022
1a0ebf2
Check differences on JSX behaviour.
cristianoc Apr 12, 2022
334b8c9
Take out code for backwards parsing jsx.
cristianoc Apr 12, 2022
80ea375
Tweak case with children.
cristianoc Apr 12, 2022
d973ad6
Don't fire unless after component name.
cristianoc Apr 12, 2022
9ec656b
Extract locations of labels in function application.
cristianoc Apr 13, 2022
2a19fc3
Tweak debug printing of positions and locations.
cristianoc Apr 13, 2022
4bb1c4b
refactor
cristianoc Apr 13, 2022
dd4cf1f
Refactor pos out of Utils.
cristianoc Apr 13, 2022
acf5344
Take label completion from the parser.
cristianoc Apr 13, 2022
f8b5b48
Remove backward parser for function calls.
cristianoc Apr 13, 2022
e423bbe
Add parser-base autocompletion for pipe.
cristianoc Apr 13, 2022
d8c45ea
Remove backwards parser for pipe.
cristianoc Apr 13, 2022
7229e85
Parser: fix location of foo["abc"]
cristianoc Apr 13, 2022
1299439
Use the parser for object completion.
cristianoc Apr 13, 2022
76269e5
Remove backwards parser for objects.
cristianoc Apr 13, 2022
27cb4a2
Use parser for common paths.
cristianoc Apr 14, 2022
49b85ae
Remove backwards parsing of common paths.
cristianoc Apr 14, 2022
88bf40b
Don't suggest a prop name if it's already used after the cursor.
cristianoc Apr 14, 2022
214ba80
Add example of toplevel module completion.
cristianoc Apr 14, 2022
4fefc26
Handle toplevel module completion.
cristianoc Apr 14, 2022
273334e
Add example of component with children.
cristianoc Apr 14, 2022
bef6e0e
Don't suggest. "children" as prop autocompletion.
cristianoc Apr 14, 2022
46efb43
Example of prop completion in the presence of children.
cristianoc Apr 14, 2022
dc337bf
Fix case where children is not the last prop.
cristianoc Apr 14, 2022
6a81b38
Add another test that triggers the last children fix.
cristianoc Apr 14, 2022
2926430
Add example that tests local opens.
cristianoc Apr 14, 2022
dfb0ca3
Example with nested opens.
cristianoc Apr 14, 2022
b566052
Compute the open's in scope using the AST iterator.
cristianoc Apr 14, 2022
314e770
Remove code that parses backwards to find open's.
cristianoc Apr 14, 2022
27cef12
cleanup
cristianoc Apr 14, 2022
a1c5bf6
Get attributes from the parser.
cristianoc Apr 14, 2022
21c5984
Remove backwards parser for attributes.
cristianoc Apr 14, 2022
bfb7808
Autocomplete for types.
cristianoc Apr 15, 2022
c1e2be5
refactor
cristianoc Apr 15, 2022
4a01260
Support interface files.
cristianoc Apr 15, 2022
e4d93c7
Types in value declarations.
cristianoc Apr 15, 2022
3665736
Complete module prefix of type path.
cristianoc Apr 15, 2022
b2377ec
Filter completion by kind: Type or Value.
cristianoc Apr 15, 2022
2d19437
In jsx, only complete with modules.
cristianoc Apr 15, 2022
6fa3bd5
Contextual completion of fields.
cristianoc Apr 15, 2022
78587a7
Refactor.
cristianoc Apr 15, 2022
f490954
Add support for module ids.
cristianoc Apr 16, 2022
13119da
Refactor
cristianoc Apr 16, 2022
fc2593d
Clean up extensions.
cristianoc Apr 17, 2022
4473d27
cleanup
cristianoc Apr 17, 2022
2470fe6
id shadowing from opens
cristianoc Apr 17, 2022
478f0d1
More examples of shadowing.
cristianoc Apr 17, 2022
4f96549
Example of qualified record access.
cristianoc Apr 17, 2022
cdca516
Introduce generalized completable Cpath
cristianoc Apr 17, 2022
ed84a7d
Fix qualified field access.
cristianoc Apr 17, 2022
70a6635
Tweak Cpath: completion context on the id.
cristianoc Apr 17, 2022
b9a3d08
rename
cristianoc Apr 17, 2022
3869bca
cleanup
cristianoc Apr 17, 2022
1f4ffeb
refactor
cristianoc Apr 17, 2022
b7ec8ac
No QualifiedRecordAccess required.
cristianoc Apr 17, 2022
7010442
refactor
cristianoc Apr 17, 2022
67bcf27
rename
cristianoc Apr 17, 2022
bcc594c
refactor
cristianoc Apr 17, 2022
810c168
refactor
cristianoc Apr 17, 2022
7c78581
rename and fix lowecase ascii
cristianoc Apr 17, 2022
8cecc55
move
cristianoc Apr 17, 2022
5d703b1
refactor
cristianoc Apr 17, 2022
32dbfcf
cleanup
cristianoc Apr 17, 2022
161f692
cleanup
cristianoc Apr 17, 2022
c84f364
refactor
cristianoc Apr 17, 2022
e04bbb7
no dedup
cristianoc Apr 17, 2022
d18ca4d
refactor
cristianoc Apr 17, 2022
6c960d7
refactor
cristianoc Apr 17, 2022
1757507
refactor
cristianoc Apr 17, 2022
e5aab9f
refactor
cristianoc Apr 17, 2022
0eaca9b
refactor
cristianoc Apr 17, 2022
204eda7
refactor
cristianoc Apr 18, 2022
a2fdc1c
Add env to completions.
cristianoc Apr 18, 2022
5377b91
refactor
cristianoc Apr 18, 2022
faf7a1a
Use new backend for CPId.
cristianoc Apr 18, 2022
7e45bcc
Compile field accesses to the new bakend.
cristianoc Apr 18, 2022
18283ea
Remove Cdotpath and associated dead code.
cristianoc Apr 18, 2022
49544fa
Handle object access with the new back-end.
cristianoc Apr 18, 2022
f039fd3
Remove now unused Cobj.
cristianoc Apr 18, 2022
6957ac1
Add pipe to the new back-end.
cristianoc Apr 18, 2022
bdf9526
Remove pipe from old backend.
cristianoc Apr 18, 2022
37e2d1b
Generalize front-end to match new back-end.
cristianoc Apr 18, 2022
a8c2313
Add example combining all the forms of completion, nested.
cristianoc Apr 18, 2022
3076bb8
clean up output
cristianoc Apr 18, 2022
ec52f8c
labels on Win newlines
cristianoc Apr 18, 2022
0882ded
First step towards scope.
cristianoc Apr 19, 2022
69f7e8a
Populate scope with values.
cristianoc Apr 20, 2022
03c5f27
rename
cristianoc Apr 20, 2022
67479f1
prepare insertion point for new local value completion.
cristianoc Apr 20, 2022
aadd9e1
local constructor infra
cristianoc Apr 20, 2022
dc4c16e
There's no local completion for fields.
cristianoc Apr 20, 2022
bb5d6e2
rename
cristianoc Apr 20, 2022
d7c402e
tweak debug print
cristianoc Apr 20, 2022
1d9dab9
rename
cristianoc Apr 20, 2022
f1210f3
Add type declarations and constructors to the scope.
cristianoc Apr 20, 2022
02e671b
refactor
cristianoc Apr 20, 2022
d55a95f
Start to push duplicate name check everywhere.
cristianoc Apr 20, 2022
c250cb8
Add example that shows repeated results with shadowed ids.
cristianoc Apr 20, 2022
9c6fb25
Use scope-based autocomplete for values and constructors.
cristianoc Apr 20, 2022
39425f6
log
cristianoc Apr 20, 2022
ace661a
push filtering inside findAllCompletions
cristianoc Apr 20, 2022
f2c95da
remove dead filtering code
cristianoc Apr 20, 2022
7307fa8
Not need to prioritize/postprocess anymore.
cristianoc Apr 20, 2022
2ca8151
No need to extentLoc in completion.
cristianoc Apr 20, 2022
ecf4e15
Handle scope for modules.
cristianoc Apr 20, 2022
c75b2c5
remove dead code
cristianoc Apr 20, 2022
b3dbab6
rename
cristianoc Apr 20, 2022
96c8263
rename
cristianoc Apr 20, 2022
5718ef9
refactor
cristianoc Apr 20, 2022
26094c0
top-level logic for getEnvWithOpens
cristianoc Apr 20, 2022
2c8df45
Use scope to find local module in path resolution.
cristianoc Apr 20, 2022
cce0d22
Remove old code to approximate scope.
cristianoc Apr 20, 2022
a457188
Remove code to process extent.
cristianoc Apr 20, 2022
6e856a8
Add example showing how parser recovery could build id too eagerly.
cristianoc Apr 20, 2022
5cbdcfa
Fix issue with "." and parser recovery.
cristianoc Apr 20, 2022
69927e4
Allow autocomplete on blank.
cristianoc Apr 20, 2022
224f4b7
Fix local completions for types and modules.
cristianoc Apr 20, 2022
511faa8
Fix issue whith completing x= in JSX.
cristianoc Apr 21, 2022
39c3cef
Clean up parser recovery.
cristianoc Apr 22, 2022
c342b8e
restore normal formatting logic
cristianoc Apr 22, 2022
20f9c3d
Move completion code to separate file.
cristianoc Apr 22, 2022
64ec49a
rename
cristianoc Apr 22, 2022
62c2183
restore check on formatting
cristianoc Apr 22, 2022
c927bbf
Move completable to own module.
cristianoc Apr 22, 2022
882b862
tweak order of fields
cristianoc Apr 23, 2022
6526a62
rename
cristianoc Apr 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions analysis/src/Cli.ml
Original file line number Diff line number Diff line change
@@ -68,8 +68,9 @@ Options:
let main () =
match Array.to_list Sys.argv with
| [_; "completion"; path; line; col; currentFile] ->
Commands.completion ~path ~line:(int_of_string line)
~col:(int_of_string col) ~currentFile
Commands.completion ~debug:false ~path
~pos:(int_of_string line, int_of_string col)
~currentFile
| [_; "definition"; path; line; col] ->
Commands.definition ~path ~line:(int_of_string line)
~col:(int_of_string col)
44 changes: 26 additions & 18 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
open SharedTypes

let completion ~path ~line ~col ~currentFile =
let pos = (line, col) in
let completion ~debug ~path ~pos ~currentFile =
let result =
let textOpt = Files.readFile currentFile in
let completionItems =
match NewCompletions.getCompletable ~textOpt ~pos with
| None -> []
| Some (completable, rawOpens) -> (
(* Only perform expensive ast operations if there are completables *)
match Cmt.fromPath ~path with
match textOpt with
| None | Some "" -> []
| Some text ->
let completionItems =
match
Completion.completionWithParser ~debug ~path ~posCursor:pos
~currentFile ~text
with
| None -> []
| Some full ->
NewCompletions.computeCompletions ~completable ~full ~pos ~rawOpens)
in
completionItems
|> List.map Protocol.stringifyCompletionItem
|> Protocol.array
| Some (completable, scope) -> (
if debug then
Printf.printf "Completable: %s\n"
(SharedTypes.Completable.toString completable);
(* Only perform expensive ast operations if there are completables *)
match Cmt.fromPath ~path with
| None -> []
| Some full ->
let env = SharedTypes.QueryEnv.fromFile full.file in
let package = full.package in
NewCompletions.computeCompletions ~completable ~package ~pos ~scope
~env)
in
completionItems
in
print_endline result
print_endline
(result |> List.map Protocol.stringifyCompletionItem |> Protocol.array)

let hover ~path ~line ~col =
let result =
@@ -291,7 +299,7 @@ let test ~path =
let line = line + 1 in
let col = len - mlen - 3 in
close_out cout;
completion ~path ~line ~col ~currentFile;
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
Sys.remove currentFile
| "hig" ->
print_endline ("Highlight " ^ path);
Loading