@@ -15,7 +15,7 @@ use vfs::{AbsPathBuf, ChangeKind, VfsPath};
15
15
use crate :: {
16
16
config:: Config ,
17
17
global_state:: GlobalState ,
18
- lsp:: { from_proto, utils:: apply_document_changes} ,
18
+ lsp:: { ext , from_proto, utils:: apply_document_changes} ,
19
19
lsp_ext:: RunFlycheckParams ,
20
20
mem_docs:: DocumentData ,
21
21
reload,
@@ -55,6 +55,7 @@ pub(crate) fn handle_did_open_text_document(
55
55
params : DidOpenTextDocumentParams ,
56
56
) -> anyhow:: Result < ( ) > {
57
57
let _p = profile:: span ( "handle_did_open_text_document" ) ;
58
+ tracing:: error!( "handle_did_open_text_document" ) ;
58
59
59
60
if let Ok ( path) = from_proto:: vfs_path ( & params. text_document . uri ) {
60
61
let already_exists = state
@@ -64,7 +65,14 @@ pub(crate) fn handle_did_open_text_document(
64
65
if already_exists {
65
66
tracing:: error!( "duplicate DidOpenTextDocument: {}" , path) ;
66
67
}
67
- state. vfs . write ( ) . 0 . set_file_contents ( path, Some ( params. text_document . text . into_bytes ( ) ) ) ;
68
+ {
69
+ let vfs = & mut state. vfs . write ( ) . 0 ;
70
+ vfs. set_file_contents ( path. clone ( ) , Some ( params. text_document . text . into_bytes ( ) ) ) ;
71
+ }
72
+
73
+ if state. config . notifications ( ) . unindexed_project {
74
+ run_unindexed_project ( state, params. text_document . uri )
75
+ }
68
76
}
69
77
Ok ( ( ) )
70
78
}
@@ -341,3 +349,24 @@ pub(crate) fn handle_run_flycheck(
341
349
}
342
350
Ok ( ( ) )
343
351
}
352
+
353
+ pub ( crate ) fn run_unindexed_project ( state : & mut GlobalState , uri : lsp_types:: Url ) {
354
+ let _p = profile:: span ( "run_unindexed_project" ) ;
355
+
356
+ if state. is_quiescent ( ) && state. process_changes ( ) {
357
+ let id = from_proto:: file_id ( & state. snapshot ( ) , & uri) . expect ( "Unable to get file ID" ) ;
358
+ if let Ok ( crates) = state. snapshot ( ) . analysis . crates_for ( id) {
359
+ if crates. is_empty ( ) {
360
+ tracing:: debug!( ?uri, "rust-analyzer does not track this file" ) ;
361
+ let text_documents = vec ! [ lsp_types:: TextDocumentIdentifier { uri: uri } ] ;
362
+ state. send_notification :: < ext:: UnindexedProject > ( ext:: UnindexedProjectParams {
363
+ text_documents,
364
+ } ) ;
365
+ } else {
366
+ tracing:: debug!( ?uri, "file is indexed by rust-analyzer" )
367
+ }
368
+ } else {
369
+ tracing:: warn!( "was unable to get analysis for crate" )
370
+ }
371
+ }
372
+ }
0 commit comments