@@ -10,7 +10,7 @@ use ide_db::{
1010} ;
1111use syntax:: {
1212 ast:: { self , edit:: IndentLevel , HasModuleItem , HasName } ,
13- AstNode , TextRange , TextSize ,
13+ AstNode , TextRange ,
1414} ;
1515use text_edit:: TextEdit ;
1616
@@ -27,14 +27,28 @@ pub(crate) fn unlinked_file(
2727) {
2828 // Limit diagnostic to the first few characters in the file. This matches how VS Code
2929 // renders it with the full span, but on other editors, and is less invasive.
30+ let fixes = fixes ( ctx, file_id) ;
31+ // FIXME: This is a hack for the vscode extension to notice whether there is an autofix or not before having to resolve diagnostics.
32+ // This is to prevent project linking popups from appearing when there is an autofix. https://github.com/rust-lang/rust-analyzer/issues/14523
33+ let message = if fixes. is_none ( ) {
34+ "file not included in crate hierarchy"
35+ } else {
36+ "file not included in module tree"
37+ } ;
38+
3039 let range = ctx. sema . db . parse ( file_id) . syntax_node ( ) . text_range ( ) ;
31- // FIXME: This is wrong if one of the first three characters is not ascii: `//Ы`.
32- let range = range. intersect ( TextRange :: up_to ( TextSize :: of ( "..." ) ) ) . unwrap_or ( range) ;
40+ let range = FileLoader :: file_text ( ctx. sema . db , file_id)
41+ . char_indices ( )
42+ . take ( 3 )
43+ . last ( )
44+ . map ( |( i, _) | i)
45+ . map ( |i| TextRange :: up_to ( i. try_into ( ) . unwrap ( ) ) )
46+ . unwrap_or ( range) ;
3347
3448 acc. push (
35- Diagnostic :: new ( "unlinked-file" , "file not included in module tree" , range)
49+ Diagnostic :: new ( "unlinked-file" , message , range)
3650 . severity ( Severity :: WeakWarning )
37- . with_fixes ( fixes ( ctx , file_id ) ) ,
51+ . with_fixes ( fixes) ,
3852 ) ;
3953}
4054
0 commit comments