|
|
@ -18,7 +18,7 @@ use parking_lot::Mutex;
|
|
|
|
use serde::Deserialize;
|
|
|
|
use serde::Deserialize;
|
|
|
|
use serde_json::Value;
|
|
|
|
use serde_json::Value;
|
|
|
|
use std::sync::{
|
|
|
|
use std::sync::{
|
|
|
|
atomic::{AtomicU64, Ordering},
|
|
|
|
atomic::{self, AtomicBool, AtomicU64, Ordering},
|
|
|
|
Arc,
|
|
|
|
Arc,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use std::{collections::HashMap, path::PathBuf};
|
|
|
|
use std::{collections::HashMap, path::PathBuf};
|
|
|
@ -60,6 +60,7 @@ pub struct Client {
|
|
|
|
initialize_notify: Arc<Notify>,
|
|
|
|
initialize_notify: Arc<Notify>,
|
|
|
|
/// workspace folders added while the server is still initializing
|
|
|
|
/// workspace folders added while the server is still initializing
|
|
|
|
req_timeout: u64,
|
|
|
|
req_timeout: u64,
|
|
|
|
|
|
|
|
supports_publish_diagnostic: AtomicBool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Client {
|
|
|
|
impl Client {
|
|
|
@ -147,6 +148,17 @@ impl Client {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_publish_diagnostic(&self, val: bool) {
|
|
|
|
|
|
|
|
self.supports_publish_diagnostic
|
|
|
|
|
|
|
|
.fetch_or(val, atomic::Ordering::Relaxed);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Whether the server supports Publish Diagnostic
|
|
|
|
|
|
|
|
pub fn publish_diagnostic(&self) -> bool {
|
|
|
|
|
|
|
|
self.supports_publish_diagnostic
|
|
|
|
|
|
|
|
.load(atomic::Ordering::Relaxed)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn add_workspace_folder(
|
|
|
|
fn add_workspace_folder(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
root_uri: Option<lsp::Url>,
|
|
|
|
root_uri: Option<lsp::Url>,
|
|
|
@ -232,6 +244,7 @@ impl Client {
|
|
|
|
root_uri,
|
|
|
|
root_uri,
|
|
|
|
workspace_folders: Mutex::new(workspace_folders),
|
|
|
|
workspace_folders: Mutex::new(workspace_folders),
|
|
|
|
initialize_notify: initialize_notify.clone(),
|
|
|
|
initialize_notify: initialize_notify.clone(),
|
|
|
|
|
|
|
|
supports_publish_diagnostic: AtomicBool::new(false),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Ok((client, server_rx, initialize_notify))
|
|
|
|
Ok((client, server_rx, initialize_notify))
|
|
|
@ -346,6 +359,7 @@ impl Client {
|
|
|
|
Some(OneOf::Left(true) | OneOf::Right(_))
|
|
|
|
Some(OneOf::Left(true) | OneOf::Right(_))
|
|
|
|
),
|
|
|
|
),
|
|
|
|
LanguageServerFeature::Diagnostics => true, // there's no extra server capability
|
|
|
|
LanguageServerFeature::Diagnostics => true, // there's no extra server capability
|
|
|
|
|
|
|
|
LanguageServerFeature::PullDiagnostics => capabilities.diagnostic_provider.is_some(),
|
|
|
|
LanguageServerFeature::RenameSymbol => matches!(
|
|
|
|
LanguageServerFeature::RenameSymbol => matches!(
|
|
|
|
capabilities.rename_provider,
|
|
|
|
capabilities.rename_provider,
|
|
|
|
Some(OneOf::Left(true)) | Some(OneOf::Right(_))
|
|
|
|
Some(OneOf::Left(true)) | Some(OneOf::Right(_))
|
|
|
@ -648,6 +662,10 @@ impl Client {
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
diagnostic: Some(lsp::DiagnosticClientCapabilities {
|
|
|
|
|
|
|
|
dynamic_registration: Some(false),
|
|
|
|
|
|
|
|
related_document_support: Some(true),
|
|
|
|
|
|
|
|
}),
|
|
|
|
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
|
|
|
|
publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities {
|
|
|
|
version_support: Some(true),
|
|
|
|
version_support: Some(true),
|
|
|
|
tag_support: Some(lsp::TagSupport {
|
|
|
|
tag_support: Some(lsp::TagSupport {
|
|
|
@ -1224,6 +1242,32 @@ impl Client {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn text_document_diagnostic(
|
|
|
|
|
|
|
|
&self,
|
|
|
|
|
|
|
|
text_document: lsp::TextDocumentIdentifier,
|
|
|
|
|
|
|
|
previous_result_id: Option<String>,
|
|
|
|
|
|
|
|
) -> Option<impl Future<Output = Result<Value>>> {
|
|
|
|
|
|
|
|
let capabilities = self.capabilities.get().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return early if the server does not support pull diagnostic.
|
|
|
|
|
|
|
|
let identifier = match capabilities.diagnostic_provider.as_ref()? {
|
|
|
|
|
|
|
|
lsp::DiagnosticServerCapabilities::Options(cap) => cap.identifier.clone(),
|
|
|
|
|
|
|
|
lsp::DiagnosticServerCapabilities::RegistrationOptions(cap) => {
|
|
|
|
|
|
|
|
cap.diagnostic_options.identifier.clone()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let params = lsp::DocumentDiagnosticParams {
|
|
|
|
|
|
|
|
text_document,
|
|
|
|
|
|
|
|
identifier,
|
|
|
|
|
|
|
|
previous_result_id,
|
|
|
|
|
|
|
|
work_done_progress_params: lsp::WorkDoneProgressParams::default(),
|
|
|
|
|
|
|
|
partial_result_params: lsp::PartialResultParams::default(),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Some(self.call::<lsp::request::DocumentDiagnosticRequest>(params))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn text_document_document_highlight(
|
|
|
|
pub fn text_document_document_highlight(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
text_document: lsp::TextDocumentIdentifier,
|
|
|
|
text_document: lsp::TextDocumentIdentifier,
|
|
|
|