[ty] Add autocomplete suggestions for function arguments
This adds autocomplete suggestions for function arguments. For example, `okay` in: ```python def foo(okay=None): foo(o<CURSOR> ``` This also ensures that we don't suggest a keyword argument if it has already been used. Closes astral-sh/issues#1550
This commit is contained in:
committed by
Andrew Gallant
parent
2d3466eccf
commit
eac8a90cc4
@@ -30,6 +30,7 @@ pub(crate) use self::infer::{
|
||||
TypeContext, infer_deferred_types, infer_definition_types, infer_expression_type,
|
||||
infer_expression_types, infer_scope_types, static_expression_truthiness,
|
||||
};
|
||||
pub use self::signatures::ParameterKind;
|
||||
pub(crate) use self::signatures::{CallableSignature, Signature};
|
||||
pub(crate) use self::subclass_of::{SubclassOfInner, SubclassOfType};
|
||||
pub use crate::diagnostic::add_inferred_python_version_hint_to_diagnostic;
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::semantic_index::definition::Definition;
|
||||
use crate::semantic_index::definition::DefinitionKind;
|
||||
use crate::semantic_index::{attribute_scopes, global_scope, semantic_index, use_def_map};
|
||||
use crate::types::call::{CallArguments, MatchedArgument};
|
||||
use crate::types::signatures::Signature;
|
||||
use crate::types::signatures::{ParameterKind, Signature};
|
||||
use crate::types::{CallDunderError, UnionType};
|
||||
use crate::types::{CallableTypes, ClassBase, KnownClass, Type, TypeContext};
|
||||
use crate::{Db, DisplaySettings, HasType, SemanticModel};
|
||||
@@ -459,6 +459,9 @@ pub struct CallSignatureDetails<'db> {
|
||||
/// This provides easy access to parameter names for documentation lookup.
|
||||
pub parameter_names: Vec<String>,
|
||||
|
||||
/// Parameter kinds, useful to determine correct autocomplete suggestions.
|
||||
pub parameter_kinds: Vec<ParameterKind<'db>>,
|
||||
|
||||
/// The definition where this callable was originally defined (useful for
|
||||
/// extracting docstrings).
|
||||
pub definition: Option<Definition<'db>>,
|
||||
@@ -517,6 +520,11 @@ pub fn call_signature_details<'db>(
|
||||
let display_details = signature.display(model.db()).to_string_parts();
|
||||
let parameter_label_offsets = display_details.parameter_ranges;
|
||||
let parameter_names = display_details.parameter_names;
|
||||
let parameter_kinds = signature
|
||||
.parameters()
|
||||
.iter()
|
||||
.map(|param| param.kind().clone())
|
||||
.collect();
|
||||
|
||||
CallSignatureDetails {
|
||||
definition: signature.definition(),
|
||||
@@ -524,6 +532,7 @@ pub fn call_signature_details<'db>(
|
||||
label: display_details.label,
|
||||
parameter_label_offsets,
|
||||
parameter_names,
|
||||
parameter_kinds,
|
||||
argument_to_parameter_mapping,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -2292,7 +2292,7 @@ impl<'db> Parameter<'db> {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, salsa::Update, get_size2::GetSize)]
|
||||
pub(crate) enum ParameterKind<'db> {
|
||||
pub enum ParameterKind<'db> {
|
||||
/// Positional-only parameter, e.g. `def f(x, /): ...`
|
||||
PositionalOnly {
|
||||
/// Parameter name.
|
||||
|
||||
Reference in New Issue
Block a user