LSP server timing out

I've stripped as much code as possible to see where the root issue lies, and it turns out it's this self.compile_project asynchronous method.

async fn did_open(&self, params: DidOpenTextDocumentParams) {
    // File path
    let path = params.text_document.uri.to_file_path().unwrap().canonicalize().unwrap();

    // Only process AS3/MXML/CSS files
    if !FlexPath::new_native(&path.to_str().unwrap()).has_extensions(["as", "mxml", "css"]) {
        return;
    }

    // Initial directory
    let dir = path.parent().unwrap().to_owned();

    eprintln!("Here 1");

    // Compile project if needed
    let result = self.compile_project(
        &dir,
        /* content_change_callback */
        || {
            // Contribute initial content
            self.opened_file_content.borrow_mut().insert(path.clone(), params.text_document.text);
        },
        /* no need to recompile */
        false,
        /* cancel compilation? */
        async |_| false
    ).await;

    eprintln!("Here 2");
}

When I run my extension I get:

[Error - 7:19:48 AM] Stopping server failed
Error: Stopping the server timed out
	at c:\Users\Hydro\Repository Groups\Whack\vscode-extension\node_modules\vscode-languageclient\lib\common\client.js:983:23
[Error - 7:19:48 AM] Stopping server failed
Error: Stopping the server timed out
	at c:\Users\Hydro\Repository Groups\Whack\vscode-extension\node_modules\vscode-languageclient\lib\common\client.js:983:23
[Error - 7:19:48 AM] Stopping server failed
Error: Stopping the server timed out
	at c:\Users\Hydro\Repository Groups\Whack\vscode-extension\node_modules\vscode-languageclient\lib\common\client.js:983:23
[Error - 7:19:51 AM] Server process exited with code 1.

If I remove the above compile_project() call the server prints Here fine.

I've put an issue at tower-lsp's repository but not sure if the maintainer is that active...

I think you will want to block the did_open handler on compiling the project. Rather spawn a background task to compile the project and then return from the did_open handler to let the editor know that you processed the did_open and for example recorded the current content of the file in your VFS.

1 Like

Is it possible to spawn a background task in the same thread though, since my compilation results are !Send + !Sync?

TBH I think I can do something different. Maybe I can spawn a background task in another thread and keep the compilation results private to that thread, and to solve IDE hovers for instance I can send a message to the thread? Not sure, might work.