-
Notifications
You must be signed in to change notification settings - Fork 304
fix hover on __init__ parameter shows parent type #2503 #3020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ use crate::export::exports::Export; | |
| use crate::export::exports::ExportLocation; | ||
| use crate::lsp::module_helpers::collect_symbol_def_paths; | ||
| use crate::lsp::wasm::completion::CompletionOptions; | ||
| use crate::lsp::wasm::signature_help::is_constructor_call; | ||
| use crate::state::ide::IntermediateDefinition; | ||
| use crate::state::ide::common_alias_target_module; | ||
| use crate::state::ide::import_regular_import_edit; | ||
|
|
@@ -872,6 +873,29 @@ impl<'a> Transaction<'a> { | |
| } | ||
| } | ||
|
|
||
| fn get_constructor_keyword_argument_type( | ||
| &self, | ||
| handle: &Handle, | ||
| position: TextSize, | ||
| ) -> Option<Type> { | ||
| let call_info = self.get_callables_from_call(handle, position)?; | ||
| let callee_type = self | ||
| .get_answers(handle)? | ||
| .get_type_trace(call_info.callee_range)?; | ||
| if !is_constructor_call(callee_type) { | ||
| return None; | ||
| } | ||
|
|
||
| let chosen_overload_index = | ||
| call_info | ||
| .chosen_overload_index | ||
| .or((call_info.callables.len() == 1).then_some(0))?; | ||
| let callable = call_info.callables.get(chosen_overload_index)?.clone(); | ||
| let params = Self::normalize_singleton_function_type_into_params(callable)?; | ||
| let arg_index = Self::active_parameter_index(¶ms, &call_info.active_argument)?; | ||
| Some(params.get(arg_index)?.as_type().clone()) | ||
| } | ||
|
|
||
| pub fn get_type_at(&self, handle: &Handle, position: TextSize) -> Option<Type> { | ||
| match self.identifier_at(handle, position) { | ||
| Some(IdentifierWithContext { | ||
|
|
@@ -1024,7 +1048,8 @@ impl<'a> Transaction<'a> { | |
| return None; | ||
| } | ||
| self.get_type(handle, &key) | ||
| }), | ||
| }) | ||
| .or_else(|| self.get_constructor_keyword_argument_type(handle, position)), | ||
|
Comment on lines
1048
to
+1052
|
||
| Some(IdentifierWithContext { | ||
| identifier: _, | ||
| context: IdentifierContext::Attribute { range, .. }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
find_definitionresult is truncated with.into_iter().next()before applying the keyword-argument filter. Iffind_definitionreturns multiple candidates (e.g., multiple callee locations), the first item might be filtered out even though a later item matches the keyword identifier, causing hover to lose definition metadata/name. Consider iterating definitions and selecting the first item whosedefinition_rangetext matches the keyword identifier (or only falling back when none match).