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

Fix references on rename and move #47

Open
cseickel opened this issue Jan 12, 2022 · 6 comments
Open

Fix references on rename and move #47

cseickel opened this issue Jan 12, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@cseickel
Copy link
Contributor

cseickel commented Jan 12, 2022

Use the LSP when available to fix references after (or before?) a file is moved or renamed.

https://github.com/jose-elias-alvarez/nvim-lsp-ts-utils/blob/main/lua/nvim-lsp-ts-utils/rename-file.lua

@cseickel cseickel added the enhancement New feature or request label Jan 12, 2022
@gegoune
Copy link

gegoune commented Mar 31, 2022

Is that for updating buffer after corresponding buffer has been renamed/moved?

@cseickel
Copy link
Contributor Author

Is that for updating buffer after corresponding buffer has been renamed/moved?

No, I think I actually have that already. This means that if the given file is imported into other files in your project, also fix those import statements to point to the new name.

@gegoune
Copy link

gegoune commented Mar 31, 2022

I don't think so, as renaming a.lua to b.lua leaves me with open buffer named a.lua (saving which recreates a.lua on filesystem) and no b.lua gets opened. Another mysterious issue in my set up?

(Please hide those comments, I can open new issue for that just wanted to check for existing one :)

@nyngwang
Copy link

To @cseickel, @gegoune:

[...] as renaming a.lua to b.lua leaves me with open buffer named a.lua, ([...]) and no b.lua gets opened. [...]

I have the same result.

@cseickel
Copy link
Contributor Author

Sorry I never responded to this. It seems like I remembered wrong and rename from neo-tree does not clean up buffers. This should probably be a separate issue.

@Gelio
Copy link
Contributor

Gelio commented Nov 6, 2022

I've just noticed I posted a comment in the wrong issue 😅 My bad. I'll copy the comment from #308 as it is more relevant here.


FYI I was able to implement this functionality for tsserver. I added the following handler https://github.com/Gelio/ubuntu-dotfiles/blob/d5f693db0e5afd10efacb3269f3a96bf3bade834/install/neovim/stowed/.config/nvim/lua/plugins.lua#L116-L134 for the rename and move neo-tree events https://github.com/Gelio/ubuntu-dotfiles/blob/d5f693db0e5afd10efacb3269f3a96bf3bade834/install/neovim/stowed/.config/nvim/lua/plugins.lua#L176-L183

It may be worth adding this snippet to the documentation or the codebase so others can easily copy/require it and use it themselves.

With this snippet, renaming/moving a file or directory in neo-tree automatically updates import paths in TypeScript.

Keep in mind that the tsserver language server needs to be running in the background for this command to run. This is easy enough, though. Just open any TypeScript file and then your subsequent renames/moves will automatically update imports in other files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants