Skip to content

Commit 2ee47d8

Browse files
authored
[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.
1 parent d324ced commit 2ee47d8

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

crates/ty_ide/src/inlay_hints.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn inlay_hints<'db>(
6767
}
6868

6969
/// Settings to control the behavior of inlay hints.
70-
#[derive(Clone, Default, Debug)]
70+
#[derive(Clone, Debug)]
7171
pub struct InlayHintSettings {
7272
/// Whether to show variable type hints.
7373
///
@@ -76,6 +76,7 @@ pub struct InlayHintSettings {
7676
/// x": Literal[1]" = 1
7777
/// ```
7878
pub variable_types: bool,
79+
7980
/// Whether to show function argument names.
8081
///
8182
/// For example, this would enable / disable hints like the ones quoted below:
@@ -86,6 +87,15 @@ pub struct InlayHintSettings {
8687
pub function_argument_names: bool,
8788
}
8889

90+
impl Default for InlayHintSettings {
91+
fn default() -> Self {
92+
Self {
93+
variable_types: true,
94+
function_argument_names: true,
95+
}
96+
}
97+
}
98+
8999
struct InlayHintVisitor<'a, 'db> {
90100
db: &'db dyn Db,
91101
model: SemanticModel<'db>,
@@ -818,7 +828,7 @@ mod tests {
818828
def foo(x: str) -> int: ...
819829
def foo(x):
820830
return x
821-
831+
822832
foo(42)
823833
foo('hello')",
824834
);

crates/ty_server/src/session/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ struct InlayHintOptions {
243243
impl InlayHintOptions {
244244
fn into_settings(self) -> InlayHintSettings {
245245
InlayHintSettings {
246-
variable_types: self.variable_types.unwrap_or_default(),
247-
function_argument_names: self.function_argument_names.unwrap_or_default(),
246+
variable_types: self.variable_types.unwrap_or(true),
247+
function_argument_names: self.function_argument_names.unwrap_or(true),
248248
}
249249
}
250250
}

crates/ty_server/tests/e2e/inlay_hints.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,60 @@ use ty_server::ClientOptions;
55

66
use crate::TestServerBuilder;
77

8+
/// Tests that the default value of inlay hints settings is correct i.e., they're all enabled
9+
/// by default.
10+
#[test]
11+
fn default_inlay_hints() -> Result<()> {
12+
let workspace_root = SystemPath::new("src");
13+
let foo = SystemPath::new("src/foo.py");
14+
let foo_content = "\
15+
x = 1
16+
17+
def foo(a: int) -> int:
18+
return a + 1
19+
20+
foo(1)
21+
";
22+
23+
let mut server = TestServerBuilder::new()?
24+
.with_initialization_options(ClientOptions::default())
25+
.with_workspace(workspace_root, None)?
26+
.with_file(foo, foo_content)?
27+
.enable_inlay_hints(true)
28+
.build()?
29+
.wait_until_workspaces_are_initialized()?;
30+
31+
server.open_text_document(foo, &foo_content, 1);
32+
let _ = server.await_notification::<PublishDiagnostics>()?;
33+
34+
let hints = server
35+
.inlay_hints_request(foo, Range::new(Position::new(0, 0), Position::new(6, 0)))?
36+
.unwrap();
37+
38+
insta::assert_json_snapshot!(hints, @r#"
39+
[
40+
{
41+
"position": {
42+
"line": 0,
43+
"character": 1
44+
},
45+
"label": ": Literal[1]",
46+
"kind": 1
47+
},
48+
{
49+
"position": {
50+
"line": 5,
51+
"character": 4
52+
},
53+
"label": "a=",
54+
"kind": 1
55+
}
56+
]
57+
"#);
58+
59+
Ok(())
60+
}
61+
862
/// Tests that disabling variable types inlay hints works correctly.
963
#[test]
1064
fn variable_inlay_hints_disabled() -> Result<()> {

0 commit comments

Comments
 (0)