From 785c388f5427c3c3d9509c124529195698b1f458 Mon Sep 17 00:00:00 2001 From: Viet Dinh <54ckb0y789@gmail.com> Date: Wed, 22 May 2024 23:25:04 -0400 Subject: [PATCH] fix: do not clobber record names --- src/index.rs | 18 ++++++++++-------- src/index/record.rs | 3 +++ testing/conftest.py | 4 +++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/index.rs b/src/index.rs index 987432f..8fca62b 100644 --- a/src/index.rs +++ b/src/index.rs @@ -7,7 +7,7 @@ use dashmap::DashMap; use globwalk::FileType; use ignore::gitignore::Gitignore; use ignore::Match; -use lasso::{Key, Spur, ThreadedRodeo}; +use lasso::{Spur, ThreadedRodeo}; use miette::{diagnostic, IntoDiagnostic}; use ropey::Rope; use smart_default::SmartDefault; @@ -100,7 +100,7 @@ impl Interner { pub struct Index { /// root -> module key -> module's relpath to root #[default(_code = "DashMap::with_shard_amount(4)")] - pub roots: DashMap>, + pub roots: DashMap, ImStr>>, pub records: record::RecordIndex, pub templates: template::TemplateIndex, pub models: ModelIndex, @@ -212,11 +212,13 @@ impl Index { module_dir, root ); - if !self.roots.entry(root.into()).or_default().insert_checked( - module_key.into_usize() as _, - module_path.to_str().expect("non-utf8 path").into(), - ) { - warn!("duplicate module {module_name} path={module_path:?}"); + if let Some(duplicate) = self + .roots + .entry(root.into()) + .or_default() + .insert(module_key.into(), module_path.to_str().expect("non-utf8 path").into()) + { + warn!(old = %duplicate, new = ?module_path, "duplicate module {module_name}"); if let (Some((client, _)), "base") = (&progress, module_name.as_str()) { let resp = client .send_request::(ShowMessageRequestParams { @@ -366,7 +368,7 @@ impl Index { for component in path.components() { if let Component::Normal(norm) = component { if let Some(module) = interner().get(&norm.to_string_lossy()) { - if entry.value().contains_key(module.into_usize() as _) { + if entry.value().contains_key(&module.into()) { return Some(module.into()); } } diff --git a/src/index/record.rs b/src/index/record.rs index a6e7534..78a07d2 100644 --- a/src/index/record.rs +++ b/src/index/record.rs @@ -31,6 +31,9 @@ pub type RecordPrefixTrie = qp_trie::Trie>; impl RecordIndex { pub async fn insert(&self, qualified_id: RecordId, record: Record, prefix: Option<&mut RecordPrefixTrie>) { + if self.inner.contains_key(&qualified_id) { + return; + } if let Some(model) = &record.model { self.by_model.entry(*model).or_default().insert(qualified_id); } diff --git a/testing/conftest.py b/testing/conftest.py index d0ee03c..9ccd582 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -26,7 +26,9 @@ odoocmd = [lsp_devtools, "agent", "--", f"{__dirname}/../target/debug/odoo-lsp"] else: odoocmd = [f"{__dirname}/../target/debug/odoo-lsp"] -ODOO_ENV = {"RUST_LOG": "info,odoo_lsp=trace", "ODOO_LSP_LOG": "1"} +ODOO_ENV = dict(os.environ) +ODOO_ENV.setdefault('RUST_LOG', 'info,odoo_lsp=trace') +ODOO_ENV.setdefault('ODOO_LSP_LOG', '1') @pytest.fixture