mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00:00
[ty] Rename functionArgumentNames
to callArgumentNames
inlay hint setting (#19911)
## Summary This PR renames `ty.inlayHints.functionArgumentNames` to `ty.inlayHints.callArgumentNames` which would contain both function calls and class initialization calls i.e., it represents a generic call expression.
This commit is contained in:
parent
2ee47d87b6
commit
1167ed61cf
3 changed files with 14 additions and 14 deletions
|
@ -24,7 +24,7 @@ impl<'db> InlayHint<'db> {
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub enum InlayHintContent<'db> {
|
pub enum InlayHintContent<'db> {
|
||||||
Type(Type<'db>),
|
Type(Type<'db>),
|
||||||
FunctionArgumentName(String),
|
CallArgumentName(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> InlayHintContent<'db> {
|
impl<'db> InlayHintContent<'db> {
|
||||||
|
@ -44,7 +44,7 @@ impl fmt::Display for DisplayInlayHint<'_, '_> {
|
||||||
InlayHintContent::Type(ty) => {
|
InlayHintContent::Type(ty) => {
|
||||||
write!(f, ": {}", ty.display(self.db))
|
write!(f, ": {}", ty.display(self.db))
|
||||||
}
|
}
|
||||||
InlayHintContent::FunctionArgumentName(name) => {
|
InlayHintContent::CallArgumentName(name) => {
|
||||||
write!(f, "{name}=")
|
write!(f, "{name}=")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,21 +77,21 @@ pub struct InlayHintSettings {
|
||||||
/// ```
|
/// ```
|
||||||
pub variable_types: bool,
|
pub variable_types: bool,
|
||||||
|
|
||||||
/// Whether to show function argument names.
|
/// Whether to show call argument names.
|
||||||
///
|
///
|
||||||
/// For example, this would enable / disable hints like the ones quoted below:
|
/// For example, this would enable / disable hints like the ones quoted below:
|
||||||
/// ```python
|
/// ```python
|
||||||
/// def foo(x: int): pass
|
/// def foo(x: int): pass
|
||||||
/// foo("x="1)
|
/// foo("x="1)
|
||||||
/// ```
|
/// ```
|
||||||
pub function_argument_names: bool,
|
pub call_argument_names: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for InlayHintSettings {
|
impl Default for InlayHintSettings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
variable_types: true,
|
variable_types: true,
|
||||||
function_argument_names: true,
|
call_argument_names: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,8 @@ impl<'a, 'db> InlayHintVisitor<'a, 'db> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_function_argument_name(&mut self, position: TextSize, name: String) {
|
fn add_call_argument_name(&mut self, position: TextSize, name: String) {
|
||||||
if !self.settings.function_argument_names {
|
if !self.settings.call_argument_names {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ impl<'a, 'db> InlayHintVisitor<'a, 'db> {
|
||||||
|
|
||||||
self.hints.push(InlayHint {
|
self.hints.push(InlayHint {
|
||||||
position,
|
position,
|
||||||
content: InlayHintContent::FunctionArgumentName(name),
|
content: InlayHintContent::CallArgumentName(name),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ impl SourceOrderVisitor<'_> for InlayHintVisitor<'_, '_> {
|
||||||
|
|
||||||
for (index, arg_or_keyword) in call.arguments.arguments_source_order().enumerate() {
|
for (index, arg_or_keyword) in call.arguments.arguments_source_order().enumerate() {
|
||||||
if let Some(name) = argument_names.get(&index) {
|
if let Some(name) = argument_names.get(&index) {
|
||||||
self.add_function_argument_name(
|
self.add_call_argument_name(
|
||||||
arg_or_keyword.range().start(),
|
arg_or_keyword.range().start(),
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
);
|
);
|
||||||
|
@ -301,7 +301,7 @@ mod tests {
|
||||||
fn inlay_hints(&self) -> String {
|
fn inlay_hints(&self) -> String {
|
||||||
self.inlay_hints_with_settings(&InlayHintSettings {
|
self.inlay_hints_with_settings(&InlayHintSettings {
|
||||||
variable_types: true,
|
variable_types: true,
|
||||||
function_argument_names: true,
|
call_argument_names: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_snapshot!(test.inlay_hints_with_settings(&InlayHintSettings {
|
assert_snapshot!(test.inlay_hints_with_settings(&InlayHintSettings {
|
||||||
function_argument_names: false,
|
call_argument_names: false,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}), @r"
|
}), @r"
|
||||||
def foo(x: int): pass
|
def foo(x: int): pass
|
||||||
|
|
|
@ -237,14 +237,14 @@ impl WorkspaceOptions {
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct InlayHintOptions {
|
struct InlayHintOptions {
|
||||||
variable_types: Option<bool>,
|
variable_types: Option<bool>,
|
||||||
function_argument_names: Option<bool>,
|
call_argument_names: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InlayHintOptions {
|
impl InlayHintOptions {
|
||||||
fn into_settings(self) -> InlayHintSettings {
|
fn into_settings(self) -> InlayHintSettings {
|
||||||
InlayHintSettings {
|
InlayHintSettings {
|
||||||
variable_types: self.variable_types.unwrap_or(true),
|
variable_types: self.variable_types.unwrap_or(true),
|
||||||
function_argument_names: self.function_argument_names.unwrap_or(true),
|
call_argument_names: self.call_argument_names.unwrap_or(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -438,7 +438,7 @@ impl Workspace {
|
||||||
// TODO: Provide a way to configure this
|
// TODO: Provide a way to configure this
|
||||||
&InlayHintSettings {
|
&InlayHintSettings {
|
||||||
variable_types: true,
|
variable_types: true,
|
||||||
function_argument_names: true,
|
call_argument_names: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue