mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 05:14:52 +00:00
[ty] Default ty.inlayHints.*
server settings to true (#19910)
## Summary This PR changes the default of `ty.inlayHints.*` settings to `true`. I somehow missed this in my initial PR. This is marked as `internal` because it's not yet released.
This commit is contained in:
parent
d324cedfc2
commit
2ee47d87b6
3 changed files with 68 additions and 4 deletions
|
@ -67,7 +67,7 @@ pub fn inlay_hints<'db>(
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Settings to control the behavior of inlay hints.
|
/// Settings to control the behavior of inlay hints.
|
||||||
#[derive(Clone, Default, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct InlayHintSettings {
|
pub struct InlayHintSettings {
|
||||||
/// Whether to show variable type hints.
|
/// Whether to show variable type hints.
|
||||||
///
|
///
|
||||||
|
@ -76,6 +76,7 @@ pub struct InlayHintSettings {
|
||||||
/// x": Literal[1]" = 1
|
/// x": Literal[1]" = 1
|
||||||
/// ```
|
/// ```
|
||||||
pub variable_types: bool,
|
pub variable_types: bool,
|
||||||
|
|
||||||
/// Whether to show function argument names.
|
/// Whether to show function 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:
|
||||||
|
@ -86,6 +87,15 @@ pub struct InlayHintSettings {
|
||||||
pub function_argument_names: bool,
|
pub function_argument_names: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for InlayHintSettings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
variable_types: true,
|
||||||
|
function_argument_names: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct InlayHintVisitor<'a, 'db> {
|
struct InlayHintVisitor<'a, 'db> {
|
||||||
db: &'db dyn Db,
|
db: &'db dyn Db,
|
||||||
model: SemanticModel<'db>,
|
model: SemanticModel<'db>,
|
||||||
|
|
|
@ -243,8 +243,8 @@ struct InlayHintOptions {
|
||||||
impl InlayHintOptions {
|
impl InlayHintOptions {
|
||||||
fn into_settings(self) -> InlayHintSettings {
|
fn into_settings(self) -> InlayHintSettings {
|
||||||
InlayHintSettings {
|
InlayHintSettings {
|
||||||
variable_types: self.variable_types.unwrap_or_default(),
|
variable_types: self.variable_types.unwrap_or(true),
|
||||||
function_argument_names: self.function_argument_names.unwrap_or_default(),
|
function_argument_names: self.function_argument_names.unwrap_or(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,60 @@ use ty_server::ClientOptions;
|
||||||
|
|
||||||
use crate::TestServerBuilder;
|
use crate::TestServerBuilder;
|
||||||
|
|
||||||
|
/// Tests that the default value of inlay hints settings is correct i.e., they're all enabled
|
||||||
|
/// by default.
|
||||||
|
#[test]
|
||||||
|
fn default_inlay_hints() -> Result<()> {
|
||||||
|
let workspace_root = SystemPath::new("src");
|
||||||
|
let foo = SystemPath::new("src/foo.py");
|
||||||
|
let foo_content = "\
|
||||||
|
x = 1
|
||||||
|
|
||||||
|
def foo(a: int) -> int:
|
||||||
|
return a + 1
|
||||||
|
|
||||||
|
foo(1)
|
||||||
|
";
|
||||||
|
|
||||||
|
let mut server = TestServerBuilder::new()?
|
||||||
|
.with_initialization_options(ClientOptions::default())
|
||||||
|
.with_workspace(workspace_root, None)?
|
||||||
|
.with_file(foo, foo_content)?
|
||||||
|
.enable_inlay_hints(true)
|
||||||
|
.build()?
|
||||||
|
.wait_until_workspaces_are_initialized()?;
|
||||||
|
|
||||||
|
server.open_text_document(foo, &foo_content, 1);
|
||||||
|
let _ = server.await_notification::<PublishDiagnostics>()?;
|
||||||
|
|
||||||
|
let hints = server
|
||||||
|
.inlay_hints_request(foo, Range::new(Position::new(0, 0), Position::new(6, 0)))?
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
insta::assert_json_snapshot!(hints, @r#"
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"position": {
|
||||||
|
"line": 0,
|
||||||
|
"character": 1
|
||||||
|
},
|
||||||
|
"label": ": Literal[1]",
|
||||||
|
"kind": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"position": {
|
||||||
|
"line": 5,
|
||||||
|
"character": 4
|
||||||
|
},
|
||||||
|
"label": "a=",
|
||||||
|
"kind": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"#);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Tests that disabling variable types inlay hints works correctly.
|
/// Tests that disabling variable types inlay hints works correctly.
|
||||||
#[test]
|
#[test]
|
||||||
fn variable_inlay_hints_disabled() -> Result<()> {
|
fn variable_inlay_hints_disabled() -> Result<()> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue