use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::RecvTimeoutError;
use std::time::{Duration, Instant};
use import_lint::{Access, FileModuleInfo, LintConfig, ModuleGraph, ProjectResolver, Provenance};
use notify::event::{AccessKind, AccessMode, MetadataKind, ModifyKind};
use notify::{Config as NotifyConfig, EventKind, PollWatcher, RecursiveMode, Watcher};
use notify_debouncer_full::{
DebounceEventResult, DebouncedEvent, Debouncer, FileIdCache, NoCache, new_debouncer,
new_debouncer_opt,
};
use oxc_allocator::AllocatorPool;
use oxc_str::CompactStr;
use crate::output::RenderedDiagnostic;
use crate::overlay::Overlays;
use crate::report::{ReportOptions, diagnostics_by_file, finish_report};
use crate::runner::{self, ExtractionCache, RunnerOptions};
use crate::setup::{self, ConfigLoadError};
use crate::source_type::source_type_for_path;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChangeKind {
ContentEdit(PathBuf),
Structural,
ConfigChanged,
TsconfigChanged,
}
pub struct WatchSessionOptions {
pub cli_paths: Vec<PathBuf>,
pub explicit_config: Option<PathBuf>,
pub cli_tsconfig: Option<PathBuf>,
pub report_unresolved: bool,
pub quiet: bool,
pub cwd: PathBuf,
}
pub struct CycleOutcome {
pub diagnostics: Vec<RenderedDiagnostic>,
pub has_error: bool,
pub rechecked_files: usize,
pub extracted_files: usize,
pub linted_files: Vec<PathBuf>,
pub duration: Duration,
pub config_error: Option<String>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct WatchTargets {
pub roots: Vec<PathBuf>,
pub config_path: Option<PathBuf>,
pub tsconfig_path: Option<PathBuf>,
pub package_json_path: Option<PathBuf>,
}
impl WatchTargets {
fn all_paths(&self) -> Vec<PathBuf> {
let mut paths = self.roots.clone();
paths.extend(self.config_path.iter().cloned());
paths.extend(self.tsconfig_path.iter().cloned());
paths.extend(self.package_json_path.iter().cloned());
paths
}
}
pub struct WatchSession {
cli_paths: Vec<PathBuf>,
explicit_config: Option<PathBuf>,
cli_tsconfig: Option<PathBuf>,
report_unresolved: bool,
quiet: bool,
cwd: PathBuf,
config: LintConfig,
project_root: PathBuf,
config_path: Option<PathBuf>,
roots: Vec<PathBuf>,
tsconfig_path: Option<PathBuf>,
resolver: ProjectResolver,
pool: AllocatorPool,
extraction_cache: ExtractionCache,
walked_paths: Vec<PathBuf>,
overlays: Overlays,
graph: ModuleGraph,
diagnostics_map: HashMap<PathBuf, Vec<RenderedDiagnostic>>,
last_diagnostics: Vec<RenderedDiagnostic>,
last_has_error: bool,
}
struct WalkAndResolver {
roots: Vec<PathBuf>,
tsconfig_path: Option<PathBuf>,
resolver: ProjectResolver,
walked_paths: Vec<PathBuf>,
initial: runner::Extracted,
}
fn build_walk_and_resolver(
cli_paths: &[PathBuf],
cli_tsconfig: Option<&Path>,
config: &LintConfig,
project_root: &Path,
pool: &AllocatorPool,
cache: &mut ExtractionCache,
overlays: &Overlays,
) -> WalkAndResolver {
let roots = setup::compute_roots(cli_paths, config, project_root);
let tsconfig_path = setup::compute_tsconfig(cli_tsconfig, config, project_root);
let self_reference_mode = setup::compute_self_reference_mode(config);
let runner_options = RunnerOptions {
roots: roots.clone(),
project_root: project_root.to_path_buf(),
tsconfig: tsconfig_path.clone(),
self_reference_mode,
exclude: config.exclude.clone(),
};
let walked_paths = crate::walk::walk_with_excludes(
&runner_options.roots,
Some(runner_options.project_root.as_path()),
&runner_options.exclude,
);
let initial = runner::extract_with_cache(&walked_paths, pool, cache, overlays);
let resolver =
runner::build_resolver_from_files(&runner_options, &walked_paths, &initial.files);
WalkAndResolver {
roots,
tsconfig_path,
resolver,
walked_paths,
initial,
}
}
struct RecheckStats {
rechecked_files: usize,
extracted_files: usize,
linted_files: Vec<PathBuf>,
}
impl WatchSession {
pub fn new(options: WatchSessionOptions) -> Result<Self, ConfigLoadError> {
let loaded = setup::load_config(options.explicit_config.as_deref(), &options.cwd)?;
let pool = AllocatorPool::new(rayon::current_num_threads());
let mut cache = ExtractionCache::new();
let overlays = Overlays::default();
let built = build_walk_and_resolver(
&options.cli_paths,
options.cli_tsconfig.as_deref(),
&loaded.config,
&loaded.project_root,
&pool,
&mut cache,
&overlays,
);
let mut session = WatchSession {
cli_paths: options.cli_paths,
explicit_config: options.explicit_config,
cli_tsconfig: options.cli_tsconfig,
report_unresolved: options.report_unresolved,
quiet: options.quiet,
cwd: options.cwd,
config: loaded.config,
project_root: loaded.project_root,
config_path: loaded.config_path,
roots: built.roots,
tsconfig_path: built.tsconfig_path,
resolver: built.resolver,
pool,
extraction_cache: cache,
walked_paths: built.walked_paths,
overlays,
graph: ModuleGraph::build(Vec::new(), HashMap::new(), HashSet::new()),
diagnostics_map: HashMap::new(),
last_diagnostics: Vec::new(),
last_has_error: false,
};
session.full_recheck(built.initial);
Ok(session)
}
pub fn set_overlay(&mut self, path: PathBuf, content: String) {
self.overlays.set(path, content);
}
pub fn clear_overlay(&mut self, path: &Path) -> bool {
self.overlays.clear(path)
}
pub fn last_diagnostics(&self) -> &[RenderedDiagnostic] {
&self.last_diagnostics
}
pub fn last_has_error(&self) -> bool {
self.last_has_error
}
pub fn watch_targets(&self) -> WatchTargets {
let package_json = self.project_root.join("package.json");
let covered_by_a_root = self.roots.iter().any(|root| package_json.starts_with(root));
WatchTargets {
roots: self.roots.clone(),
config_path: self.config_path.clone(),
tsconfig_path: self.tsconfig_path.clone(),
package_json_path: (!covered_by_a_root).then_some(package_json),
}
}
pub fn run_cycle(&mut self, changes: &[ChangeKind]) -> CycleOutcome {
let start = Instant::now();
let mut config_error = None;
let mut need_full_reload = changes
.iter()
.any(|c| matches!(c, ChangeKind::TsconfigChanged | ChangeKind::Structural));
if changes
.iter()
.any(|c| matches!(c, ChangeKind::ConfigChanged))
{
match setup::load_config(self.explicit_config.as_deref(), &self.cwd) {
Ok(loaded) => {
self.config = loaded.config;
self.project_root = loaded.project_root;
self.config_path = loaded.config_path;
need_full_reload = true;
}
Err(err) => {
config_error = Some(err.to_string());
}
}
}
let stats = if need_full_reload {
let initial = self.full_reload();
self.full_recheck(initial)
} else {
let changed_paths: Vec<PathBuf> = changes
.iter()
.filter_map(|change| match change {
ChangeKind::ContentEdit(path) => Some(path.clone()),
_ => None,
})
.collect();
match self.run_fast_cycle(&changed_paths) {
Some(stats) => stats,
None => {
let initial = self.full_reload();
self.full_recheck(initial)
}
}
};
CycleOutcome {
diagnostics: self.last_diagnostics.clone(),
has_error: self.last_has_error,
rechecked_files: stats.rechecked_files,
extracted_files: stats.extracted_files,
linted_files: stats.linted_files,
duration: start.elapsed(),
config_error,
}
}
fn full_reload(&mut self) -> runner::Extracted {
let built = build_walk_and_resolver(
&self.cli_paths,
self.cli_tsconfig.as_deref(),
&self.config,
&self.project_root,
&self.pool,
&mut self.extraction_cache,
&self.overlays,
);
self.roots = built.roots;
self.tsconfig_path = built.tsconfig_path;
self.resolver = built.resolver;
self.walked_paths = built.walked_paths;
built.initial
}
fn full_recheck(&mut self, initial: runner::Extracted) -> RecheckStats {
let outcome = runner::extract_and_link_from(
&self.walked_paths,
initial,
&self.resolver,
&self.pool,
&mut self.extraction_cache,
&self.overlays,
);
let rechecked_files = crate::timing::phase("rechecked_files_count", || {
outcome
.graph
.lint_targets
.iter()
.filter(|path| outcome.graph.file(path).is_some())
.count()
});
let extracted_files = outcome.extracted_files;
let linted_files: Vec<PathBuf> = crate::timing::phase("linted_files_clone", || {
outcome.graph.lint_targets.iter().cloned().collect()
});
self.graph = outcome.graph;
let targets: Vec<&Path> = self
.graph
.lint_targets
.iter()
.map(PathBuf::as_path)
.collect();
self.diagnostics_map = crate::timing::phase("build_report_total", || {
diagnostics_by_file(
&self.graph,
&self.config,
&self.project_root,
&ReportOptions {
report_unresolved: self.report_unresolved,
quiet: self.quiet,
},
&targets,
&self.overlays,
)
});
self.compose_from_map();
RecheckStats {
rechecked_files,
extracted_files,
linted_files,
}
}
fn run_fast_cycle(&mut self, changed_paths: &[PathBuf]) -> Option<RecheckStats> {
let mut unique_paths: Vec<PathBuf> = changed_paths.to_vec();
unique_paths.sort();
unique_paths.dedup();
for path in &unique_paths {
self.extraction_cache.remove(path);
}
let extracted = runner::extract_with_cache(
&unique_paths,
&self.pool,
&mut self.extraction_cache,
&self.overlays,
);
let extracted_files = extracted.extracted_files;
let mut new_files: HashMap<PathBuf, Arc<FileModuleInfo>> = HashMap::new();
for info in extracted.files {
new_files.insert(info.path.clone(), info);
}
for path in &unique_paths {
if !new_files.contains_key(path) || !self.graph.files.contains_key(path) {
return None;
}
}
for path in &unique_paths {
if self.graph.files[path].ambient_modules != new_files[path].ambient_modules {
return None;
}
}
let mut surface_changed: HashSet<PathBuf> = HashSet::new();
for path in &unique_paths {
if export_surface(&self.graph.files[path]) != export_surface(&new_files[path]) {
surface_changed.insert(path.clone());
}
}
for path in &unique_paths {
let old_info = self.graph.files[path].clone();
for specifier in &old_info.specifiers {
let key = (path.clone(), specifier.clone());
if let Some(Provenance::Internal(target)) = self.graph.resolutions.remove(&key) {
if let Some(set) = self.graph.importers.get_mut(&target) {
set.remove(path);
}
if let Some(set) = self.graph.star_importers.get_mut(&target) {
set.remove(path);
}
}
}
let new_info = new_files.remove(path).expect("checked above");
let star_specifiers: HashSet<&CompactStr> = new_info.star_exports.iter().collect();
for specifier in &new_info.specifiers {
let provenance = self.resolver.resolve(path, specifier);
if let Provenance::Internal(target) = &provenance {
if !self.graph.files.contains_key(target) {
return None;
}
self.graph
.importers
.entry(target.clone())
.or_default()
.insert(path.clone());
if star_specifiers.contains(specifier) {
self.graph
.star_importers
.entry(target.clone())
.or_default()
.insert(path.clone());
}
}
self.graph
.resolutions
.insert((path.clone(), specifier.clone()), provenance);
}
self.graph.files.insert(path.clone(), new_info);
}
let mut dirty: HashSet<PathBuf> = unique_paths.iter().cloned().collect();
for path in &unique_paths {
if surface_changed.contains(path) {
propagate_star_closure(&self.graph, path, &mut dirty);
}
}
dirty.retain(|path| self.graph.lint_targets.contains(path));
let dirty_refs: Vec<&Path> = dirty.iter().map(PathBuf::as_path).collect();
let dirty_result = crate::timing::phase("build_report_total", || {
diagnostics_by_file(
&self.graph,
&self.config,
&self.project_root,
&ReportOptions {
report_unresolved: self.report_unresolved,
quiet: self.quiet,
},
&dirty_refs,
&self.overlays,
)
});
self.diagnostics_map.extend(dirty_result);
self.compose_from_map();
let linted_files: Vec<PathBuf> = self.graph.lint_targets.iter().cloned().collect();
Some(RecheckStats {
rechecked_files: dirty.len(),
extracted_files,
linted_files,
})
}
fn compose_from_map(&mut self) {
let report = finish_report(
self.diagnostics_map.values().flatten().cloned(),
&ReportOptions {
report_unresolved: self.report_unresolved,
quiet: self.quiet,
},
);
self.last_diagnostics = report.diagnostics;
self.last_has_error = report.has_error;
}
}
#[derive(PartialEq, Eq)]
struct ExportSurface {
export_table: HashMap<CompactStr, Option<Access>>,
star_exports: Vec<CompactStr>,
}
fn export_surface(info: &FileModuleInfo) -> ExportSurface {
ExportSurface {
export_table: info
.export_table
.iter()
.map(|(name, export)| (name.clone(), export.access))
.collect(),
star_exports: info.star_exports.clone(),
}
}
fn propagate_star_closure(graph: &ModuleGraph, start: &Path, dirty: &mut HashSet<PathBuf>) {
let mut visited_barrels: HashSet<PathBuf> = HashSet::new();
let mut stack: Vec<PathBuf> = vec![start.to_path_buf()];
while let Some(file) = stack.pop() {
if let Some(direct_importers) = graph.importers.get(&file) {
dirty.extend(direct_importers.iter().cloned());
}
if let Some(barrels) = graph.star_importers.get(&file) {
for barrel in barrels {
if visited_barrels.insert(barrel.clone()) {
stack.push(barrel.clone());
}
}
}
}
}
pub fn classify_event(event: &DebouncedEvent, watch: &WatchTargets) -> Vec<ChangeKind> {
match event.kind {
EventKind::Create(_) | EventKind::Remove(_) => vec![ChangeKind::Structural],
EventKind::Modify(ModifyKind::Name(_)) => vec![ChangeKind::Structural],
EventKind::Modify(ModifyKind::Metadata(
MetadataKind::Permissions | MetadataKind::Ownership | MetadataKind::AccessTime,
)) => Vec::new(),
EventKind::Modify(_) => event
.paths
.iter()
.filter_map(|path| classify_path(path, watch))
.collect(),
EventKind::Access(AccessKind::Close(AccessMode::Write)) => event
.paths
.iter()
.filter_map(|path| classify_path(path, watch))
.collect(),
EventKind::Access(_) | EventKind::Other | EventKind::Any => Vec::new(),
}
}
fn classify_path(path: &Path, watch: &WatchTargets) -> Option<ChangeKind> {
if path.file_name().is_some_and(|name| name == "package.json") {
return Some(ChangeKind::Structural);
}
if watch.config_path.as_deref() == Some(path) {
return Some(ChangeKind::ConfigChanged);
}
if watch.tsconfig_path.as_deref() == Some(path) {
return Some(ChangeKind::TsconfigChanged);
}
if source_type_for_path(path).is_some() {
return Some(ChangeKind::ContentEdit(path.to_path_buf()));
}
None
}
pub fn watch_loop(
session: &mut WatchSession,
debounce: Duration,
poll_interval: Option<Duration>,
shutdown: &Arc<AtomicBool>,
mut on_cycle: impl FnMut(&CycleOutcome),
) -> notify::Result<()> {
let (tx, rx) = std::sync::mpsc::channel::<DebounceEventResult>();
let poll_shutdown_every = Duration::from_millis(200).min(debounce);
match poll_interval {
Some(interval) => {
let config = NotifyConfig::default().with_poll_interval(interval);
let mut debouncer =
new_debouncer_opt::<_, PollWatcher, NoCache>(debounce, None, tx, NoCache, config)?;
let mut watched = session.watch_targets();
register_watches(&mut debouncer, &watched);
run_event_loop(
&mut debouncer,
&rx,
poll_shutdown_every,
shutdown,
session,
&mut watched,
&mut on_cycle,
);
}
None => {
let mut debouncer = new_debouncer(debounce, None, tx)?;
let mut watched = session.watch_targets();
register_watches(&mut debouncer, &watched);
run_event_loop(
&mut debouncer,
&rx,
poll_shutdown_every,
shutdown,
session,
&mut watched,
&mut on_cycle,
);
}
}
Ok(())
}
fn register_watches<T: Watcher, C: FileIdCache>(
debouncer: &mut Debouncer<T, C>,
targets: &WatchTargets,
) {
for root in &targets.roots {
if !root.exists() {
eprintln!(
"import-lint: {}: no such file or directory, not watching",
root.display()
);
continue;
}
if let Err(err) = debouncer.watch(root, RecursiveMode::Recursive) {
eprintln!("import-lint: failed to watch {}: {err}", root.display());
}
}
for extra in [
&targets.config_path,
&targets.tsconfig_path,
&targets.package_json_path,
]
.into_iter()
.flatten()
{
if !extra.is_file() {
continue;
}
if let Err(err) = debouncer.watch(extra, RecursiveMode::NonRecursive) {
eprintln!("import-lint: failed to watch {}: {err}", extra.display());
}
}
}
fn reconcile_watches<T: Watcher, C: FileIdCache>(
debouncer: &mut Debouncer<T, C>,
old: &WatchTargets,
new: &WatchTargets,
) {
let new_paths = new.all_paths();
for path in old.all_paths() {
if !new_paths.contains(&path) {
let _ = debouncer.unwatch(&path);
}
}
let old_paths = old.all_paths();
for path in new_paths {
if old_paths.contains(&path) || !path.exists() {
continue;
}
let mode = if new.roots.contains(&path) {
RecursiveMode::Recursive
} else {
RecursiveMode::NonRecursive
};
let _ = debouncer.watch(&path, mode);
}
}
#[allow(clippy::too_many_arguments)]
fn run_event_loop<T: Watcher, C: FileIdCache>(
debouncer: &mut Debouncer<T, C>,
rx: &std::sync::mpsc::Receiver<DebounceEventResult>,
recv_tick: Duration,
shutdown: &Arc<AtomicBool>,
session: &mut WatchSession,
watched: &mut WatchTargets,
on_cycle: &mut impl FnMut(&CycleOutcome),
) {
loop {
if shutdown.load(Ordering::Relaxed) {
return;
}
match rx.recv_timeout(recv_tick) {
Ok(Ok(events)) => {
let changes: Vec<ChangeKind> = events
.iter()
.flat_map(|event| classify_event(event, watched))
.collect();
if changes.is_empty() {
continue;
}
let outcome = session.run_cycle(&changes);
on_cycle(&outcome);
let new_watched = session.watch_targets();
if new_watched != *watched {
reconcile_watches(debouncer, watched, &new_watched);
*watched = new_watched;
}
}
Ok(Err(errors)) => {
for err in errors {
eprintln!("import-lint: watch error: {err}");
}
}
Err(RecvTimeoutError::Timeout) => {}
Err(RecvTimeoutError::Disconnected) => return,
}
}
}
#[cfg(test)]
mod classify_tests {
use super::*;
use notify::Event;
use notify::event::{CreateKind, RemoveKind, RenameMode};
use std::time::Instant;
fn debounced(kind: EventKind, paths: &[&str]) -> DebouncedEvent {
let mut event = Event::new(kind);
for path in paths {
event = event.add_path(PathBuf::from(path));
}
DebouncedEvent::new(event, Instant::now())
}
fn targets() -> WatchTargets {
WatchTargets {
roots: vec![PathBuf::from("/proj/src")],
config_path: Some(PathBuf::from("/proj/.importlintrc.jsonc")),
tsconfig_path: Some(PathBuf::from("/proj/tsconfig.json")),
package_json_path: Some(PathBuf::from("/proj/package.json")),
}
}
#[test]
fn create_is_structural_regardless_of_path() {
let event = debounced(EventKind::Create(CreateKind::File), &["/proj/src/new.ts"]);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::Structural]
);
}
#[test]
fn remove_is_structural() {
let event = debounced(EventKind::Remove(RemoveKind::File), &["/proj/src/gone.ts"]);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::Structural]
);
}
#[test]
fn rename_is_structural() {
let event = debounced(
EventKind::Modify(ModifyKind::Name(RenameMode::Both)),
&["/proj/src/old.ts", "/proj/src/new.ts"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::Structural]
);
}
#[test]
fn data_modify_of_a_source_file_is_content_edit() {
let event = debounced(
EventKind::Modify(ModifyKind::Data(notify::event::DataChange::Any)),
&["/proj/src/a.ts"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::ContentEdit(PathBuf::from("/proj/src/a.ts"))]
);
}
#[test]
fn close_write_of_a_source_file_is_content_edit() {
let event = debounced(
EventKind::Access(AccessKind::Close(AccessMode::Write)),
&["/proj/src/a.ts"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::ContentEdit(PathBuf::from("/proj/src/a.ts"))]
);
}
#[test]
fn access_open_is_ignored() {
let event = debounced(
EventKind::Access(AccessKind::Open(AccessMode::Read)),
&["/proj/src/a.ts"],
);
assert_eq!(classify_event(&event, &targets()), Vec::<ChangeKind>::new());
}
#[test]
fn metadata_write_time_modify_is_content_edit() {
let event = debounced(
EventKind::Modify(ModifyKind::Metadata(notify::event::MetadataKind::WriteTime)),
&["/proj/src/a.ts"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::ContentEdit(PathBuf::from("/proj/src/a.ts"))]
);
}
#[test]
fn metadata_permissions_modify_is_ignored() {
let event = debounced(
EventKind::Modify(ModifyKind::Metadata(
notify::event::MetadataKind::Permissions,
)),
&["/proj/src/a.ts"],
);
assert_eq!(classify_event(&event, &targets()), Vec::<ChangeKind>::new());
}
#[test]
fn metadata_access_time_modify_is_ignored() {
let event = debounced(
EventKind::Modify(ModifyKind::Metadata(
notify::event::MetadataKind::AccessTime,
)),
&["/proj/src/a.ts"],
);
assert_eq!(classify_event(&event, &targets()), Vec::<ChangeKind>::new());
}
#[test]
fn package_json_modify_is_structural_even_nested() {
let event = debounced(
EventKind::Modify(ModifyKind::Data(notify::event::DataChange::Any)),
&["/proj/src/nested/package.json"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::Structural]
);
}
#[test]
fn config_path_modify_is_config_changed() {
let event = debounced(
EventKind::Modify(ModifyKind::Data(notify::event::DataChange::Any)),
&["/proj/.importlintrc.jsonc"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::ConfigChanged]
);
}
#[test]
fn tsconfig_path_modify_is_tsconfig_changed() {
let event = debounced(
EventKind::Modify(ModifyKind::Data(notify::event::DataChange::Any)),
&["/proj/tsconfig.json"],
);
assert_eq!(
classify_event(&event, &targets()),
vec![ChangeKind::TsconfigChanged]
);
}
#[test]
fn modify_of_an_unrecognized_extension_is_ignored() {
let event = debounced(
EventKind::Modify(ModifyKind::Data(notify::event::DataChange::Any)),
&["/proj/src/readme.md"],
);
assert_eq!(classify_event(&event, &targets()), Vec::<ChangeKind>::new());
}
#[test]
fn event_with_no_special_kind_is_ignored() {
let event = debounced(EventKind::Other, &["/proj/src/a.ts"]);
assert_eq!(classify_event(&event, &targets()), Vec::<ChangeKind>::new());
}
#[test]
fn multiple_paths_classify_independently() {
let event = debounced(
EventKind::Modify(ModifyKind::Data(notify::event::DataChange::Any)),
&["/proj/src/a.ts", "/proj/tsconfig.json", "/proj/README.md"],
);
let mut got = classify_event(&event, &targets());
got.sort_by_key(|c| format!("{c:?}"));
let mut want = vec![
ChangeKind::ContentEdit(PathBuf::from("/proj/src/a.ts")),
ChangeKind::TsconfigChanged,
];
want.sort_by_key(|c| format!("{c:?}"));
assert_eq!(got, want);
}
}