Open AFCMS opened 2 days ago
@AFCMS could you share the repository with me. Makes it a lot easier to understand what is going on.
Didn't have a repository yet, created one.
https://github.com/AFCMS/vscode-oxipng
It aims to provide the oxipng right inside VSCode.
There are two VSCode commands, the hello world one (which works) and the optimise one (which no longer works). For the optimise one, it's accessible in the file explorer and it should work on PNG files (small files can be used for testing since bigger ones tends to take a long time to process).
I am exploring the use of a Rust file treatment library straight inside VSCode in WebAssembly.
I successfully built my fist POC, using the
wasm32-unknown-unknown
target + wit2ts. It exports a single function which takes file data (Uint8Array) as a parameter and return the modified file in the same format (it's a trivial function on my side since the library have already a Uint8Array->Uint8Array function). So the extension command handler read the file (withvscode.workspace.fs.readFile
), call the WASM function and write it back. (not sure if it's the best thing to do, but reading/writing file from WASI directly for just a single function which access one file at a time seemed a bit too much for me)This setup worked really well, but according to the second blog post long running tasks should be put in a worker. In my case the treatment can go from half a second to more than 10 seconds, so it should ideally be in a worker I guess.
I followed the exemple to make the wasm part run in a worker, and I went into a strange problem.
WIT file:
Rust code (minus boilerplate):
Extension code:
I didn't change anything on the Rust/WIT side and the
testExtension.helloWorld
command works fine in both cases but now when calling thetestExtension.optimise
command, the first info message is displayed, the two log messages from the worker are displayed in the right output channel, but the second info message is never displayed and neither is the file modified on disk.What I don't understand is why it was working without the worker, and now it seems the rest of the command callback is just never called, despite the wasm function apparently succeeding, without any extension error message or anything in logs.
I am still a beginner in WASM, maybe it's just a stupid error but I really can't figure where to search at this point.