learn-a icon indicating copy to clipboard operation
learn-a copied to clipboard

Question on Editor Integration

Open EisenbergEffect opened this issue 7 years ago • 5 comments
trafficstars

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.

EisenbergEffect avatar Jun 28 '18 07:06 EisenbergEffect

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.

EisenbergEffect avatar Jun 28 '18 07:06 EisenbergEffect

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.

RyanCavanaugh avatar Jun 28 '18 16:06 RyanCavanaugh

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?

EisenbergEffect avatar Jun 29 '18 06:06 EisenbergEffect

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:

  1. In your consuming project (e.g. in this repo, pkg3), create a tsconfig-tsc.json file, containing the main TS configuration. This is what everything should reference, including - in the case of this repo, the top-level tsconfig.json file. This is the config file you'll give to TSC because it contains precisely what you want.
  2. Create a tsconfig.json file in the same location, which extends tsconfig-tsc.json. Add a paths section to compilerOptions and manually specify the root locations of your packages (e.g. "@ryancavanaugh/pkg2": ["../pkg2/src"] for this repo) and, depending on configuration, an explicit baseUrl (e.g. "."). THIS tsconfig.json file 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.

RoystonS avatar Aug 27 '18 18:08 RoystonS

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.

Izhaki avatar Dec 29 '18 00:12 Izhaki