aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-06-21 20:41:06 +0100
committerLukas Wirth <[email protected]>2021-06-21 20:47:54 +0100
commit99c95b8fa15f2d9239625c19463f552c84ad99a2 (patch)
tree1ce5b6d19086eefba3585306bf794f4ddc86a858 /crates/rust-analyzer
parent8b3d93ee29619c090878679d06477fe9d32bc14d (diff)
Split hover actions config into its own config struct
Diffstat (limited to 'crates/rust-analyzer')
-rw-r--r--crates/rust-analyzer/src/config.rs50
-rw-r--r--crates/rust-analyzer/src/handlers.rs24
2 files changed, 53 insertions, 21 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3aeca8839..de70959a5 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -32,6 +32,9 @@ use crate::{
32// 32//
33// However, editor specific config, which the server doesn't know about, should 33// However, editor specific config, which the server doesn't know about, should
34// be specified directly in `package.json`. 34// be specified directly in `package.json`.
35//
36// To deprecate an option by replacing it with another name use `new_name | `old_name` so that we keep
37// parsing the old name.
35config_data! { 38config_data! {
36 struct ConfigData { 39 struct ConfigData {
37 /// How imports should be grouped into use statements. 40 /// How imports should be grouped into use statements.
@@ -309,6 +312,37 @@ impl LensConfig {
309 } 312 }
310} 313}
311 314
315#[derive(Clone, Debug, PartialEq, Eq)]
316pub struct HoverActionsConfig {
317 pub implementations: bool,
318 pub references: bool,
319 pub run: bool,
320 pub debug: bool,
321 pub goto_type_def: bool,
322}
323
324impl HoverActionsConfig {
325 pub const NO_ACTIONS: Self = Self {
326 implementations: false,
327 references: false,
328 run: false,
329 debug: false,
330 goto_type_def: false,
331 };
332
333 pub fn any(&self) -> bool {
334 self.implementations || self.references || self.runnable() || self.goto_type_def
335 }
336
337 pub fn none(&self) -> bool {
338 !self.any()
339 }
340
341 pub fn runnable(&self) -> bool {
342 self.run || self.debug
343 }
344}
345
312#[derive(Debug, Clone)] 346#[derive(Debug, Clone)]
313pub struct FilesConfig { 347pub struct FilesConfig {
314 pub watcher: FilesWatcher, 348 pub watcher: FilesWatcher,
@@ -527,7 +561,7 @@ impl Config {
527 pub fn code_action_group(&self) -> bool { 561 pub fn code_action_group(&self) -> bool {
528 self.experimental("codeActionGroup") 562 self.experimental("codeActionGroup")
529 } 563 }
530 pub fn hover_actions(&self) -> bool { 564 pub fn experimental_hover_actions(&self) -> bool {
531 self.experimental("hoverActions") 565 self.experimental("hoverActions")
532 } 566 }
533 pub fn server_status_notification(&self) -> bool { 567 pub fn server_status_notification(&self) -> bool {
@@ -727,17 +761,21 @@ impl Config {
727 refs: self.data.lens_enable && self.data.lens_references, 761 refs: self.data.lens_enable && self.data.lens_references,
728 } 762 }
729 } 763 }
730 pub fn highlighting_strings(&self) -> bool { 764 pub fn hover_actions(&self) -> HoverActionsConfig {
731 self.data.highlighting_strings 765 HoverActionsConfig {
732 }
733 pub fn hover(&self) -> HoverConfig {
734 HoverConfig {
735 implementations: self.data.hoverActions_enable 766 implementations: self.data.hoverActions_enable
736 && self.data.hoverActions_implementations, 767 && self.data.hoverActions_implementations,
737 references: self.data.hoverActions_enable && self.data.hoverActions_references, 768 references: self.data.hoverActions_enable && self.data.hoverActions_references,
738 run: self.data.hoverActions_enable && self.data.hoverActions_run, 769 run: self.data.hoverActions_enable && self.data.hoverActions_run,
739 debug: self.data.hoverActions_enable && self.data.hoverActions_debug, 770 debug: self.data.hoverActions_enable && self.data.hoverActions_debug,
740 goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef, 771 goto_type_def: self.data.hoverActions_enable && self.data.hoverActions_gotoTypeDef,
772 }
773 }
774 pub fn highlighting_strings(&self) -> bool {
775 self.data.highlighting_strings
776 }
777 pub fn hover(&self) -> HoverConfig {
778 HoverConfig {
741 links_in_hover: self.data.hover_linksInHover, 779 links_in_hover: self.data.hover_linksInHover,
742 markdown: try_or!( 780 markdown: try_or!(
743 self.caps 781 self.caps
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index eff1e6c93..dcead5f5c 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -861,13 +861,7 @@ pub(crate) fn handle_hover(
861) -> Result<Option<lsp_ext::Hover>> { 861) -> Result<Option<lsp_ext::Hover>> {
862 let _p = profile::span("handle_hover"); 862 let _p = profile::span("handle_hover");
863 let position = from_proto::file_position(&snap, params.text_document_position_params)?; 863 let position = from_proto::file_position(&snap, params.text_document_position_params)?;
864 let hover_config = snap.config.hover(); 864 let info = match snap.analysis.hover(position, &snap.config.hover())? {
865 let info = match snap.analysis.hover(
866 position,
867 hover_config.links_in_hover,
868 hover_config.documentation,
869 hover_config.markdown,
870 )? {
871 None => return Ok(None), 865 None => return Ok(None),
872 Some(info) => info, 866 Some(info) => info,
873 }; 867 };
@@ -1487,7 +1481,7 @@ fn show_impl_command_link(
1487 snap: &GlobalStateSnapshot, 1481 snap: &GlobalStateSnapshot,
1488 position: &FilePosition, 1482 position: &FilePosition,
1489) -> Option<lsp_ext::CommandLinkGroup> { 1483) -> Option<lsp_ext::CommandLinkGroup> {
1490 if snap.config.hover().implementations { 1484 if snap.config.hover_actions().implementations {
1491 if let Some(nav_data) = snap.analysis.goto_implementation(*position).unwrap_or(None) { 1485 if let Some(nav_data) = snap.analysis.goto_implementation(*position).unwrap_or(None) {
1492 let uri = to_proto::url(snap, position.file_id); 1486 let uri = to_proto::url(snap, position.file_id);
1493 let line_index = snap.file_line_index(position.file_id).ok()?; 1487 let line_index = snap.file_line_index(position.file_id).ok()?;
@@ -1513,7 +1507,7 @@ fn show_ref_command_link(
1513 snap: &GlobalStateSnapshot, 1507 snap: &GlobalStateSnapshot,
1514 position: &FilePosition, 1508 position: &FilePosition,
1515) -> Option<lsp_ext::CommandLinkGroup> { 1509) -> Option<lsp_ext::CommandLinkGroup> {
1516 if snap.config.hover().references { 1510 if snap.config.hover_actions().references {
1517 if let Some(ref_search_res) = snap.analysis.find_all_refs(*position, None).unwrap_or(None) { 1511 if let Some(ref_search_res) = snap.analysis.find_all_refs(*position, None).unwrap_or(None) {
1518 let uri = to_proto::url(snap, position.file_id); 1512 let uri = to_proto::url(snap, position.file_id);
1519 let line_index = snap.file_line_index(position.file_id).ok()?; 1513 let line_index = snap.file_line_index(position.file_id).ok()?;
@@ -1544,8 +1538,8 @@ fn runnable_action_links(
1544 runnable: Runnable, 1538 runnable: Runnable,
1545) -> Option<lsp_ext::CommandLinkGroup> { 1539) -> Option<lsp_ext::CommandLinkGroup> {
1546 let cargo_spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id).ok()?; 1540 let cargo_spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id).ok()?;
1547 let hover_config = snap.config.hover(); 1541 let hover_actions_config = snap.config.hover_actions();
1548 if !hover_config.runnable() || should_skip_target(&runnable, cargo_spec.as_ref()) { 1542 if !hover_actions_config.runnable() || should_skip_target(&runnable, cargo_spec.as_ref()) {
1549 return None; 1543 return None;
1550 } 1544 }
1551 1545
@@ -1553,12 +1547,12 @@ fn runnable_action_links(
1553 to_proto::runnable(snap, runnable).ok().map(|r| { 1547 to_proto::runnable(snap, runnable).ok().map(|r| {
1554 let mut group = lsp_ext::CommandLinkGroup::default(); 1548 let mut group = lsp_ext::CommandLinkGroup::default();
1555 1549
1556 if hover_config.run { 1550 if hover_actions_config.run {
1557 let run_command = to_proto::command::run_single(&r, action.run_title); 1551 let run_command = to_proto::command::run_single(&r, action.run_title);
1558 group.commands.push(to_command_link(run_command, r.label.clone())); 1552 group.commands.push(to_command_link(run_command, r.label.clone()));
1559 } 1553 }
1560 1554
1561 if hover_config.debug { 1555 if hover_actions_config.debug {
1562 let dbg_command = to_proto::command::debug_single(&r); 1556 let dbg_command = to_proto::command::debug_single(&r);
1563 group.commands.push(to_command_link(dbg_command, r.label)); 1557 group.commands.push(to_command_link(dbg_command, r.label));
1564 } 1558 }
@@ -1571,7 +1565,7 @@ fn goto_type_action_links(
1571 snap: &GlobalStateSnapshot, 1565 snap: &GlobalStateSnapshot,
1572 nav_targets: &[HoverGotoTypeData], 1566 nav_targets: &[HoverGotoTypeData],
1573) -> Option<lsp_ext::CommandLinkGroup> { 1567) -> Option<lsp_ext::CommandLinkGroup> {
1574 if !snap.config.hover().goto_type_def || nav_targets.is_empty() { 1568 if !snap.config.hover_actions().goto_type_def || nav_targets.is_empty() {
1575 return None; 1569 return None;
1576 } 1570 }
1577 1571
@@ -1591,7 +1585,7 @@ fn prepare_hover_actions(
1591 snap: &GlobalStateSnapshot, 1585 snap: &GlobalStateSnapshot,
1592 actions: &[HoverAction], 1586 actions: &[HoverAction],
1593) -> Vec<lsp_ext::CommandLinkGroup> { 1587) -> Vec<lsp_ext::CommandLinkGroup> {
1594 if snap.config.hover().no_actions() || !snap.config.hover_actions() { 1588 if snap.config.hover_actions().none() || !snap.config.experimental_hover_actions() {
1595 return Vec::new(); 1589 return Vec::new();
1596 } 1590 }
1597 1591