Add a language server support in stlite #1328
Replies: 2 comments 1 reply
-
Hi @bdimitrijoski, thank you!
So, yes, I'm looking forward to it! |
Beta Was this translation helpful? Give feedback.
-
Thank you so much @bdimitrijoski for the amazing contributions for this feature! |
Beta Was this translation helpful? Give feedback.
-
Hi there,
First off, big kudos for creating stlite! Your work is truly impressive. It provides a rock-solid and flexible foundation for running Streamlit apps directly in the browser.
At Cognite, we've been using a fork of this repo to inject authentication token, configure startup settings, and implement a language server on top of the existing kernel. The users on our platform can create and run Streamlit apps seamlessly.
To enhance the user experience, especially in dev mode, we've integrated the Monaco code editor. It communicates with stlite via postMessage to offer language server features like autocomplete and hover support.
We're hoping to move away from our fork and contribute our language server logic to the upstream repo, if that’s alright with you. 😊
I’ll outline the potential solution below, and if it looks good to you, I'd be happy to start working on a draft PR (only autocomplete part first, later we can add other features like hover support).
Modify the Kernel and Worker to load the libraries needed for the language server
To be able to provide a language server features, we used a third party package (jedi).
Jedi is a static analysis tool for Python that is already used in few IDEs/editors plugins, but it is also lightweight.
To load and use it in stlite, we’ll need to do some orchestration. This involves loading the Jedi wheel file and registering it in the kernel.
And modify the
worker-runtime
to inject the jedi wheelCreate new MessageIn and MessageOut types for autocomplete
Modify the kernel and worker to listen for the new events
Add the event listener in the worker-runtime
Add the method in the Kernel
From this point, you can utilize the language server and extend it with features like hover, validation, and more. You can then connect it to a UI such as a code editor.
I’m more than happy to help integrate it with the Monaco code editor in stlite. However, I’ll need to review the code and get familiar with where changes need to be made.
Beta Was this translation helpful? Give feedback.
All reactions