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

feat: add FlutterRename command #234

Merged
merged 7 commits into from
Apr 9, 2023
Merged

feat: add FlutterRename command #234

merged 7 commits into from
Apr 9, 2023

Conversation

sidlatau
Copy link
Collaborator

@sidlatau sidlatau commented Apr 6, 2023

This command adds support for updateImportsOnRename setting (https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/tool/lsp_spec/README.md#client-workspace-configuration).

It is useful when the file is renamed after a class rename (when enabled renameFilesWithClasses setting).
It will fall back to vim.lsp.buf.rename() if no dartls client is found.
If the client is found, the file is the same as the class name, and the class is being renamed, it will request for changes via workspace/willRenameFiles. Results of workspace/willRenameFiles will be applied after the class rename.

To test it try to rename the class that is in the file with the same file name.

  • with vim.lsp.buf.rename(): class renamed, file renamed, usage of class renamed, but imports are not updated.
  • with FlutterRename: class renamed, file renamed, usage and imports are updated.

This command adds support for `updateImportsOnRename` setting (https://github.com/dart-lang/sdk/blob/master/pkg/analysis_server/tool/lsp_spec/README.md#client-workspace-configuration).
It is useful when file is renamed after class rename (when enabled `renameFilesWithClasses` setting).
It will fallback to `vim.lsp.buf.rename()` if no `dartls` client found.
If client is found, file is the same as class name, and class is being renamed,  it will request for changes via `workspace/willRenameFiles`.
Results of `workspace/willRenameFiles` will be applied after class rename.

To test it try to rename class which is in the file with same file name.
Before: class renamed, file renamed, usage of class renamed, but imports are not updated.
After: class renamed, file renamed, usage and imports are updated.
@sidlatau sidlatau linked an issue Apr 6, 2023 that may be closed by this pull request
Copy link
Collaborator

@akinsho akinsho left a comment

Choose a reason for hiding this comment

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

Just had a quick look, not a super detailed review atm. Looks good generally, just some stylistic comments. Also one somewhat big comment which is mainly I wonder if a lot of this logic isn't already handled by the lsp stuff like calculating which files to update etc. also I wonder if vim.lsp.util.rename can't also be used here

lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
@akinsho
Copy link
Collaborator

akinsho commented Apr 6, 2023

will fix #233

@sidlatau sidlatau requested a review from akinsho April 6, 2023 17:27
Copy link
Collaborator

@akinsho akinsho left a comment

Choose a reason for hiding this comment

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

@sidlatau thanks for factoring out the ui.input calls and the lsp.get_client stuff makes things much cleaner. The remaining stuff I've flagged are almost entirely stylistic. Things like

  • Adding type annotations to make the code easier to use with lua ls
  • preferring old -> prev, actual -> current
  • expand("magic") -> vim.fs.(base|dir)name(api.nvim_buf_get_name())

lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
lua/flutter-tools/lsp/rename.lua Outdated Show resolved Hide resolved
@sidlatau sidlatau requested a review from akinsho April 7, 2023 07:37
Copy link
Collaborator

@akinsho akinsho left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏾

@akinsho akinsho merged commit 4d9391b into main Apr 9, 2023
@akinsho akinsho deleted the flutter-rename branch April 9, 2023 20:40
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.

Support file rename with imports update
2 participants