lsp: Add support for workspace/workspaceFolders request (#17639)

Related to: #17574

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-09-10 14:41:02 +02:00 committed by GitHub
parent 56bc3c36ad
commit 75256bdfe1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,7 +40,7 @@ use lsp::{
CompletionContext, DiagnosticSeverity, DiagnosticTag, DidChangeWatchedFilesRegistrationOptions,
Edit, FileSystemWatcher, InsertTextFormat, LanguageServer, LanguageServerBinary,
LanguageServerId, LspRequestFuture, MessageActionItem, MessageType, OneOf, ServerHealthStatus,
ServerStatus, SymbolKind, TextEdit, WorkDoneProgressCancelParams,
ServerStatus, SymbolKind, TextEdit, Url, WorkDoneProgressCancelParams, WorkspaceFolder,
};
use parking_lot::{Mutex, RwLock};
use postage::watch;
@ -4774,6 +4774,30 @@ impl LspStore {
})
.detach();
let id = language_server.server_id();
language_server
.on_request::<lsp::request::WorkspaceFoldersRequest, _, _>({
let this = this.clone();
move |_, mut cx| {
let this = this.clone();
async move {
let Some(server) =
this.update(&mut cx, |this, _| this.language_server_for_id(id))?
else {
return Ok(None);
};
let root = server.root_path();
let Ok(uri) = Url::from_file_path(&root) else {
return Ok(None);
};
Ok(Some(vec![WorkspaceFolder {
uri,
name: Default::default(),
}]))
}
}
})
.detach();
// Even though we don't have handling for these requests, respond to them to
// avoid stalling any language server like `gopls` which waits for a response
// to these requests when initializing.