Skip to content

Commit 120984c

Browse files
committed
Give priority to non-section entries
1 parent 729ec23 commit 120984c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/ark/src/lsp/indexer.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,17 @@ fn insert(path: &Path, entry: IndexEntry) -> anyhow::Result<()> {
121121

122122
let index = index.entry(path.to_string()).or_default();
123123

124-
// Retain the first occurrence in the index. In the future we'll track every occurrences and
125-
// their scopes but for now we only track the first definition of an object (in a way, its
124+
// We generally retain only the first occurrence in the index. In the
125+
// future we'll track every occurrences and their scopes but for now we
126+
// only track the first definition of an object (in a way, its
126127
// declaration).
127-
if !index.contains_key(&entry.key) {
128+
if let Some(existing_entry) = index.get(&entry.key) {
129+
// Give priority to non-section entries.
130+
if matches!(existing_entry.data, IndexEntryData::Section { .. }) {
131+
index.insert(entry.key.clone(), entry);
132+
}
133+
// Else, ignore.
134+
} else {
128135
index.insert(entry.key.clone(), entry);
129136
}
130137

0 commit comments

Comments
 (0)