Skip to content

Commit f64661e

Browse files
move initializer to ClientFlags
1 parent 5742e63 commit f64661e

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed
Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
1+
use lsp_types::InitializeParams;
2+
13
/// Contains information about the client's capabilities.
24
/// This is used to determine which features the server can use.
35
#[derive(Debug, Clone)]
46
pub struct ClientFlags {
5-
/// If `true`, the server can pull the configuration from the client.
6-
pub configuration_pull: bool,
7+
/// If `true`, the server can pull configuration from the client.
8+
pub has_configuration: bool,
9+
10+
/// If `true`, the client notifies the server when its configuration changes.
11+
pub will_push_configuration: bool,
12+
}
13+
14+
impl ClientFlags {
15+
pub(crate) fn from_initialize_request_params(params: &InitializeParams) -> Self {
16+
let has_configuration = params
17+
.capabilities
18+
.workspace
19+
.as_ref()
20+
.and_then(|w| w.configuration)
21+
.unwrap_or(false);
22+
23+
let will_push_configuration = params
24+
.capabilities
25+
.workspace
26+
.as_ref()
27+
.and_then(|w| w.did_change_configuration)
28+
.and_then(|c| c.dynamic_registration)
29+
.unwrap_or(false);
730

8-
/// If `true`, the client notifies the server when the configuration changes.
9-
pub configuration_push: bool,
31+
Self {
32+
has_configuration,
33+
will_push_configuration,
34+
}
35+
}
1036
}

crates/pg_lsp/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use pg_lsp::server::Server;
44
#[tokio::main]
55
async fn main() -> anyhow::Result<()> {
66
let (connection, threads) = Connection::stdio();
7-
let server = Server::init(connection)?;
87

8+
let server = Server::init(connection)?;
99
server.run().await?;
1010
threads.join()?;
1111

crates/pg_lsp/src/server.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl Server {
127127

128128
connection.initialize_finish(id, serde_json::to_value(result)?)?;
129129

130-
let client_flags = Arc::new(from_proto::client_flags(params.capabilities));
130+
let client_flags = Arc::new(ClientFlags::from_initialize_request_params(&params));
131131

132132
let pool = Arc::new(threadpool::Builder::new().build());
133133

@@ -200,7 +200,7 @@ impl Server {
200200

201201
self.compute_debouncer.clear();
202202

203-
self.pool.execute(move || {
203+
tokio::spawn(async move {
204204
client
205205
.send_notification::<ShowMessage>(ShowMessageParams {
206206
typ: lsp_types::MessageType::INFO,
@@ -778,7 +778,7 @@ impl Server {
778778
&mut self,
779779
params: DidChangeConfigurationParams,
780780
) -> anyhow::Result<()> {
781-
if self.client_flags.configuration_pull {
781+
if self.client_flags.has_configuration {
782782
self.pull_options();
783783
} else {
784784
let options = self.client.parse_options(params.settings)?;
@@ -869,7 +869,7 @@ impl Server {
869869
}
870870

871871
fn pull_options(&mut self) {
872-
if !self.client_flags.configuration_pull {
872+
if !self.client_flags.has_configuration {
873873
return;
874874
}
875875

@@ -899,7 +899,7 @@ impl Server {
899899
}
900900

901901
fn register_configuration(&mut self) {
902-
if self.client_flags.configuration_push {
902+
if self.client_flags.will_push_configuration {
903903
let registration = Registration {
904904
id: "pull-config".to_string(),
905905
method: DidChangeConfiguration::METHOD.to_string(),

crates/pg_lsp/src/utils/from_proto.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::client::client_flags::ClientFlags;
2-
31
use super::line_index_ext::LineIndexExt;
42
use pg_base_db::{Change, Document};
53

@@ -17,23 +15,3 @@ pub fn content_changes(
1715
})
1816
.collect()
1917
}
20-
21-
pub fn client_flags(capabilities: lsp_types::ClientCapabilities) -> ClientFlags {
22-
let configuration_pull = capabilities
23-
.workspace
24-
.as_ref()
25-
.and_then(|cap| cap.configuration)
26-
.unwrap_or(false);
27-
28-
let configuration_push = capabilities
29-
.workspace
30-
.as_ref()
31-
.and_then(|cap| cap.did_change_configuration)
32-
.and_then(|cap| cap.dynamic_registration)
33-
.unwrap_or(false);
34-
35-
ClientFlags {
36-
configuration_pull,
37-
configuration_push,
38-
}
39-
}

0 commit comments

Comments
 (0)