Skip to content

Commit f6213a0

Browse files
committed
ref: replace FastStr with ImStr
1 parent a48df4e commit f6213a0

File tree

10 files changed

+232
-127
lines changed

10 files changed

+232
-127
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ tower-lsp = { version = "0.20.0", features = ["proposed"] }
3434
serde = { version = "1.0", features = ["derive"] }
3535
dashmap = "5.1.0"
3636
log = "0.4.14"
37-
im-rc = "15.0.0"
38-
faststr = "0.2.11"
3937
globwalk = "0.8.1"
4038
miette = { version = "5.10.0", features = ["fancy"] }
4139
futures = "0.3.28"

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Alternatively, you can grab the latest nightly builds from [Releases].
4141

4242
See [.helix/languages.toml](./examples/.helix/languages.toml)
4343

44-
1. Ensure that you have `odoo-lsp` on your path (or define the SERVER_PATH environment variable pointing to one)
44+
1. Ensure that you have `odoo-lsp` on your path
4545
2. Determine your Helix runtime folder, e.g. `~/.config/helix/` on Linux
4646
3. Modify `languages.toml` in your Helix runtime folder (create one if none exists) to include these lines:
4747

@@ -53,9 +53,14 @@ odoo-lsp.command = "odoo-lsp"
5353
[[language]]
5454
name = "xml"
5555
language-servers = ["odoo-lsp"]
56+
roots = [".odoo_lsp", ".odoo_lsp.json"]
5657

5758
[[language]]
5859
name = "python"
60+
roots = [
61+
".odoo_lsp", ".odoo_lsp.json",
62+
# add the default roots here
63+
]
5964
# Order is important here
6065
language-servers = [
6166
"odoo-lsp",

src/index.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::OnceLock;
33
use std::time::Duration;
44

55
use dashmap::DashSet;
6-
use faststr::FastStr;
76
use globwalk::FileType;
87
use log::{debug, warn};
98
use miette::{diagnostic, Context, IntoDiagnostic};
@@ -16,21 +15,21 @@ use xmlparser::{Token, Tokenizer};
1615
use crate::format_loc;
1716
use crate::model::{Model, ModelIndex};
1817
use crate::record::Record;
19-
use crate::utils::{offset_range_to_lsp_range, ByteOffset, CharOffset, RangeExt};
18+
use crate::utils::{offset_range_to_lsp_range, ByteOffset, CharOffset, ImStr, RangeExt};
2019

2120
mod record;
2221

2322
#[derive(Default)]
2423
pub struct ModuleIndex {
25-
pub roots: DashSet<String>,
26-
pub modules: DashSet<String>,
24+
pub roots: DashSet<ImStr>,
25+
pub modules: DashSet<ImStr>,
2726
pub records: record::RecordIndex,
2827
pub models: ModelIndex,
2928
}
3029

3130
enum Output {
3231
Records(Vec<Record>),
33-
Models { path: FastStr, models: Vec<Model> },
32+
Models { path: ImStr, models: Vec<Model> },
3433
}
3534

3635
pub struct AddRootResults {
@@ -49,7 +48,7 @@ impl ModuleIndex {
4948
root: &str,
5049
progress: Option<(&tower_lsp::Client, ProgressToken)>,
5150
) -> miette::Result<Option<AddRootResults>> {
52-
if !self.roots.insert(root.to_string()) {
51+
if !self.roots.insert(root.into()) {
5352
return Ok(None);
5453
}
5554

@@ -83,8 +82,8 @@ impl ModuleIndex {
8382
})
8483
.await;
8584
}
86-
let module_name = FastStr::from(module_name);
87-
if !self.modules.insert(module_name.to_string()) {
85+
let module_name = ImStr::from(module_name);
86+
if !self.modules.insert(module_name.clone()) {
8887
debug!("duplicate module {module_name}");
8988
continue;
9089
}
@@ -173,7 +172,7 @@ impl ModuleIndex {
173172
}
174173
}
175174
}
176-
pub fn module_of_path(&self, path: &Path) -> Option<dashmap::setref::one::Ref<String>> {
175+
pub fn module_of_path(&self, path: &Path) -> Option<dashmap::setref::one::Ref<ImStr>> {
177176
let mut path = Some(path);
178177
while let Some(path_) = &path {
179178
if let Some(module) = self.modules.get(path_.file_name()?.to_string_lossy().as_ref()) {
@@ -185,7 +184,7 @@ impl ModuleIndex {
185184
}
186185
}
187186

188-
async fn add_root_xml(path: PathBuf, module_name: FastStr) -> miette::Result<Output> {
187+
async fn add_root_xml(path: PathBuf, module_name: ImStr) -> miette::Result<Output> {
189188
let path_uri = path.to_string_lossy();
190189
let file = tokio::fs::read(&path)
191190
.await
@@ -238,7 +237,7 @@ fn model_query() -> &'static Query {
238237
})
239238
}
240239

241-
async fn add_root_py(path: PathBuf, _: FastStr) -> miette::Result<Output> {
240+
async fn add_root_py(path: PathBuf, _: ImStr) -> miette::Result<Output> {
242241
let file = tokio::fs::read(&path)
243242
.await
244243
.into_diagnostic()

src/index/record.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,89 @@
11
use std::{ops::Deref, sync::Arc};
22

33
use dashmap::{mapref::one::Ref, DashMap, DashSet};
4+
use qp_trie::wrapper::BString;
45
use tokio::sync::RwLock;
56

6-
use crate::{record::Record, utils::PrefixTrie};
7+
use crate::{
8+
record::Record,
9+
utils::{ImStr, PrefixTrie},
10+
};
711

812
#[derive(Default)]
913
pub struct RecordIndex {
10-
inner: DashMap<String, Record>,
11-
by_model: DashMap<String, DashSet<String>>,
12-
by_inherit_id: DashMap<String, DashSet<String>>,
14+
inner: DashMap<ImStr, Record>,
15+
by_model: DashMap<ImStr, DashSet<ImStr>>,
16+
by_inherit_id: DashMap<ImStr, DashSet<ImStr>>,
1317
pub by_prefix: Arc<RwLock<PrefixTrie>>,
1418
}
1519

1620
impl Deref for RecordIndex {
17-
type Target = DashMap<String, Record>;
21+
type Target = DashMap<ImStr, Record>;
1822
#[inline]
1923
fn deref(&self) -> &Self::Target {
2024
&self.inner
2125
}
2226
}
2327

2428
impl RecordIndex {
25-
pub async fn insert(&self, qualified_id: String, record: Record, prefix: Option<&mut PrefixTrie>) {
29+
pub async fn insert(&self, qualified_id: ImStr, record: Record, prefix: Option<&mut PrefixTrie>) {
2630
if let Some(model) = &record.model {
2731
self.by_model
28-
.entry(model.to_string())
32+
.entry(model.clone())
2933
.or_default()
30-
.insert(qualified_id.to_string());
34+
.insert(qualified_id.clone());
3135
}
3236
if let Some(inherit_id) = &record.inherit_id {
3337
let inherit_id = match inherit_id {
3438
(Some(module), xml_id) => format!("{module}.{xml_id}"),
3539
(None, xml_id) => format!("{}.{xml_id}", record.module),
3640
};
3741
self.by_inherit_id
38-
.entry(inherit_id)
42+
.entry(inherit_id.into())
3943
.or_default()
40-
.insert(qualified_id.to_string());
44+
.insert(qualified_id.clone());
4145
}
4246
if let Some(prefix) = prefix {
43-
prefix.insert_str(&qualified_id, qualified_id.to_string());
47+
prefix
48+
.entry(BString::from(record.id.as_str()))
49+
.or_insert_with(DashSet::default)
50+
.insert(qualified_id.clone());
4451
} else {
4552
self.by_prefix
4653
.write()
4754
.await
48-
.insert_str(&qualified_id, qualified_id.to_string());
55+
.entry(BString::from(record.id.as_str()))
56+
.or_insert_with(DashSet::default)
57+
.insert(qualified_id.clone());
4958
}
50-
self.inner.insert(qualified_id, record);
59+
self.inner.insert(qualified_id.into(), record);
5160
}
5261
pub async fn extend_records(&self, prefix: Option<&mut PrefixTrie>, records: impl IntoIterator<Item = Record>) {
5362
if let Some(prefix) = prefix {
5463
for record in records {
55-
self.insert(record.qualified_id(), record, Some(prefix)).await;
64+
self.insert(record.qualified_id().into(), record, Some(prefix)).await;
5665
}
5766
} else {
5867
let mut prefix = self.by_prefix.write().await;
5968
for record in records {
60-
self.insert(record.qualified_id(), record, Some(&mut prefix)).await;
69+
self.insert(record.qualified_id().into(), record, Some(&mut prefix))
70+
.await;
6171
}
6272
}
6373
}
64-
pub fn by_model(&self, model: &str) -> impl Iterator<Item = Ref<String, Record>> {
74+
pub fn by_model(&self, model: &str) -> impl Iterator<Item = Ref<ImStr, Record>> {
6575
self.by_model
6676
.get(model)
6777
.into_iter()
6878
.flat_map(|ids| self.resolve_references(ids))
6979
}
70-
pub fn by_inherit_id(&self, inherit_id: &str) -> impl Iterator<Item = Ref<String, Record>> {
80+
pub fn by_inherit_id(&self, inherit_id: &str) -> impl Iterator<Item = Ref<ImStr, Record>> {
7181
self.by_inherit_id
7282
.get(inherit_id)
7383
.into_iter()
7484
.flat_map(|ids| self.resolve_references(ids))
7585
}
76-
fn resolve_references(&self, ids: Ref<String, DashSet<String>>) -> impl IntoIterator<Item = Ref<String, Record>> {
86+
fn resolve_references(&self, ids: Ref<ImStr, DashSet<ImStr>>) -> impl IntoIterator<Item = Ref<ImStr, Record>> {
7787
ids.value()
7888
.iter()
7989
.flat_map(|id| self.get(id.key()).into_iter())

0 commit comments

Comments
 (0)