lua-language-server
lua-language-server copied to clipboard
[Feature Request] Browser based support
Is there any plan to add support for the browser based version of vscode (eg https://vscode.dev)?
Interesting, I will do some research in the few days.
I did some research, unfortunately it was not supported.
- 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.
- File system cannot be used, but most Lua projects need to analyze the files in the entire workspace to provide correct intelligent.
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.
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!
Also, I realise I should probably have added this issue to the https://github.com/sumneko/vscode-lua repo, apologies!
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 🙂.
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
Here are the problems that need to be solved:
- [ ] Need to access fengari
- [ ]
fengarionly 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.
- [ ]
- [ ]
fengaridose not support__gc
Not important, only used for counting cached files. - [ ]
fengaridose not support weak table, important.
maybe compile all C++ code to webassembly
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.
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.
Would be very useful for embedding this in Monaco too
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
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.
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.
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?
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.