aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/completion.rs4
-rw-r--r--crates/ra_ide/src/inlay_hints.rs52
-rw-r--r--crates/ra_ide/src/lib.rs4
-rw-r--r--crates/rust-analyzer/src/config.rs13
-rw-r--r--crates/rust-analyzer/src/conv.rs18
-rw-r--r--crates/rust-analyzer/src/main_loop.rs8
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs6
-rw-r--r--crates/rust-analyzer/src/req.rs14
-rw-r--r--crates/rust-analyzer/src/world.rs4
-rw-r--r--docs/user/features.md5
-rw-r--r--editors/code/src/client.ts7
11 files changed, 73 insertions, 62 deletions
diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs
index 93e53c921..cd0757be5 100644
--- a/crates/ra_ide/src/completion.rs
+++ b/crates/ra_ide/src/completion.rs
@@ -75,9 +75,9 @@ impl Default for CompletionOptions {
75pub(crate) fn completions( 75pub(crate) fn completions(
76 db: &RootDatabase, 76 db: &RootDatabase,
77 position: FilePosition, 77 position: FilePosition,
78 opts: &CompletionOptions, 78 options: &CompletionOptions,
79) -> Option<Completions> { 79) -> Option<Completions> {
80 let ctx = CompletionContext::new(db, position, opts)?; 80 let ctx = CompletionContext::new(db, position, options)?;
81 81
82 let mut acc = Completions::default(); 82 let mut acc = Completions::default();
83 83
diff --git a/crates/ra_ide/src/inlay_hints.rs b/crates/ra_ide/src/inlay_hints.rs
index 59922e14c..ecd615cf4 100644
--- a/crates/ra_ide/src/inlay_hints.rs
+++ b/crates/ra_ide/src/inlay_hints.rs
@@ -11,13 +11,13 @@ use ra_syntax::{
11use crate::{FileId, FunctionSignature}; 11use crate::{FileId, FunctionSignature};
12 12
13#[derive(Clone, Debug, PartialEq, Eq)] 13#[derive(Clone, Debug, PartialEq, Eq)]
14pub struct InlayConfig { 14pub struct InlayHintsOptions {
15 pub type_hints: bool, 15 pub type_hints: bool,
16 pub parameter_hints: bool, 16 pub parameter_hints: bool,
17 pub max_length: Option<usize>, 17 pub max_length: Option<usize>,
18} 18}
19 19
20impl Default for InlayConfig { 20impl Default for InlayHintsOptions {
21 fn default() -> Self { 21 fn default() -> Self {
22 Self { type_hints: true, parameter_hints: true, max_length: None } 22 Self { type_hints: true, parameter_hints: true, max_length: None }
23 } 23 }
@@ -39,7 +39,7 @@ pub struct InlayHint {
39pub(crate) fn inlay_hints( 39pub(crate) fn inlay_hints(
40 db: &RootDatabase, 40 db: &RootDatabase,
41 file_id: FileId, 41 file_id: FileId,
42 inlay_hint_opts: &InlayConfig, 42 options: &InlayHintsOptions,
43) -> Vec<InlayHint> { 43) -> Vec<InlayHint> {
44 let _p = profile("inlay_hints"); 44 let _p = profile("inlay_hints");
45 let sema = Semantics::new(db); 45 let sema = Semantics::new(db);
@@ -49,9 +49,9 @@ pub(crate) fn inlay_hints(
49 for node in file.syntax().descendants() { 49 for node in file.syntax().descendants() {
50 match_ast! { 50 match_ast! {
51 match node { 51 match node {
52 ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, inlay_hint_opts, ast::Expr::from(it)); }, 52 ast::CallExpr(it) => { get_param_name_hints(&mut res, &sema, options, ast::Expr::from(it)); },
53 ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, inlay_hint_opts, ast::Expr::from(it)); }, 53 ast::MethodCallExpr(it) => { get_param_name_hints(&mut res, &sema, options, ast::Expr::from(it)); },
54 ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, inlay_hint_opts, it); }, 54 ast::BindPat(it) => { get_bind_pat_hints(&mut res, &sema, options, it); },
55 _ => (), 55 _ => (),
56 } 56 }
57 } 57 }
@@ -62,10 +62,10 @@ pub(crate) fn inlay_hints(
62fn get_param_name_hints( 62fn get_param_name_hints(
63 acc: &mut Vec<InlayHint>, 63 acc: &mut Vec<InlayHint>,
64 sema: &Semantics<RootDatabase>, 64 sema: &Semantics<RootDatabase>,
65 inlay_hint_opts: &InlayConfig, 65 options: &InlayHintsOptions,
66 expr: ast::Expr, 66 expr: ast::Expr,
67) -> Option<()> { 67) -> Option<()> {
68 if !inlay_hint_opts.parameter_hints { 68 if !options.parameter_hints {
69 return None; 69 return None;
70 } 70 }
71 71
@@ -102,10 +102,10 @@ fn get_param_name_hints(
102fn get_bind_pat_hints( 102fn get_bind_pat_hints(
103 acc: &mut Vec<InlayHint>, 103 acc: &mut Vec<InlayHint>,
104 sema: &Semantics<RootDatabase>, 104 sema: &Semantics<RootDatabase>,
105 inlay_hint_opts: &InlayConfig, 105 options: &InlayHintsOptions,
106 pat: ast::BindPat, 106 pat: ast::BindPat,
107) -> Option<()> { 107) -> Option<()> {
108 if !inlay_hint_opts.type_hints { 108 if !options.type_hints {
109 return None; 109 return None;
110 } 110 }
111 111
@@ -118,7 +118,7 @@ fn get_bind_pat_hints(
118 acc.push(InlayHint { 118 acc.push(InlayHint {
119 range: pat.syntax().text_range(), 119 range: pat.syntax().text_range(),
120 kind: InlayKind::TypeHint, 120 kind: InlayKind::TypeHint,
121 label: ty.display_truncated(sema.db, inlay_hint_opts.max_length).to_string().into(), 121 label: ty.display_truncated(sema.db, options.max_length).to_string().into(),
122 }); 122 });
123 Some(()) 123 Some(())
124} 124}
@@ -224,7 +224,7 @@ fn get_fn_signature(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<
224 224
225#[cfg(test)] 225#[cfg(test)]
226mod tests { 226mod tests {
227 use crate::inlay_hints::InlayConfig; 227 use crate::inlay_hints::InlayHintsOptions;
228 use insta::assert_debug_snapshot; 228 use insta::assert_debug_snapshot;
229 229
230 use crate::mock_analysis::single_file; 230 use crate::mock_analysis::single_file;
@@ -238,7 +238,7 @@ mod tests {
238 let _x = foo(4, 4); 238 let _x = foo(4, 4);
239 }"#, 239 }"#,
240 ); 240 );
241 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ parameter_hints: true, type_hints: false, max_length: None}).unwrap(), @r###" 241 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ parameter_hints: true, type_hints: false, max_length: None}).unwrap(), @r###"
242 [ 242 [
243 InlayHint { 243 InlayHint {
244 range: [106; 107), 244 range: [106; 107),
@@ -262,7 +262,7 @@ mod tests {
262 let _x = foo(4, 4); 262 let _x = foo(4, 4);
263 }"#, 263 }"#,
264 ); 264 );
265 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ type_hints: false, parameter_hints: false, max_length: None}).unwrap(), @r###"[]"###); 265 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ type_hints: false, parameter_hints: false, max_length: None}).unwrap(), @r###"[]"###);
266 } 266 }
267 267
268 #[test] 268 #[test]
@@ -274,7 +274,7 @@ mod tests {
274 let _x = foo(4, 4); 274 let _x = foo(4, 4);
275 }"#, 275 }"#,
276 ); 276 );
277 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig{ type_hints: true, parameter_hints: false, max_length: None}).unwrap(), @r###" 277 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions{ type_hints: true, parameter_hints: false, max_length: None}).unwrap(), @r###"
278 [ 278 [
279 InlayHint { 279 InlayHint {
280 range: [97; 99), 280 range: [97; 99),
@@ -298,7 +298,7 @@ fn main() {
298}"#, 298}"#,
299 ); 299 );
300 300
301 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 301 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
302 [ 302 [
303 InlayHint { 303 InlayHint {
304 range: [69; 71), 304 range: [69; 71),
@@ -355,7 +355,7 @@ fn main() {
355}"#, 355}"#,
356 ); 356 );
357 357
358 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 358 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
359 [ 359 [
360 InlayHint { 360 InlayHint {
361 range: [193; 197), 361 range: [193; 197),
@@ -435,7 +435,7 @@ fn main() {
435}"#, 435}"#,
436 ); 436 );
437 437
438 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 438 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
439 [ 439 [
440 InlayHint { 440 InlayHint {
441 range: [21; 30), 441 range: [21; 30),
@@ -499,7 +499,7 @@ fn main() {
499}"#, 499}"#,
500 ); 500 );
501 501
502 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 502 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
503 [ 503 [
504 InlayHint { 504 InlayHint {
505 range: [21; 30), 505 range: [21; 30),
@@ -549,7 +549,7 @@ fn main() {
549}"#, 549}"#,
550 ); 550 );
551 551
552 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 552 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
553 [ 553 [
554 InlayHint { 554 InlayHint {
555 range: [188; 192), 555 range: [188; 192),
@@ -644,7 +644,7 @@ fn main() {
644}"#, 644}"#,
645 ); 645 );
646 646
647 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 647 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
648 [ 648 [
649 InlayHint { 649 InlayHint {
650 range: [188; 192), 650 range: [188; 192),
@@ -739,7 +739,7 @@ fn main() {
739}"#, 739}"#,
740 ); 740 );
741 741
742 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 742 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
743 [ 743 [
744 InlayHint { 744 InlayHint {
745 range: [252; 256), 745 range: [252; 256),
@@ -811,7 +811,7 @@ fn main() {
811}"#, 811}"#,
812 ); 812 );
813 813
814 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" 814 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
815 [ 815 [
816 InlayHint { 816 InlayHint {
817 range: [74; 75), 817 range: [74; 75),
@@ -899,7 +899,7 @@ fn main() {
899}"#, 899}"#,
900 ); 900 );
901 901
902 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig::default()).unwrap(), @r###" 902 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions::default()).unwrap(), @r###"
903 [ 903 [
904 InlayHint { 904 InlayHint {
905 range: [798; 809), 905 range: [798; 809),
@@ -1021,7 +1021,7 @@ fn main() {
1021}"#, 1021}"#,
1022 ); 1022 );
1023 1023
1024 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" 1024 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
1025 [] 1025 []
1026 "### 1026 "###
1027 ); 1027 );
@@ -1047,7 +1047,7 @@ fn main() {
1047}"#, 1047}"#,
1048 ); 1048 );
1049 1049
1050 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayConfig { max_length: Some(8), ..Default::default() }).unwrap(), @r###" 1050 assert_debug_snapshot!(analysis.inlay_hints(file_id, &InlayHintsOptions { max_length: Some(8), ..Default::default() }).unwrap(), @r###"
1051 [] 1051 []
1052 "### 1052 "###
1053 ); 1053 );
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 922e4caa8..e9af80b6c 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -68,7 +68,7 @@ pub use crate::{
68 expand_macro::ExpandedMacro, 68 expand_macro::ExpandedMacro,
69 folding_ranges::{Fold, FoldKind}, 69 folding_ranges::{Fold, FoldKind},
70 hover::HoverResult, 70 hover::HoverResult,
71 inlay_hints::{InlayConfig, InlayHint, InlayKind}, 71 inlay_hints::{InlayHint, InlayHintsOptions, InlayKind},
72 references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult}, 72 references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
73 runnables::{Runnable, RunnableKind, TestId}, 73 runnables::{Runnable, RunnableKind, TestId},
74 source_change::{FileSystemEdit, SourceChange, SourceFileEdit}, 74 source_change::{FileSystemEdit, SourceChange, SourceFileEdit},
@@ -319,7 +319,7 @@ impl Analysis {
319 pub fn inlay_hints( 319 pub fn inlay_hints(
320 &self, 320 &self,
321 file_id: FileId, 321 file_id: FileId,
322 inlay_hint_opts: &InlayConfig, 322 inlay_hint_opts: &InlayHintsOptions,
323 ) -> Cancelable<Vec<InlayHint>> { 323 ) -> Cancelable<Vec<InlayHint>> {
324 self.with_db(|db| inlay_hints::inlay_hints(db, file_id, inlay_hint_opts)) 324 self.with_db(|db| inlay_hints::inlay_hints(db, file_id, inlay_hint_opts))
325 } 325 }
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index bd5904db0..084e17b04 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -7,8 +7,6 @@
7//! configure the server itself, feature flags are passed into analysis, and 7//! configure the server itself, feature flags are passed into analysis, and
8//! tweak things like automatic insertion of `()` in completions. 8//! tweak things like automatic insertion of `()` in completions.
9 9
10use crate::req::InlayConfigDef;
11use ra_ide::InlayConfig;
12use rustc_hash::FxHashMap; 10use rustc_hash::FxHashMap;
13 11
14use ra_project_model::CargoFeatures; 12use ra_project_model::CargoFeatures;
@@ -32,8 +30,11 @@ pub struct ServerConfig {
32 30
33 pub lru_capacity: Option<usize>, 31 pub lru_capacity: Option<usize>,
34 32
35 #[serde(with = "InlayConfigDef")] 33 #[serde(deserialize_with = "nullable_bool_true")]
36 pub inlay_hints: InlayConfig, 34 pub inlay_hints_type: bool,
35 #[serde(deserialize_with = "nullable_bool_true")]
36 pub inlay_hints_parameter: bool,
37 pub inlay_hints_max_length: Option<usize>,
37 38
38 pub cargo_watch_enable: bool, 39 pub cargo_watch_enable: bool,
39 pub cargo_watch_args: Vec<String>, 40 pub cargo_watch_args: Vec<String>,
@@ -63,7 +64,9 @@ impl Default for ServerConfig {
63 exclude_globs: Vec::new(), 64 exclude_globs: Vec::new(),
64 use_client_watching: false, 65 use_client_watching: false,
65 lru_capacity: None, 66 lru_capacity: None,
66 inlay_hints: Default::default(), 67 inlay_hints_type: true,
68 inlay_hints_parameter: true,
69 inlay_hints_max_length: None,
67 cargo_watch_enable: true, 70 cargo_watch_enable: true,
68 cargo_watch_args: Vec::new(), 71 cargo_watch_args: Vec::new(),
69 cargo_watch_command: "check".to_string(), 72 cargo_watch_command: "check".to_string(),
diff --git a/crates/rust-analyzer/src/conv.rs b/crates/rust-analyzer/src/conv.rs
index a2d68c344..fd4657d7e 100644
--- a/crates/rust-analyzer/src/conv.rs
+++ b/crates/rust-analyzer/src/conv.rs
@@ -11,8 +11,8 @@ use lsp_types::{
11use ra_ide::{ 11use ra_ide::{
12 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, 12 translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition,
13 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag, 13 FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HighlightModifier, HighlightTag,
14 InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, ReferenceAccess, Severity, 14 InlayHint, InlayKind, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo,
15 SourceChange, SourceFileEdit, 15 ReferenceAccess, Severity, SourceChange, SourceFileEdit,
16}; 16};
17use ra_syntax::{SyntaxKind, TextRange, TextUnit}; 17use ra_syntax::{SyntaxKind, TextRange, TextUnit};
18use ra_text_edit::{AtomTextEdit, TextEdit}; 18use ra_text_edit::{AtomTextEdit, TextEdit};
@@ -323,6 +323,20 @@ impl ConvWith<&FoldConvCtx<'_>> for Fold {
323 } 323 }
324} 324}
325 325
326impl ConvWith<&LineIndex> for InlayHint {
327 type Output = req::InlayHint;
328 fn conv_with(self, line_index: &LineIndex) -> Self::Output {
329 req::InlayHint {
330 label: self.label.to_string(),
331 range: self.range.conv_with(line_index),
332 kind: match self.kind {
333 InlayKind::ParameterHint => req::InlayKind::ParameterHint,
334 InlayKind::TypeHint => req::InlayKind::TypeHint,
335 },
336 }
337 }
338}
339
326impl Conv for Highlight { 340impl Conv for Highlight {
327 type Output = (u32, u32); 341 type Output = (u32, u32);
328 342
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 495056da3..2b3b16d35 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -18,7 +18,7 @@ use crossbeam_channel::{select, unbounded, RecvError, Sender};
18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response}; 18use lsp_server::{Connection, ErrorCode, Message, Notification, Request, RequestId, Response};
19use lsp_types::{ClientCapabilities, NumberOrString}; 19use lsp_types::{ClientCapabilities, NumberOrString};
20use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask}; 20use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckTask};
21use ra_ide::{Canceled, FileId, LibraryData, SourceRootId}; 21use ra_ide::{Canceled, FileId, InlayHintsOptions, LibraryData, SourceRootId};
22use ra_prof::profile; 22use ra_prof::profile;
23use ra_vfs::{VfsFile, VfsTask, Watch}; 23use ra_vfs::{VfsFile, VfsTask, Watch};
24use relative_path::RelativePathBuf; 24use relative_path::RelativePathBuf;
@@ -177,7 +177,11 @@ pub fn main_loop(
177 .and_then(|it| it.folding_range.as_ref()) 177 .and_then(|it| it.folding_range.as_ref())
178 .and_then(|it| it.line_folding_only) 178 .and_then(|it| it.line_folding_only)
179 .unwrap_or(false), 179 .unwrap_or(false),
180 inlay_hints: config.inlay_hints, 180 inlay_hints: InlayHintsOptions {
181 type_hints: config.inlay_hints_type,
182 parameter_hints: config.inlay_hints_parameter,
183 max_length: config.inlay_hints_max_length,
184 },
181 cargo_watch: CheckOptions { 185 cargo_watch: CheckOptions {
182 enable: config.cargo_watch_enable, 186 enable: config.cargo_watch_enable,
183 args: config.cargo_watch_args, 187 args: config.cargo_watch_args,
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 921990da0..6482f3b77 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -999,11 +999,7 @@ pub fn handle_inlay_hints(
999 Ok(analysis 999 Ok(analysis
1000 .inlay_hints(file_id, &world.options.inlay_hints)? 1000 .inlay_hints(file_id, &world.options.inlay_hints)?
1001 .into_iter() 1001 .into_iter()
1002 .map(|api_type| InlayHint { 1002 .map_conv_with(&line_index)
1003 label: api_type.label.to_string(),
1004 range: api_type.range.conv_with(&line_index),
1005 kind: api_type.kind,
1006 })
1007 .collect()) 1003 .collect())
1008} 1004}
1009 1005
diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs
index 1dcab2703..a3efe3b9f 100644
--- a/crates/rust-analyzer/src/req.rs
+++ b/crates/rust-analyzer/src/req.rs
@@ -4,8 +4,6 @@ use lsp_types::{Location, Position, Range, TextDocumentIdentifier, Url};
4use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
5use serde::{Deserialize, Serialize}; 5use serde::{Deserialize, Serialize};
6 6
7use ra_ide::{InlayConfig, InlayKind};
8
9pub use lsp_types::{ 7pub use lsp_types::{
10 notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, 8 notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
11 CodeLensParams, CompletionParams, CompletionResponse, DiagnosticTag, 9 CodeLensParams, CompletionParams, CompletionResponse, DiagnosticTag,
@@ -198,24 +196,14 @@ pub struct InlayHintsParams {
198} 196}
199 197
200#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)] 198#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
201#[serde(remote = "InlayKind")] 199pub enum InlayKind {
202pub enum InlayKindDef {
203 TypeHint, 200 TypeHint,
204 ParameterHint, 201 ParameterHint,
205} 202}
206 203
207#[derive(Deserialize)]
208#[serde(remote = "InlayConfig", rename_all = "camelCase")]
209pub struct InlayConfigDef {
210 pub type_hints: bool,
211 pub parameter_hints: bool,
212 pub max_length: Option<usize>,
213}
214
215#[derive(Debug, Deserialize, Serialize)] 204#[derive(Debug, Deserialize, Serialize)]
216pub struct InlayHint { 205pub struct InlayHint {
217 pub range: Range, 206 pub range: Range,
218 #[serde(with = "InlayKindDef")]
219 pub kind: InlayKind, 207 pub kind: InlayKind,
220 pub label: String, 208 pub label: String,
221} 209}
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs
index d358f6b47..058ce2af8 100644
--- a/crates/rust-analyzer/src/world.rs
+++ b/crates/rust-analyzer/src/world.rs
@@ -13,7 +13,7 @@ use lsp_types::Url;
13use parking_lot::RwLock; 13use parking_lot::RwLock;
14use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher}; 14use ra_cargo_watch::{url_from_path_with_drive_lowercasing, CheckOptions, CheckWatcher};
15use ra_ide::{ 15use ra_ide::{
16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayConfig, LibraryData, 16 Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, InlayHintsOptions, LibraryData,
17 SourceRootId, 17 SourceRootId,
18}; 18};
19use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; 19use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace};
@@ -35,7 +35,7 @@ pub struct Options {
35 pub publish_decorations: bool, 35 pub publish_decorations: bool,
36 pub supports_location_link: bool, 36 pub supports_location_link: bool,
37 pub line_folding_only: bool, 37 pub line_folding_only: bool,
38 pub inlay_hints: InlayConfig, 38 pub inlay_hints: InlayHintsOptions,
39 pub rustfmt_args: Vec<String>, 39 pub rustfmt_args: Vec<String>,
40 pub cargo_watch: CheckOptions, 40 pub cargo_watch: CheckOptions,
41} 41}
diff --git a/docs/user/features.md b/docs/user/features.md
index 06bc7ded5..45360c633 100644
--- a/docs/user/features.md
+++ b/docs/user/features.md
@@ -191,8 +191,9 @@ Two types of inlay hints are displayed currently:
191 191
192In VS Code, the following settings can be used to configure the inlay hints: 192In VS Code, the following settings can be used to configure the inlay hints:
193 193
194* `rust-analyzer.inlayHintOpts.displayType` configure which types of inlay hints are shown. 194* `rust-analyzer.inlayHints.typeHints` - enable hints for inferred types.
195* `rust-analyzer.inlayHintOpts.maxLength` — shortens the hints if their length exceeds the value specified. If no value is specified (`null`), no shortening is applied. 195* `rust-analyzer.inlayHints.parameterHints` - enable hints for function parameters.
196* `rust-analyzer.inlayHints.maxLength` — shortens the hints if their length exceeds the value specified. If no value is specified (`null`), no shortening is applied.
196 197
197**Note:** VS Code does not have native support for inlay hints [yet](https://github.com/microsoft/vscode/issues/16221) and the hints are implemented using decorations. 198**Note:** VS Code does not have native support for inlay hints [yet](https://github.com/microsoft/vscode/issues/16221) and the hints are implemented using decorations.
198This approach has limitations, the caret movement and bracket highlighting near the edges of the hint may be weird: 199This approach has limitations, the caret movement and bracket highlighting near the edges of the hint may be weird:
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index e9f261c24..b2c830b30 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -29,11 +29,16 @@ export async function createClient(config: Config, serverPath: string): Promise<
29 initializationOptions: { 29 initializationOptions: {
30 publishDecorations: !config.highlightingSemanticTokens, 30 publishDecorations: !config.highlightingSemanticTokens,
31 lruCapacity: config.lruCapacity, 31 lruCapacity: config.lruCapacity,
32 inlayHints: config.inlayHints, 32
33 inlayHintsType: config.inlayHints.typeHints,
34 inlayHintsParameter: config.inlayHints.parameterHints,
35 inlayHintsMaxLength: config.inlayHints.maxLength,
36
33 cargoWatchEnable: cargoWatchOpts.enable, 37 cargoWatchEnable: cargoWatchOpts.enable,
34 cargoWatchArgs: cargoWatchOpts.arguments, 38 cargoWatchArgs: cargoWatchOpts.arguments,
35 cargoWatchCommand: cargoWatchOpts.command, 39 cargoWatchCommand: cargoWatchOpts.command,
36 cargoWatchAllTargets: cargoWatchOpts.allTargets, 40 cargoWatchAllTargets: cargoWatchOpts.allTargets,
41
37 excludeGlobs: config.excludeGlobs, 42 excludeGlobs: config.excludeGlobs,
38 useClientWatching: config.useClientWatching, 43 useClientWatching: config.useClientWatching,
39 featureFlags: config.featureFlags, 44 featureFlags: config.featureFlags,