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
use gen_lsp_types::*;
use super::document;
use crate::{Client, Protocol, Result};
fn whole_document(text: String) -> TextDocumentContentChangeEvent {
TextDocumentContentChangeWholeDocument { text }.into()
}
fn change(
uri: &Uri,
version: i32,
content_changes: Vec<TextDocumentContentChangeEvent>,
) -> DidChangeTextDocumentParams {
DidChangeTextDocumentParams {
text_document: VersionedTextDocumentIdentifier {
version,
text_document_identifier: document(uri),
},
content_changes,
}
}
impl Client {
pub fn did_open(
&mut self,
uri: Uri,
text: impl Into<String>,
language: LanguageKind,
) -> Result<()> {
let version = self.next_open_version(&uri);
self.protocol_did_open(DidOpenTextDocumentParams {
text_document: TextDocumentItem {
uri,
language_id: language,
version,
text: text.into(),
},
})
}
pub fn did_change_full(&mut self, uri: &Uri, text: impl Into<String>) -> Result<()> {
let (version, _) = self.next_document_version_and_text(uri)?;
self.protocol_did_change(change(uri, version, vec![whole_document(text.into())]))
}
/// Sends edits as incremental or whole-document changes.
pub fn did_change(&mut self, uri: &Uri, edits: &[TextEdit]) -> Result<()> {
if edits.is_empty() {
self.require_open_document(uri)?;
return Ok(());
}
let (version, text) = self.next_document_version_and_text(uri)?;
let content_changes = self.content_changes(text, edits)?;
self.protocol_did_change(change(uri, version, content_changes))
}
pub fn did_close(&mut self, uri: &Uri) -> Result<()> {
self.protocol_did_close(DidCloseTextDocumentParams {
text_document: document(uri),
})
}
pub fn document_text(&self, uri: &Uri) -> Option<&str> {
self.tracked_text(uri).ok()
}
/// Sends [`textDocument/willSave`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_willSave).
///
/// Use [`Protocol::protocol_will_save`] for full params.
pub fn will_save(&mut self, uri: &Uri, reason: TextDocumentSaveReason) -> Result<()> {
self.protocol_will_save(WillSaveTextDocumentParams {
text_document: document(uri),
reason,
})
}
/// Sends [`textDocument/willSaveWaitUntil`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_willSaveWaitUntil).
///
/// Use [`Protocol::protocol_will_save_wait_until`] for full params.
pub fn will_save_wait_until(
&mut self,
uri: &Uri,
reason: TextDocumentSaveReason,
) -> Result<Option<Vec<TextEdit>>> {
self.protocol_will_save_wait_until(WillSaveTextDocumentParams {
text_document: document(uri),
reason,
})
}
/// Sends [`textDocument/didSave`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_didSave).
///
/// Use [`Protocol::protocol_did_save`] for full params.
pub fn did_save(&mut self, uri: &Uri) -> Result<()> {
let text = self
.supports_save_text()
.then(|| self.tracked_text(uri).map(str::to_owned))
.transpose()?;
self.protocol_did_save(DidSaveTextDocumentParams {
text_document: document(uri),
text,
})
}
/// Sends [`notebookDocument/didOpen`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#notebookDocument_didOpen).
///
/// Use [`Protocol::protocol_notebook_document_did_open`] for full params.
pub fn notebook_document_did_open(
&mut self,
params: DidOpenNotebookDocumentParams,
) -> Result<()> {
self.protocol_notebook_document_did_open(params)
}
/// Sends [`notebookDocument/didChange`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#notebookDocument_didChange).
///
/// Use [`Protocol::protocol_notebook_document_did_change`] for full params.
pub fn notebook_document_did_change(
&mut self,
params: DidChangeNotebookDocumentParams,
) -> Result<()> {
self.protocol_notebook_document_did_change(params)
}
/// Sends [`notebookDocument/didSave`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#notebookDocument_didSave).
///
/// Use [`Protocol::protocol_notebook_document_did_save`] for full params.
pub fn notebook_document_did_save(
&mut self,
params: DidSaveNotebookDocumentParams,
) -> Result<()> {
self.protocol_notebook_document_did_save(params)
}
/// Sends [`notebookDocument/didClose`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#notebookDocument_didClose).
///
/// Use [`Protocol::protocol_notebook_document_did_close`] for full params.
pub fn notebook_document_did_close(
&mut self,
params: DidCloseNotebookDocumentParams,
) -> Result<()> {
self.protocol_notebook_document_did_close(params)
}
}