Skip to content

Commit e6cd085

Browse files
authored
Merge pull request #20506 from Veykril/veykril/push-xlytslrrylzq
Fix panic in syntax_highlighting
2 parents 14872a5 + 0914f78 commit e6cd085

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

crates/ide/src/syntax_highlighting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,10 @@ fn traverse(
452452
}
453453
hl
454454
}
455-
NodeOrToken::Token(token) => {
455+
NodeOrToken::Token(token) => salsa::attach(sema.db, || {
456456
highlight::token(sema, token, edition, &is_unsafe_node, tt_level > 0)
457457
.zip(Some(None))
458-
}
458+
}),
459459
};
460460
if let Some((mut highlight, binding_hash)) = element {
461461
if is_unlinked && highlight.tag == HlTag::UnresolvedReference {

crates/ide/src/syntax_highlighting/inject.rs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::mem;
55
use either::Either;
66
use hir::{EditionedFileId, HirFileId, InFile, Semantics, sym};
77
use ide_db::{
8-
SymbolKind, active_parameter::ActiveParameter, defs::Definition,
8+
SymbolKind, active_parameter::ActiveParameter, base_db::salsa, defs::Definition,
99
documentation::docs_with_rangemap, rust_doc::is_rust_fence,
1010
};
1111
use syntax::{
@@ -126,32 +126,34 @@ pub(super) fn doc_comment(
126126

127127
// Extract intra-doc links and emit highlights for them.
128128
if let Some((docs, doc_mapping)) = docs_with_rangemap(sema.db, &attributes) {
129-
extract_definitions_from_docs(&docs)
130-
.into_iter()
131-
.filter_map(|(range, link, ns)| {
132-
doc_mapping
133-
.map(range)
134-
.filter(|(mapping, _)| mapping.file_id == src_file_id)
135-
.and_then(|(InFile { value: mapped_range, .. }, attr_id)| {
136-
Some(mapped_range).zip(resolve_doc_path_for_def(
137-
sema.db,
138-
def,
139-
&link,
140-
ns,
141-
attr_id.is_inner_attr(),
142-
))
129+
salsa::attach(sema.db, || {
130+
extract_definitions_from_docs(&docs)
131+
.into_iter()
132+
.filter_map(|(range, link, ns)| {
133+
doc_mapping
134+
.map(range)
135+
.filter(|(mapping, _)| mapping.file_id == src_file_id)
136+
.and_then(|(InFile { value: mapped_range, .. }, attr_id)| {
137+
Some(mapped_range).zip(resolve_doc_path_for_def(
138+
sema.db,
139+
def,
140+
&link,
141+
ns,
142+
attr_id.is_inner_attr(),
143+
))
144+
})
145+
})
146+
.for_each(|(range, def)| {
147+
hl.add(HlRange {
148+
range,
149+
highlight: module_def_to_hl_tag(def)
150+
| HlMod::Documentation
151+
| HlMod::Injected
152+
| HlMod::IntraDocLink,
153+
binding_hash: None,
143154
})
144-
})
145-
.for_each(|(range, def)| {
146-
hl.add(HlRange {
147-
range,
148-
highlight: module_def_to_hl_tag(def)
149-
| HlMod::Documentation
150-
| HlMod::Injected
151-
| HlMod::IntraDocLink,
152-
binding_hash: None,
153155
})
154-
});
156+
});
155157
}
156158

157159
// Extract doc-test sources from the docs and calculate highlighting for them.

0 commit comments

Comments
 (0)