-
Notifications
You must be signed in to change notification settings - Fork 470
Support universal dot completion in editor tooling #7226
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
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
625c60c
Port PR from rescript-vscode
nojaf e4d3f7d
Run all tests locally
nojaf 12d0057
Revert changes in CompletionBackEnd and TypeUtils
nojaf f67ac21
Revert CompletionFrontEnd.ml
nojaf 489569f
Remove some unnecessary recs
nojaf a87aef9
Whoops
nojaf 173c178
Add changelog entry
nojaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
let filterRecordFields ~env ~recordAsString ~prefix ~exact fields = | ||
fields | ||
|> Utils.filterMap (fun (field : SharedTypes.field) -> | ||
if Utils.checkName field.fname.txt ~prefix ~exact then | ||
Some | ||
(SharedTypes.Completion.create field.fname.txt ~env | ||
?deprecated:field.deprecated ~docstring:field.docstring | ||
~kind:(SharedTypes.Completion.Field (field, recordAsString))) | ||
else None) | ||
|
||
let fieldCompletionsForDotCompletion ?posOfDot typ ~env ~package ~prefix ~exact | ||
= | ||
let asObject = typ |> TypeUtils.extractObjectType ~env ~package in | ||
match asObject with | ||
| Some (objEnv, obj) -> | ||
(* Handle obj completion via dot *) | ||
if Debug.verbose () then | ||
Printf.printf "[dot_completion]--> Obj type found:\n"; | ||
obj |> TypeUtils.getObjFields | ||
|> Utils.filterMap (fun (field, _typ) -> | ||
if Utils.checkName field ~prefix ~exact then | ||
let fullObjFieldName = Printf.sprintf "[\"%s\"]" field in | ||
Some | ||
(SharedTypes.Completion.create fullObjFieldName ~synthetic:true | ||
~insertText:fullObjFieldName ~env:objEnv | ||
~kind:(SharedTypes.Completion.ObjLabel typ) | ||
?additionalTextEdits: | ||
(match posOfDot with | ||
| None -> None | ||
| Some posOfDot -> | ||
Some | ||
(TypeUtils.makeAdditionalTextEditsForRemovingDot | ||
posOfDot))) | ||
else None) | ||
| None -> ( | ||
match typ |> TypeUtils.extractRecordType ~env ~package with | ||
| Some (env, fields, typDecl) -> | ||
fields | ||
|> filterRecordFields ~env ~prefix ~exact | ||
~recordAsString: | ||
(typDecl.item.decl |> Shared.declToString typDecl.name.txt) | ||
| None -> []) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
let addJsxCompletionItems ~mainTypeId ~env ~prefix ~(full : SharedTypes.full) | ||
~rawOpens typ = | ||
match mainTypeId with | ||
| ("array" | "float" | "string" | "int") as builtinNameToComplete -> | ||
if Utils.checkName builtinNameToComplete ~prefix ~exact:false then | ||
let name = | ||
match full.package.genericJsxModule with | ||
| None -> "React." ^ builtinNameToComplete | ||
| Some g -> | ||
g ^ "." ^ builtinNameToComplete | ||
|> String.split_on_char '.' | ||
|> TypeUtils.removeOpensFromCompletionPath ~rawOpens | ||
~package:full.package | ||
|> String.concat "." | ||
in | ||
[ | ||
SharedTypes.Completion.create name ~synthetic:true | ||
~includesSnippets:true ~kind:(Value typ) ~env ~sortText:"A" | ||
~docstring: | ||
[ | ||
"Turns `" ^ builtinNameToComplete | ||
^ "` into a JSX element so it can be used inside of JSX."; | ||
]; | ||
] | ||
else [] | ||
| _ -> [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.