-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlsp_interactor.rs
More file actions
75 lines (64 loc) · 2.28 KB
/
lsp_interactor.rs
File metadata and controls
75 lines (64 loc) · 2.28 KB
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
use tower_lsp::{
jsonrpc::Result,
lsp_types::{Diagnostic, MessageType, Position, Range},
};
use super::{InMemoryDocumentDatabase, LSPClient};
pub struct LspInteractor<C> {
client: C,
document_database: InMemoryDocumentDatabase,
}
impl<C> LspInteractor<C> {
pub fn new(client: C, document_database: InMemoryDocumentDatabase) -> Self {
Self {
client,
document_database,
}
}
}
impl<C> LspInteractor<C>
where
C: LSPClient,
{
pub async fn update_document_with_text(&self, uri: &str, text: &str) {
self.document_database.write_document_text(uri, text).await;
self.document_database.remove_diagnostics(uri).await;
self.document_database.remove_documentations(uri).await;
let _ = self.publish_all_diagnostics().await;
}
pub async fn show_message(&self, message_type: MessageType, message: &str) {
self.client.show_message(message_type, message).await;
}
pub async fn publish_all_diagnostics(&self) -> Result<()> {
let all_diagnostics = self.document_database.all_diagnostics().await;
for (url, diagnostics) in all_diagnostics {
self.client
.publish_diagnostics(&url, diagnostics, None)
.await;
}
Ok(())
}
pub async fn read_document_text(&self, uri: &str) -> Option<String> {
self.document_database.read_document_text(uri).await
}
pub async fn remove_diagnostics(&self, uri: &str) {
self.document_database.remove_diagnostics(uri).await
}
pub async fn append_document_diagnostics(&self, uri: &str, diagnostics: &[Diagnostic]) {
self.document_database
.append_document_diagnostics(uri, diagnostics)
.await
}
pub async fn append_documentation(&self, uri: &str, range: Range, documentation: String) {
self.document_database
.append_documentation(uri, range, documentation)
.await
}
pub async fn read_documentation_at(&self, uri: &str, position: Position) -> Option<String> {
self.document_database
.read_documentation_at(uri, position)
.await
}
pub async fn remove_documentations(&self, uri: &str) {
self.document_database.remove_documentations(uri).await
}
}