@@ -13,7 +13,6 @@ use tower_lsp_server::lsp_types::DidOpenTextDocumentParams;
1313use tower_lsp_server:: lsp_types:: InitializeParams ;
1414use tower_lsp_server:: lsp_types:: InitializeResult ;
1515use tower_lsp_server:: lsp_types:: InitializedParams ;
16- use tower_lsp_server:: lsp_types:: MessageType ;
1716use tower_lsp_server:: lsp_types:: OneOf ;
1817use tower_lsp_server:: lsp_types:: SaveOptions ;
1918use tower_lsp_server:: lsp_types:: ServerCapabilities ;
@@ -25,7 +24,8 @@ use tower_lsp_server::lsp_types::WorkspaceFoldersServerCapabilities;
2524use tower_lsp_server:: lsp_types:: WorkspaceServerCapabilities ;
2625use tower_lsp_server:: LanguageServer ;
2726
28- use crate :: client;
27+ use crate :: log_error;
28+ use crate :: log_info;
2929use crate :: queue:: Queue ;
3030use crate :: session:: Session ;
3131
@@ -55,10 +55,7 @@ impl DjangoLanguageServer {
5555 if let Some ( s) = & * session {
5656 f ( s)
5757 } else {
58- client:: log_message (
59- MessageType :: ERROR ,
60- "Attempted to access session before initialization" ,
61- ) ;
58+ log_error ! ( "Attempted to access session before initialization" ) ;
6259 R :: default ( )
6360 }
6461 }
@@ -72,10 +69,7 @@ impl DjangoLanguageServer {
7269 if let Some ( s) = & mut * session {
7370 f ( s)
7471 } else {
75- client:: log_message (
76- MessageType :: ERROR ,
77- "Attempted to access session before initialization" ,
78- ) ;
72+ log_error ! ( "Attempted to access session before initialization" ) ;
7973 R :: default ( )
8074 }
8175 }
@@ -88,16 +82,16 @@ impl DjangoLanguageServer {
8882 let session_arc = Arc :: clone ( & self . session ) ;
8983
9084 if let Err ( e) = self . queue . submit ( async move { f ( session_arc) . await } ) . await {
91- client :: log_message ( MessageType :: ERROR , format ! ( "Failed to submit task: {e}" ) ) ;
85+ log_error ! ( "Failed to submit task: {}" , e ) ;
9286 } else {
93- client :: log_message ( MessageType :: INFO , "Task submitted successfully" ) ;
87+ log_info ! ( "Task submitted successfully" ) ;
9488 }
9589 }
9690}
9791
9892impl LanguageServer for DjangoLanguageServer {
9993 async fn initialize ( & self , params : InitializeParams ) -> LspResult < InitializeResult > {
100- client :: log_message ( MessageType :: INFO , "Initializing server..." ) ;
94+ log_info ! ( "Initializing server..." ) ;
10195
10296 let session = Session :: new ( & params) ;
10397
@@ -145,10 +139,7 @@ impl LanguageServer for DjangoLanguageServer {
145139
146140 #[ allow( clippy:: too_many_lines) ]
147141 async fn initialized ( & self , _params : InitializedParams ) {
148- client:: log_message (
149- MessageType :: INFO ,
150- "Server received initialized notification." ,
151- ) ;
142+ log_info ! ( "Server received initialized notification." ) ;
152143
153144 self . with_session_task ( |session_arc| async move {
154145 let project_path_and_venv = {
@@ -168,16 +159,13 @@ impl LanguageServer for DjangoLanguageServer {
168159 } ;
169160
170161 if let Some ( ( path_display, venv_path) ) = project_path_and_venv {
171- client :: log_message (
172- MessageType :: INFO ,
173- format ! ( "Task: Starting initialization for project at: { path_display}" ) ,
162+ log_info ! (
163+ "Task: Starting initialization for project at: {}" ,
164+ path_display
174165 ) ;
175166
176167 if let Some ( ref path) = venv_path {
177- client:: log_message (
178- MessageType :: INFO ,
179- format ! ( "Using virtual environment from config: {path}" ) ,
180- ) ;
168+ log_info ! ( "Using virtual environment from config: {}" , path) ;
181169 }
182170
183171 let init_result = {
@@ -197,17 +185,13 @@ impl LanguageServer for DjangoLanguageServer {
197185
198186 match init_result {
199187 Ok ( ( ) ) => {
200- client:: log_message (
201- MessageType :: INFO ,
202- format ! ( "Task: Successfully initialized project: {path_display}" ) ,
203- ) ;
188+ log_info ! ( "Task: Successfully initialized project: {}" , path_display) ;
204189 }
205190 Err ( e) => {
206- client:: log_message (
207- MessageType :: ERROR ,
208- format ! (
209- "Task: Failed to initialize Django project at {path_display}: {e}"
210- ) ,
191+ log_error ! (
192+ "Task: Failed to initialize Django project at {}: {}" ,
193+ path_display,
194+ e
211195 ) ;
212196
213197 // Clear project on error
@@ -218,10 +202,7 @@ impl LanguageServer for DjangoLanguageServer {
218202 }
219203 }
220204 } else {
221- client:: log_message (
222- MessageType :: INFO ,
223- "Task: No project instance found to initialize." ,
224- ) ;
205+ log_info ! ( "Task: No project instance found to initialize." ) ;
225206 }
226207 Ok ( ( ) )
227208 } )
@@ -233,10 +214,7 @@ impl LanguageServer for DjangoLanguageServer {
233214 }
234215
235216 async fn did_open ( & self , params : DidOpenTextDocumentParams ) {
236- client:: log_message (
237- MessageType :: INFO ,
238- format ! ( "Opened document: {:?}" , params. text_document. uri) ,
239- ) ;
217+ log_info ! ( "Opened document: {:?}" , params. text_document. uri) ;
240218
241219 self . with_session_mut ( |session| {
242220 let db = session. db ( ) ;
@@ -246,10 +224,7 @@ impl LanguageServer for DjangoLanguageServer {
246224 }
247225
248226 async fn did_change ( & self , params : DidChangeTextDocumentParams ) {
249- client:: log_message (
250- MessageType :: INFO ,
251- format ! ( "Changed document: {:?}" , params. text_document. uri) ,
252- ) ;
227+ log_info ! ( "Changed document: {:?}" , params. text_document. uri) ;
253228
254229 self . with_session_mut ( |session| {
255230 let db = session. db ( ) ;
@@ -259,10 +234,7 @@ impl LanguageServer for DjangoLanguageServer {
259234 }
260235
261236 async fn did_close ( & self , params : DidCloseTextDocumentParams ) {
262- client:: log_message (
263- MessageType :: INFO ,
264- format ! ( "Closed document: {:?}" , params. text_document. uri) ,
265- ) ;
237+ log_info ! ( "Closed document: {:?}" , params. text_document. uri) ;
266238
267239 self . with_session_mut ( |session| {
268240 session. documents_mut ( ) . handle_did_close ( & params) ;
@@ -290,10 +262,7 @@ impl LanguageServer for DjangoLanguageServer {
290262 }
291263
292264 async fn did_change_configuration ( & self , _params : DidChangeConfigurationParams ) {
293- client:: log_message (
294- MessageType :: INFO ,
295- "Configuration change detected. Reloading settings..." ,
296- ) ;
265+ log_info ! ( "Configuration change detected. Reloading settings..." ) ;
297266
298267 let project_path = self
299268 . with_session ( |session| session. project ( ) . map ( |p| p. path ( ) . to_path_buf ( ) ) )
@@ -305,7 +274,7 @@ impl LanguageServer for DjangoLanguageServer {
305274 session. set_settings ( new_settings) ;
306275 }
307276 Err ( e) => {
308- client :: log_message ( MessageType :: ERROR , format ! ( "Error loading settings: {e}" ) ) ;
277+ log_error ! ( "Error loading settings: {}" , e ) ;
309278 }
310279 } )
311280 . await ;
0 commit comments