@@ -183,7 +183,8 @@ pub(crate) fn highlight(
183
183
traverse (
184
184
& mut hl,
185
185
& sema,
186
- InFile :: new ( file_id. into ( ) , & root) ,
186
+ file_id,
187
+ & root,
187
188
sema. scope ( & root) . krate ( ) ,
188
189
range_to_highlight,
189
190
syntactic_name_ref_highlighting,
@@ -194,11 +195,13 @@ pub(crate) fn highlight(
194
195
fn traverse (
195
196
hl : & mut Highlights ,
196
197
sema : & Semantics < RootDatabase > ,
197
- root : InFile < & SyntaxNode > ,
198
+ file_id : FileId ,
199
+ root : & SyntaxNode ,
198
200
krate : Option < hir:: Crate > ,
199
201
range_to_highlight : TextRange ,
200
202
syntactic_name_ref_highlighting : bool ,
201
203
) {
204
+ let is_unlinked = sema. to_module_def ( file_id) . is_none ( ) ;
202
205
let mut bindings_shadow_count: FxHashMap < Name , u32 > = FxHashMap :: default ( ) ;
203
206
204
207
let mut current_macro_call: Option < ast:: MacroCall > = None ;
@@ -209,7 +212,7 @@ fn traverse(
209
212
210
213
// Walk all nodes, keeping track of whether we are inside a macro or not.
211
214
// If in macro, expand it first and highlight the expanded code.
212
- for event in root. value . preorder_with_tokens ( ) {
215
+ for event in root. preorder_with_tokens ( ) {
213
216
let range = match & event {
214
217
WalkEvent :: Enter ( it) | WalkEvent :: Leave ( it) => it. text_range ( ) ,
215
218
} ;
@@ -283,7 +286,7 @@ fn traverse(
283
286
WalkEvent :: Enter ( it) => it,
284
287
WalkEvent :: Leave ( NodeOrToken :: Token ( _) ) => continue ,
285
288
WalkEvent :: Leave ( NodeOrToken :: Node ( node) ) => {
286
- inject:: doc_comment ( hl, sema, root . with_value ( & node) ) ;
289
+ inject:: doc_comment ( hl, sema, InFile :: new ( file_id . into ( ) , & node) ) ;
287
290
continue ;
288
291
}
289
292
} ;
@@ -378,6 +381,11 @@ fn traverse(
378
381
NodeOrToken :: Token ( token) => highlight:: token ( sema, token) . zip ( Some ( None ) ) ,
379
382
} ;
380
383
if let Some ( ( mut highlight, binding_hash) ) = element {
384
+ if is_unlinked && highlight. tag == HlTag :: UnresolvedReference {
385
+ // do not emit unresolved references if the file is unlinked
386
+ // let the editor do its highlighting for these tokens instead
387
+ continue ;
388
+ }
381
389
if inside_attribute {
382
390
highlight |= HlMod :: Attribute
383
391
}
0 commit comments