This commit is contained in:
Josh Thomas 2025-09-14 18:21:19 -05:00
parent 3145342d70
commit 873180cd80
2 changed files with 34 additions and 7 deletions

View file

@ -287,7 +287,7 @@ impl LanguageServer for DjangoLanguageServer {
async fn did_change(&self, params: lsp_types::DidChangeTextDocumentParams) {
tracing::info!("Changed document: {:?}", params.text_document.uri);
self.with_session_mut(|session| {
let url_version = self.with_session_mut(|session| {
let Some(url) =
paths::parse_lsp_uri(&params.text_document.uri, paths::LspContext::DidChange)
else {
@ -295,9 +295,15 @@ impl LanguageServer for DjangoLanguageServer {
};
session.update_document(&url, params.content_changes, params.text_document.version);
Some(url)
Some((url, params.text_document.version))
})
.await;
// Publish diagnostics after document change
// (analysis already happened in session.update_document)
if let Some((url, version)) = url_version {
self.publish_diagnostics(&url, Some(version)).await;
}
}
async fn did_close(&self, params: lsp_types::DidCloseTextDocumentParams) {

View file

@ -12,6 +12,7 @@ use djls_project::Db as ProjectDb;
use djls_project::Interpreter;
use djls_workspace::db::SourceFile;
use djls_workspace::paths;
use djls_workspace::FileKind;
use djls_workspace::PositionEncoding;
use djls_workspace::TextDocument;
use djls_workspace::Workspace;
@ -163,12 +164,18 @@ impl Session {
if let Some(path) = paths::url_to_path(url) {
// Check if file already exists (was previously read from disk)
let already_exists = self.db.has_file(&path);
let _file = self.db.get_or_create_file(&path);
let file = self.db.get_or_create_file(&path);
if already_exists {
// File was already read - touch to invalidate cache
self.db.touch_file(&path);
}
// Trigger template analysis immediately for template files
// This accumulates diagnostics right away
if FileKind::from_path(&path) == FileKind::Template {
let _ = djls_templates::analyze_template(&self.db, file);
}
}
}
@ -189,6 +196,14 @@ impl Session {
if let Some(path) = paths::url_to_path(url) {
if self.db.has_file(&path) {
self.db.touch_file(&path);
// Trigger template analysis immediately for template files
// This accumulates diagnostics right away
if FileKind::from_path(&path) == FileKind::Template {
if let Some(file) = self.db.get_file(&path) {
let _ = djls_templates::analyze_template(&self.db, file);
}
}
}
}
}
@ -196,11 +211,17 @@ impl Session {
pub fn save_document(&mut self, url: &Url) {
// Touch file in database to trigger re-analysis
if let Some(path) = paths::url_to_path(url) {
self.with_db_mut(|db| {
if db.has_file(&path) {
db.touch_file(&path);
if self.db.has_file(&path) {
self.db.touch_file(&path);
// Trigger template analysis immediately for template files
// This accumulates diagnostics right away
if FileKind::from_path(&path) == FileKind::Template {
if let Some(file) = self.db.get_file(&path) {
let _ = djls_templates::analyze_template(&self.db, file);
}
}
});
}
}
}