Skip to content

Commit f39b51d

Browse files
bors[bot]matklad
andauthored
Merge #3809
3809: Less config r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents aaf100f + 1225f71 commit f39b51d

File tree

14 files changed

+196
-374
lines changed

14 files changed

+196
-374
lines changed

crates/ra_flycheck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::conv::{map_rust_diagnostic_to_lsp, MappedRustDiagnostic};
2222

2323
pub use crate::conv::url_from_path_with_drive_lowercasing;
2424

25-
#[derive(Clone, Debug)]
25+
#[derive(Clone, Debug, PartialEq, Eq)]
2626
pub enum FlycheckConfig {
2727
CargoCommand { command: String, all_targets: bool, extra_args: Vec<String> },
2828
CustomCommand { command: String, args: Vec<String> },

crates/ra_project_model/src/cargo_workspace.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use cargo_metadata::{BuildScript, CargoOpt, Message, MetadataCommand, PackageId}
1313
use ra_arena::{Arena, Idx};
1414
use ra_db::Edition;
1515
use rustc_hash::FxHashMap;
16-
use serde::Deserialize;
1716

1817
/// `CargoWorkspace` represents the logical structure of, well, a Cargo
1918
/// workspace. It pretty closely mirrors `cargo metadata` output.
@@ -43,9 +42,8 @@ impl ops::Index<Target> for CargoWorkspace {
4342
}
4443
}
4544

46-
#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
47-
#[serde(rename_all = "camelCase", default)]
48-
pub struct CargoFeatures {
45+
#[derive(Clone, Debug, PartialEq, Eq)]
46+
pub struct CargoConfig {
4947
/// Do not activate the `default` feature.
5048
pub no_default_features: bool,
5149

@@ -60,9 +58,9 @@ pub struct CargoFeatures {
6058
pub load_out_dirs_from_check: bool,
6159
}
6260

63-
impl Default for CargoFeatures {
61+
impl Default for CargoConfig {
6462
fn default() -> Self {
65-
CargoFeatures {
63+
CargoConfig {
6664
no_default_features: false,
6765
all_features: true,
6866
features: Vec::new(),
@@ -141,7 +139,7 @@ impl PackageData {
141139
impl CargoWorkspace {
142140
pub fn from_cargo_metadata(
143141
cargo_toml: &Path,
144-
cargo_features: &CargoFeatures,
142+
cargo_features: &CargoConfig,
145143
) -> Result<CargoWorkspace> {
146144
let mut meta = MetadataCommand::new();
147145
meta.manifest_path(cargo_toml);
@@ -275,7 +273,7 @@ pub struct ExternResources {
275273

276274
pub fn load_extern_resources(
277275
cargo_toml: &Path,
278-
cargo_features: &CargoFeatures,
276+
cargo_features: &CargoConfig,
279277
) -> Result<ExternResources> {
280278
let mut cmd = Command::new(cargo_binary());
281279
cmd.args(&["check", "--message-format=json", "--manifest-path"]).arg(cargo_toml);
@@ -293,9 +291,8 @@ pub fn load_extern_resources(
293291

294292
let mut res = ExternResources::default();
295293

296-
let stdout = String::from_utf8(output.stdout)?;
297-
for line in stdout.lines() {
298-
if let Ok(message) = serde_json::from_str::<cargo_metadata::Message>(&line) {
294+
for message in cargo_metadata::parse_messages(output.stdout.as_slice()) {
295+
if let Ok(message) = message {
299296
match message {
300297
Message::BuildScriptExecuted(BuildScript { package_id, out_dir, .. }) => {
301298
res.out_dirs.insert(package_id, out_dir);

crates/ra_project_model/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_hash::FxHashMap;
1919
use serde_json::from_reader;
2020

2121
pub use crate::{
22-
cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind},
22+
cargo_workspace::{CargoConfig, CargoWorkspace, Package, Target, TargetKind},
2323
json_project::JsonProject,
2424
sysroot::Sysroot,
2525
};
@@ -78,14 +78,14 @@ impl PackageRoot {
7878
}
7979

8080
impl ProjectWorkspace {
81-
pub fn discover(path: &Path, cargo_features: &CargoFeatures) -> Result<ProjectWorkspace> {
81+
pub fn discover(path: &Path, cargo_features: &CargoConfig) -> Result<ProjectWorkspace> {
8282
ProjectWorkspace::discover_with_sysroot(path, true, cargo_features)
8383
}
8484

8585
pub fn discover_with_sysroot(
8686
path: &Path,
8787
with_sysroot: bool,
88-
cargo_features: &CargoFeatures,
88+
cargo_features: &CargoConfig,
8989
) -> Result<ProjectWorkspace> {
9090
match find_rust_project_json(path) {
9191
Some(json_path) => {

crates/rust-analyzer/src/bin/main.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
mod args;
55

66
use lsp_server::Connection;
7-
8-
use rust_analyzer::{cli, from_json, show_message, Result, ServerConfig};
7+
use rust_analyzer::{cli, config::Config, from_json, Result};
98

109
use crate::args::HelpPrinted;
1110

@@ -78,24 +77,18 @@ fn run_server() -> Result<()> {
7877
.filter(|workspaces| !workspaces.is_empty())
7978
.unwrap_or_else(|| vec![root]);
8079

81-
let server_config = initialize_params
82-
.initialization_options
83-
.and_then(|v| {
84-
from_json::<ServerConfig>("config", v)
85-
.map_err(|e| {
86-
log::error!("{}", e);
87-
show_message(lsp_types::MessageType::Error, e.to_string(), &connection.sender);
88-
})
89-
.ok()
90-
})
91-
.unwrap_or_default();
80+
let config = {
81+
let mut config = Config::default();
82+
if let Some(value) = &initialize_params.initialization_options {
83+
config.update(value);
84+
}
85+
if let Some(caps) = &initialize_params.capabilities.text_document {
86+
config.update_caps(caps);
87+
}
88+
config
89+
};
9290

93-
rust_analyzer::main_loop(
94-
workspace_roots,
95-
initialize_params.capabilities,
96-
server_config,
97-
connection,
98-
)?;
91+
rust_analyzer::main_loop(workspace_roots, config, connection)?;
9992

10093
log::info!("shutting down IO...");
10194
io_threads.join()?;

crates/rust-analyzer/src/cli/load_cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crossbeam_channel::{unbounded, Receiver};
88
use ra_db::{ExternSourceId, FileId, SourceRootId};
99
use ra_ide::{AnalysisChange, AnalysisHost};
1010
use ra_project_model::{
11-
get_rustc_cfg_options, CargoFeatures, PackageRoot, ProcMacroClient, ProjectWorkspace,
11+
get_rustc_cfg_options, CargoConfig, PackageRoot, ProcMacroClient, ProjectWorkspace,
1212
};
1313
use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
1414
use rustc_hash::{FxHashMap, FxHashSet};
@@ -29,7 +29,7 @@ pub(crate) fn load_cargo(
2929
let root = std::env::current_dir()?.join(root);
3030
let ws = ProjectWorkspace::discover(
3131
root.as_ref(),
32-
&CargoFeatures { load_out_dirs_from_check, ..Default::default() },
32+
&CargoConfig { load_out_dirs_from_check, ..Default::default() },
3333
)?;
3434

3535
let mut extern_dirs = FxHashSet::default();

0 commit comments

Comments
 (0)