Skip to content

Commit 873180c

Browse files
wip
1 parent 3145342 commit 873180c

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

crates/djls-server/src/server.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,23 @@ impl LanguageServer for DjangoLanguageServer {
287287
async fn did_change(&self, params: lsp_types::DidChangeTextDocumentParams) {
288288
tracing::info!("Changed document: {:?}", params.text_document.uri);
289289

290-
self.with_session_mut(|session| {
290+
let url_version = self.with_session_mut(|session| {
291291
let Some(url) =
292292
paths::parse_lsp_uri(&params.text_document.uri, paths::LspContext::DidChange)
293293
else {
294294
return None; // Error parsing uri (unlikely), skip processing this change
295295
};
296296

297297
session.update_document(&url, params.content_changes, params.text_document.version);
298-
Some(url)
298+
Some((url, params.text_document.version))
299299
})
300300
.await;
301+
302+
// Publish diagnostics after document change
303+
// (analysis already happened in session.update_document)
304+
if let Some((url, version)) = url_version {
305+
self.publish_diagnostics(&url, Some(version)).await;
306+
}
301307
}
302308

303309
async fn did_close(&self, params: lsp_types::DidCloseTextDocumentParams) {

crates/djls-server/src/session.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use djls_project::Db as ProjectDb;
1212
use djls_project::Interpreter;
1313
use djls_workspace::db::SourceFile;
1414
use djls_workspace::paths;
15+
use djls_workspace::FileKind;
1516
use djls_workspace::PositionEncoding;
1617
use djls_workspace::TextDocument;
1718
use djls_workspace::Workspace;
@@ -163,12 +164,18 @@ impl Session {
163164
if let Some(path) = paths::url_to_path(url) {
164165
// Check if file already exists (was previously read from disk)
165166
let already_exists = self.db.has_file(&path);
166-
let _file = self.db.get_or_create_file(&path);
167+
let file = self.db.get_or_create_file(&path);
167168

168169
if already_exists {
169170
// File was already read - touch to invalidate cache
170171
self.db.touch_file(&path);
171172
}
173+
174+
// Trigger template analysis immediately for template files
175+
// This accumulates diagnostics right away
176+
if FileKind::from_path(&path) == FileKind::Template {
177+
let _ = djls_templates::analyze_template(&self.db, file);
178+
}
172179
}
173180
}
174181

@@ -189,18 +196,32 @@ impl Session {
189196
if let Some(path) = paths::url_to_path(url) {
190197
if self.db.has_file(&path) {
191198
self.db.touch_file(&path);
199+
200+
// Trigger template analysis immediately for template files
201+
// This accumulates diagnostics right away
202+
if FileKind::from_path(&path) == FileKind::Template {
203+
if let Some(file) = self.db.get_file(&path) {
204+
let _ = djls_templates::analyze_template(&self.db, file);
205+
}
206+
}
192207
}
193208
}
194209
}
195210

196211
pub fn save_document(&mut self, url: &Url) {
197212
// Touch file in database to trigger re-analysis
198213
if let Some(path) = paths::url_to_path(url) {
199-
self.with_db_mut(|db| {
200-
if db.has_file(&path) {
201-
db.touch_file(&path);
214+
if self.db.has_file(&path) {
215+
self.db.touch_file(&path);
216+
217+
// Trigger template analysis immediately for template files
218+
// This accumulates diagnostics right away
219+
if FileKind::from_path(&path) == FileKind::Template {
220+
if let Some(file) = self.db.get_file(&path) {
221+
let _ = djls_templates::analyze_template(&self.db, file);
222+
}
202223
}
203-
});
224+
}
204225
}
205226
}
206227

0 commit comments

Comments
 (0)