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

Support rename/move of Svelte files #111

Closed
dummdidumm opened this issue May 23, 2020 · 2 comments · Fixed by #113
Closed

Support rename/move of Svelte files #111

dummdidumm opened this issue May 23, 2020 · 2 comments · Fixed by #113
Labels
feature request New feature or request

Comments

@dummdidumm
Copy link
Member

Is your feature request related to a problem? Please describe.
Right now renaming/moving svelte files does not update the imports in other svelte files.

Describe the solution you'd like
Renaming/moving svelte files should update the imports in other svelte files.

Additional context
I dug around the language server protocol a little but found no event that says "file X moved from A to B" or "file X was renamed to Y". Instead, onDidCloseTextDocument and onDidOpenTextDocument events fire, and also the onCodeAction event is invoked with the new file path and a range with start/end of 0. One could infer a file rename/move from these events, if they appear shortly after each other, but I'm not sure if this is a hack or the only possible solution. If someone knows more about this, please comment.

@jasonlyu123
Copy link
Member

jasonlyu123 commented May 25, 2020

I found vscode's typescript features is using workspace API which doesn't seem to be accessible in the language server. So we can't just copy their solution. And with the structure of this repo, it will be quite difficult to done it on the client.

There is some issue in language-server-protocol about proposals of rename file. I think we could have some workaround and update later to fit the protocol if it has been added.

There are two additional solutions:

  1. Sent a custom request or command to pipe the workspace event to the language server. Dart Code seems to use this solution.
  2. use onWatchFileChanges to detect rename. file rename would trigger a create and remove change in the same request. But I can't make it watch directory.

@dummdidumm
Copy link
Member Author

Thanks for finding those things out!

I tried out the workspace.onDidRenameFiles event a little and it seems that would fit our needs. As you said, we could translate that event into a command that is sent to the language server and handle the rest there. Inside TypescriptPlugin we then should be able to let the ts language service handle this by calling getEditsForFileRename.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue May 26, 2020
dummdidumm added a commit that referenced this issue May 28, 2020
* (feat) update imports for renames/moves files

closes #111

* (fix) bump ts version, refresh files

- Bumping ts version speeds up rename files
- Not refreshing the files will result in the ts service not noticing some updates which would create a bug where if you rename a file and rename it again, the ts service would have old files and rename would not update all locations.

* (fix) cleanup, tests

* (fix) add tsconfig to testfiles folder to speed up tests

Now that tsconfig is used, the ts service is many times faster because it only knows the files inside the test folder

* (feat) add updating imports indicator

* (fix) rewire imports changes of moved file

The language service might want to do edits to the old path, not the new path -> rewire it.
If there is a better solution for this, please file a PR :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants