1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
use std::collections::hash_map::Entry;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::env;
use std::io::ErrorKind;
use std::ops::Deref;
use std::path::Path;
use std::process::Stdio;
use std::sync::atomic::{AtomicI64, Ordering};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{bail, Context, Result};
use serde_json::{json, Value};
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::{Child, ChildStderr, ChildStdin, ChildStdout, Command};
use tokio::sync::mpsc::error::SendError;
use tokio::sync::{mpsc, Mutex, Notify};
use tokio::{select, task};
use tracing::{debug, error, field, info, instrument, trace, warn, Instrument};
use crate::client::Client;
use crate::config::Config;
use crate::lsp::ext::Tag;
use crate::lsp::jsonrpc::{Message, Notification, Request, RequestId, ResponseSuccess, Version};
use crate::lsp::transport::{LspReader, LspWriter};
use crate::lsp::{self, ext};
/// Specifies server configuration
///
/// If another server with the same configuration is requested we can reuse it.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct InstanceKey {
pub server: String,
pub args: Vec<String>,
pub env: BTreeMap<String, String>,
pub workspace_root: String,
}
/// Language server instance
pub struct Instance {
key: InstanceKey,
/// Language server child process id
pid: u32,
/// Server's response to `initialize` request
init_result: lsp::InitializeResult,
/// Handle for sending messages to the language server instance
server: mpsc::Sender<Message>,
/// Data of associated clients
clients: Mutex<HashMap<usize, ClientData>>,
/// Dynamic capabilities registered by the server
dynamic_capabilities: Mutex<HashMap<String, lsp::Registration>>,
/// Wakes up `wait_task` and asks it to send SIGKILL to the instance.
close: Notify,
/// Last time a message was sent to this instance
///
/// Uses UTC unix timestamp ([utc_now] function)
last_used: AtomicI64,
}
impl Drop for Instance {
fn drop(&mut self) {
// Make sure we're not leaking anything
debug!("instance dropped");
}
}
/// Wrapper around client handle with additional data only the server instance
/// knows about
struct ClientData {
/// Handle for sending messages to clients
client: Client,
/// URIs of files currently opened by this client
files: HashSet<String>,
}
impl ClientData {
fn get_status(&self) -> ext::Client {
ext::Client {
id: self.client.id(),
files: self.files.iter().cloned().collect(),
}
}
}
impl Deref for ClientData {
type Target = Client;
fn deref(&self) -> &Self::Target {
&self.client
}
}
// Current unix timestamp with second precission
fn utc_now() -> i64 {
time::OffsetDateTime::now_utc().unix_timestamp()
}
impl Instance {
/// Mark the instance as used
pub fn keep_alive(&self) {
self.last_used.store(utc_now(), Ordering::Relaxed);
}
/// How many seconds is the instance idle for
pub fn idle(&self) -> i64 {
i64::max(0, utc_now() - self.last_used.load(Ordering::Relaxed))
}
pub fn initialize_result(&self) -> lsp::InitializeResult {
self.init_result.clone()
}
/// Add client to the instance so it can receive traffic from it
///
/// It replays all registered dynamic capabilities to it.
pub async fn add_client(&self, client: Client) {
let mut clients = self.clients.lock().await;
let dyn_capabilities = self.dynamic_capabilities.lock().await;
if !dyn_capabilities.is_empty() {
// Register all currently cached dynamic capabilities if there are
// any. We will drop the client response and we need to make sure
// the request ID is unique.
let id = RequestId::String("replay:registerCapabilities".into()).tag(Tag::Drop);
let params = lsp::RegistrationParams {
registrations: dyn_capabilities.values().cloned().collect(),
};
let req = Request {
id,
method: "client/registerCapability".into(),
params: serde_json::to_value(params).unwrap(),
jsonrpc: Version,
};
debug!(?req, "replaying server request");
let _ = client.send_message(req.into()).await;
}
let client = ClientData {
client,
files: HashSet::new(),
};
if clients.insert(client.id(), client).is_some() {
unreachable!("BUG: added two clients with the same ID");
}
}
/// Send cleanup messages and remove remove client for client map
pub async fn cleanup_client(&self, client: Client) -> Result<()> {
debug!("cleaning up client");
let mut clients = self.clients.lock().await;
let Some(client) = clients.remove(&client.id()) else {
// TODO This happens for example when the language server died while
// client was still connected, and the client cleanup is attempted
// with the instance being gone already. We should try notifying
// these clients immediately and handling the cleanup separately.
bail!("client was not connected");
};
let files = client.files.into_iter().collect::<Vec<_>>();
self.close_all_files(&clients, files)
.await
.context("error closing files")?;
Ok(())
}
/// Send a message to the language server channel
pub async fn send_message(&self, message: Message) -> Result<(), SendError<Message>> {
self.server.send(message).await
}
/// Save registered capabilities to allow later replaying them to new clients
async fn register_capabilities(&self, params: Value) -> Result<()> {
let params =
serde_json::from_value::<lsp::RegistrationParams>(params).context("parsing params")?;
let mut dyn_capabilities = self.dynamic_capabilities.lock().await;
for reg in params.registrations {
dyn_capabilities.insert(reg.id.clone(), reg);
}
Ok(())
}
/// Remove cached capability registration to stop replaying them to new clients
async fn unregister_capabilities(&self, params: Value) -> Result<()> {
let params = serde_json::from_value::<lsp::UnregistrationParams>(params)
.context("parsing params")?;
let mut dyn_capabilities = self.dynamic_capabilities.lock().await;
for unreg in params.unregistrations {
dyn_capabilities.remove(&unreg.id);
}
Ok(())
}
/// Handle `textDocument/didOpen` client notification
pub async fn open_file(&self, client_id: usize, params: Value) -> Result<()> {
let params = serde_json::from_value::<lsp::DidOpenTextDocumentParams>(params)
.context("parsing params")?;
let uri = ¶ms.text_document.uri;
let mut send_notification = true;
let mut clients = self.clients.lock().await;
for client in clients.values() {
if client.files.contains(uri) {
debug!(?uri, "file is already opened by another client");
send_notification = false;
break;
}
}
clients
.get_mut(&client_id)
.expect("no matching client")
.files
.insert(uri.clone());
if send_notification {
let notif = Notification {
jsonrpc: Version,
method: "textDocument/didOpen".into(),
params: serde_json::to_value(params).unwrap(),
};
debug!(?notif, "first client opened file");
let _ = self.send_message(notif.into()).await;
}
Ok(())
}
/// Handle `textDocument/didClose` client notification
pub async fn close_file(&self, client_id: usize, params: Value) -> Result<()> {
let params = serde_json::from_value::<lsp::DidCloseTextDocumentParams>(params)
.context("parsing params")?;
let mut clients = self.clients.lock().await;
clients
.get_mut(&client_id)
.context("no matching client")?
.files
.remove(¶ms.text_document.uri);
self.close_all_files(&clients, vec![params.text_document.uri])
.await
}
/// Handle closing many files at once and sending notifications for
/// definitely closed files
async fn close_all_files(
&self,
clients: &HashMap<usize, ClientData>,
files: Vec<String>,
) -> Result<()> {
for uri in files {
let mut send_notification = true;
for client in clients.values() {
if client.files.contains(&uri) {
debug!(?uri, "file still opened by another client");
send_notification = false;
break;
}
}
if send_notification {
let params = lsp::DidCloseTextDocumentParams {
text_document: lsp::TextDocumentIdentifier { uri },
};
let notif = Notification {
jsonrpc: Version,
method: "textDocument/didClose".into(),
params: serde_json::to_value(params).unwrap(),
};
debug!(?notif, "last client closed file");
let _ = self.send_message(notif.into()).await;
}
}
Ok(())
}
async fn get_status(&self) -> ext::Instance {
let clients = self
.clients
.lock()
.await
.values()
.map(|client| client.get_status())
.collect();
let registered_dyn_capabilities = self
.dynamic_capabilities
.lock()
.await
.values()
.map(|reg| reg.method.clone())
.collect();
ext::Instance {
pid: self.pid,
server: self.key.server.clone(),
args: self.key.args.clone(),
env: self.key.env.clone(),
workspace_root: self.key.workspace_root.clone(),
last_used: self.last_used.load(Ordering::Relaxed),
clients,
registered_dyn_capabilities,
}
}
}
pub struct InstanceMap(HashMap<InstanceKey, Arc<Instance>>);
impl InstanceMap {
pub fn new(config: &Config) -> Arc<Mutex<Self>> {
let instance_map = Arc::new(Mutex::new(InstanceMap(HashMap::new())));
task::spawn(gc_task(
instance_map.clone(),
config.gc_interval,
config.instance_timeout,
));
instance_map
}
/// Finds an instance with the longest path such as
/// `cwd.starts_with(workspace_root)` is true
pub fn get_by_cwd(&self, cwd: &str) -> Option<&Instance> {
self.0
.iter()
.filter(|(key, _)| Path::new(cwd).starts_with(&key.workspace_root))
.max_by_key(|(key, _)| key.workspace_root.len())
.map(|(_, inst)| inst.deref())
}
pub async fn get_status(&self) -> ext::StatusResponse {
let mut instances = Vec::with_capacity(self.0.len());
for instance in self.0.values() {
instances.push(instance.get_status().await);
}
ext::StatusResponse { instances }
}
}
/// Periodically check for for idle language server instances
#[instrument("garbage collector", skip_all)]
async fn gc_task(
instance_map: Arc<Mutex<InstanceMap>>,
gc_interval: u32,
instance_timeout: Option<u32>,
) {
let mut interval = tokio::time::interval(Duration::from_secs(gc_interval.into()));
loop {
interval.tick().await;
for (key, instance) in &instance_map.lock().await.0 {
let clients = instance.clients.lock().await;
let idle = instance.idle();
debug!(path = ?key.workspace_root, idle, clients = clients.len(), "check instance");
if let Some(instance_timeout) = instance_timeout {
// Close timed out instance
if idle > i64::from(instance_timeout) && clients.is_empty() {
info!(pid = instance.pid, path = ?key.workspace_root, idle, "instance timed out");
instance.close.notify_one();
}
}
}
}
}
/// Find existing or spawn a new language server instance
///
/// The instance is looked up based on `instance_key`. If an existing one is
/// found then it's returned and `init_req_params` are discarded. If it's
/// not found a new instance is spawned and initialized using the provided
/// `init_req_params`, this insance is then inserted into the map and returned.
pub async fn get_or_spawn(
map: Arc<Mutex<InstanceMap>>,
key: InstanceKey,
init_req_params: lsp::InitializeParams,
) -> Result<Arc<Instance>> {
// We have locked a clone of an Arc of the map, we can assume noone else
// tries to spawn the same instance again. But we have to make sure `spawn`
// doesn't try to lock its copy as well. This is a bit unfortunate code
// organization but we want to have spawn in a separate tracing context and
// we want to include `wait_task` in it as well in it as well
match map.clone().lock().await.0.entry(key.clone()) {
Entry::Occupied(e) => {
info!("reusing language server instance");
Ok(e.get().clone())
}
Entry::Vacant(e) => {
let instance = spawn(key, init_req_params, map)
.await
.context("spawning instance")?;
e.insert(instance.clone());
Ok(instance)
}
}
}
#[instrument(name = "instance", fields(pid = field::Empty), skip_all, parent = None)]
async fn spawn(
key: InstanceKey,
init_req_params: lsp::InitializeParams,
// Caller `get_or_spawn` is holding a lock to the map, we must not try to
// lock it within this function to not cause deadlock, only spawned tasks
// are allowed to lock it again.
map: Arc<Mutex<InstanceMap>>,
) -> Result<Arc<Instance>> {
let mut child = Command::new(&key.server)
.args(&key.args)
.envs(&key.env)
.current_dir(&key.workspace_root)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.with_context(|| {
let InstanceKey {
server,
args,
env,
workspace_root,
} = &key;
let path = env
.get("PATH")
.map(<_>::to_owned)
// Display PATH from our environment Command will if none was
// passed from the client environment.
.or_else(|| env::var("PATH").ok())
.unwrap_or_default();
format!(
"spawning language server: server={server:?}, args={args:?}, \
cwd={workspace_root:?}, path={path:?}, env={env:?}",
)
})?;
let pid = child.id().context("child exited early, couldn't get PID")?;
tracing::Span::current().record("pid", pid);
info!(server = ?key.server, args = ?key.args, cwd = ?key.workspace_root, "spawned language server");
let stderr = child.stderr.take().unwrap();
task::spawn(stderr_task(stderr).in_current_span());
let stdout = child.stdout.take().unwrap();
let mut reader = LspReader::new(BufReader::new(stdout), "server");
let stdin = child.stdin.take().unwrap();
let mut writer = LspWriter::new(stdin, "server");
let init_result = initialize_handshake(init_req_params, &mut reader, &mut writer)
.await
.context("server handshake")?;
info!("initialized server");
let (message_writer, rx) = mpsc::channel(64);
let instance = Arc::new(Instance {
key,
pid,
init_result,
server: message_writer,
clients: Mutex::default(),
dynamic_capabilities: Mutex::default(),
close: Notify::new(),
last_used: AtomicI64::new(utc_now()),
});
task::spawn(stdout_task(instance.clone(), reader).in_current_span());
task::spawn(stdin_task(rx, writer).in_current_span());
task::spawn(wait_task(instance.clone(), map, child).in_current_span());
Ok(instance)
}
#[instrument(skip_all)]
async fn initialize_handshake(
init_req_params: lsp::InitializeParams,
reader: &mut LspReader<BufReader<ChildStdout>>,
writer: &mut LspWriter<ChildStdin>,
) -> Result<lsp::InitializeResult> {
let request_id = "lspmux:initialize_request";
// Use the first client's `InitializeParams` to initialize server. We assume
// all subsequent clients configuration will be somewhat compatible with
// whatever the first client negotiated for the same `workspace_root`,
// `server` and `args`.
let req = Request {
jsonrpc: Version,
method: "initialize".into(),
params: serde_json::to_value(init_req_params).unwrap(),
id: RequestId::String(request_id.into()),
};
writer
.write_message(&req.into())
.await
.context("send initialize request")?;
let res = match reader
.read_message()
.await
.context("receive initialize response")?
.context("stream ended")?
{
Message::ResponseSuccess(res) if res.id == request_id => res,
_ => bail!("first server message was not initialize response"),
};
let result = serde_json::from_value(res.result).context("parse initialize response result")?;
// Send a "fake" `initialized` notification to the server. We wait for them
// from each client's `initialized` notification ourselves and they don't
// contain any data that would need passing on.
let init_notif = Notification {
jsonrpc: Version,
method: "initialized".into(),
params: json!({}),
};
writer
.write_message(&init_notif.into())
.await
.context("send initialized notification")?;
Ok(result)
}
/// Read errors from language server stderr and log them
async fn stderr_task(stderr: ChildStderr) {
let mut stderr = BufReader::new(stderr);
let mut buffer = String::new();
loop {
buffer.clear();
match stderr.read_line(&mut buffer).await {
Ok(0) => {
// reached EOF
debug!("stderr closed");
break;
}
Ok(_) => {
let line = buffer.trim_end(); // remove trailing '\n' or possibly '\r\n'
error!(%line, "stderr");
}
Err(err) => {
let err = anyhow::Error::from(err);
error!(?err, "error reading from stderr");
}
}
}
}
/// Receive messages from clients' channel and write them into language server stdin
async fn stdin_task(mut receiver: mpsc::Receiver<Message>, mut writer: LspWriter<ChildStdin>) {
// Because we (stdin task) don't keep a reference to `self` it will be dropped when the
// child closes and all the clients disconnect including the sender and this receiver
// will not keep blocking (unlike in client input task)
while let Some(message) = receiver.recv().await {
if let Err(err) = writer.write_message(&message).await {
match err.kind() {
// stdin is closed, no need to log an error
ErrorKind::BrokenPipe => {}
_ => {
let err = anyhow::Error::from(err);
error!(?err, "error writing to stdin");
}
}
break;
}
}
debug!("stdin closed");
}
/// Wait for child and log when it exits
async fn wait_task(
instance: Arc<Instance>,
instance_map: Arc<Mutex<InstanceMap>>,
mut child: Child,
) {
let key = instance.key.clone();
loop {
select! {
_ = instance.close.notified() => {
if let Err(err) = child.start_kill() {
error!(?err, "failed to close child");
}
}
exit = child.wait() => {
// Remove the closing instance from the map so new clients spawn their own instance
instance_map.lock().await.0.remove(&key);
// Disconnect all current clients
//
// We'll rely on the editor client to restart the ra-multiplex client,
// start a new connection and we'll spawn another instance like we'd with
// any other new client.
instance.clients.lock().await.clear();
match exit {
Ok(status) => {
#[cfg(unix)]
let signal = std::os::unix::process::ExitStatusExt::signal(&status);
#[cfg(not(unix))]
let signal = tracing::field::Empty;
error!(
success = status.success(),
code = status.code(),
signal,
"child exited",
);
}
Err(err) => error!(?err, "error waiting for child"),
}
break;
}
}
}
}
/// Read messages from server stdout and send them to corresponding client channels
async fn stdout_task(instance: Arc<Instance>, mut reader: LspReader<BufReader<ChildStdout>>) {
loop {
let message = match reader.read_message().await {
Ok(Some(message)) => message,
Ok(None) => {
debug!("stdout closed");
break;
}
Err(err) => {
error!(?err, "reading message");
continue;
}
};
// Lock _after_ we have a message to send, then send and immediately release the lock
let clients = instance.clients.lock().await;
match message {
Message::ResponseSuccess(mut res) => {
// Forward successful response to the right client based on the
// Request ID tag.
match res.id.untag() {
(Some(Tag::ClientId(client_id)), id) => {
res.id = id;
if let Some(client) = clients.get(&client_id) {
let _ = client.send_message(res.into()).await;
} else {
debug!(?client_id, "no matching client");
}
}
(Some(Tag::Drop), _) => {
// Drop the message
}
_ => {
warn!(?res, "ignoring improperly tagged server response")
}
}
}
Message::ResponseError(mut res) => {
// Forward the error response to the right client based on the
// Request ID tag.
match res.id.untag() {
(Some(Tag::ClientId(client_id)), id) => {
warn!(?res, "server responded with error");
res.id = id;
if let Some(client) = clients.get(&client_id) {
let _ = client.send_message(res.into()).await;
} else {
debug!(?client_id, "no matching client");
}
}
(Some(Tag::Drop), _) => {
// Drop the message
}
_ => {
warn!(?res, "ignoring improperly tagged server response")
}
}
}
Message::Request(mut req)
if [
"window/workDoneProgress/create",
"workspace/codeLens/refresh",
"workspace/semanticTokens/refresh",
"workspace/inlayHint/refresh",
"workspace/inlineValue/refresh",
"workspace/diagnostic/refresh",
]
.contains(&req.method.as_str()) =>
{
// All these server requests have null responses and we need
// to inform all clients. We can forward the request to all
// clients, send a fake successful response and ignore the real
// client responses.
trace!(?req, "server request {}", req.method.as_str());
let id = req.id;
req.id = id.tag(Tag::Drop);
for client in clients.values() {
let _ = client.send_message(req.clone().into()).await;
}
let _ = instance
.send_message(ResponseSuccess::null(id).into())
.await;
}
Message::Request(mut req) if req.method == "workspace/configuration" => {
// Response to `workspace/configuration` should be the same from
// any client. So we'll just pick the first and let it answer.
debug!(?req, "server request workspace/configuration");
req.id = req.id.tag(Tag::Forward);
if let Some(client) = clients.values().next() {
let _ = client.send_message(req.into()).await;
} else {
// If there is no client connected at this moment we'll
// ignore the request.
}
}
Message::Request(mut req) if req.method == "client/registerCapability" => {
// These need to be forwarded to every client so they're aware
// of the capability. The response doesn't contain anything
// important so we can safely ignore the real answers and send a
// fake one to the server.
debug!(?req, "server request client/registerCapability");
let id = req.id;
req.id = id.tag(Tag::Drop);
for client in clients.values() {
let _ = client.send_message(req.clone().into()).await;
}
// We need to cache the dynamic capabilities registrations for
// any client that might come later.
if let Err(err) = instance.register_capabilities(req.params).await {
warn!(?err, "error registering capabilities");
}
let _ = instance
.send_message(ResponseSuccess::null(id).into())
.await;
}
Message::Request(mut req) if req.method == "client/unregisterCapability" => {
// These need to be forwarded to every client so they're aware
// of the capability not being available anymore. The response
// doesn't contain anything important so we can safely ignore
// the real answers and send a fake one to the server.
debug!(?req, "server request client/unregisterCapability");
let id = req.id;
req.id = id.tag(Tag::Drop);
for client in clients.values() {
let _ = client.send_message(req.clone().into()).await;
}
// We need to remove this registration from the cache so we
// don't announce it to new clients anymore.
if let Err(err) = instance.unregister_capabilities(req.params).await {
warn!(?err, "error unregistering capabilities");
}
let _ = instance
.send_message(ResponseSuccess::null(id).into())
.await;
}
Message::Request(req) => {
// Unimplemented server -> client requests I've found in the LSP Spec.
// TODO workspace/workspaceFolders request
// TODO workspace/applyEdit request
debug!(message = ?req, "ignoring unknown server request");
}
Message::Notification(notif) => {
// Server notifications don't expect a response. We can forward
// them to all clients.
for client in clients.values() {
let _ = client.send_message(notif.clone().into()).await;
}
}
}
}
}