One of the most common things in coding is refactoring bad code into better code. Especially in Agile development. How are people doing it in haxe?
When I try to rename a file or class it fails about 80% of the time saying ‘could not find identifier to rename’. When I move files the packages don’t update. Is there a specific way people are doing to refactor?
renaming a file works by doing a rename on the main type name. moving a file to a different package currently needs a rename on package <your.package.name>;. there is probably a hook or callback to subscribe to in order to receive rename or drag&drop events from vscode file explorer, but that’s for future versions to figure out.
your 80% failure rate when trying to rename an identifier seems a bit high. while current rename functionality for sure has some hidden bugs, it should work in a lot of cases. so either your setup needs adjusting (see Rename Symbol · vshaxe/vshaxe Wiki · GitHub) or you are running into a bug that should be investigated in more detail. can you provide sample code where rename operations fail for you?
Dug a little deeper, I’ve added a lib folder that houses all my common library files. I have multiple projects in one VSCode project. It’s my attempt to set up my own personal monorepo. Looking deeper into this, it turns out if I try to rename anything in this lib folder it fails with this error: could not find identifier to rename. It even fails on simple variables in tiny scopes like in functions:
Here is my hxml file which should give a better picture of what I’m doing.
-cp lib # If I try to rename anything in here it doesn't work, anything in the main src is fine though.
I have multiple projects that pull from that single lib folder. Of course the reason for this is to save time when refactoring especially with multiple projects. The only issue though is that the refactoring doesn’t work …
Edit: This seems to be the case for anything in the .haxelib folder as well…
rename will only look in folders specified via haxe.renameSourceFolders config option (defaults to ["src, "source", "Source", "test", "tests"]), if you use additional source folders, you need to add them, otherwise they won’t be included when renaming
current vshaxe does not support multiroot workspaces, so if you have multiple projects in one workspace you are bound to run into problems. e.g. all compiler services (completion, hover, etc.) will only work for the first Haxe project in your workspace.
80% failure rate for renames? You lucky guy . For me it’s more like 99% . And yes, my project has files in multiple roots, but renaming fails even in files that are local to a single directory, even when renaming a local function variable. The moment I’m not in the “main” project, everything fails.
I really love vshaxe though. So… what I do is this: I code in VS Code and when I need to refactor, I use the severely out-dated IntelliJ plugin (which can’t comprehend all Haxe syntax, but still can refactor 90% of the situations).
This is where the small Haxe ecosystem really bites us. If we had more projects, bigger companies, stuff like this would have been addressed long ago. But we’re few, and we have to split our time between N projects.
Do you setup haxe.renameSourceFolders for your roots?
And there is zero opened issues in vshaxe repo about this feature, so it seems strange to me saying how nothing works for you, when you can open actual bug report and don’t wait for bigger companies to do it for you.
currently vshaxe does not support multi-root workspaces which affects all languageserver services. in general most things will only work for first project in workspace, if at all.
so unless vshaxe learns how to handle multi-root workspaces, developer experience will remain far below that of a single project workspace.
Haxe language server has several issues. Many times I try to go to definition and it goes to the definition of another module . Some other times, I select one auto completion and it fills a different one.