feat: establish first-class lexical language parity #2
1 changed files with 25 additions and 1 deletions
fix(scan): suppress type declaration calls
commit
2c66bec1e9
26
src/scan.rs
26
src/scan.rs
|
|
@ -302,9 +302,11 @@ impl ScanState {
|
|||
});
|
||||
}
|
||||
|
||||
let mut type_definition_name = None;
|
||||
if let Some(captures) = patterns.class.captures(line)
|
||||
&& let Some(name) = captures.name("name")
|
||||
{
|
||||
type_definition_name = Some(name.as_str().to_owned());
|
||||
let id = self.add_symbol(
|
||||
file_id,
|
||||
path,
|
||||
|
|
@ -418,7 +420,10 @@ impl ScanState {
|
|||
.as_deref()
|
||||
.and_then(|name| name.rsplit('.').next())
|
||||
.map(|name| name.trim_start_matches('~'));
|
||||
if definition_call_name != Some(target) && !is_keyword(target) {
|
||||
if definition_call_name != Some(target)
|
||||
&& type_definition_name.as_deref() != Some(target)
|
||||
&& !is_keyword(target)
|
||||
{
|
||||
self.pending.push(PendingRelationship {
|
||||
source: source.clone(),
|
||||
target_name: clean_target(target),
|
||||
|
|
@ -1234,6 +1239,25 @@ mod tests {
|
|||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_promote_python_type_declarations_to_calls() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
fs::write(
|
||||
dir.path().join("worker.py"),
|
||||
"class Base:\n pass\nclass Worker(Base):\n pass\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let building = scan(dir.path()).unwrap();
|
||||
assert!(building.edges.iter().all(|edge| {
|
||||
edge.kind != EdgeKind::Calls
|
||||
|| !building
|
||||
.nodes
|
||||
.iter()
|
||||
.any(|node| node.id == edge.target && node.name == "Worker")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retains_every_location_for_a_deduplicated_dependency_edge() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue