Skip to content

Moved LSP main loop to use tokio.#11036

Draft
anlumo wants to merge 2 commits intomasterfrom
anlumo/lsp-tokio
Draft

Moved LSP main loop to use tokio.#11036
anlumo wants to merge 2 commits intomasterfrom
anlumo/lsp-tokio

Conversation

@anlumo
Copy link
Contributor

@anlumo anlumo commented Mar 18, 2026

Not yet tested.

@anlumo anlumo requested review from LeonMatthes and ogoffart March 18, 2026 15:03
@anlumo anlumo self-assigned this Mar 18, 2026
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
clap = { workspace = true }
crossbeam-channel = "0.5" # must match the version used by lsp-server
crossbeam-channel = "0.5" # must match the version used by lsp-server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this dependency?


let preview_to_lsp_channel = self.preview_to_lsp_channel.clone();

let communication_handle = std::thread::spawn(move || -> Result<(), String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we no longer need a thread for this? (but we don't need to change this in this PR)

let connection = Arc::new(connection);
let (from_lsp_sender, mut from_lsp_receiver) = tokio::sync::mpsc::unbounded_channel();
let inner_connection = connection.clone();
std::thread::spawn(move || {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit curious about the live time of this thread.
Should we not try to join it on exit?

match msg? {
tokio::select! {
msg = from_lsp_receiver.recv() => {
match msg.ok_or_else(|| "LSP connection closed".to_owned())? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that always an error or can it be part of the normal shutdown as well?
I just want to be sure that we don't send spurious error message to the user when we exit normally.

recv(recompile_timeout) -> _ => {
{
let ctx = ctx.clone();
let msg = _msg.ok_or_else(|| "Preview to LSP connection closed".to_owned())?;
Copy link
Member

@ogoffart ogoffart Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment: I hope we don't treat normally closing the preview as an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants