ocaml-lsp
ocaml-lsp copied to clipboard
Add extract code actions
Adds two new code actions: Extract local and Extract function.
Extract local transforms:
let f x = $x+1$ + 2
to
let f x =
let new_var = x + 1 in
new_var + 2
The new variable gets placed at the tightest enclosing binder of the extracted expression.
Extract function would transform the same code to:
let new_fun x = x + 1
let f x = new_fun x + 2
The new function will be inserted directly before the enclosing structure item. Any free variables in the expression will be passed as arguments.
Just wanted to get opinions on whether this is a useful feature, and whether these behaviors make sense.
TODO:
- Should extract local move the expression to the loosest binder rather than the tightest?
- Extract function doesn't handle free variables with nontrivial
Longidents. - Add tests.