Skip to content

Commit

Permalink
refactor(server): refactor sending requests
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored Jan 30, 2025
1 parent 256e0cc commit ad22239
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 8 additions & 1 deletion crates/server/src/sent.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::message::Message;
use rustc_hash::FxHashMap;
use serde_json::Value;

#[derive(Debug, Default)]
pub struct SentRequests<T> {
Expand All @@ -8,7 +9,13 @@ pub struct SentRequests<T> {
}

impl<T> SentRequests<T> {
pub fn add(&mut self, method: String, params: serde_json::Value, data: T) -> Message {
pub fn add(&mut self, method: String, params: Value) -> Message {
let id = self.id;
self.id += 1;
Message::Request { id, method, params }
}

pub fn add_with_data(&mut self, method: String, params: Value, data: T) -> Message {
let id = self.id;
self.data.insert(id, data);
self.id += 1;
Expand Down
6 changes: 2 additions & 4 deletions crates/server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ impl Server {
stdio::write(self.sent_requests.add(
RegisterCapability::METHOD.into(),
serde_json::to_value(self.service.dynamic_capabilities())?,
vec![],
))
.await?;

Expand Down Expand Up @@ -418,7 +417,6 @@ impl Server {
stdio::write(self.sent_requests.add(
WorkspaceDiagnosticRefresh::METHOD.into(),
serde_json::Value::Null,
vec![],
))
.await?;
}
Expand All @@ -436,7 +434,7 @@ impl Server {
self.publish_diagnostics(uri.clone()).await?;
}
if self.support_pull_config {
stdio::write(self.sent_requests.add(
stdio::write(self.sent_requests.add_with_data(
WorkspaceConfiguration::METHOD.into(),
serde_json::to_value(ConfigurationParams {
items: vec![ConfigurationItem {
Expand Down Expand Up @@ -476,7 +474,7 @@ impl Server {
.map(|(uri, _)| uri)
.collect::<Vec<_>>();
stdio::write(
self.sent_requests.add(
self.sent_requests.add_with_data(
WorkspaceConfiguration::METHOD.into(),
serde_json::to_value(ConfigurationParams {
items: uris
Expand Down

0 comments on commit ad22239

Please sign in to comment.