Skip to content

Commit

Permalink
Automatically reload project on config change
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jul 1, 2020
1 parent 298adb2 commit a03cfa4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions crates/ra_project_model/src/project_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ use serde::{de, Deserialize};
use stdx::split_delim;

/// Roots and crates that compose this Rust project.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ProjectJson {
pub(crate) roots: Vec<Root>,
pub(crate) crates: Vec<Crate>,
}

/// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
/// all roots. Roots might be nested.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Root {
pub(crate) path: AbsPathBuf,
}

/// 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.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Crate {
pub(crate) root_module: AbsPathBuf,
pub(crate) edition: Edition,
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct Config {
pub root_path: AbsPathBuf,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum LinkedProject {
ProjectManifest(ProjectManifest),
InlineJsonProject(ProjectJson),
Expand Down
5 changes: 4 additions & 1 deletion crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ impl GlobalState {
if self.config.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();
}
}
pub(crate) fn reload(&mut self) {
log::info!("reloading projects: {:?}", self.config.linked_projects);
let workspaces = {
if self.config.linked_projects.is_empty()
&& self.config.notifications.cargo_toml_not_found
Expand Down

0 comments on commit a03cfa4

Please sign in to comment.