From 1067a1c5f649cc206e35b427eaa8d6553280cc96 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Thu, 3 Oct 2019 02:02:53 +0800 Subject: Read default cfgs from rustc --- crates/ra_lsp_server/Cargo.toml | 1 + crates/ra_lsp_server/src/world.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 677d81835..aedc55a95 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml @@ -19,6 +19,7 @@ jod-thread = "0.1.0" ra_vfs = "0.4.0" ra_syntax = { path = "../ra_syntax" } ra_db = { path = "../ra_db" } +ra_cfg = { path = "../ra_cfg" } ra_text_edit = { path = "../ra_text_edit" } ra_ide_api = { path = "../ra_ide_api" } lsp-server = "0.2.0" diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index b55046ec9..27da751ab 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -13,7 +13,7 @@ use ra_ide_api::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, FeatureFlags, FileId, LibraryData, SourceRootId, }; -use ra_project_model::ProjectWorkspace; +use ra_project_model::{get_rustc_cfg_options, ProjectWorkspace}; use ra_vfs::{LineEndings, RootEntry, Vfs, VfsChange, VfsFile, VfsRoot, VfsTask, Watch}; use ra_vfs_glob::{Glob, RustPackageFilterBuilder}; use relative_path::RelativePathBuf; @@ -97,6 +97,10 @@ impl WorldState { change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string()); } + // FIXME: Read default cfgs from config + let default_cfg_options = + get_rustc_cfg_options().atom("test".into()).atom("debug_assertion".into()); + // Create crate graph from all the workspaces let mut crate_graph = CrateGraph::default(); let mut load = |path: &std::path::Path| { @@ -104,7 +108,7 @@ impl WorldState { vfs_file.map(|f| FileId(f.0)) }; for ws in workspaces.iter() { - let (graph, crate_names) = ws.to_crate_graph(&mut load); + let (graph, crate_names) = ws.to_crate_graph(&default_cfg_options, &mut load); let shift = crate_graph.extend(graph); for (crate_id, name) in crate_names { change.set_debug_crate_name(crate_id.shift(shift), name) -- cgit v1.2.3 From c6303d9fee98232ac83a77f943c39d65c9c6b6db Mon Sep 17 00:00:00 2001 From: oxalica Date: Sat, 5 Oct 2019 20:55:27 +0800 Subject: Use raw cfgs in json project and fix typo --- crates/ra_lsp_server/tests/heavy_tests/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 152681062..2ba82ab05 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs @@ -286,7 +286,13 @@ fn test_missing_module_code_action_in_json_project() { let project = json!({ "roots": [path], - "crates": [ { "root_module": path.join("src/lib.rs"), "deps": [], "edition": "2015" } ] + "crates": [ { + "root_module": path.join("src/lib.rs"), + "deps": [], + "edition": "2015", + "atom_cfgs": [], + "key_value_cfgs": {} + } ] }); let code = format!( -- cgit v1.2.3