Open samuelstroschein opened 3 months ago
Hi @samuelstroschein
That's a good idea, it didn't cross my mind. I will check the SDK and see how I can use it from a WS plugin. I think there's a cli too, maybe that's more convenient for this kind of work.
I will check and get back to you.
Here is the package on NPM https://www.npmjs.com/package/@inlang/sdk. I saw on the Kotlin docs that you can use NPM packages in Kotlin https://kotlinlang.org/docs/using-packages-from-npm.html
The SDK in v1 exports a loadProject
function, which is the entry point for a project. Here is Sherlock's code on calling the function https://github.com/opral/monorepo/blob/647b62abf2d1323472220cc751d82d762894c23f/inlang/source-code/ide-extension/src/utilities/project/project.ts#L110-L116.
Problem though: You need to pass a nodeish fs interface and load the (git) repository. I think that will be too complicated from Kotlin.
Suggestion
Wait till v2 of the inlang SDK. The expected pre-release is at the end of August.
You will be able to load the project from a path without dealing with repositories, importers, etc. The only thing we need to ensure is that the node's fs can be called in Kotlin, or you can provide a wrapper from Kotlin.
const project = await loadProjectFromDirectory({ path: "/project.inlang", fs: FsWrapperFromKotlin })
Alternatively, publishing Sherlock as VSCode extension to WebStorm might be even easier. There seems to be no straightforward way to publish a VSCode extension to WebStorm though :(
Interesting how easy they made it to call an npm module!
I will wait for v2 then, it seems much simpler.
It would have been perfect if jetbrains would support js/ts plugins 🤷♂️
I checked the possibility of using an npm module. It looks like jetbrains only supports jvm and not js.
My simpler solution is to use nodejs scripts and call them from kotlin, something like node src/random-id.mjs
or better yet node sdk-cli.mjs --generate-random-id
I had some success with it so far
If the inlang cli could do this in the future, it would be the perfect solution
Have you tried the Kotlin WASM/JS interop https://kotlinlang.org/docs/wasm-js-interop.html#javascript-modules ?
Well, I found the answer, we can't mix jvm and js
Our best bet is the cli, it's the max interop solution short of a language server 🫣
I am unsure about the CLI. It would replicate the SDK API but with a custom layer on top ... except if we expose SQL queries. Even then, it seems complicated because you would have to open PRs against the CLI, wait for them to be merged, etc. And users are required to install the CLI.
Can you leverage web views in WebStorm?
If you can leverage web views, you can let the SDK run in the web view and also render the UI components we are offering (see the Fink2 prototype as an example for components). You would only need to copy the contents of/package the inlang directory in git into the webview and out of the webview again. Here is pseudocode:
let inlangFile = inlangDirectoryToFile("/project.inlang")
let webview = createWebview()
webview.postMessage("file", inlangFile)
webview.onMessage("export-file", fileToDirectory)
I found https://plugins.jetbrains.com/docs/intellij/jcef.html#executing-javascript and other resources that indicate that webviews might be an option.
Example UI component that you could embed in your extension
looping @felixhaeberle into the conversation. he maintains sherlock and might have ideas.
@unlocomqx awesome to see work on a webstorm extension!
Have you considered using the inlang SDK?
I saw that you wrote your own utility class for operating on an inlang directory. The approach will only work for a few projects that use the json plugin, and will likely be error prone.
We build the inlang SDK precisely for anyone to build inlang apps. The SDK takes care of loading messages, CRUD operations, loading plugins, etc. I strongly recommend using the inlang SDK to simplify your code logic, make your webstorm extension work for any project, and avoiding bugs. It's written in JavaScript though, which opens two questions: