mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Cleanup project.json deserialization
This commit is contained in:
parent
a07cad16ab
commit
e6c61d5072
15 changed files with 141 additions and 144 deletions
|
@ -1,8 +1,7 @@
|
|||
//! See `CargoTargetSpec`
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use ra_cfg::CfgExpr;
|
||||
use ra_db::AbsPathBuf;
|
||||
use ra_ide::{FileId, RunnableKind, TestId};
|
||||
use ra_project_model::{self, TargetKind};
|
||||
|
||||
|
@ -14,7 +13,7 @@ use crate::{global_state::GlobalStateSnapshot, Result};
|
|||
/// build/test/run the target.
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct CargoTargetSpec {
|
||||
pub(crate) workspace_root: PathBuf,
|
||||
pub(crate) workspace_root: AbsPathBuf,
|
||||
pub(crate) package: String,
|
||||
pub(crate) target: String,
|
||||
pub(crate) target_kind: TargetKind,
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
//! Loads a Cargo project into a static instance of analysis, without support
|
||||
//! for incorporating changes.
|
||||
use std::{convert::TryFrom, path::Path, sync::Arc};
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use anyhow::Result;
|
||||
use crossbeam_channel::{unbounded, Receiver};
|
||||
use ra_db::{AbsPathBuf, CrateGraph};
|
||||
use ra_ide::{AnalysisChange, AnalysisHost};
|
||||
use ra_project_model::{CargoConfig, ProcMacroClient, ProjectManifest, ProjectWorkspace};
|
||||
use vfs::loader::Handle;
|
||||
use vfs::{loader::Handle, AbsPath};
|
||||
|
||||
use crate::global_state::{ProjectFolders, SourceRootConfig};
|
||||
|
||||
|
@ -39,10 +39,9 @@ pub fn load_cargo(
|
|||
ProcMacroClient::dummy()
|
||||
};
|
||||
|
||||
let crate_graph = ws.to_crate_graph(None, &proc_macro_client, &mut |path: &Path| {
|
||||
let path = AbsPathBuf::try_from(path.to_path_buf()).unwrap();
|
||||
let contents = loader.load_sync(&path);
|
||||
let path = vfs::VfsPath::from(path);
|
||||
let crate_graph = ws.to_crate_graph(None, &proc_macro_client, &mut |path: &AbsPath| {
|
||||
let contents = loader.load_sync(path);
|
||||
let path = vfs::VfsPath::from(path.to_path_buf());
|
||||
vfs.set_file_contents(path.clone(), contents);
|
||||
vfs.file_id(&path)
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ use lsp_types::ClientCapabilities;
|
|||
use ra_db::AbsPathBuf;
|
||||
use ra_flycheck::FlycheckConfig;
|
||||
use ra_ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig};
|
||||
use ra_project_model::{CargoConfig, ProjectJson, ProjectManifest};
|
||||
use ra_project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -273,19 +273,19 @@ impl Config {
|
|||
self.lens = LensConfig::NO_LENS;
|
||||
}
|
||||
|
||||
if let Some(linked_projects) = get::<Vec<ManifestOrJsonProject>>(value, "/linkedProjects") {
|
||||
if let Some(linked_projects) = get::<Vec<ManifestOrProjectJson>>(value, "/linkedProjects") {
|
||||
if !linked_projects.is_empty() {
|
||||
self.linked_projects.clear();
|
||||
for linked_project in linked_projects {
|
||||
let linked_project = match linked_project {
|
||||
ManifestOrJsonProject::Manifest(it) => {
|
||||
ManifestOrProjectJson::Manifest(it) => {
|
||||
let path = self.root_path.join(it);
|
||||
match ProjectManifest::from_manifest_file(path) {
|
||||
Ok(it) => it.into(),
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
ManifestOrJsonProject::JsonProject(it) => it.into(),
|
||||
ManifestOrProjectJson::ProjectJson(it) => ProjectJson::new(&self.root_path, it).into(),
|
||||
};
|
||||
self.linked_projects.push(linked_project);
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ impl Config {
|
|||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum ManifestOrJsonProject {
|
||||
enum ManifestOrProjectJson {
|
||||
Manifest(PathBuf),
|
||||
JsonProject(ProjectJson),
|
||||
ProjectJson(ProjectJsonData),
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//!
|
||||
//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
|
||||
|
||||
use std::{convert::TryFrom, path::Path, sync::Arc};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
|
||||
use crossbeam_channel::{unbounded, Receiver};
|
||||
use lsp_types::Url;
|
||||
|
@ -13,7 +13,7 @@ use ra_flycheck::{Flycheck, FlycheckConfig};
|
|||
use ra_ide::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId};
|
||||
use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target};
|
||||
use stdx::format_to;
|
||||
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPathBuf};
|
||||
use vfs::{file_set::FileSetConfig, loader::Handle, AbsPath, AbsPathBuf};
|
||||
|
||||
use crate::{
|
||||
config::{Config, FilesWatcher},
|
||||
|
@ -31,7 +31,7 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &FlycheckConfig) ->
|
|||
workspaces.iter().find_map(|w| match w {
|
||||
ProjectWorkspace::Cargo { cargo, .. } => {
|
||||
let cargo_project_root = cargo.workspace_root().to_path_buf();
|
||||
Some(Flycheck::new(config.clone(), cargo_project_root))
|
||||
Some(Flycheck::new(config.clone(), cargo_project_root.into()))
|
||||
}
|
||||
ProjectWorkspace::Json { .. } => {
|
||||
log::warn!("Cargo check watching only supported for cargo workspaces, disabling");
|
||||
|
@ -112,10 +112,9 @@ impl GlobalState {
|
|||
|
||||
// Create crate graph from all the workspaces
|
||||
let mut crate_graph = CrateGraph::default();
|
||||
let mut load = |path: &Path| {
|
||||
let path = AbsPathBuf::try_from(path.to_path_buf()).ok()?;
|
||||
let contents = loader.load_sync(&path);
|
||||
let path = vfs::VfsPath::from(path);
|
||||
let mut load = |path: &AbsPath| {
|
||||
let contents = loader.load_sync(path);
|
||||
let path = vfs::VfsPath::from(path.to_path_buf());
|
||||
vfs.set_file_contents(path.clone(), contents);
|
||||
vfs.file_id(&path)
|
||||
};
|
||||
|
|
|
@ -114,10 +114,7 @@ pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
|
|||
.ok()
|
||||
}
|
||||
LinkedProject::InlineJsonProject(it) => {
|
||||
Some(ra_project_model::ProjectWorkspace::Json {
|
||||
project: it.clone(),
|
||||
project_location: config.root_path.clone(),
|
||||
})
|
||||
Some(ra_project_model::ProjectWorkspace::Json { project: it.clone() })
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
|
|
|
@ -419,7 +419,7 @@ pub fn handle_runnables(
|
|||
location: None,
|
||||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: lsp_ext::CargoRunnable {
|
||||
workspace_root: Some(spec.workspace_root.clone()),
|
||||
workspace_root: Some(spec.workspace_root.clone().into()),
|
||||
cargo_args: vec![
|
||||
cmd.to_string(),
|
||||
"--package".to_string(),
|
||||
|
|
|
@ -663,7 +663,7 @@ pub(crate) fn runnable(
|
|||
location: Some(location),
|
||||
kind: lsp_ext::RunnableKind::Cargo,
|
||||
args: lsp_ext::CargoRunnable {
|
||||
workspace_root: workspace_root,
|
||||
workspace_root: workspace_root.map(|it| it.into()),
|
||||
cargo_args,
|
||||
executable_args,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue