@@ -6,6 +6,7 @@ use djls_project::Db as ProjectDb;
66use djls_semantic:: Db as SemanticDb ;
77use djls_source:: FileKind ;
88use djls_workspace:: paths;
9+ use djls_workspace:: LanguageId ;
910use tokio:: sync:: Mutex ;
1011use tower_lsp_server:: jsonrpc:: Result as LspResult ;
1112use tower_lsp_server:: lsp_types;
@@ -179,19 +180,12 @@ impl LanguageServer for DjangoLanguageServer {
179180 tracing:: info!( "Server received initialized notification." ) ;
180181
181182 self . with_session_task ( move |session_arc| async move {
182- let session_lock = session_arc. lock ( ) . await ;
183+ let session = session_arc. lock ( ) . await ;
183184
184- let project_path = session_lock
185- . project ( )
186- . map ( |p| p. root ( session_lock. database ( ) ) . clone ( ) ) ;
187-
188- if let Some ( path) = project_path {
185+ if let Some ( project) = session. project ( ) {
186+ let path = project. root ( session. database ( ) ) . clone ( ) ;
189187 tracing:: info!( "Task: Starting initialization for project at: {}" , path) ;
190-
191- if let Some ( project) = session_lock. project ( ) {
192- project. initialize ( session_lock. database ( ) ) ;
193- }
194-
188+ project. initialize ( session. database ( ) ) ;
195189 tracing:: info!( "Task: Successfully initialized project: {}" , path) ;
196190 } else {
197191 tracing:: info!( "Task: No project configured, skipping initialization." ) ;
@@ -211,21 +205,16 @@ impl LanguageServer for DjangoLanguageServer {
211205
212206 let url_version = self
213207 . with_session_mut ( |session| {
214- let Some ( url) =
215- paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidOpen )
216- else {
217- return None ; // Error parsing uri (unlikely), skip processing this document
218- } ;
219-
220- let language_id =
221- djls_workspace:: LanguageId :: from ( params. text_document . language_id . as_str ( ) ) ;
208+ let url =
209+ paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidOpen ) ?;
222210 let document = djls_workspace:: TextDocument :: new (
223211 params. text_document . text . clone ( ) ,
224212 params. text_document . version ,
225- language_id,
213+ LanguageId :: from ( params . text_document . language_id . as_str ( ) ) ,
226214 ) ;
227215
228216 session. open_document ( & url, document) ;
217+
229218 Some ( ( url, params. text_document . version ) )
230219 } )
231220 . await ;
@@ -242,11 +231,7 @@ impl LanguageServer for DjangoLanguageServer {
242231 . with_session_mut ( |session| {
243232 let url =
244233 paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidSave ) ?;
245-
246- session. save_document ( & url) ;
247-
248- // Get current version from document buffer
249- let version = session. get_document ( & url) . map ( |doc| doc. version ( ) ) ;
234+ let version = session. save_document ( & url) . map ( |doc| doc. version ( ) ) ;
250235 Some ( ( url, version) )
251236 } )
252237 . await ;
@@ -260,12 +245,8 @@ impl LanguageServer for DjangoLanguageServer {
260245 tracing:: info!( "Changed document: {:?}" , params. text_document. uri) ;
261246
262247 self . with_session_mut ( |session| {
263- let Some ( url) =
264- paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidChange )
265- else {
266- return None ; // Error parsing uri (unlikely), skip processing this change
267- } ;
268-
248+ let url =
249+ paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidChange ) ?;
269250 session. update_document ( & url, params. content_changes , params. text_document . version ) ;
270251 Some ( url)
271252 } )
@@ -277,12 +258,8 @@ impl LanguageServer for DjangoLanguageServer {
277258
278259 let url = self
279260 . with_session_mut ( |session| {
280- let Some ( url) =
281- paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidClose )
282- else {
283- return None ; // Error parsing uri (unlikely), skip processing this close
284- } ;
285-
261+ let url =
262+ paths:: parse_lsp_uri ( & params. text_document . uri , paths:: LspContext :: DidClose ) ?;
286263 if session. close_document ( & url) . is_none ( ) {
287264 tracing:: warn!( "Attempted to close document without overlay: {}" , url) ;
288265 }
@@ -435,10 +412,10 @@ impl LanguageServer for DjangoLanguageServer {
435412 tracing:: info!( "Configuration change detected. Reloading settings..." ) ;
436413
437414 self . with_session_mut ( |session| {
438- if let Some ( project ) = session. project ( ) {
439- let project_root = project . root ( session. database ( ) ) ;
415+ if session. project ( ) . is_some ( ) {
416+ let project_root = session. database ( ) . project_root_or_cwd ( ) ;
440417
441- match djls_conf:: Settings :: new ( project_root) {
418+ match djls_conf:: Settings :: new ( & project_root) {
442419 Ok ( new_settings) => {
443420 session. set_settings ( new_settings) ;
444421 }
0 commit comments