-
Notifications
You must be signed in to change notification settings - Fork 125
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
Add code action for inlining #847
Conversation
This is great! Thanks! I will review it this week.
Perhaps, @voodoos could advise as an expert here. Otherwise, you could find quite a bit of help from people on ocaml discord (eg octachron is quite active and has expertise in the typechecker) or ocaml discourse, which also may attract many enthusiasts First things that come to mind are to
|
Also, inlining is always unsound in OCaml, since it can duplicate side effects. But I think the issue with shadowing is more likely to introduce subtle bugs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It was an interesting read; the feature seems to work well.
I will also think what we can do with shadowed variables and side-effects.
d6884af
to
481ea2a
Compare
Comments should all be addressed. |
Inlining now does a best-effort round of beta reduction after inlining a function. It also works on top level let bindings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
@ulugbekna are you still reviewing?
Let's ping @voodoos so that he has the feature and the issues with shadowing in the back of his mind. Perhaps merlin can help us make this more robust one day?
I was off past two weeks. Will finish reviewing asap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for this awesome work! I especially liked thoroughness and visual explicitness of tests. I left a couple of nits that definitely don't block this PR. Feel free to merge or let us know when you'd like to merge. I think it's best to squash before merging, btw.
CHANGES: ## Features - Code action for inlining let bindings within a module or expression. (ocaml/ocaml-lsp#847) - Tag "unused code" and "deprecated" warnings, allowing clients to better display them. (ocaml/ocaml-lsp#848) - Refresh merlin configuration after every dune build in watch mode (ocaml/ocaml-lsp#853) ## Fixes - Respect `showDocument` capabilities. Do not offer commands or code actions that rely on this request without client support. (ocaml/ocaml-lsp#836) - Fix signatureHelp on .mll files: avoid "Document.dune" exceptions
* master: fix(go-to-def): report error in response (ocaml#899) Update readme (ocaml#895) chore(nix): update flakes and dune-release (ocaml#894) chore: remove ocamlformat-rpc (ocaml#892) chore(nix): pass opam-repository and nixpkgs (ocaml#893) chore: unvendor ocamlc-loc (ocaml#869) fix: merlin document safety (ocaml#890) chore: more precise CHANGES (ocaml#889) fix: diagnostics on non dune files (ocaml#887) refactor: remove Document.is_merlin (ocaml#888) fix: symbols in non merlin docs (ocaml#886) refactor: style tweaks in document_symbol (ocaml#885) fix: handle incorrect document types (ocaml#884) Ignore unknown config tags (ocaml#883) Make sure nodejs packages required are installed chore: prepare 1.14.0 Don't let opam ask when not needed Allow copy-and-paste of contributing instructions Add code action for inlining (ocaml#847) Add note about protocol extensions to the readme
I used this code action twice today to inline top-level functions, and it worked great! If not for this, inlining would be quite annoying for those fns. Thanks again! :-) Let me know if you need any help with "extract" code action PR! |
This PR adds an inlining code action for non-top-level let bindings. For example,
turns into
after inlining.
Caveats:
Untypeast
followed byPprintast
to turn the body of the let into a string. This means that comments are stripped and the inlined code contains expanded PPXes. This should be fixable by using the source code the body, but it requires a bit more care when inlining functions.