-
-
Notifications
You must be signed in to change notification settings - Fork 82
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 Support for Renaming module #636
base: main
Are you sure you want to change the base?
Conversation
1ce421a
to
28bf64e
Compare
apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex
Outdated
Show resolved
Hide resolved
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.
I think we need to talk more about the ergonomics of this PR and whether and how we do file renames. They can be tricky.
2c6f7bb
to
af600cc
Compare
c5f8027
to
c5d4b46
Compare
24f72eb
to
1be53a3
Compare
apps/remote_control/lib/lexical/remote_control/code_mod/rename.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename/module.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename/prepare.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename/prepare.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename/prepare.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_intelligence/rename/module.ex
Outdated
Show resolved
Hide resolved
e86d49e
to
dc10439
Compare
I played around with this a little bit, here are my observations: I did a big rename, renaming One troubling bug that I noticed is that it renamed usages of VSCode fared much better, the rename was more or less instantaneous, and the rename completed successfully with no compile errors.However, the server crashed with the following
|
apps/remote_control/lib/lexical/remote_control/code_mod/rename.ex
Outdated
Show resolved
Hide resolved
apps/remote_control/lib/lexical/remote_control/code_mod/rename.ex
Outdated
Show resolved
Hide resolved
I think i've found the issue that caused the hard crash, I'll write up a PR for that soon. I've tried this a couple times, renaming Of course, you'll have to wait until after my other fix. |
5cdad5f
to
95cd316
Compare
@scohen I tried merging 663, and then everything seems to be working well now. |
96d3ffb
to
d72a46f
Compare
I got a chance to test this out extensively today.
It still saved me hours of tedious, error-prone work. |
This issue you mentioned do exist and are indeed difficult to handle.
This is what we're currently doing; you don't need to reindex every time before renaming." |
Can you elaborate? After the rename, we should have knowledge of what the aliases at a given line are. You should look for the module you want to replace in the aliases at the line, and if it's present, use the alias, if not, use the full module.
Then it doesn't seem to be work, the index was most definitely out of date. |
2910c54
to
8ad087d
Compare
@scohen The reason I say this issue is difficult to handle is because renaming encompasses many scenarios, such as:
For the second scenario, if there is an To thoroughly resolve this type of issue, what we really need is to apply different modification strategies to lines like EDIT: My latest commit: 2898e78 should help with the issue you mentioned. |
e4bb866
to
2898e78
Compare
2898e78
to
a21b40c
Compare
Enhanced the application by integrating rename functionality, increasing its editing capabilities. This includes supporting the preparation and execution of rename operations in various modules such as the lexical AST module, protocol request and response modules, remote control API, and server provider handling. Key additions entail aliasing for easier reference, handling new rename-related requests and responses, and implementing server state updates to acknowledge rename capabilities. The changes underscore our dedication to improving the tool's utility and ensuring a more dynamic and responsive user experience in code manipulation scenarios. Filter out the `:struct` type references Add some handler tests for `rename` Add doc for `local_module_name` Move `rename` from `code_intelligence` to `code_mod` Move the prepare logic to a individual module This PR is primarily copied from #374, but compared to the previous implementation, we have made two changes: 1. We constrained the scope of renaming, meaning that renaming a module is only allowed at its definition. This simplification reduces a lot of computations. 2. Based on the first point, our preparation no longer returns just a single local module, but instead, the entire module. This means that module renaming has become more powerful. We can not only rename a single local module but also simplify a module. For example, renaming TopLevel.Parent.Child to TopLevel.Child, or renaming some middle parts, like TopLevel.Parent.Child to TopLevel.Renamed. I personally really like this change, especially the second point, which makes module renaming much more practical. Surround the whole module when renaming happens Remove logic related to the rename function. Apply some code review suggestions Fix a bug when expanding the module Fix a merge error Apply a format module usage suggestion Update apps/remote_control/lib/lexical/remote_control/code_mod/rename.ex Co-authored-by: Steve Cohen <scohen@scohen.org> Apply the `defdelegate` suggestion Fix a bug when the descendant containing the old suffix
* Rename the file while renaming the module. It first determines whether the module meets certain hard constraints, such as having no parent, then performs some conventional checks. If both are satisfied, it proceeds to return the file renaming. * Maybe insert special folder for PhoenixWeb's module * Apply some code review changes for using `Document.Changes` Use `Document.Changes` instead of `CodeMod.Rename.DocumentChanges` Make `Document.Changes.RenameFile` a struct and use `root_module?` instead of `has_silibings?` and `has_parent?` * Use `rename progress marker` instead of suspending build * Use `file_changed` instead of `file_compile_requested` for reindexing * `uri_with_operations_counts` by client name * Apply some code review suggestions for `rename/file` * Apply suggestions from code review Co-authored-by: Steve Cohen <scohen@scohen.org> * Do not need to care about the `DidClose` message * Apply some code review suggestions 1. Move the `if-else` logic to the `Commands.Rename` module 2. Add `file_opened` message type 3. modify the format error message * Shouldn't returns `RenameFile` if the file name not changed * Change `uri_with_operation_counts` to `uri_with_expected_operation` and special some message type for emacs --------- Co-authored-by: Steve Cohen <scohen@scohen.org> Add `WorkDoneProgress` for the rename expected_operation Apply suggestions from code review Co-authored-by: Steve Cohen <scohen@scohen.org> Update apps/remote_control/lib/lexical/remote_control/code_mod/rename/module.ex Co-authored-by: Steve Cohen <scohen@scohen.org> Update apps/remote_control/lib/lexical/remote_control/commands/rename.ex Co-authored-by: Zach Allaun <zach.allaun@gmail.com> Use record message instead of Protocol structs Replace the asynchronous subscription method of `dispatch` with synchronous `updates`. In the previous commit, we tried the method of registering and subscribing to messages via `dispatch`. I found that this method has significant issues, as it causes the message triggering compilation, the modification of rename status, and the judgment of progress to be out of sync, leading to rename failures and crashes. Apply another code review suggestions
Co-authored-by: Steve Cohen <scohen@scohen.org>
When the entity at the cursor supports renaming but is at the wrong location, return nil. When the entity is of an unsupported type, return an appropriate error.
…aming non-alias reference modules. This can fix some errors that occur when renaming without changing the local name.
7862fb5
to
528a1c0
Compare
This PR is primarily copied from #374, but compared to the previous implementation, we have made two changes:
TopLevel.Parent.Child
toTopLevel.Child
, or renaming some middle parts, likeTopLevel.Parent.Child
toTopLevel.Renamed.Child
.I personally really like this change, especially the second point, which makes module renaming much more practical.