mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Also reload when adding new examples, tests, etc
This commit is contained in:
parent
c1eed627d9
commit
86bc4d20b3
4 changed files with 58 additions and 11 deletions
|
@ -122,6 +122,9 @@ impl GlobalState {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn process_changes(&mut self) -> bool {
|
pub(crate) fn process_changes(&mut self) -> bool {
|
||||||
|
let mut fs_changes = Vec::new();
|
||||||
|
let mut has_fs_changes = false;
|
||||||
|
|
||||||
let change = {
|
let change = {
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
let (vfs, line_endings_map) = &mut *self.vfs.write();
|
let (vfs, line_endings_map) = &mut *self.vfs.write();
|
||||||
|
@ -130,13 +133,14 @@ impl GlobalState {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let fs_op = changed_files.iter().any(|it| it.is_created_or_deleted());
|
|
||||||
if fs_op {
|
|
||||||
let roots = self.source_root_config.partition(&vfs);
|
|
||||||
change.set_roots(roots)
|
|
||||||
}
|
|
||||||
|
|
||||||
for file in changed_files {
|
for file in changed_files {
|
||||||
|
if file.is_created_or_deleted() {
|
||||||
|
if let Some(path) = vfs.file_path(file.file_id).as_path() {
|
||||||
|
fs_changes.push((path.to_path_buf(), file.change_kind));
|
||||||
|
has_fs_changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let text = if file.exists() {
|
let text = if file.exists() {
|
||||||
let bytes = vfs.file_contents(file.file_id).to_vec();
|
let bytes = vfs.file_contents(file.file_id).to_vec();
|
||||||
match String::from_utf8(bytes).ok() {
|
match String::from_utf8(bytes).ok() {
|
||||||
|
@ -152,10 +156,15 @@ impl GlobalState {
|
||||||
};
|
};
|
||||||
change.change_file(file.file_id, text);
|
change.change_file(file.file_id, text);
|
||||||
}
|
}
|
||||||
|
if has_fs_changes {
|
||||||
|
let roots = self.source_root_config.partition(&vfs);
|
||||||
|
change.set_roots(roots);
|
||||||
|
}
|
||||||
change
|
change
|
||||||
};
|
};
|
||||||
|
|
||||||
self.analysis_host.apply_change(change);
|
self.analysis_host.apply_change(change);
|
||||||
|
self.maybe_refresh(&fs_changes);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ use crate::{
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
use ra_project_model::ProjectWorkspace;
|
use ra_project_model::ProjectWorkspace;
|
||||||
|
use vfs::ChangeKind;
|
||||||
|
|
||||||
pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
|
pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
|
||||||
log::info!("initial config: {:#?}", config);
|
log::info!("initial config: {:#?}", config);
|
||||||
|
@ -428,7 +429,9 @@ impl GlobalState {
|
||||||
if let Some(flycheck) = &this.flycheck {
|
if let Some(flycheck) = &this.flycheck {
|
||||||
flycheck.handle.update();
|
flycheck.handle.update();
|
||||||
}
|
}
|
||||||
this.maybe_refresh(params.text_document.uri.as_str());
|
if let Ok(abs_path) = from_proto::abs_path(¶ms.text_document.uri) {
|
||||||
|
this.maybe_refresh(&[(abs_path, ChangeKind::Modify)]);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
.on::<lsp_types::notification::DidChangeConfiguration>(|this, _params| {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use flycheck::FlycheckHandle;
|
||||||
use ra_db::{CrateGraph, SourceRoot, VfsPath};
|
use ra_db::{CrateGraph, SourceRoot, VfsPath};
|
||||||
use ra_ide::AnalysisChange;
|
use ra_ide::AnalysisChange;
|
||||||
use ra_project_model::{PackageRoot, ProcMacroClient, ProjectWorkspace};
|
use ra_project_model::{PackageRoot, ProcMacroClient, ProjectWorkspace};
|
||||||
use vfs::{file_set::FileSetConfig, AbsPath};
|
use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{Config, FilesWatcher, LinkedProject},
|
config::{Config, FilesWatcher, LinkedProject},
|
||||||
|
@ -27,8 +27,8 @@ impl GlobalState {
|
||||||
self.reload_flycheck();
|
self.reload_flycheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub(crate) fn maybe_refresh(&mut self, saved_doc_url: &str) {
|
pub(crate) fn maybe_refresh(&mut self, changes: &[(AbsPathBuf, ChangeKind)]) {
|
||||||
if !(saved_doc_url.ends_with("Cargo.toml") || saved_doc_url.ends_with("Cargo.lock")) {
|
if !changes.iter().any(|(path, kind)| is_interesting(path, *kind)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match self.status {
|
match self.status {
|
||||||
|
@ -40,6 +40,41 @@ impl GlobalState {
|
||||||
} else {
|
} else {
|
||||||
self.transition(Status::NeedsReload);
|
self.transition(Status::NeedsReload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_interesting(path: &AbsPath, change_kind: ChangeKind) -> bool {
|
||||||
|
const IMPLICIT_TARGET_FILES: &[&str] = &["build.rs", "src/main.rs", "src/lib.rs"];
|
||||||
|
const IMPLICIT_TARGET_DIRS: &[&str] = &["src/bin", "examples", "tests", "benches"];
|
||||||
|
|
||||||
|
if path.ends_with("Cargo.toml") || path.ends_with("Cargo.lock") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if change_kind == ChangeKind::Modify {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if path.extension().map(|it| it.to_str()) != Some("rs".into()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if IMPLICIT_TARGET_FILES.iter().any(|it| path.ends_with(it)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
let parent = match path.parent() {
|
||||||
|
Some(it) => it,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
if IMPLICIT_TARGET_DIRS.iter().any(|it| parent.ends_with(it)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if path.ends_with("main.rs") {
|
||||||
|
let grand_parent = match parent.parent() {
|
||||||
|
Some(it) => it,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
if IMPLICIT_TARGET_DIRS.iter().any(|it| grand_parent.ends_with(it)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub(crate) fn transition(&mut self, new_status: Status) {
|
pub(crate) fn transition(&mut self, new_status: Status) {
|
||||||
self.status = new_status;
|
self.status = new_status;
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl ChangedFile {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq)]
|
#[derive(Eq, PartialEq, Copy, Clone)]
|
||||||
pub enum ChangeKind {
|
pub enum ChangeKind {
|
||||||
Create,
|
Create,
|
||||||
Modify,
|
Modify,
|
||||||
|
|
Loading…
Reference in a new issue