Skip to content

Commit a9cea7c

Browse files
committed
refactor(language_server): use FxHashSet for ServerLinter::extended_paths (#14517)
Fixes duplicate entries in `extended_paths`, found by the tests in #14516.
1 parent bfe1ecd commit a9cea7c

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55
use ignore::gitignore::Gitignore;
66
use log::{debug, warn};
77
use oxc_linter::{AllowWarnDeny, LintIgnoreMatcher};
8-
use rustc_hash::{FxBuildHasher, FxHashMap};
8+
use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet};
99
use tokio::sync::Mutex;
1010
use tower_lsp_server::lsp_types::Uri;
1111

@@ -40,7 +40,7 @@ pub struct ServerLinter {
4040
gitignore_glob: Vec<Gitignore>,
4141
lint_on_run: Run,
4242
diagnostics: ServerLinterDiagnostics,
43-
pub extended_paths: Vec<PathBuf>,
43+
pub extended_paths: FxHashSet<PathBuf>,
4444
}
4545

4646
#[derive(Debug, Default)]
@@ -189,8 +189,8 @@ impl ServerLinter {
189189
root_path: &Path,
190190
options: &LSPLintOptions,
191191
nested_ignore_patterns: &mut Vec<(Vec<String>, PathBuf)>,
192-
) -> (ConcurrentHashMap<PathBuf, Config>, Vec<PathBuf>) {
193-
let mut extended_paths = Vec::new();
192+
) -> (ConcurrentHashMap<PathBuf, Config>, FxHashSet<PathBuf>) {
193+
let mut extended_paths = FxHashSet::default();
194194
// nested config is disabled, no need to search for configs
195195
if !options.use_nested_configs() {
196196
return (ConcurrentHashMap::default(), extended_paths);

crates/oxc_language_server/src/worker.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,9 +516,8 @@ mod test_init_watchers {
516516
let tester = Tester::new("fixtures/watcher/linter_extends", &Options::default());
517517
let watchers = tester.init_watchers();
518518

519-
// The root `.oxlintrc.json` extends `./lint.json -> 2 watchers
520-
// The nested configs are enabled, so it finds `.oxlintrc.json` a second time -> 3 watchers
521-
assert_eq!(watchers.len(), 3);
519+
// The `.oxlintrc.json` extends `./lint.json -> 2 watchers
520+
assert_eq!(watchers.len(), 2);
522521

523522
// nested configs pattern
524523
assert_eq!(
@@ -529,24 +528,14 @@ mod test_init_watchers {
529528
})
530529
);
531530

532-
// nested config extends
531+
// extends of root config
533532
assert_eq!(
534533
watchers[1].glob_pattern,
535534
GlobPattern::Relative(RelativePattern {
536535
base_uri: OneOf::Right(tester.worker.get_root_uri().clone()),
537536
pattern: "lint.json".to_string(),
538537
})
539538
);
540-
541-
// base config extends
542-
// TODO: filter duplicates
543-
assert_eq!(
544-
watchers[2].glob_pattern,
545-
GlobPattern::Relative(RelativePattern {
546-
base_uri: OneOf::Right(tester.worker.get_root_uri().clone()),
547-
pattern: "lint.json".to_string(),
548-
})
549-
);
550539
}
551540

552541
#[test]

0 commit comments

Comments
 (0)