Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 75e466f

Browse files
committed
Pull config from the client instead of using rls.toml
1 parent 931aba8 commit 75e466f

File tree

10 files changed

+221
-309
lines changed

10 files changed

+221
-309
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ build = "build.rs"
1313
cargo = { git = "https://github.com/rust-lang/cargo" }
1414
derive-new = "0.3"
1515
env_logger = "0.4"
16-
languageserver-types = "0.11"
16+
languageserver-types = "0.11.1"
1717
log = "0.3"
1818
racer = "2.0.6"
1919
rls-analysis = "0.4"

src/actions/mod.rs

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use vfs::{Vfs, Change, FileContents};
1616
use racer;
1717
use rustfmt::{Input as FmtInput, format_input};
1818
use rustfmt::file_lines::{Range as RustfmtRange, FileLines};
19-
use config::FmtConfig;
19+
use config::{Config, FmtConfig};
2020
use serde_json;
2121
use span;
2222
use Span;
@@ -42,19 +42,22 @@ pub struct ActionHandler {
4242
build_queue: Arc<BuildQueue>,
4343
current_project: Mutex<Option<PathBuf>>,
4444
previous_build_results: Arc<Mutex<BuildResults>>,
45+
config: Arc<Mutex<Config>>,
4546
fmt_config: Mutex<FmtConfig>,
4647
}
4748

4849
impl ActionHandler {
4950
pub fn new(analysis: Arc<AnalysisHost>,
50-
vfs: Arc<Vfs>,
51-
build_queue: Arc<BuildQueue>) -> ActionHandler {
51+
vfs: Arc<Vfs>) -> ActionHandler {
52+
let config = Arc::new(Mutex::new(Config::default()));
53+
let build_queue = Arc::new(BuildQueue::new(vfs.clone(), config.clone()));
5254
ActionHandler {
5355
analysis,
5456
vfs: vfs.clone(),
5557
build_queue,
5658
current_project: Mutex::new(None),
5759
previous_build_results: Arc::new(Mutex::new(HashMap::new())),
60+
config,
5861
fmt_config: Mutex::new(FmtConfig::default()),
5962
}
6063
}
@@ -77,10 +80,10 @@ impl ActionHandler {
7780
*current_project = Some(new_path);
7881
}
7982
}
80-
self.build(&root_path, BuildPriority::Immediate, out);
83+
self.build(&root_path, BuildPriority::Immediate, true, out);
8184
}
8285

83-
pub fn build<O: Output>(&self, project_path: &Path, priority: BuildPriority, out: O) {
86+
pub fn build<O: Output>(&self, project_path: &Path, priority: BuildPriority, force_clean: bool, out: O) {
8487
fn clear_build_results(results: &mut BuildResults) {
8588
// We must not clear the hashmap, just the values in each list.
8689
// This allows us to save allocated before memory.
@@ -138,14 +141,20 @@ impl ActionHandler {
138141
let previous_build_results = self.previous_build_results.clone();
139142
let project_path = project_path.to_owned();
140143
let out = out.clone();
144+
let show_warnings = {
145+
let config = self.config.lock().unwrap();
146+
config.show_warnings
147+
};
148+
149+
141150
thread::spawn(move || {
142151
// We use `rustDocument` document here since these notifications are
143152
// custom to the RLS and not part of the LS protocol.
144153
out.notify("rustDocument/diagnosticsBegin");
145154
// let start_time = ::std::time::Instant::now();
146155

147156
debug!("build {:?}", project_path);
148-
let result = build_queue.request_build(&project_path, priority);
157+
let result = build_queue.request_build(&project_path, priority, force_clean);
149158
match result {
150159
BuildResult::Success(messages, new_analysis) | BuildResult::Failure(messages, new_analysis) => {
151160
// eprintln!("built {:?}", start_time.elapsed());
@@ -155,11 +164,6 @@ impl ActionHandler {
155164
// which had errors, but now don't. This instructs the IDE to clear
156165
// errors for those files.
157166
let notifications = {
158-
let show_warnings = {
159-
let config = build_queue.config.lock().unwrap();
160-
config.show_warnings
161-
};
162-
163167
let mut results = previous_build_results.lock().unwrap();
164168
clear_build_results(&mut results);
165169
parse_compiler_messages(&messages, &mut results);
@@ -223,21 +227,21 @@ impl ActionHandler {
223227
}).collect();
224228
self.vfs.on_changes(&changes).expect("error committing to VFS");
225229

226-
self.build_current_project(BuildPriority::Normal, out);
230+
self.build_current_project(BuildPriority::Normal, false, out);
227231
}
228232

229233
pub fn on_save<O: Output>(&self, save: DidSaveTextDocumentParams, _out: O) {
230234
let fname = parse_file_path(&save.text_document.uri).unwrap();
231235
self.vfs.file_saved(&fname).unwrap();
232236
}
233237

234-
fn build_current_project<O: Output>(&self, priority: BuildPriority, out: O) {
238+
fn build_current_project<O: Output>(&self, priority: BuildPriority, force_clean: bool, out: O) {
235239
let current_project = {
236240
let current_project = self.current_project.lock().unwrap();
237241
current_project.clone()
238242
};
239243
match current_project {
240-
Some(ref current_project) => self.build(current_project, priority, out),
244+
Some(ref current_project) => self.build(current_project, priority, force_clean, out),
241245
None => debug!("build_current_project - no project path"),
242246
}
243247
}
@@ -619,18 +623,59 @@ impl ActionHandler {
619623
range: range_whole_file,
620624
new_text: text,
621625
}];
622-
out.success(id, ResponseData::TextEdit(result))
626+
out.success(id, ResponseData::TextEdit(result));
623627
} else {
624628
debug!("reformat: format_input failed: has errors, summary = {:?}", summary);
625629

626-
out.failure(id, "Reformat failed to complete successfully")
630+
out.failure(id, "Reformat failed to complete successfully");
627631
}
628632
}
629633
Err(e) => {
630634
debug!("Reformat failed: {:?}", e);
631-
out.failure(id, "Reformat failed to complete successfully")
635+
out.failure(id, "Reformat failed to complete successfully");
636+
}
637+
}
638+
}
639+
640+
pub fn on_change_config<O: Output>(&self, params: DidChangeConfigurationParams, out: O) {
641+
trace!("config change: {:?}", params.settings);
642+
if let Some(config) = params.settings.get("rust") {
643+
if let Ok(new_config) = serde_json::from_value(config.clone()): Result<Config, _> {
644+
let unstable_features = new_config.unstable_features;
645+
646+
{
647+
let mut config = self.config.lock().unwrap();
648+
*config = new_config;
649+
}
650+
// We do a clean build so that if we've changed any relevant options
651+
// for Cargo, we'll notice them. But if nothing relevant changes
652+
// then we don't do unnecessary building (i.e., we don't delete
653+
// artifacts on disk).
654+
self.build_current_project(BuildPriority::Immediate, true, out.clone());
655+
656+
const RANGE_FORMATTING_ID: &'static str = "rls-range-formatting";
657+
const RENAME_ID: &'static str = "rls-rename";
658+
// FIXME should handle the response
659+
if unstable_features {
660+
let output = serde_json::to_string(
661+
&RequestMessage::new(NOTIFICATION__RegisterCapability.to_owned(),
662+
RegistrationParams { registrations: vec![Registration { id: RANGE_FORMATTING_ID.to_owned(), method: REQUEST__RangeFormatting.to_owned(), register_options: serde_json::Value::Null },
663+
Registration { id: RENAME_ID.to_owned(), method: REQUEST__Rename.to_owned(), register_options: serde_json::Value::Null }] })
664+
).unwrap();
665+
out.response(output);
666+
} else {
667+
let output = serde_json::to_string(
668+
&RequestMessage::new(NOTIFICATION__UnregisterCapability.to_owned(),
669+
UnregistrationParams { unregisterations: vec![Unregistration { id: RANGE_FORMATTING_ID.to_owned(), method: REQUEST__RangeFormatting.to_owned() },
670+
Unregistration { id: RENAME_ID.to_owned(), method: REQUEST__Rename.to_owned() }] })
671+
).unwrap();
672+
out.response(output);
673+
}
674+
675+
return;
632676
}
633677
}
678+
debug!("Received unactionable config: {:?}", params.settings);
634679
}
635680

636681
fn convert_pos_to_span(&self, doc: &TextDocumentIdentifier, pos: Position) -> Span {

0 commit comments

Comments
 (0)