-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
RuntimeTypeInspector.js: Add RTI build target + Examples integration #5817
base: main
Are you sure you want to change the base?
Conversation
…context has no access to RTI)
… for IntelliSense)
This is pretty cool!
|
Hey @Maksims, thank you for the feedback!
Yep, for this there is this button: Currently it supports a "warn once" or "spam all the time" mode, but do you mean even more fine-grained control with N + source? (I just uploaded to latest HEAD + fixed a issue with the spam-button-state, now it saves/restores properly from
It's a Then you can click on the file location under So currently it takes two clicks to get to the place of the type error, but I'm not sure what you mean with deep linking from Launcher to IDE, could you elaborate a bit on that? Thank you again! |
Hm, maybe the intention of the button isn't clear, when "Spam type reports" is checked it means that every type error is calling Thank you for pointing out the stack trace issue when DevTools isn't open from the beginning - I wasn't aware of that, so I will save the stack traces aswell for better inspection (would be nice to see in UI too).
Right, I made a little experiment what kind of information we can get out of the stack trace for Editor integration: const info = () => {
try {
throw new Error(); // Dummy exception to retrieve stack trace
} catch(e) {
const {stack} = e;
if (stack.toLowerCase().includes('script')) {
const lines = stack.split('\n');
const i = lines.findIndex(_ => _.includes('ScriptComponent'));
let scriptLine = lines[i - 1];
scriptLine = scriptLine.replace(/at/, '').trim().split(' ')[0];
console.warn('Type error in script: ', scriptLine);
}
}
}
info(), false; // false so it doesn't breakpoint here This is "breakpoint code" we can enter here: (clicking on the function source) Then you have integrated the "breakpoint code" into the code flow and now you can play around with stack traces: Thinking about the editor, we could just add "quick links" to the actual scripts now. Thank you for the suggestion! Edit: I think I finally understood it: Instead of "spam" and "once", it should have an option "never", so it doesn't spam anything in the console (I will work on that). Edit 2: Added the type error reporting mode (this keeps DevTools completely "clean", only reporting in the UI) |
# Conflicts: # examples/package-lock.json
# Conflicts: # rollup.config.mjs
…rget-rti for engine and examples instead (this ensures we only have one function which configures a RTI plugin, so it's mentally easier to navigate)
I'm finally coming to a resolution here, it just feels so spammy for many examples still, even tho they run fine (simply based on wrong types in the engine). My main goal is "0 errors" - so developers can start editing examples and only see type errors they introduced themselves during their coding session. If anyone has time, I would love to have these issues fixed:
Any volunteers? 😅 |
A good cause 👍 I might tackle some of those next week. |
# Conflicts: # package-lock.json
# Conflicts: # package-lock.json # package.json
# Conflicts: # package-lock.json
# Conflicts: # examples/rollup.config.mjs # examples/utils/plugins/rollup-build-examples.mjs
# Conflicts: # examples/package-lock.json # examples/package.json
…. error in <iframe> is send to parent window)
Fixes #2529
I'm excited to introduce RuntimeTypeInspector.js, which I believe will benefit PlayCanvas as a whole and our debugging workflows in specific. RTI is designed to type-check the arguments of every function and method. It detects type errors while the engine is running in a way that goes beyond the capabilities of TypeScript, as demonstrated in this video (there is another one on the website debugging the Microsoft Holometric Video PC project).
During the development of RTI it already helped me to open issues or make PR's for various issues (e.g. NaN bugs).
I believe that RTI will help improve productivity and efficiency for both engine developers and users, by catching errors early on and reporting them in detail.
Runtime Type Inspector is implemented using Babel AST traversal with custom JSDoc parsing (powered by TypeScript itself for highest compatibility), customized to PlayCanvas requirements. That means for example supporting polymorphing
this
types.TLDR: It adds type assertions for runtime type checking, for example:
Being able to set breakpoints exactly where the errors are happening for the first time helps to track down problems that are otherwise difficult to pinpoint (and saves a lot of time 😅).
Try for yourself: http://pc.runtimetypeinspector.org/
Just make sure to pick the right JS context - the exampleIframe:
I'm working on this for quite some time by now, a mix of fun and frustration - rewriting code on the AST level first seemed tricky, but given enough time, it was a rather straightforward way to automate type validations. I'm excited to read feedback and suggestions. 🙏
I confirm I have read the contributing guidelines and signed the Contributor License Agreement.