@@ -12,6 +12,7 @@ use djls_project::Db as ProjectDb;
1212use djls_project:: Interpreter ;
1313use djls_workspace:: db:: SourceFile ;
1414use djls_workspace:: paths;
15+ use djls_workspace:: FileKind ;
1516use djls_workspace:: PositionEncoding ;
1617use djls_workspace:: TextDocument ;
1718use 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