quarylabs / sqruff

Fast SQL formatter/linter
https://playground.quary.dev/?secondary=Format
Apache License 2.0
310 stars 13 forks source link

VS Code extension #366

Open benfdking opened 3 months ago

benfdking commented 3 months ago

We should be able to package the whole thing in WASI. I was looking at this guide: https://code.visualstudio.com/blogs/2024/06/07/wasm-part2

gvozdvmozgu commented 3 months ago

WASI needs an extension from here, but it only works with VS Code Insiders. I think I'll try using regular WASM instead

benfdking commented 3 months ago

We've got a setup working for quary itself. It's pretty fiddly but you should be able to copy the setup.

benfdking commented 3 months ago

Are probably the two main building blocks.

We essentially read wasm into a string because for web extensions you need to deploy it as a single js file that gets loaded and then you can call the functions.

Sorry, should have mentioned that this should really work as a VSCode web extension.

benfdking commented 3 months ago

I think there are a few things we should improve, but in the meantime, we should merge this:

Ignore this for authoritative list at the top.

benfdking commented 3 months ago

In deployed version when running on mac locally, getting the following error:

image

benfdking commented 3 months ago

Here's the extension by the way https://marketplace.visualstudio.com/items?itemName=Quary.sqruff

gvozdvmozgu commented 3 months ago

I can't find an API for file system access in the browser. I've checked extensions that work in the browser, and they seem limited to user-opened files. It looks like there isn't a file system API available.

benfdking commented 3 months ago

If you look at

https://github.com/quarylabs/quary/blob/main/js/packages/quary-extension/src/web/servicesRustWasm.ts https://github.com/quarylabs/quary/blob/main/rust/wasm-binding/src/rpc_proto_scaffolding.rs

we have created a "fileSystem" that is passed in through JS function calls? Do you think it would be possible to implement the same thing?

gvozdvmozgu commented 3 months ago

image I tried using vscode.workspace.fs, but I get this error (maybe because we are in a WebWorker?). I'll try to find a workaround again

gvozdvmozgu commented 3 months ago

It seems that it's possible to send a request from lsp-worker to browser.ts.

lsp-worker.ts:

async function load_file(path: string): Promise<string> {
    return await connection.sendRequest("load_file", path);
}

browser.ts:

 cl.onRequest("load_file", async (param: string) => {
     let contents = await vscode.workspace.fs.readFile(Uri.parse(param, true));
     return new TextDecoder().decode(contents);
  });

I am not sure if this is correct and if I fully understand the nature of the error above, but I will settle for this option.

benfdking commented 3 months ago

Nice work @gvozdvmozgu! I've copied the list of "tasks" at the top. Anything else you can think of?

gvozdvmozgu commented 3 months ago

Reading the config can cause a panic (for example, if the dialect is not supported). It would be great to have the ability to apply fixes individually, similar to quick fixes from rust-analyzer.