Skip to content

Commit 5d9785c

Browse files
committed
Split out oak_index_vec/ crate
1 parent dc27b52 commit 5d9785c

10 files changed

Lines changed: 45 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ oak_core = { path = "crates/oak_core" }
7575
oak_fs = { path = "crates/oak_fs" }
7676
oak_ide = { path = "crates/oak_ide" }
7777
oak_index = { path = "crates/oak_index" }
78+
oak_index_vec = { path = "crates/oak_index_vec" }
7879
oak_package = { path = "crates/oak_package" }
7980
oak_r_process = { path = "crates/oak_r_process" }
8081
oak_sources = { path = "crates/oak_sources" }

crates/oak_index/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ itertools.workspace = true
2020
log.workspace = true
2121
oak_core.workspace = true
2222
oak_package.workspace = true
23+
oak_index_vec.workspace = true
2324
rustc-hash.workspace = true
2425
smallvec.workspace = true
2526
stdext.workspace = true

crates/oak_index/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use biome_rowan::TextRange;
1818
use biome_rowan::WalkEvent;
1919
use oak_core::syntax_ext::RIdentifierExt;
2020
use oak_core::syntax_ext::RStringValueExt;
21+
use oak_index_vec::Idx;
22+
use oak_index_vec::IndexVec;
2123
use rustc_hash::FxHashMap;
2224
use smallvec::SmallVec;
2325

24-
use crate::index_vec::Idx;
25-
use crate::index_vec::IndexVec;
2626
use crate::semantic_index::Definition;
2727
use crate::semantic_index::DefinitionId;
2828
use crate::semantic_index::DefinitionKind;

crates/oak_index/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
pub mod builder;
22
pub mod external;
3-
pub(crate) mod index_vec;
4-
pub(crate) mod range;
53
pub mod semantic_index;
64
pub mod use_def_map;
75

crates/oak_index/src/range.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

crates/oak_index/src/semantic_index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use aether_syntax::RSyntaxNode;
44
use biome_rowan::TextRange;
55
use biome_rowan::TextSize;
66
use oak_core::range::Ranged;
7+
use oak_index_vec::define_index;
8+
use oak_index_vec::IndexVec;
79
use rustc_hash::FxHashMap;
810

9-
use crate::index_vec::define_index;
10-
use crate::index_vec::IndexVec;
1111
use crate::use_def_map::Bindings;
1212
use crate::use_def_map::UseDefMap;
1313

crates/oak_index/src/use_def_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use itertools::EitherOrBoth;
22
use itertools::Itertools;
3+
use oak_index_vec::Idx;
4+
use oak_index_vec::IndexVec;
35
use rustc_hash::FxHashMap;
46
use smallvec::SmallVec;
57

6-
use crate::index_vec::Idx;
7-
use crate::index_vec::IndexVec;
88
use crate::semantic_index::DefinitionId;
99
use crate::semantic_index::EnclosingSnapshotId;
1010
use crate::semantic_index::SymbolId;

crates/oak_index_vec/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "oak_index_vec"
3+
version = "0.1.0"
4+
authors.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
description = """
8+
`Vec<V>` indexed by a strongly-typed newtype so that indices from different
9+
vectors can't be mixed up.
10+
"""
11+
license.workspace = true
12+
13+
[dependencies]
14+
biome_text_size.workspace = true
15+
oak_core.workspace = true
16+
17+
[lints]
18+
workspace = true
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ impl<I: Idx, V> IndexVec<I, V> {
4646
}
4747
}
4848

49+
impl<I: Idx, V: oak_core::range::Ranged> IndexVec<I, V> {
50+
/// Find the `V` containing `offset`, if any.
51+
pub fn contains(&self, offset: biome_text_size::TextSize) -> Option<(I, &V)> {
52+
self.iter()
53+
.find(|(_index, value)| value.range().contains(offset))
54+
}
55+
}
56+
4957
impl<I: Idx, V> IntoIterator for IndexVec<I, V> {
5058
type Item = V;
5159
type IntoIter = std::vec::IntoIter<V>;
@@ -90,6 +98,7 @@ impl<I: Idx, V> ops::IndexMut<I> for IndexVec<I, V> {
9098
}
9199
}
92100

101+
#[macro_export]
93102
macro_rules! define_index {
94103
($name:ident) => {
95104
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -105,7 +114,7 @@ macro_rules! define_index {
105114
}
106115
}
107116

108-
impl $crate::index_vec::Idx for $name {
117+
impl $crate::Idx for $name {
109118
fn new(value: usize) -> Self {
110119
assert!(value <= Self::MAX);
111120
Self(value as u32)
@@ -117,5 +126,3 @@ macro_rules! define_index {
117126
}
118127
};
119128
}
120-
121-
pub(crate) use define_index;

0 commit comments

Comments
 (0)