Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit ac50ecb

Browse files
committed
Track all Cargo.tomls, not just the top one
Closes #546
1 parent 04da9ed commit ac50ecb

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,28 @@ build = "build.rs"
1212
[dependencies]
1313
cargo = { git = "https://github.com/rust-lang/cargo", rev = "9e53ac6e6525da914cb05a85e5e8eff7b5dca81f" }
1414
cargo_metadata = "0.5.2"
15+
clippy_lints = { version = "0.0.200", optional = true }
1516
env_logger = "0.5"
1617
failure = "0.1.1"
1718
jsonrpc-core = "8.0.1"
1819
languageserver-types = "0.41"
1920
lazy_static = "1"
2021
log = "0.4"
22+
num_cpus = "1"
2123
racer = "2.0.14"
24+
rayon = "1"
2225
rls-analysis = "0.13"
2326
rls-blacklist = "0.1.2"
2427
rls-data = { version = "0.16", features = ["serialize-serde"] }
2528
rls-rustc = "0.2.1"
2629
rls-span = { version = "0.4", features = ["serialize-serde"] }
2730
rls-vfs = { version = "0.4.5", features = ["racer-impls"] }
2831
rustfmt-nightly = "0.7"
29-
clippy_lints = { version = "0.0.200", optional = true }
3032
serde = "1.0"
3133
serde_json = "1.0"
3234
serde_derive = "1.0"
3335
url = "1.1.0"
34-
rayon = "1"
35-
num_cpus = "1"
36+
walkdir = "2.1"
3637

3738
[dev-dependencies]
3839
json = "0.11"

src/actions/mod.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use serde_json;
1919
use url::Url;
2020
use span;
2121
use Span;
22+
use walkdir::WalkDir;
2223

2324
use actions::post_build::{BuildResults, PostBuildHandler, AnalysisQueue};
2425
use actions::progress::{BuildProgressNotifier, BuildDiagnosticsNotifier};
@@ -364,7 +365,6 @@ fn find_word_at_pos(line: &str, pos: &Column) -> (Column, Column) {
364365
)
365366
}
366367

367-
// TODO include workspace Cargo.tomls in watchers / relevant
368368
/// Client file-watching request / filtering logic
369369
/// We want to watch workspace 'Cargo.toml', root 'Cargo.lock' & the root 'target' dir
370370
pub struct FileWatch<'ctx> {
@@ -384,16 +384,37 @@ impl<'ctx> FileWatch<'ctx> {
384384
}
385385

386386
/// Returns json config for desired file watches
387-
pub fn watchers_config(&self) -> serde_json::Value {
388-
let cargo_toml_pattern = format!("{}/Cargo.toml", self.project_str);
389-
let cargo_lock_pattern = format!("{}/Cargo.lock", self.project_str);
390-
let target_pattern = format!("{}/target", self.project_str);
391-
// For target, we only watch if it gets deleted.
387+
pub fn watchers_config(&self) -> serde_json::Value {
388+
fn watcher(pat: String) -> FileSystemWatcher {
389+
FileSystemWatcher {
390+
glob_pattern: pat,
391+
kind: None,
392+
}
393+
}
394+
fn watcher_with_kind(pat: String, kind: WatchKind) -> FileSystemWatcher {
395+
FileSystemWatcher {
396+
glob_pattern: pat,
397+
kind: Some(kind),
398+
}
399+
}
400+
401+
let mut watchers = vec![
402+
watcher(format!("{}/Cargo.lock", self.project_str)),
403+
// For target, we only watch if it gets deleted.
404+
watcher_with_kind(format!("{}/target", self.project_str), WatchKind::Delete),
405+
];
406+
407+
// Find any Cargo.tomls in the project
408+
for entry in WalkDir::new(self.project_str)
409+
.into_iter()
410+
.filter_map(|e| e.ok())
411+
.filter(|e| e.file_name() == "Cargo.toml")
412+
{
413+
watchers.push(watcher(entry.path().display().to_string()));
414+
}
415+
392416
json!({
393-
"watchers": [
394-
{ "globPattern": cargo_toml_pattern },
395-
{ "globPattern": cargo_lock_pattern },
396-
{ "globPattern": target_pattern, "kind": 4 }]
417+
"watchers": watchers
397418
})
398419
}
399420

@@ -408,10 +429,13 @@ impl<'ctx> FileWatch<'ctx> {
408429
return false;
409430
}
410431

432+
if path.ends_with("/Cargo.toml") {
433+
return true;
434+
}
435+
411436
let local = &path[self.project_uri.len()..];
412437

413-
local == "/Cargo.lock" || local == "/Cargo.toml"
414-
|| local == "/target" && change.typ == FileChangeType::Deleted
438+
local == "/Cargo.lock" || (local == "/target" && change.typ == FileChangeType::Deleted)
415439
}
416440
}
417441

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern crate cargo_metadata;
2828
extern crate env_logger;
2929
#[macro_use]
3030
extern crate failure;
31+
extern crate jsonrpc_core;
3132
extern crate languageserver_types as ls_types;
3233
#[macro_use]
3334
extern crate lazy_static;
@@ -50,8 +51,8 @@ extern crate serde_derive;
5051
#[macro_use]
5152
extern crate serde_json;
5253

53-
extern crate jsonrpc_core;
5454
extern crate url;
55+
extern crate walkdir;
5556

5657
use std::env;
5758
use std::sync::Arc;

0 commit comments

Comments
 (0)