lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

[Feature Request] Browser based support

Open tommitytom opened this issue 3 years ago • 17 comments

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

tommitytom avatar Nov 11 '22 13:11 tommitytom

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

sumneko avatar Nov 11 '22 13:11 sumneko

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.

sumneko avatar Nov 12 '22 12:11 sumneko

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.

carsakiller avatar Nov 13 '22 17:11 carsakiller

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 avatar Nov 13 '22 23:11 tommitytom

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

tommitytom avatar Nov 13 '22 23:11 tommitytom

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 🙂.

carsakiller avatar Nov 14 '22 03:11 carsakiller

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

tommitytom avatar Nov 14 '22 04:11 tommitytom

Here are the problems that need to be solved:

  • [ ] Need to access fengari
  • [ ] fengari only supports Lua 5.3, however this server is using Lua 5.4
    • [ ] to-be-closed variable https://github.com/sumneko/lua-language-server/blob/946e0c7a5f60e116739c2e0e09b1cdfbe02500e1/script/provider/provider.lua#L384
    • [ ] coroutine.close
  • [ ] Need to implement the following functions
    • [ ] bee.filesystem: Can implement by file system API
    • [ ] bee.platform: Do some special treatment for Windows
    • [ ] bee.subprocess: Get process ID, not important, can be removed
    • [ ] bee.filewatch: Can be replaced by API of LSP
    • [ ] bee.time: Used for timer and log
    • [ ] bee.thread: Create sub-thread. Used for load protocol from stdin, sleep and wakeup main thread per second.
  • [ ] fengari dose not support __gc
    Not important, only used for counting cached files.
  • [ ] fengari dose not support weak table, important.

sumneko avatar Nov 14 '22 07:11 sumneko

maybe compile all C++ code to webassembly

CppCXY avatar Nov 14 '22 09:11 CppCXY

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.

tommitytom avatar Nov 15 '22 01:11 tommitytom

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.

notpeter avatar Nov 16 '22 14:11 notpeter

Would be very useful for embedding this in Monaco too

JSH32 avatar Feb 02 '23 02:02 JSH32

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

JSH32 avatar Sep 14 '23 16:09 JSH32

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.

jbromberg avatar Dec 28 '23 17:12 jbromberg

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.

ceifa avatar Dec 28 '23 17:12 ceifa

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?

JSH32 avatar Dec 28 '23 17:12 JSH32

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.

jbromberg avatar Dec 28 '23 17:12 jbromberg