Skip to content
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

Rename file when renaming module #651

Merged
merged 12 commits into from
Apr 26, 2024

Conversation

scottming
Copy link
Collaborator

@scottming scottming commented Mar 19, 2024

This PR is an implementation of renaming 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.

CleanShot.2024-03-20.at.21.29.46.mp4

@scottming scottming force-pushed the rename-file-when-renaming-module branch from 257e77c to ca45d9e Compare March 19, 2024 14:10
@scohen
Copy link
Collaborator

scohen commented Mar 19, 2024

In the end, don't we just want the module name to match the file path? I was thinking this could be accomplished by indexing the file with the Module extractor, then, for each module, getting its name, and if it's not in the right file, doing one of the following:

If there is one module in the file:

  1. If the file has the correct name, then do nothing
  2. If the file name or path is incorrect, determine the right path and issue a RenameFIle, then emit edits for the file with the new contents.

If there is more than one module in the file:

  1. Determine if any of the modules have the correct name
  2. If one does, emit an edit for the current file with the others removed
  3. For all modules in the current file that don't have the right name, follow the above steps.

There's a caveat here, since there can be global aliases / imports, etc. in the file, and if there are, they need to be relocated to the new files as well.

@scottming scottming force-pushed the rename-file-when-renaming-module branch 5 times, most recently from f097634 to c02d2f6 Compare March 20, 2024 11:51
@scottming scottming force-pushed the rename-file-when-renaming-module branch from c02d2f6 to f6f6972 Compare March 20, 2024 13:18
@scottming scottming marked this pull request as ready for review March 20, 2024 13:18
@scottming
Copy link
Collaborator Author

In the end, don't we just want the module name to match the file path?

Yes, essentially, that's exactly what we need to do.

I was thinking this could be accomplished by indexing the file with the Module extractor

If we can achieve that, it would certainly be ideal, but these steps also sound quite challenging.

@scottming scottming force-pushed the rename-file-when-renaming-module branch from f6f6972 to 49008bc Compare March 20, 2024 13:51
@scohen
Copy link
Collaborator

scohen commented Mar 20, 2024

Why do you think it's challenging?

@scottming
Copy link
Collaborator Author

Why do you think it's challenging?

Perhaps I was overthinking it at the time, feeling that there were too many conventions. However, if we start with some simple conventions, like in this PR, then the complexity should be manageable.

@scottming scottming force-pushed the rename-file-when-renaming-module branch from 10c36b6 to 91d6f58 Compare March 21, 2024 11:14
alias Lexical.RemoteControl
alias Lexical.RemoteControl.Search.Store

def maybe_rename(entry, new_suffix) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just pass the project in here rather than using RemoteControl.get_project(). It makes it easier to test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means I need to pass the project down from RemoteControl.Api.rename all the way through. I'm not very keen on doing that; it doesn't seem to simplify the testing. prefer to your above suggestion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would simplify testing because you don't need to set something that's effectively global.

@scohen
Copy link
Collaborator

scohen commented Mar 21, 2024

Why do we care if there are parents or siblings before we rename a file?

@scottming
Copy link
Collaborator Author

scottming commented Mar 22, 2024

Why do we care if there are parents or siblings before we rename a file?

When there are some sibling modules at the first level, we usually don't use one of those modules as a mapping for the file name.

Regarding the issue of parent modules, consider examples like state modules inside GenServer modules.

There are tests for these cases.

@scohen
Copy link
Collaborator

scohen commented Mar 25, 2024

Regarding the issue of parent modules, consider examples like state modules inside GenServer modules.

This is why I was suggesting using the indexer, you can index the file with the module extractor, and see if there are multiple modules in the file (as well as get their hierarchy). If there are, you would treat the file as the parent module, and only rename that.

There are multiple cases for this, of course. You can have a file whose name has no bearing on the modules contained inside as well.

@scottming
Copy link
Collaborator Author

This is why I was suggesting using the indexer, you can index the file with the module extractor, and see if there are multiple modules in the file (as well as get their hierarchy)

To be honest, I'm not sure exactly how to do it. It sounds like I need to add some fields to Indexer.Entry, right? And append this information when Entry.block_definition is called. Do you want me to take care of this in this PR?

@scottming scottming force-pushed the rename-file-when-renaming-module branch from 4d41168 to 44955b4 Compare March 27, 2024 09:57
@scohen
Copy link
Collaborator

scohen commented Mar 27, 2024

It sounds like I need to add some fields to Indexer.Entry, right?

No, I don't think so. You just need to run the indexer on the document, giving it only the module extractor, and it will return all the module definitions in the document.
You can then look at the entries to find out if they're nested (you can get all the top-level modules by collecting those modules whose block_id is :root. any others are nested.

to index using a subset of extractors, do the following

document
modules =
  |> Indexer.Source.index([Indexer.Extractors.Module])
  |> Enum.reject(& &1.type == :metadata)

@scottming scottming force-pushed the rename-file-when-renaming-module branch from 44955b4 to 9e4ee39 Compare March 28, 2024 07:46
@scottming scottming force-pushed the rename-file-when-renaming-module branch 2 times, most recently from 2e7c300 to 2e6cb4c Compare March 29, 2024 08:44
@scottming scottming force-pushed the rename-file-when-renaming-module branch 2 times, most recently from c39424e to c2f5029 Compare April 21, 2024 01:46
@scottming scottming force-pushed the rename-file-when-renaming-module branch from c2f5029 to 35d7caf Compare April 21, 2024 12:18
@scottming scottming force-pushed the rename-file-when-renaming-module branch from 35d7caf to a36ad78 Compare April 21, 2024 12:23
@scottming scottming merged commit a971f2a into rename-module-v2 Apr 26, 2024
scottming added a commit that referenced this pull request Apr 26, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request Apr 26, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request Apr 26, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request May 4, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request May 12, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request May 24, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request May 24, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request May 25, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit to scottming/lexical that referenced this pull request May 31, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request Jun 1, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit to scottming/lexical that referenced this pull request Jun 1, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit that referenced this pull request Jun 15, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit to scottming/lexical that referenced this pull request Jul 4, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit to scottming/lexical that referenced this pull request Jul 12, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit to scottming/lexical that referenced this pull request Jul 12, 2024
* 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 <[email protected]>

* 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 <[email protected]>
scottming added a commit to scottming/lexical that referenced this pull request Jul 12, 2024
* 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 <[email protected]>

* 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 <[email protected]>

Add `WorkDoneProgress` for the rename expected_operation

Apply suggestions from code review

Co-authored-by: Steve Cohen <[email protected]>

Update apps/remote_control/lib/lexical/remote_control/code_mod/rename/module.ex

Co-authored-by: Steve Cohen <[email protected]>

Update apps/remote_control/lib/lexical/remote_control/commands/rename.ex

Co-authored-by: Zach Allaun <[email protected]>

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
scottming added a commit that referenced this pull request Sep 6, 2024
* 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 <[email protected]>

* 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 <[email protected]>

Add `WorkDoneProgress` for the rename expected_operation

Apply suggestions from code review

Co-authored-by: Steve Cohen <[email protected]>

Update apps/remote_control/lib/lexical/remote_control/code_mod/rename/module.ex

Co-authored-by: Steve Cohen <[email protected]>

Update apps/remote_control/lib/lexical/remote_control/commands/rename.ex

Co-authored-by: Zach Allaun <[email protected]>

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants