aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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--editors/code/src/client.ts7
6 files changed, 38 insertions, 28 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index a6f832ed7..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::InlayHintsOptions;
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: InlayHintsOptions, 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 fa7a42099..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::{InlayHintsOptions, 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/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,