This commit is contained in:
Aria Desires 2025-07-03 19:14:55 -04:00
parent 1bee527cb2
commit 5cc6762c23
3 changed files with 66 additions and 45 deletions

View file

@ -1195,8 +1195,9 @@ f(**kwargs<CURSOR>)
fn goto_def_class() { fn goto_def_class() {
let test = cursor_test( let test = cursor_test(
r#" r#"
class AB(val: int): class AB:
self.myval = val def __init__(self, val: int):
self.myval = val
x = A<CURSOR>B(5) x = A<CURSOR>B(5)
"#, "#,
@ -1206,27 +1207,46 @@ f(**kwargs<CURSOR>)
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:19 --> main.py:2:19
| |
2 | class AB(val: int): 2 | class AB:
| ^^ | ^^
3 | self.myval = val 3 | def __init__(self, val: int):
4 | self.myval = val
| |
info: Source info: Source
--> main.py:5:17 --> main.py:6:17
| |
3 | self.myval = val 4 | self.myval = val
4 | 5 |
5 | x = AB(5) 6 | x = AB(5)
| ^^ | ^^
| |
"); ");
} }
#[test] #[test]
fn goto_def_class_instance_variable() { fn goto_def_class_implicit_instance_variable() {
let test = cursor_test( let test = cursor_test(
r#" r#"
class AB(val: int): class AB:
self.myval = val def __init__(self, val: int):
self.myval = val
x = AB(5)
print(x.my<CURSOR>val)
"#,
);
assert_snapshot!(test.goto_definition(), @"No goto target found");
}
#[test]
fn goto_def_class_explicit_instance_variable() {
let test = cursor_test(
r#"
class AB:
myval: int
def __init__(self, val: int):
self.myval = val
x = AB(5) x = AB(5)
print(x.my<CURSOR>val) print(x.my<CURSOR>val)
@ -1240,8 +1260,9 @@ f(**kwargs<CURSOR>)
fn goto_def_path_parent() { fn goto_def_path_parent() {
let test = cursor_test( let test = cursor_test(
r#" r#"
class AB(val: int): class AB:
self.myval = val def __init__(self, val: int):
self.myval = val
xyz = AB(5) xyz = AB(5)
print(x<CURSOR>yz.myval) print(x<CURSOR>yz.myval)
@ -1250,19 +1271,19 @@ f(**kwargs<CURSOR>)
assert_snapshot!(test.goto_definition(), @r" assert_snapshot!(test.goto_definition(), @r"
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:5:13 --> main.py:6:13
| |
3 | self.myval = val 4 | self.myval = val
4 | 5 |
5 | xyz = AB(5) 6 | xyz = AB(5)
| ^^^ | ^^^
6 | print(xyz.myval) 7 | print(xyz.myval)
| |
info: Source info: Source
--> main.py:6:19 --> main.py:7:19
| |
5 | xyz = AB(5) 6 | xyz = AB(5)
6 | print(xyz.myval) 7 | print(xyz.myval)
| ^^^ | ^^^
| |
"); ");
@ -1272,7 +1293,7 @@ f(**kwargs<CURSOR>)
fn goto_def_class_class_variable() { fn goto_def_class_class_variable() {
let test = cursor_test( let test = cursor_test(
r#" r#"
class AB(): class AB:
RED = "red" RED = "red"
BLUE = "blue" BLUE = "blue"
@ -1287,7 +1308,7 @@ f(**kwargs<CURSOR>)
fn goto_def_class_path_parent() { fn goto_def_class_path_parent() {
let test = cursor_test( let test = cursor_test(
r#" r#"
class AB(): class AB:
RED = "red" RED = "red"
BLUE = "blue" BLUE = "blue"
@ -1299,7 +1320,7 @@ f(**kwargs<CURSOR>)
info[goto-type-definition]: Type definition info[goto-type-definition]: Type definition
--> main.py:2:19 --> main.py:2:19
| |
2 | class AB(): 2 | class AB:
| ^^ | ^^
3 | RED = "red" 3 | RED = "red"
4 | BLUE = "blue" 4 | BLUE = "blue"

View file

@ -187,27 +187,27 @@ pub trait HasDefinition {
impl HasDefinition for ast::ExprRef<'_> { impl HasDefinition for ast::ExprRef<'_> {
fn definitions<'db>(&self, model: &SemanticModel<'db>) -> Option<Vec<Definition<'db>>> { fn definitions<'db>(&self, model: &SemanticModel<'db>) -> Option<Vec<Definition<'db>>> {
let ExprRef::Name(name) = self else { match self {
return None; ExprRef::Name(name) => match name.ctx {
}; ExprContext::Load => {
match name.ctx { let index = semantic_index(model.db, model.file);
ExprContext::Load => { let file_scope = index.expression_scope_id(*self);
let index = semantic_index(model.db, model.file); let scope = file_scope.to_scope_id(model.db, model.file);
let file_scope = index.expression_scope_id(*self); let use_def = index.use_def_map(file_scope);
let scope = file_scope.to_scope_id(model.db, model.file); let use_id = self.scoped_use_id(model.db, scope);
let use_def = index.use_def_map(file_scope);
let use_id = self.scoped_use_id(model.db, scope);
Some( Some(
use_def use_def
.bindings_at_use(use_id) .bindings_at_use(use_id)
.filter_map(|binding| binding.binding.definition()) .filter_map(|binding| binding.binding.definition())
.collect(), .collect(),
) )
} }
ExprContext::Store => None, ExprContext::Store => None,
ExprContext::Del => None, ExprContext::Del => None,
ExprContext::Invalid => None, ExprContext::Invalid => None,
},
_ => None,
} }
} }
} }

View file

@ -2667,7 +2667,7 @@ impl<'db> BindingError<'db> {
if let Some(builder) = context.report_lint(&MISSING_ARGUMENT, node) { if let Some(builder) = context.report_lint(&MISSING_ARGUMENT, node) {
let s = if parameters.0.len() == 1 { "" } else { "s" }; let s = if parameters.0.len() == 1 { "" } else { "s" };
let mut diag = builder.into_diagnostic(format_args!( let mut diag = builder.into_diagnostic(format_args!(
"No argument{s} provided for required parameterzz{s} {parameters}{}", "No argument{s} provided for required parameter{s} {parameters}{}",
if let Some(CallableDescription { kind, name }) = callable_description { if let Some(CallableDescription { kind, name }) = callable_description {
format!(" of {kind} `{name}`") format!(" of {kind} `{name}`")
} else { } else {