learn-a
learn-a copied to clipboard
Question on Editor Integration
First, thanks for putting this together Ryan! I had a look at it this evening. I downloaded, followed the instructions and then played around a bit. In VS Code, I did a rename on a function in package 2 from package 3 to see how it would work across packages. I noticed that it renamed the function in the d.ts file for package 2, rather than in the source. This resulted in no change to source, and thus no build update. It also resulted in a situation where the build would succeed even though there was an error (incorrect function name). I wasn't sure if this was because VS Code wasn't updated yet or if this was something in the TS project support itself, so I wanted to mention it here.
Update: Renaming doesn't appear to work at all. If I rename something in package 2 from package 2, it doesn't propagate. Additionally, if I navigate to a definition in another package, it opens a tab with the source, but an odd path...and if I navigate manually to the same source file it will open an additional tab. Again, I wasn't sure if this was a VS Code thing or something in the TS compiler itself.
This is an issue on the TypeScript side - cross-project rename is a feature we're really hoping to get in for 3.0 (@andy-ms is working on it) but if we don't get it in in time, we'll probably explicitly block this operation the same way we do for renames of names originating in lib.d.ts.
Go-to-def works because we did the work to wire up the .d.ts sourcemaps to the go-to-def feature; rename is just a matter of figuring out what all the upstream and downstream effects of a rename should be.
It's good to know you're aware of the issue. It will be pretty important for us so I do hope that @andy-ms is able to complete the work. If it doesn't make it in time, you mention you would block the operation. That would be a deal-killer if it blocked the rename within the individual project as it would make it impossible to rename anything once a TS project was setup. Is that the intention or was there a different behavior in mind?
Might be worth trying a trick/workaround that we've been using since before project references (which is still needed, sadly). It enables cross-project renaming, and proper CTRL-click to navigate to reference (without opening a weirdly named file as pure project references cause right now) even in this repo:
- In your consuming project (e.g. in this repo,
pkg3), create atsconfig-tsc.jsonfile, containing the main TS configuration. This is what everything should reference, including - in the case of this repo, the top-leveltsconfig.jsonfile. This is the config file you'll give to TSC because it contains precisely what you want. - Create a
tsconfig.jsonfile in the same location, whichextendstsconfig-tsc.json. Add apathssection tocompilerOptionsand manually specify the root locations of your packages (e.g."@ryancavanaugh/pkg2": ["../pkg2/src"]for this repo) and, depending on configuration, an explicitbaseUrl(e.g."."). THIStsconfig.jsonfile will only be used by VSCode, and enables it to find all the source code.
Why do we need two files? tsconfig.json is what VSCode will use automatically, and we want that to see the original source for packages we depend on. We don't want TSC to see those, as we want those packages to compile themselves, and don't want to cause, for instance, pkg3 to also compile pkg2.
It's definitely a workaround: dragging around extra tsconfig files is a bit annoying, and it's not difficult to use the wrong one accidentally. But it's been working well for us in an 8-project lerna repo for about 8 months now.
Here's a repo that demonstrates @RoystonS 'workaround'.
It's not exactly this repo + the changes he suggests, but it's based fully on his setup.