Rename function/variable
- Implements rename functionality for variables and functions
- Partly addresses https://github.com/elixir-lsp/elixir-ls/issues/765
- Built on the work started in https://github.com/elixir-lsp/elixir-ls/pull/676
Note that this uses ElixirSense to get the definition and references under the hood, which limits the rename functionality. There is a PR raised against elixir_sense already to address some of the current issues with the find references functionality - https://github.com/elixir-lsp/elixir_sense/pull/173 - I'm waiting for feedback on that one.
I do suspect that there are other cases where find definition/references doesn't work 100% - for example I know find references doesn't work for a variable in a list comprehension. I've not had time to properly test and identify all of those cases, but know they will impact rename functionality. Still feel like this is a good improvement to merge in, but let me know what you think!
Nice work @timgent. The problem with that approach is that it's error prone. We recently had to revert a similar text based code transformation (https://github.com/elixir-lsp/elixir-ls/pull/775). A better option would be to express the code changes in terms of AST transformations. See https://github.com/elixir-lsp/elixir-ls/pull/773
@lukaszsamson thanks for the update. Sounds like it's best for me to stop looking at improvements to support rename functionality in elixir sense and elixir-ls until https://github.com/elixir-lsp/elixir-ls/pull/773 gets merged and other existing features are ported over?
Sounds like the existing elixir-sense find references functionality will also be replaced so I should close this PR too? https://github.com/elixir-lsp/elixir_sense/pull/173
In the meantime let me know if there's any support that could be helpful to improve elixir-ls. I'm up for contributing but want to make sure what I do is useful!
@timgent #773 has merged. There's an example of using AST in https://github.com/elixir-lsp/elixir-ls/blob/master/apps/language_server/lib/language_server/experimental/code_mod/replace_with_underscore.ex
@timgent don't wont to push :), but is any plan to finish renaming, or you are blocking by something?
@illia-danko I've since got a new baby so been struggling to find time. Any more guidance on using the AST as suggested would be helpful though. I've not had the chance to look into that in depth, but if I could get a few pointers that might make it easier :)
@timgent congratulations on the baby born! Sure, take your time, hopefully you'll come back at some point
AST based transforms landed in https://github.com/elixir-lsp/elixir-ls/pull/1057. Would you be interested in reworking the PR using this approach? Possibly also with Code.string_to_quoted_with_comments
@lukaszsamson I'm still a bit time-poor to be honest but would love to get this over the line. Will try to get my head back into this and give it a go if I find the time