diff options
Diffstat (limited to 'crates/rust-analyzer/src/config.rs')
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index a3866c1ba..339014fd3 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -24,7 +24,8 @@ use vfs::AbsPathBuf; | |||
24 | 24 | ||
25 | use crate::{ | 25 | use crate::{ |
26 | caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfig, | 26 | caps::completion_item_edit_resolve, diagnostics::DiagnosticsMapConfig, |
27 | line_index::OffsetEncoding, lsp_ext::supports_utf8, | 27 | line_index::OffsetEncoding, lsp_ext::supports_utf8, lsp_ext::WorkspaceSymbolSearchKind, |
28 | lsp_ext::WorkspaceSymbolSearchScope, | ||
28 | }; | 29 | }; |
29 | 30 | ||
30 | // Defines the server-side configuration of the rust-analyzer. We generate | 31 | // Defines the server-side configuration of the rust-analyzer. We generate |
@@ -215,6 +216,11 @@ config_data! { | |||
215 | /// Advanced option, fully override the command rust-analyzer uses for | 216 | /// Advanced option, fully override the command rust-analyzer uses for |
216 | /// formatting. | 217 | /// formatting. |
217 | rustfmt_overrideCommand: Option<Vec<String>> = "null", | 218 | rustfmt_overrideCommand: Option<Vec<String>> = "null", |
219 | |||
220 | /// Workspace symbol search scope. | ||
221 | workspace_symbol_search_scope: WorskpaceSymbolSearchScopeDef = "\"workspace\"", | ||
222 | /// Workspace symbol search kind. | ||
223 | workspace_symbol_search_kind: WorskpaceSymbolSearchKindDef = "\"only_types\"", | ||
218 | } | 224 | } |
219 | } | 225 | } |
220 | 226 | ||
@@ -309,6 +315,15 @@ pub struct RunnablesConfig { | |||
309 | pub cargo_extra_args: Vec<String>, | 315 | pub cargo_extra_args: Vec<String>, |
310 | } | 316 | } |
311 | 317 | ||
318 | /// Configuration for workspace symbol search requests. | ||
319 | #[derive(Debug, Clone)] | ||
320 | pub struct WorkspaceSymbolConfig { | ||
321 | /// In what scope should the symbol be searched in. | ||
322 | pub search_scope: WorkspaceSymbolSearchScope, | ||
323 | /// What kind of symbol is being search for. | ||
324 | pub search_kind: WorkspaceSymbolSearchKind, | ||
325 | } | ||
326 | |||
312 | impl Config { | 327 | impl Config { |
313 | pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self { | 328 | pub fn new(root_path: AbsPathBuf, caps: ClientCapabilities) -> Self { |
314 | Config { caps, data: ConfigData::default(), discovered_projects: None, root_path } | 329 | Config { caps, data: ConfigData::default(), discovered_projects: None, root_path } |
@@ -687,6 +702,22 @@ impl Config { | |||
687 | .contains(&MarkupKind::Markdown), | 702 | .contains(&MarkupKind::Markdown), |
688 | } | 703 | } |
689 | } | 704 | } |
705 | |||
706 | pub fn workspace_symbol(&self) -> WorkspaceSymbolConfig { | ||
707 | WorkspaceSymbolConfig { | ||
708 | search_scope: match self.data.workspace_symbol_search_scope { | ||
709 | WorskpaceSymbolSearchScopeDef::Workspace => WorkspaceSymbolSearchScope::Workspace, | ||
710 | WorskpaceSymbolSearchScopeDef::WorkspaceAndDependencies => { | ||
711 | WorkspaceSymbolSearchScope::WorkspaceAndDependencies | ||
712 | } | ||
713 | }, | ||
714 | search_kind: match self.data.workspace_symbol_search_kind { | ||
715 | WorskpaceSymbolSearchKindDef::OnlyTypes => WorkspaceSymbolSearchKind::OnlyTypes, | ||
716 | WorskpaceSymbolSearchKindDef::AllSymbols => WorkspaceSymbolSearchKind::AllSymbols, | ||
717 | }, | ||
718 | } | ||
719 | } | ||
720 | |||
690 | pub fn semantic_tokens_refresh(&self) -> bool { | 721 | pub fn semantic_tokens_refresh(&self) -> bool { |
691 | try_or!(self.caps.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?, false) | 722 | try_or!(self.caps.workspace.as_ref()?.semantic_tokens.as_ref()?.refresh_support?, false) |
692 | } | 723 | } |
@@ -733,6 +764,20 @@ enum ImportPrefixDef { | |||
733 | ByCrate, | 764 | ByCrate, |
734 | } | 765 | } |
735 | 766 | ||
767 | #[derive(Deserialize, Debug, Clone)] | ||
768 | #[serde(rename_all = "snake_case")] | ||
769 | enum WorskpaceSymbolSearchScopeDef { | ||
770 | Workspace, | ||
771 | WorkspaceAndDependencies, | ||
772 | } | ||
773 | |||
774 | #[derive(Deserialize, Debug, Clone)] | ||
775 | #[serde(rename_all = "snake_case")] | ||
776 | enum WorskpaceSymbolSearchKindDef { | ||
777 | OnlyTypes, | ||
778 | AllSymbols, | ||
779 | } | ||
780 | |||
736 | macro_rules! _config_data { | 781 | macro_rules! _config_data { |
737 | (struct $name:ident { | 782 | (struct $name:ident { |
738 | $( | 783 | $( |
@@ -903,6 +948,22 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json | |||
903 | "type": "array", | 948 | "type": "array", |
904 | "items": { "type": ["string", "object"] }, | 949 | "items": { "type": ["string", "object"] }, |
905 | }, | 950 | }, |
951 | "WorskpaceSymbolSearchScopeDef" => set! { | ||
952 | "type": "string", | ||
953 | "enum": ["workspace", "workspace_and_dependencies"], | ||
954 | "enumDescriptions": [ | ||
955 | "Search in current workspace only", | ||
956 | "Search in current workspace and dependencies" | ||
957 | ], | ||
958 | }, | ||
959 | "WorskpaceSymbolSearchKindDef" => set! { | ||
960 | "type": "string", | ||
961 | "enum": ["only_types", "all_symbols"], | ||
962 | "enumDescriptions": [ | ||
963 | "Search for types only", | ||
964 | "Search for all symbols kinds" | ||
965 | ], | ||
966 | }, | ||
906 | _ => panic!("{}: {}", ty, default), | 967 | _ => panic!("{}: {}", ty, default), |
907 | } | 968 | } |
908 | 969 | ||