LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.26k stars 306 forks source link

[Feature Request] Browser based support #1689

Open tommitytom opened 1 year ago

tommitytom commented 1 year ago

Is there any plan to add support for the browser based version of vscode (eg https://vscode.dev)?

sumneko commented 1 year ago

Interesting, I will do some research in the few days.

sumneko commented 1 year ago

I did some research, unfortunately it was not supported.

  1. The server is running in the browser, so only JS can be used as the server language. But this server is developed using Lua and cannot run in the browser.
  2. File system cannot be used, but most Lua projects need to analyze the files in the entire workspace to provide correct intelligent.
carsakiller commented 1 year ago

It looks like we could have access to local files using the file system API. The web extension article claims we will, at least.

The biggest problem is of course trying to get the server (Lua) to run in the browser. It may be possible to run the server in the browser using Fengari but it would likely be a lot of work for a not-so-great user experience, I would think.

tommitytom commented 1 year ago

As @carsakiller mentions it is possible to access the file system from the browser, but it's only possible in chromium based browsers right now. You can test this out by going to https://vscode.dev/ and clicking "open folder" to see what the user experience is like. However it is also possible to go direct to a repository, (for example by going to https://github.dev/sumneko/lua-language-server, or you can press . on any repo or pull request to switch to vscode).

As far as running lua in the browser, that's not too hard at all! Where there is fengari, you can also just compile lua to wasm which runs at near native speed in the browser. It's also pretty simple to do, I use it for some projects. I'm happy to help with this!

tommitytom commented 1 year ago

Also, I realise I should probably have added this issue to the https://github.com/sumneko/vscode-lua repo, apologies!

carsakiller commented 1 year ago

You can test this out by going to https://vscode.dev/ and clicking "open folder" to see what the user experience is like

My experience is "Firefox is not supported" 😛

About 80% of browsers use a Chromium browser, but that does leave 20% of people out of luck when it comes to opening folders in their browser 😕. That's assuming that the average user of VS Code is also the average browser user and that user-agent tracking is at all accurate. It is likely that the split is very different in actuality for vscode.dev as its users are developers and more "techy" people.

That being said, it can certainly be useful for editing a repo (assuming SSH and PGP is still supported) and if it is actually possible and not unreasonably difficult to pull off, it could be a nice touch for the language server to run entirely in the browser 🙂.

tommitytom commented 1 year ago

It's also worth mentioning that the Monaco editor itself can be embedded on any website, which as far as I'm aware has support for communicating with language servers. Could make for some interesting live coding tools with great intellisense!

In any case, I'll take a look at this if getting the dev env setup isn't too time consuming

sumneko commented 1 year ago

Here are the problems that need to be solved:

CppCXY commented 1 year ago

maybe compile all C++ code to webassembly

tommitytom commented 1 year ago

I had a look yesterday, and it doesn't make sense to use fengari - the runtime from bee.lua could be compiled direct to WASM negating the need for an external JS lua wrapper. That should remove a few things from the above list.

notpeter commented 1 year ago

Wanted to put https://github.com/ceifa/wasmoon on your radar. It's a real Lua 5.4 VM with JS bindings made with webassembly.

JSH32 commented 1 year ago

Would be very useful for embedding this in Monaco too

JSH32 commented 1 year ago

Was thinking, can we run this all in WASM? Have a C++/Rust binding which runs the embedded lua VM with WASI and setup filesystem to point to a virtual one?

Or a more realistic approach. We use https://webcontainers.io/ with something like https://github.com/arnoson/monaco-lua-example/tree/main to run everything in a tiny linux WASM env

jbromberg commented 8 months ago

Looking into this as it would greatly simplify my project as opposed to running a server. I think compiling and running the server to WASM via web workers could get it done.

ceifa commented 8 months ago

Wanted to put https://github.com/ceifa/wasmoon on your radar. It's a real Lua 5.4 VM with JS bindings made with webassembly.

Creator of wasmoon here. Let me know if I can help you guys on this.

JSH32 commented 8 months ago

I tried doing this a while ago and the problems were mostly the native modules/cpp code in the repo. Might need a few advances or to port to WASIX maybe?

jbromberg commented 8 months ago

Taking a closer look at wasmoon, what would stop us from just running the language server inside of wasmoon?

Edit: I see what you mean now @JSH32. I mistakenly thought this was 100% lua but i see there are some other native modules being used.