Hi everyone! I have a Kotlin Multiplatform project...
# javascript
i
Hi everyone! I have a Kotlin Multiplatform project that has: 1. A JVM target for an IntelliJ Platform plugin 2. A NodeJS target that produces functionality for a VS Code extension (compiled to JS). I want to debug the Kotlin code for that Node/VS Code extension directly from IntelliJ. Right now, if I debug the extension in VS Code, I end up debugging the compiled JS. But I’d like to set breakpoints in the actual .kt sources and step through them in IntelliJ (similar to how we do for JVM). I’ve tried: • Generating source maps, using @vscode/test-electron or spawning Electron from a Node run config in IntelliJ, • Various run configurations and --inspect setups, • Attempting to run a Kotlin/JS test that calls runTests(...) to launch VS Code, then debugging that Node process. Unfortunately, I still can’t step through .kt files in IntelliJ, or sometimes I get multiple Electron windows launching. Question: Has anyone had success debugging Kotlin/JS code in a Node/Electron environment (like a VS Code extension) from IntelliJ, with real Kotlin breakpoints? Any tips on the best build or config approach, or if that is even possible? I know this might be uncharted territory but i’m hoping i’m not the first one to explore it Thanks in advance!
c
I don't encourage such personal adventures unless you've been sponsored by some big capitals.
To most projects the aiming to be Multiplatform leads to be a proven illusion. Although it is a very good will.
t
сс @Edoardo Luppi
🙌 1
i
@turansky You read my mind, i wanted to tag him as well, but was told by someone not to tag people
t
Edoardo tags me regularly 🧌 Edoardo
23 : 1
Victor
😂 1
c
You are free to tag.
You can hide my replies if you want see my responses.
And I have done this for avoiding future interactions.
i
Actually I have yet to try one approach that might be the simplest one and working out of the box, which in theory wasn’t working out of the box for me because the i’m running the vscode extension in a workspace that only includes the subproject of the vscode extension, and the kotlin files are in another subproject. And also i didn’t install the vscode kotlin extension
e
A long time ago I did attempt to set up IntelliJ to be able to run and debug VS Code extensions. To some extent I managed to do it (see https://github.com/lppedd/idea-vscode), but the overall experience wasn't great. It would have required too much time for me to implement that extension. For my team I then rolled back to developing in IntelliJ, and debugging the extensions via VS Code's run configurations. I don't have issues with stepping through Kotlin code, as you can see from my screenshot. The important piece of configuration is
Copy code
"resolveSourceMapLocations": [
   "${workspaceFolder}/dist/tsc/**",
   // Workaround to resolve Kotlin source maps.
   // VS Code seems unable to load source maps through symlinked dirs
   "${workspaceFolder}/generated-packages/**" <-- K/JS stuff
],
i
Ok great, that means it’s possible! Where does that config piece go?
e
The big problem with IntelliJ, is that opening a VS Code extension host is possible only via command line. Attaching the debugger is done after the process has been spawned, and it doesn't work reliably.
That's the
launch.json
file.
i
I think the case i have is what i said in my last message, i.e workspace scope and kotlin plugin. Plus the config. But yeah i only resorted to running from IJ because i thought it’s impossible to debug the kotlin code in vs
e
And also i didn’t install the vscode kotlin extension
I believe it's not required. I have it just for syntax highlighting, but you wouldn't be able to actually develop K/JS code.
But yeah i only resorted to running from IJ because i thought it’s impossible to debug the kotlin code in vs
Most Kotlin code is debuggable (the one you js-export mostly). The stdlib isn't tho, unless you downloaded the sources yourself (never tried tho). And coroutines are also a problem.
From my perspective, I've decided to implement the Kotlin side of things as separate libraries, capable of being tested and debugged in isolation. That means stepping through Kotlin code in VS Code isn't required 99% of the times.
i
Yeah you told me when we talked about it almost a year ago when I started this project, all this time I’ve been debugging by logging… I wish I’d have turned to slack earlier about this 🥲 Interesting news about wasm! That means it’d be much easier to build MP plugins for IJ and VS, if one wants more than what LSP provides. I did see that IJ platform expanded their support for LSP though
Also performance wise, I’ve been struggling with a bit with what seems like limitations of nodejs, so If I understand correctly, this would also help with that
e
In our case we can't switch to WASM simply because we interop with other extensions and it would be a PITA. But in your case it would probably simplify things quite a lot. You'd need Component Model support in K/WASM tho, which isn't there yet.