Skip to content

Commit 0d192e8

Browse files
committed
refactor(language_server): introduce ServerLinter.extended_paths property (#11223)
1 parent c64f800 commit 0d192e8

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ use super::config_walker::ConfigWalker;
2121
pub struct ServerLinter {
2222
isolated_linter: Arc<IsolatedLintHandler>,
2323
gitignore_glob: Vec<Gitignore>,
24+
#[expect(dead_code)]
25+
extended_paths: Vec<PathBuf>,
2426
}
2527

2628
impl ServerLinter {
2729
pub fn new(root_uri: &Uri, options: &Options) -> Self {
28-
let nested_configs = Self::create_nested_configs(root_uri, options);
30+
let (nested_configs, mut extended_paths) = Self::create_nested_configs(root_uri, options);
2931
let root_path = root_uri.to_file_path().unwrap();
3032
let relative_config_path = options.config_path.clone();
3133
let oxlintrc = if let Some(relative_config_path) = relative_config_path {
@@ -61,6 +63,7 @@ impl ServerLinter {
6163
config_builder.plugins().has_import()
6264
};
6365

66+
extended_paths.extend(config_builder.extended_paths.clone());
6467
let base_config = config_builder.build();
6568

6669
let lint_options = LintOptions { fix: options.fix_kind(), ..Default::default() };
@@ -88,6 +91,7 @@ impl ServerLinter {
8891
Self {
8992
isolated_linter: Arc::new(isolated_linter),
9093
gitignore_glob: Self::create_ignore_glob(root_uri, &oxlintrc),
94+
extended_paths,
9195
}
9296
}
9397

@@ -96,10 +100,11 @@ impl ServerLinter {
96100
fn create_nested_configs(
97101
root_uri: &Uri,
98102
options: &Options,
99-
) -> ConcurrentHashMap<PathBuf, Config> {
103+
) -> (ConcurrentHashMap<PathBuf, Config>, Vec<PathBuf>) {
104+
let mut extended_paths = Vec::new();
100105
// nested config is disabled, no need to search for configs
101106
if !options.use_nested_configs() {
102-
return ConcurrentHashMap::default();
107+
return (ConcurrentHashMap::default(), extended_paths);
103108
}
104109

105110
let root_path = root_uri.to_file_path().expect("Failed to convert URI to file path");
@@ -123,12 +128,11 @@ impl ServerLinter {
123128
warn!("Skipping config (builder failed): {}", file_path.display());
124129
continue;
125130
};
126-
let config_store = config_store_builder.build();
127-
128-
nested_configs.pin().insert(dir_path.to_path_buf(), config_store);
131+
extended_paths.extend(config_store_builder.extended_paths.clone());
132+
nested_configs.pin().insert(dir_path.to_path_buf(), config_store_builder.build());
129133
}
130134

131-
nested_configs
135+
(nested_configs, extended_paths)
132136
}
133137

134138
fn create_ignore_glob(root_uri: &Uri, oxlintrc: &Oxlintrc) -> Vec<Gitignore> {
@@ -257,7 +261,7 @@ mod test {
257261
let mut flags = FxHashMap::default();
258262
flags.insert("disable_nested_configs".to_string(), "true".to_string());
259263

260-
let configs = ServerLinter::create_nested_configs(
264+
let (configs, _) = ServerLinter::create_nested_configs(
261265
&Uri::from_str("file:///root/").unwrap(),
262266
&Options { flags, ..Options::default() },
263267
);
@@ -267,7 +271,7 @@ mod test {
267271

268272
#[test]
269273
fn test_create_nested_configs() {
270-
let configs = ServerLinter::create_nested_configs(
274+
let (configs, _) = ServerLinter::create_nested_configs(
271275
&get_file_uri("fixtures/linter/init_nested_configs"),
272276
&Options::default(),
273277
);

crates/oxc_language_server/src/worker.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ impl WorkspaceWorker {
5353
*self.server_linter.write().await = Some(ServerLinter::new(&self.root_uri, options));
5454
}
5555

56+
// WARNING: start all programs (linter, formatter) before calling this function
57+
// each program can tell us customized file watcher patterns
5658
pub async fn init_watchers(&self) -> FileSystemWatcher {
5759
// ToDo: check with ServerLinter for `extends` files (oxc-project/oxc@10373)
5860

0 commit comments

Comments
 (0)