darklang/dark

Component: Refactors

Opened this issue · 0 comments

This issue is to organize work related to Darklang's "refactors" - (usually) editor functionality of augmenting some code based on AST manipulations.

We should advance the language and editor a bit more before advancing here.


How refactors should be applied (general)

  • refactors should manipulate ASTs, and be written in Dark
  • (?) only applicable if they pass some AST query
  • users should be able to highlight some code and explicitly refactor it with commands
  • users should be able to see a list of suggested refactors in-editor
  • we should support some process that crawls throughout a user's code-base making recommendations for more substantial refactors and improvements
  • use AI to help collect and perform refactors (maybe some refactors call upon a prompt rather than manipulate ASTs directly)

Common refactors to include

  • TODO: review all of the commands available in dark-classic
  • fix: extract variable should select the variable so that we can edit its name
  • inline a variable
    • old note: "Add a command to the command palette to inline a variable. Should be a straightforward addition with code in client/src/fluid/Commands.ml and tests in client/test/fluid_command_test.ml"
  • extract all uses of an expression (see #2702)
  • add / remove pipes
    • If you have a |> b |> c, convert it to (c (b a)). And vice versa.
    • Most useful if you have (func value) and you want to start piping.
  • wrap in if
  • wrap in match
  • convert if to match