akinsho / flutter-tools.nvim

Tools to help create flutter apps in neovim using the native lsp
MIT License
935 stars 75 forks source link

fix: FlutterRename when files with import is opened in another buffer #290

Closed m-salman-a closed 9 months ago

m-salman-a commented 9 months ago

Fixes #289

akinsho commented 9 months ago

@m-salman-a ~I need a bit more context on what this PR is trying to do~ nevermind just saw the associated issues. Looks good to me but as @sidlatau added this feature will see what he says about it 🙏🏾

sidlatau commented 9 months ago

Hmm, I tested the original and changed version and I see no difference in behavior. As I understand it the reason why the import update is not applied is because the file had changes that were not saved yet. If I save changes - renaming works.

m-salman-a commented 9 months ago

Hi, thanks for the quick reply. Upon recreating the issue, I found that you have to use the FlutterRename command more than once for the import to not be updated. I also made sure to save all the files before performing the second FlutterRename. Here is a video reproduction of the issue before and after applying the fix provided in the PR. This is the minimal config that I used.

Before

https://github.com/akinsho/flutter-tools.nvim/assets/51153904/bfb8f8b3-2fb3-4431-ab54-27d3e1eaaebf

After

https://github.com/akinsho/flutter-tools.nvim/assets/51153904/bd3ab94f-2d86-4f6f-bc81-9e4d1c90dfee

Explanation

As for the explanation, the "Buffer .... newer than edits" error comes from this check here in the vim.lsp.utils.apply_text_document_edit function which is called from vim.lsp.utils.apply_workspace_edit. I'm currently not sure why this check is failing (if anyone can help that'd be great) but applying the workSpace/willRenameFiles request before calling the textDocument/rename handler makes this check pass.

sidlatau commented 9 months ago

@m-salman-a thanks for the detailed explanation! Yea, when renaming more than once I am able to reproduce the issue, and your fix solves it. LGTM