-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix typescript compiler watch path inconsistency #5155
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 typescript compiler watch path inconsistency #5155
Conversation
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I've left a few questions and suggestions in the code for your consideration. Let me know what you think!
| "noImplicitOverride": true, | ||
| "noImplicitReturns": true, | ||
| "noUnusedLocals": false, | ||
| "resolveJsonModule": true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the implications of removing rootDir. Could this affect TypeScript's module resolution or output structure in other build scenarios beyond the watch mode?
For instance, would this change how TypeScript resolves relative imports or affect the structure of declaration files if they were to be generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how it would affect ts module resolution. There are two tsc commands that use this tsconfig.json, and they're both without output because of --noEmit. The actual compilation is done by esbuild. So our change really only affects the error reporting.
(Plus, I think it's a better practice and the original rootDir property isn't beneficial in any way)
| "publish:marketplace": "vsce publish --no-dependencies && ovsx publish --no-dependencies", | ||
| "watch:bundle": "pnpm bundle --watch", | ||
| "watch:tsc": "tsc --noEmit --watch --project tsconfig.json", | ||
| "watch:tsc": "cd .. && tsc --noEmit --watch --project src/tsconfig.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is changing the working directory the most maintainable approach here? I'm wondering if there might be alternative solutions that could achieve the same result without requiring the script to cd ...
For example:
- Could we use TypeScript's
--rootDirCLI flag instead? - Would adjusting the
includepaths in tsconfig.json work? - Could we leverage the
baseUrlcompiler option?
The current approach works, but I'm curious if you considered these alternatives and what led to choosing this specific solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually the only change I managed to come up with that can be minimal in the command itself.
Changing the include paths or baseUrl doesn't affect error reporting. The --rootDir only works with an absolute path (which isn't viable).
Only other alternative I could think of was to write a script instead of a one liner, which is even uglier.
|
Hi @daniel-lxs @hannesrudolph , I've addressed the concerns in the comments, please let me know if it makes sense to you. Thanks. |
daniel-lxs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested main and this PR with a compiler error and it seems to work, I didn't notice any negative side effects.
|
yay! this has been driving me nuts! |
|
I am not sure this completely fixed the issue, there is still some noise in the file name:
The text notice the bottom two lines of this image.
|

Related GitHub Issue
Closes: #5133
Description
Fixes TypeScript compiler watch mode reporting incorrect file paths without the
src/prefix, which prevented VS Code from properly navigating to error locations.Before:
core/webview/webviewMessageHandler.ts:439:7After:
src/core/webview/webviewMessageHandler.ts:439:7Changes Made
rootDir: "."fromsrc/tsconfig.jsoncd .. && tsc --noEmit --watch --project src/tsconfig.json)rootDirallows TypeScript to use default behavior and includesrc/in error pathsTest Procedure
Pre-Submission Checklist
Documentation Updates
Additional Notes
Get in Touch
Discord username is
gooner4everImportant
Fixes TypeScript compiler watch mode path inconsistency by removing
rootDirfromtsconfig.json, enabling correct VS Code navigation.rootDir: "."fromsrc/tsconfig.json.src/prefix, enabling correct VS Code navigation.watch:tscscript inpackage.jsonto run from project root (cd .. && tsc --noEmit --watch --project src/tsconfig.json).This description was created by
for 994c206. You can customize this summary. It will automatically update as commits are pushed.