Skip to content

Commit

Permalink
fix: store inherit_id as full XML ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Mar 6, 2024
1 parent 135fcfd commit c09a54b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
10 changes: 2 additions & 8 deletions src/index/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokio::sync::RwLock;

use crate::{model::ModelName, record::Record};

use super::{interner, Symbol};
use super::Symbol;

#[derive(Default, Deref)]
pub struct RecordIndex {
Expand All @@ -27,18 +27,12 @@ pub type RecordPrefixTrie = qp_trie::Trie<BString, SymbolSet<Record>>;

impl RecordIndex {
pub async fn insert(&self, qualified_id: RecordId, record: Record, prefix: Option<&mut RecordPrefixTrie>) {
let interner = interner();
if let Some(model) = &record.model {
self.by_model.entry(*model).or_default().insert(qualified_id);
}
if let Some(inherit_id) = &record.inherit_id {
let inherit_id = match inherit_id {
(Some(module), xml_id) => format!("{}.{xml_id}", interner.resolve(module)),
(None, xml_id) => format!("{}.{xml_id}", interner.resolve(&record.module)),
};
let inherit_id = interner.get_or_intern(inherit_id);
self.by_inherit_id
.entry(inherit_id.into())
.entry(inherit_id.clone())
.or_default()
.insert(qualified_id);
}
Expand Down
29 changes: 19 additions & 10 deletions src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ropey::Rope;
use tower_lsp::lsp_types::*;
use xmlparser::{ElementEnd, Token, Tokenizer};

use crate::index::{interner, ModuleName};
use crate::index::{interner, ModuleName, RecordId};
use crate::model::ModelName;
use crate::utils::{offset_to_position, position_to_offset};
use crate::utils::{ByteOffset, MinLoc};
Expand All @@ -17,7 +17,7 @@ pub struct Record {
pub module: ModuleName,
pub model: Option<ModelName>,
/// (inherit_module?, xml_id)
pub inherit_id: Option<(Option<ModelName>, ImStr)>,
pub inherit_id: Option<RecordId>,
pub location: MinLoc,
}

Expand Down Expand Up @@ -85,10 +85,14 @@ impl Record {
let Some(maybe_inherit_id) = maybe_inherit_id else {
continue;
};
if let Some((module, xml_id)) = maybe_inherit_id.split_once('.') {
inherit_id = Some((Some(interner().get_or_intern(module).into()), xml_id.into()));
if maybe_inherit_id.contains(',') {
inherit_id = Some(interner().get_or_intern(maybe_inherit_id).into());
} else {
inherit_id = Some((None, maybe_inherit_id.into()));
inherit_id = Some(
interner()
.get_or_intern(&format!("{}.{maybe_inherit_id}", interner().resolve(&module)))
.into(),
);
}
}
}
Expand Down Expand Up @@ -167,12 +171,17 @@ impl Record {
id = Some(value.as_str().into());
}
}
b"inherit_id" => match value.split_once('.') {
Some((module, xml_id)) => {
inherit_id = Some((Some(interner().get_or_intern(module).into()), xml_id.into()))
b"inherit_id" => {
if value.contains('.') {
inherit_id = Some(interner().get_or_intern(value.as_str()).into());
} else {
inherit_id = Some(
interner()
.get_or_intern(&format!("{}.{value}", interner().resolve(&module)))
.into(),
)
}
None => inherit_id = Some((None, value.as_str().into())),
},
}
_ => {}
},
Some(Ok(Token::ElementEnd {
Expand Down

0 comments on commit c09a54b

Please sign in to comment.