Skip to content

Commit 9e6974d

Browse files
implement textDocument/didSave (#196)
1 parent 554bbe2 commit 9e6974d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

crates/djls-server/src/server.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ impl LanguageServer for DjangoLanguageServer {
208208
.await;
209209
}
210210

211+
async fn did_save(&self, params: lsp_types::DidSaveTextDocumentParams) {
212+
tracing::info!("Saved document: {:?}", params.text_document.uri);
213+
214+
self.with_session_mut(|session| {
215+
let Some(url) =
216+
paths::parse_lsp_uri(&params.text_document.uri, paths::LspContext::DidSave)
217+
else {
218+
return;
219+
};
220+
221+
session.save_document(&url);
222+
})
223+
.await;
224+
}
225+
211226
async fn did_change(&self, params: lsp_types::DidChangeTextDocumentParams) {
212227
tracing::info!("Changed document: {:?}", params.text_document.uri);
213228

crates/djls-server/src/session.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ impl Session {
172172
}
173173
}
174174

175+
pub fn save_document(&mut self, url: &Url) {
176+
// Touch file in database to trigger re-analysis
177+
if let Some(path) = paths::url_to_path(url) {
178+
self.with_db_mut(|db| {
179+
if db.has_file(&path) {
180+
db.touch_file(&path);
181+
}
182+
});
183+
}
184+
}
185+
175186
/// Close a document.
176187
///
177188
/// Removes from workspace buffers and triggers database invalidation to fall back to disk.

crates/djls-workspace/src/paths.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub enum LspContext {
4242
DidChange,
4343
/// textDocument/didClose notification
4444
DidClose,
45+
/// textDocument/didSave notification
46+
DidSave,
4547
/// textDocument/completion request
4648
Completion,
4749
}
@@ -52,6 +54,7 @@ impl std::fmt::Display for LspContext {
5254
Self::DidOpen => write!(f, "didOpen"),
5355
Self::DidChange => write!(f, "didChange"),
5456
Self::DidClose => write!(f, "didClose"),
57+
Self::DidSave => write!(f, "didSave"),
5558
Self::Completion => write!(f, "completion"),
5659
}
5760
}

0 commit comments

Comments
 (0)