Skip to content

Explore type based autocomplete #493

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

Closed
wants to merge 81 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
7db9012
add base test case for completing jsx prop and labelled argument
zth Jul 14, 2022
4362bdf
commit the rest of the updated test result files
zth Jul 14, 2022
87508b3
fix accidentally broken completion example
zth Jul 14, 2022
5ed8bb4
identify typed context for labelled argument assignments
zth Jul 15, 2022
d121e73
remove special handling of equality char
zth Jul 16, 2022
57e7cce
use trick from JSX prop completion to identify empty assignment of la…
zth Jul 16, 2022
b125207
crude implementation of completing variant constructors
zth Jul 17, 2022
431ab48
rename and specialize test file so that it will only contain tests fo…
zth Jul 17, 2022
bdd2e11
generalize completion so it theoretically can handle more than variants
zth Jul 17, 2022
bea78fe
add assigned identifier to test file
zth Jul 17, 2022
5ebe602
add more args to test function in test file
zth Jul 17, 2022
b85c4ae
filter completed variant constructors on what the user has already wr…
zth Jul 17, 2022
dd8333e
add example completing variant from other file
zth Jul 17, 2022
ffa06f4
complete polyvariants in addition to regular variants
zth Jul 17, 2022
37e4f9b
clarifications and touch ups after pr comments
zth Jul 18, 2022
c2e2adf
add dedicated example file for JSX completions
zth Jul 18, 2022
d1d86e8
inline contextPath into NamedArg to pave way for JsxProp, that will n…
zth Jul 18, 2022
90ccf19
add jsx example completing across files
zth Jul 19, 2022
d54b562
basic JSX prop completion via type
zth Jul 18, 2022
2b29291
add completions from context in addition to the explicit type based c…
zth Jul 19, 2022
27532b0
bring contextual completions to labelled arguments as well
zth Jul 19, 2022
e87ad5a
remove redundant comment#
zth Jul 19, 2022
f79a38d
Merge branch 'master' into type-based-autocomplete
zth Jul 25, 2022
b260d38
take a step back and remove typed completions for now. focus on ident…
zth Jul 27, 2022
54e596c
add some completion cases for records
zth Jul 30, 2022
8c49fa5
refactor to continuously setting the typed context we're currently lo…
zth Jul 30, 2022
c8f112a
fix + debug util
zth Jul 30, 2022
49e45d8
identify and complete for record fields when destructuring
zth Jul 30, 2022
7c8a1ad
allow any expr, which makes fn returns also work
zth Jul 30, 2022
b34c35d
basic, slightly buggy completion for nested record fields
zth Jul 31, 2022
7b1b8cd
do not complete if we cant find the cursor inside of nested pattern
zth Aug 1, 2022
f79f21b
add more broken test cases
zth Aug 1, 2022
0df2b0c
ensure completing from empty root records work as expected
zth Aug 1, 2022
33cd645
look for ',' as first char before cursor to trigger completion in cas…
zth Aug 1, 2022
f21a06e
refactor
zth Aug 1, 2022
44698e4
refactor completion to use new way of recursively digging to the targ…
zth Aug 2, 2022
48b7bec
start refactoring the typed context
zth Aug 2, 2022
295be6b
add another label to the record so we can test prefix etc in a better…
zth Aug 2, 2022
5a2097e
bring back prefix and seen record fields filtering for destructuring …
zth Aug 2, 2022
da23ca8
change test message some
zth Aug 2, 2022
39a35ec
more completion exploration
zth Aug 4, 2022
f9515d1
cleanup and comments on where I'm at right now
zth Aug 4, 2022
a268d24
narrow the places where type based completion is invoked
zth Aug 9, 2022
9f511cd
complete record field destructuring in switch patterns
zth Aug 9, 2022
ef427d2
comment
zth Aug 9, 2022
555110f
wip
zth Aug 10, 2022
cf8b472
more work on nested completion in patterns
zth Aug 10, 2022
3a6a6e5
pick up already seen idents for constructors/record fields
zth Aug 11, 2022
339417c
basic completion of options
zth Aug 11, 2022
928e84e
complete empty | patterns
zth Aug 11, 2022
d134b8b
fix only descending to record field if valid
zth Aug 11, 2022
0d06fc6
more filtering of idents
zth Aug 11, 2022
d2ef230
fix record completion of empty ,
zth Aug 11, 2022
013680e
temp disable local completions + constructor completions in general s…
zth Aug 11, 2022
303eb57
commit test output from last commit
zth Aug 11, 2022
858be8f
handle completing empty patterns in records
zth Aug 11, 2022
d5ced33
complete booleans
zth Aug 11, 2022
1679769
more work, plugging holes etc
zth Aug 13, 2022
f262a50
complete patterns in arguments of fns passed to named arguments
zth Aug 13, 2022
28dddca
rename
zth Aug 14, 2022
8a98793
add debug tool and start setting up spec for typed context completion
zth Aug 15, 2022
5647a1e
start moving to rewrite of finding pattern completable
zth Aug 15, 2022
2c1b721
hook up completion backend with new pattern completion stuff
zth Aug 16, 2022
5d69adb
complete clean up of the old way of doing pattern completion
zth Aug 16, 2022
f061119
simplify
zth Aug 16, 2022
82796f9
complete empty tuples
zth Aug 16, 2022
6a0a884
introduce snippets
zth Aug 16, 2022
f98db04
properly apply command
zth Aug 16, 2022
5558995
implement support for tuple context paths in completion
zth Aug 16, 2022
5320d9e
dump pexp_field
zth Aug 16, 2022
36832cc
add typed expression completion type
zth Aug 17, 2022
eb3eb80
some cleanup and other fixes
zth Aug 17, 2022
859c3fd
track seen record fields when constructing a record
zth Aug 17, 2022
e67f63c
add a few test fixtures where the parser doesnt do quite what I need …
zth Aug 18, 2022
64f4f77
another broken case
zth Aug 20, 2022
40e3ec1
support completing expressions when assigning variables, even if the …
zth Aug 20, 2022
e330b68
pull put var from constraint pattern for now
zth Aug 20, 2022
fc48ca8
more cases
zth Aug 20, 2022
cd2161a
make sure the newest env is always propagated
zth Sep 2, 2022
0522d01
fix issue where Some variants wouldnt be handled properly
zth Sep 7, 2022
16a6f0f
complete inline records
zth Sep 7, 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
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"typescript.preferences.quoteStyle": "single",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"ocaml.sandbox": {
"kind": "opam",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot why we have settings checked in at all

"switch": "4.12.1"
}
}
11 changes: 8 additions & 3 deletions analysis/src/Cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let help =
**Private CLI For rescript-vscode usage only**

API examples:
./rescript-editor-analysis.exe completion src/MyFile.res 0 4 currentContent.res
./rescript-editor-analysis.exe completion src/MyFile.res 0 4 currentContent.res true
./rescript-editor-analysis.exe definition src/MyFile.res 9 3
./rescript-editor-analysis.exe typeDefinition src/MyFile.res 9 3
./rescript-editor-analysis.exe documentSymbol src/Foo.res
Expand All @@ -24,8 +24,9 @@ https://microsoft.github.io/language-server-protocol/specification#position
Options:
completion: compute autocomplete for MyFile.res at line 0 and column 4,
where MyFile.res is being edited and the editor content is in file current.res.
The final boolean indicates whether the completion should return snippets or not.

./rescript-editor-analysis.exe completion src/MyFile.res 0 4 current.res
./rescript-editor-analysis.exe completion src/MyFile.res 0 4 current.res true

definition: get definition for item in MyFile.res at line 10 column 2:

Expand Down Expand Up @@ -82,10 +83,14 @@ Options:

let main () =
match Array.to_list Sys.argv with
| [_; "completion"; path; line; col; currentFile] ->
| [_; "completion"; path; line; col; currentFile; supportsSnippets] ->
Commands.completion ~debug:false ~path
~pos:(int_of_string line, int_of_string col)
~currentFile
~supportsSnippets:
(match supportsSnippets with
| "true" -> true
| _ -> false)
| [_; "definition"; path; line; col] ->
Commands.definition ~path
~pos:(int_of_string line, int_of_string col)
Expand Down
29 changes: 24 additions & 5 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ let getCompletions ~debug ~path ~pos ~currentFile ~forHover =
|> CompletionBackEnd.processCompletable ~debug ~package ~pos ~scope ~env
~forHover))

let completion ~debug ~path ~pos ~currentFile =
let completion ~debug ~path ~pos ~currentFile ~supportsSnippets =
print_endline
(getCompletions ~debug ~path ~pos ~currentFile ~forHover:false
|> List.map CompletionBackEnd.completionToItem
|> List.map (fun completionItem ->
if supportsSnippets then completionItem
else
{
completionItem with
Protocol.insertText = None;
insertTextFormat = None;
})
|> List.map Protocol.stringifyCompletionItem
|> Protocol.array)

Expand Down Expand Up @@ -320,7 +328,8 @@ let test ~path =
("Complete " ^ path ^ " " ^ string_of_int line ^ ":"
^ string_of_int col);
let currentFile = createCurrentFile () in
completion ~debug:true ~path ~pos:(line, col) ~currentFile;
completion ~debug:true ~path ~pos:(line, col) ~currentFile
~supportsSnippets:true;
Sys.remove currentFile
| "dce" ->
print_endline ("DCE " ^ path);
Expand Down Expand Up @@ -390,14 +399,24 @@ let test ~path =
(Protocol.stringifyRange range)
indent indent newText)))
| "dia" -> diagnosticSyntax ~path
| "hin" -> (
| "hin" ->
let line_start = 0 in
let line_end = 6 in
print_endline ("Inlay Hint " ^ path ^ " " ^ string_of_int line_start ^ ":" ^ string_of_int line_end);
inlayhint ~path ~pos:(line_start, line_end) ~maxLength:"25" ~debug:false)
print_endline
("Inlay Hint " ^ path ^ " " ^ string_of_int line_start ^ ":"
^ string_of_int line_end);
inlayhint ~path ~pos:(line_start, line_end) ~maxLength:"25"
~debug:false
| "cle" ->
print_endline ("Code Lens " ^ path);
codeLens ~path ~debug:false
| "ast" ->
print_endline
("Dump AST " ^ path ^ " " ^ string_of_int line ^ ":"
^ string_of_int col);
let currentFile = createCurrentFile () in
DumpAst.dump ~pos:(line, col) ~currentFile;
Sys.remove currentFile
| _ -> ());
print_newline ())
in
Expand Down
Loading