aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-02 13:05:46 +0100
committerGitHub <[email protected]>2020-04-02 13:05:46 +0100
commit3c9e9d3f3ebbc7a22d932dd2a3fd63f1e44c4568 (patch)
tree0dbb6b8c37601a7d0c617a1d88a342b8f4c97a32 /crates
parent9ee96dcf4a2b47a6df0e3ea379d36aec2e6e1784 (diff)
parent7a4ebd2c8dfee8ca15dab7ba053a6521840aa5e3 (diff)
Merge #3824
3824: New config names r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/rust-analyzer/src/config.rs119
-rw-r--r--crates/rust-analyzer/src/main_loop.rs28
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs30
-rw-r--r--crates/rust-analyzer/src/req.rs4
4 files changed, 98 insertions, 83 deletions
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 602423919..f3d8773cc 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -16,20 +16,33 @@ use serde::Deserialize;
16#[derive(Debug, Clone)] 16#[derive(Debug, Clone)]
17pub struct Config { 17pub struct Config {
18 pub client_caps: ClientCapsConfig, 18 pub client_caps: ClientCapsConfig,
19
20 pub with_sysroot: bool,
19 pub publish_diagnostics: bool, 21 pub publish_diagnostics: bool,
22 pub lru_capacity: Option<usize>,
23 pub proc_macro_srv: Option<String>,
24 pub files: FilesConfig,
20 pub notifications: NotificationsConfig, 25 pub notifications: NotificationsConfig,
26
27 pub cargo: CargoConfig,
28 pub rustfmt: RustfmtConfig,
29 pub check: Option<FlycheckConfig>,
30
21 pub inlay_hints: InlayHintsConfig, 31 pub inlay_hints: InlayHintsConfig,
22 pub completion: CompletionConfig, 32 pub completion: CompletionConfig,
23 pub call_info_full: bool, 33 pub call_info_full: bool,
24 pub rustfmt: RustfmtConfig, 34}
25 pub check: Option<FlycheckConfig>, 35
26 pub vscode_lldb: bool, 36#[derive(Debug, Clone)]
27 pub proc_macro_srv: Option<String>, 37pub struct FilesConfig {
28 pub lru_capacity: Option<usize>, 38 pub watcher: FilesWatcher,
29 pub use_client_watching: bool, 39 pub exclude: Vec<String>,
30 pub exclude_globs: Vec<String>, 40}
31 pub cargo: CargoConfig, 41
32 pub with_sysroot: bool, 42#[derive(Debug, Clone)]
43pub enum FilesWatcher {
44 Client,
45 Notify,
33} 46}
34 47
35#[derive(Debug, Clone)] 48#[derive(Debug, Clone)]
@@ -59,12 +72,26 @@ pub struct ClientCapsConfig {
59impl Default for Config { 72impl Default for Config {
60 fn default() -> Self { 73 fn default() -> Self {
61 Config { 74 Config {
75 client_caps: ClientCapsConfig::default(),
76
77 with_sysroot: true,
62 publish_diagnostics: true, 78 publish_diagnostics: true,
79 lru_capacity: None,
80 proc_macro_srv: None,
81 files: FilesConfig { watcher: FilesWatcher::Notify, exclude: Vec::new() },
63 notifications: NotificationsConfig { 82 notifications: NotificationsConfig {
64 workspace_loaded: true, 83 workspace_loaded: true,
65 cargo_toml_not_found: true, 84 cargo_toml_not_found: true,
66 }, 85 },
67 client_caps: ClientCapsConfig::default(), 86
87 cargo: CargoConfig::default(),
88 rustfmt: RustfmtConfig::Rustfmt { extra_args: Vec::new() },
89 check: Some(FlycheckConfig::CargoCommand {
90 command: "check".to_string(),
91 all_targets: true,
92 extra_args: Vec::new(),
93 }),
94
68 inlay_hints: InlayHintsConfig { 95 inlay_hints: InlayHintsConfig {
69 type_hints: true, 96 type_hints: true,
70 parameter_hints: true, 97 parameter_hints: true,
@@ -77,19 +104,6 @@ impl Default for Config {
77 add_call_argument_snippets: true, 104 add_call_argument_snippets: true,
78 }, 105 },
79 call_info_full: true, 106 call_info_full: true,
80 rustfmt: RustfmtConfig::Rustfmt { extra_args: Vec::new() },
81 check: Some(FlycheckConfig::CargoCommand {
82 command: "check".to_string(),
83 all_targets: true,
84 extra_args: Vec::new(),
85 }),
86 vscode_lldb: false,
87 proc_macro_srv: None,
88 lru_capacity: None,
89 use_client_watching: false,
90 exclude_globs: Vec::new(),
91 cargo: CargoConfig::default(),
92 with_sysroot: true,
93 } 107 }
94 } 108 }
95} 109}
@@ -103,45 +117,44 @@ impl Config {
103 *self = Default::default(); 117 *self = Default::default();
104 self.client_caps = client_caps; 118 self.client_caps = client_caps;
105 119
106 set(value, "/excludeGlobs", &mut self.exclude_globs); 120 set(value, "/withSysroot", &mut self.with_sysroot);
107 set(value, "/useClientWatching", &mut self.use_client_watching); 121 set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics);
108 set(value, "/lruCapacity", &mut self.lru_capacity); 122 set(value, "/lruCapacity", &mut self.lru_capacity);
123 if let Some(watcher) = get::<String>(value, "/files/watcher") {
124 self.files.watcher = match watcher.as_str() {
125 "client" => FilesWatcher::Client,
126 "notify"| _ => FilesWatcher::Notify,
127 }
128 }
129 set(value, "/notifications/workspaceLoaded", &mut self.notifications.workspace_loaded);
130 set(value, "/notifications/cargoTomlNotFound", &mut self.notifications.cargo_toml_not_found);
109 131
110 set(value, "/inlayHintsType", &mut self.inlay_hints.type_hints); 132 set(value, "/cargo/noDefaultFeatures", &mut self.cargo.no_default_features);
111 set(value, "/inlayHintsParameter", &mut self.inlay_hints.parameter_hints); 133 set(value, "/cargo/allFeatures", &mut self.cargo.all_features);
112 set(value, "/inlayHintsChaining", &mut self.inlay_hints.chaining_hints); 134 set(value, "/cargo/features", &mut self.cargo.features);
113 set(value, "/inlayHintsMaxLength", &mut self.inlay_hints.max_length); 135 set(value, "/cargo/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
114 136 if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt {
115 if let Some(false) = get(value, "cargo_watch_enable") { 137 set(value, "/rustfmt/extraArgs", extra_args);
138 }
139 if let Some(false) = get(value, "/checkOnSave/enable") {
116 self.check = None 140 self.check = None
117 } else { 141 } else {
118 if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) = &mut self.check 142 if let Some(FlycheckConfig::CargoCommand { command, extra_args, all_targets }) = &mut self.check
119 { 143 {
120 set(value, "/cargoWatchArgs", extra_args); 144 set(value, "/checkOnSave/extraArgs", extra_args);
121 set(value, "/cargoWatchCommand", command); 145 set(value, "/checkOnSave/command", command);
122 set(value, "/cargoWatchAllTargets", all_targets); 146 set(value, "/checkOnSave/allTargets", all_targets);
123 } 147 }
124 }; 148 };
125 149
126 set(value, "/withSysroot", &mut self.with_sysroot); 150 set(value, "/inlayHints/typeHints", &mut self.inlay_hints.type_hints);
127 if let RustfmtConfig::Rustfmt { extra_args } = &mut self.rustfmt { 151 set(value, "/inlayHints/parameterHints", &mut self.inlay_hints.parameter_hints);
128 set(value, "/rustfmtArgs", extra_args); 152 set(value, "/inlayHints/chainingHints", &mut self.inlay_hints.chaining_hints);
129 } 153 set(value, "/inlayHints/maxLength", &mut self.inlay_hints.max_length);
130 154 set(value, "/completion/postfix/enable", &mut self.completion.enable_postfix_completions);
131 set(value, "/cargoFeatures/noDefaultFeatures", &mut self.cargo.no_default_features); 155 set(value, "/completion/addCallParenthesis", &mut self.completion.add_call_parenthesis);
132 set(value, "/cargoFeatures/allFeatures", &mut self.cargo.all_features); 156 set(value, "/completion/addCallArgumentSnippets", &mut self.completion.add_call_argument_snippets);
133 set(value, "/cargoFeatures/features", &mut self.cargo.features); 157 set(value, "/callInfo/full", &mut self.call_info_full);
134 set(value, "/cargoFeatures/loadOutDirsFromCheck", &mut self.cargo.load_out_dirs_from_check);
135
136 set(value, "/vscodeLldb", &mut self.vscode_lldb);
137
138 set(value, "/featureFlags/lsp.diagnostics", &mut self.publish_diagnostics);
139 set(value, "/featureFlags/notifications.workspace-loaded", &mut self.notifications.workspace_loaded);
140 set(value, "/featureFlags/notifications.cargo-toml-not-found", &mut self.notifications.cargo_toml_not_found);
141 set(value, "/featureFlags/completion.enable-postfix", &mut self.completion.enable_postfix_completions);
142 set(value, "/featureFlags/completion.insertion.add-call-parenthesis", &mut self.completion.add_call_parenthesis);
143 set(value, "/featureFlags/completion.insertion.add-argument-snippets", &mut self.completion.add_call_argument_snippets);
144 set(value, "/featureFlags/call-info.full", &mut self.call_info_full);
145 158
146 log::info!("Config::update() = {:#?}", self); 159 log::info!("Config::update() = {:#?}", self);
147 160
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 47fef59d4..95e676e0f 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -30,7 +30,7 @@ use serde::{de::DeserializeOwned, Serialize};
30use threadpool::ThreadPool; 30use threadpool::ThreadPool;
31 31
32use crate::{ 32use crate::{
33 config::Config, 33 config::{Config, FilesWatcher},
34 diagnostics::DiagnosticTask, 34 diagnostics::DiagnosticTask,
35 main_loop::{ 35 main_loop::{
36 pending_requests::{PendingRequest, PendingRequests}, 36 pending_requests::{PendingRequest, PendingRequests},
@@ -40,7 +40,6 @@ use crate::{
40 world::{WorldSnapshot, WorldState}, 40 world::{WorldSnapshot, WorldState},
41 Result, 41 Result,
42}; 42};
43use req::ConfigurationParams;
44 43
45#[derive(Debug)] 44#[derive(Debug)]
46pub struct LspError { 45pub struct LspError {
@@ -122,12 +121,13 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
122 }; 121 };
123 122
124 let globs = config 123 let globs = config
125 .exclude_globs 124 .files
125 .exclude
126 .iter() 126 .iter()
127 .map(|glob| crate::vfs_glob::Glob::new(glob)) 127 .map(|glob| crate::vfs_glob::Glob::new(glob))
128 .collect::<std::result::Result<Vec<_>, _>>()?; 128 .collect::<std::result::Result<Vec<_>, _>>()?;
129 129
130 if config.use_client_watching { 130 if let FilesWatcher::Client = config.files.watcher {
131 let registration_options = req::DidChangeWatchedFilesRegistrationOptions { 131 let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
132 watchers: workspaces 132 watchers: workspaces
133 .iter() 133 .iter()
@@ -153,7 +153,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
153 workspaces, 153 workspaces,
154 config.lru_capacity, 154 config.lru_capacity,
155 &globs, 155 &globs,
156 Watch(!config.use_client_watching), 156 Watch(matches!(config.files.watcher, FilesWatcher::Notify)),
157 config, 157 config,
158 ) 158 )
159 }; 159 };
@@ -607,7 +607,12 @@ fn on_notification(
607 let request_id = loop_state.next_request_id(); 607 let request_id = loop_state.next_request_id();
608 let request = request_new::<req::WorkspaceConfiguration>( 608 let request = request_new::<req::WorkspaceConfiguration>(
609 request_id.clone(), 609 request_id.clone(),
610 ConfigurationParams::default(), 610 req::ConfigurationParams {
611 items: vec![req::ConfigurationItem {
612 scope_uri: None,
613 section: Some("rust-analyzer".to_string()),
614 }],
615 },
611 ); 616 );
612 msg_sender.send(request.into())?; 617 msg_sender.send(request.into())?;
613 loop_state.configuration_request_id = Some(request_id); 618 loop_state.configuration_request_id = Some(request_id);
@@ -884,10 +889,9 @@ fn update_file_notifications_on_threadpool(
884 subscriptions: Vec<FileId>, 889 subscriptions: Vec<FileId>,
885) { 890) {
886 log::trace!("updating notifications for {:?}", subscriptions); 891 log::trace!("updating notifications for {:?}", subscriptions);
887 let publish_diagnostics = world.config.publish_diagnostics; 892 if world.config.publish_diagnostics {
888 pool.execute(move || { 893 pool.execute(move || {
889 for file_id in subscriptions { 894 for file_id in subscriptions {
890 if publish_diagnostics {
891 match handlers::publish_diagnostics(&world, file_id) { 895 match handlers::publish_diagnostics(&world, file_id) {
892 Err(e) => { 896 Err(e) => {
893 if !is_canceled(&e) { 897 if !is_canceled(&e) {
@@ -899,8 +903,8 @@ fn update_file_notifications_on_threadpool(
899 } 903 }
900 } 904 }
901 } 905 }
902 } 906 })
903 }); 907 }
904} 908}
905 909
906pub fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Sender<Message>) { 910pub fn show_message(typ: req::MessageType, message: impl Into<String>, sender: &Sender<Message>) {
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index db620dca3..b207f0764 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -810,23 +810,21 @@ pub fn handle_code_lens(
810 }; 810 };
811 lenses.push(lens); 811 lenses.push(lens);
812 812
813 if world.config.vscode_lldb { 813 if r.args[0] == "run" {
814 if r.args[0] == "run" { 814 r.args[0] = "build".into();
815 r.args[0] = "build".into(); 815 } else {
816 } else { 816 r.args.push("--no-run".into());
817 r.args.push("--no-run".into());
818 }
819 let debug_lens = CodeLens {
820 range: r.range,
821 command: Some(Command {
822 title: "Debug".into(),
823 command: "rust-analyzer.debugSingle".into(),
824 arguments: Some(vec![to_value(r).unwrap()]),
825 }),
826 data: None,
827 };
828 lenses.push(debug_lens);
829 } 817 }
818 let debug_lens = CodeLens {
819 range: r.range,
820 command: Some(Command {
821 title: "Debug".into(),
822 command: "rust-analyzer.debugSingle".into(),
823 arguments: Some(vec![to_value(r).unwrap()]),
824 }),
825 data: None,
826 };
827 lenses.push(debug_lens);
830 } 828 }
831 829
832 // Handle impls 830 // Handle impls
diff --git a/crates/rust-analyzer/src/req.rs b/crates/rust-analyzer/src/req.rs
index ce799a683..b8b627e28 100644
--- a/crates/rust-analyzer/src/req.rs
+++ b/crates/rust-analyzer/src/req.rs
@@ -6,8 +6,8 @@ use serde::{Deserialize, Serialize};
6 6
7pub use lsp_types::{ 7pub use lsp_types::{
8 notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens, 8 notification::*, request::*, ApplyWorkspaceEditParams, CodeActionParams, CodeLens,
9 CodeLensParams, CompletionParams, CompletionResponse, ConfigurationParams, DiagnosticTag, 9 CodeLensParams, CompletionParams, CompletionResponse, ConfigurationItem, ConfigurationParams,
10 DidChangeConfigurationParams, DidChangeWatchedFilesParams, 10 DiagnosticTag, DidChangeConfigurationParams, DidChangeWatchedFilesParams,
11 DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams, 11 DidChangeWatchedFilesRegistrationOptions, DocumentOnTypeFormattingParams, DocumentSymbolParams,
12 DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType, 12 DocumentSymbolResponse, FileSystemWatcher, Hover, InitializeResult, MessageType,
13 PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken, 13 PartialResultParams, ProgressParams, ProgressParamsValue, ProgressToken,