diff options
author | Emil Lauridsen <[email protected]> | 2019-11-18 17:02:28 +0000 |
---|---|---|
committer | Emil Lauridsen <[email protected]> | 2019-11-19 16:23:50 +0000 |
commit | dadad36bb9770f9b13ed84bc219ea0168a7a5bf1 (patch) | |
tree | 00051540da204b4294501f3c56960975177ae502 /crates/ra_lsp_server | |
parent | c24ee0990486b04723534f072d7a58e829bbd1bd (diff) |
Move type inlay hint truncation to language server
This commit implements a general truncation framework for HirFormatter
that keeps track of how much has been output so far. This information
can then be used to perform truncation inside the language server,
instead of relying on the client.
Initial support is implemented for truncating types hints using the
maxInlayHintLength server config option. The existing solution in the
VSCode extension has been removed in favor of letting the server
truncate type hints.
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/config.rs | 3 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 1 |
4 files changed, 6 insertions, 1 deletions
diff --git a/crates/ra_lsp_server/src/config.rs b/crates/ra_lsp_server/src/config.rs index 9871a3b37..8045f3d60 100644 --- a/crates/ra_lsp_server/src/config.rs +++ b/crates/ra_lsp_server/src/config.rs | |||
@@ -29,6 +29,8 @@ pub struct ServerConfig { | |||
29 | 29 | ||
30 | pub lru_capacity: Option<usize>, | 30 | pub lru_capacity: Option<usize>, |
31 | 31 | ||
32 | pub max_inlay_hint_length: Option<usize>, | ||
33 | |||
32 | /// For internal usage to make integrated tests faster. | 34 | /// For internal usage to make integrated tests faster. |
33 | #[serde(deserialize_with = "nullable_bool_true")] | 35 | #[serde(deserialize_with = "nullable_bool_true")] |
34 | pub with_sysroot: bool, | 36 | pub with_sysroot: bool, |
@@ -44,6 +46,7 @@ impl Default for ServerConfig { | |||
44 | exclude_globs: Vec::new(), | 46 | exclude_globs: Vec::new(), |
45 | use_client_watching: false, | 47 | use_client_watching: false, |
46 | lru_capacity: None, | 48 | lru_capacity: None, |
49 | max_inlay_hint_length: None, | ||
47 | with_sysroot: true, | 50 | with_sysroot: true, |
48 | feature_flags: FxHashMap::default(), | 51 | feature_flags: FxHashMap::default(), |
49 | } | 52 | } |
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 379dab438..3e2ac3683 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -123,6 +123,7 @@ pub fn main_loop( | |||
123 | .and_then(|it| it.folding_range.as_ref()) | 123 | .and_then(|it| it.folding_range.as_ref()) |
124 | .and_then(|it| it.line_folding_only) | 124 | .and_then(|it| it.line_folding_only) |
125 | .unwrap_or(false), | 125 | .unwrap_or(false), |
126 | max_inlay_hint_length: config.max_inlay_hint_length, | ||
126 | } | 127 | } |
127 | }; | 128 | }; |
128 | 129 | ||
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 20f9aee13..7347a78c7 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -870,7 +870,7 @@ pub fn handle_inlay_hints( | |||
870 | let analysis = world.analysis(); | 870 | let analysis = world.analysis(); |
871 | let line_index = analysis.file_line_index(file_id)?; | 871 | let line_index = analysis.file_line_index(file_id)?; |
872 | Ok(analysis | 872 | Ok(analysis |
873 | .inlay_hints(file_id)? | 873 | .inlay_hints(file_id, world.options.max_inlay_hint_length)? |
874 | .into_iter() | 874 | .into_iter() |
875 | .map(|api_type| InlayHint { | 875 | .map(|api_type| InlayHint { |
876 | label: api_type.label.to_string(), | 876 | label: api_type.label.to_string(), |
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index 51824e7a3..9bdea70c7 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -28,6 +28,7 @@ pub struct Options { | |||
28 | pub publish_decorations: bool, | 28 | pub publish_decorations: bool, |
29 | pub supports_location_link: bool, | 29 | pub supports_location_link: bool, |
30 | pub line_folding_only: bool, | 30 | pub line_folding_only: bool, |
31 | pub max_inlay_hint_length: Option<usize>, | ||
31 | } | 32 | } |
32 | 33 | ||
33 | /// `WorldState` is the primary mutable state of the language server | 34 | /// `WorldState` is the primary mutable state of the language server |