Automatically reload project on config change

This commit is contained in:
Aleksey Kladov 2020-07-01 16:42:14 +02:00
parent 298adb27b9
commit a03cfa4926
3 changed files with 8 additions and 5 deletions

View File

@ -10,7 +10,7 @@
use stdx::split_delim; use stdx::split_delim;
/// Roots and crates that compose this Rust project. /// Roots and crates that compose this Rust project.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProjectJson { pub struct ProjectJson {
pub(crate) roots: Vec<Root>, pub(crate) roots: Vec<Root>,
pub(crate) crates: Vec<Crate>, pub(crate) crates: Vec<Crate>,
@ -18,14 +18,14 @@ pub struct ProjectJson {
/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
/// all roots. Roots might be nested. /// all roots. Roots might be nested.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct Root { pub struct Root {
pub(crate) path: AbsPathBuf, pub(crate) path: AbsPathBuf,
} }
/// A crate points to the root module of a crate and lists the dependencies of the crate. This is /// A crate points to the root module of a crate and lists the dependencies of the crate. This is
/// useful in creating the crate graph. /// useful in creating the crate graph.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct Crate { pub struct Crate {
pub(crate) root_module: AbsPathBuf, pub(crate) root_module: AbsPathBuf,
pub(crate) edition: Edition, pub(crate) edition: Edition,

View File

@ -44,7 +44,7 @@ pub struct Config {
pub root_path: AbsPathBuf, pub root_path: AbsPathBuf,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Eq, PartialEq)]
pub enum LinkedProject { pub enum LinkedProject {
ProjectManifest(ProjectManifest), ProjectManifest(ProjectManifest),
InlineJsonProject(ProjectJson), InlineJsonProject(ProjectJson),

View File

@ -19,11 +19,14 @@ pub(crate) fn update_configuration(&mut self, config: Config) {
if self.config.lru_capacity != old_config.lru_capacity { if self.config.lru_capacity != old_config.lru_capacity {
self.analysis_host.update_lru_capacity(old_config.lru_capacity); self.analysis_host.update_lru_capacity(old_config.lru_capacity);
} }
if self.config.flycheck != old_config.flycheck { if self.config.linked_projects != old_config.linked_projects {
self.reload()
} else if self.config.flycheck != old_config.flycheck {
self.reload_flycheck(); self.reload_flycheck();
} }
} }
pub(crate) fn reload(&mut self) { pub(crate) fn reload(&mut self) {
log::info!("reloading projects: {:?}", self.config.linked_projects);
let workspaces = { let workspaces = {
if self.config.linked_projects.is_empty() if self.config.linked_projects.is_empty()
&& self.config.notifications.cargo_toml_not_found && self.config.notifications.cargo_toml_not_found