Support dynamic formatting capabilities [un]registration (#14478)
Closes https://github.com/zed-industries/zed/issues/12661 Release Notes: - Added dynamic [un]registration for LSP formatting capabilities ([#12661](https://github.com/zed-industries/zed/issues/12661))
This commit is contained in:
parent
684d9dde56
commit
977a1b7a82
3 changed files with 167 additions and 38 deletions
|
@ -7,7 +7,7 @@ use anyhow::{anyhow, Context, Result};
|
|||
use collections::HashMap;
|
||||
use futures::{channel::oneshot, io::BufWriter, select, AsyncRead, AsyncWrite, Future, FutureExt};
|
||||
use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Task};
|
||||
use parking_lot::Mutex;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use postage::{barrier, prelude::Stream};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use serde_json::{json, value::RawValue, Value};
|
||||
|
@ -24,6 +24,7 @@ use std::{
|
|||
ffi::OsString,
|
||||
fmt,
|
||||
io::Write,
|
||||
ops::DerefMut,
|
||||
path::PathBuf,
|
||||
pin::Pin,
|
||||
sync::{
|
||||
|
@ -69,7 +70,7 @@ pub struct LanguageServer {
|
|||
next_id: AtomicI32,
|
||||
outbound_tx: channel::Sender<String>,
|
||||
name: Arc<str>,
|
||||
capabilities: ServerCapabilities,
|
||||
capabilities: RwLock<ServerCapabilities>,
|
||||
code_action_kinds: Option<Vec<CodeActionKind>>,
|
||||
notification_handlers: Arc<Mutex<HashMap<&'static str, NotificationHandler>>>,
|
||||
response_handlers: Arc<Mutex<Option<HashMap<RequestId, ResponseHandler>>>>,
|
||||
|
@ -640,10 +641,13 @@ impl LanguageServer {
|
|||
..Default::default()
|
||||
}),
|
||||
formatting: Some(DynamicRegistrationClientCapabilities {
|
||||
dynamic_registration: None,
|
||||
dynamic_registration: Some(true),
|
||||
}),
|
||||
range_formatting: Some(DynamicRegistrationClientCapabilities {
|
||||
dynamic_registration: Some(true),
|
||||
}),
|
||||
on_type_formatting: Some(DynamicRegistrationClientCapabilities {
|
||||
dynamic_registration: None,
|
||||
dynamic_registration: Some(true),
|
||||
}),
|
||||
signature_help: Some(SignatureHelpClientCapabilities {
|
||||
signature_information: Some(SignatureInformationSettings {
|
||||
|
@ -693,7 +697,7 @@ impl LanguageServer {
|
|||
if let Some(info) = response.server_info {
|
||||
self.name = info.name.into();
|
||||
}
|
||||
self.capabilities = response.capabilities;
|
||||
self.capabilities = RwLock::new(response.capabilities);
|
||||
|
||||
self.notify::<notification::Initialized>(InitializedParams {})?;
|
||||
Ok(Arc::new(self))
|
||||
|
@ -908,8 +912,12 @@ impl LanguageServer {
|
|||
}
|
||||
|
||||
/// Get the reported capabilities of the running language server.
|
||||
pub fn capabilities(&self) -> &ServerCapabilities {
|
||||
&self.capabilities
|
||||
pub fn capabilities(&self) -> ServerCapabilities {
|
||||
self.capabilities.read().clone()
|
||||
}
|
||||
|
||||
pub fn update_capabilities(&self, update: impl FnOnce(&mut ServerCapabilities)) {
|
||||
update(self.capabilities.write().deref_mut());
|
||||
}
|
||||
|
||||
/// Get the id of the running language server.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue