Skip to content

Commit b1e1531

Browse files
committed
refactor(language_server): Extract library interface from main.rs (#15036)
## Summary - Created `lib.rs` to expose the language server as a library - Moved module declarations, type aliases, and constants from `main.rs` to `lib.rs` - Simplified `main.rs` to only contain the binary entry point ## Test plan - [ ] Build succeeds: `cargo build -p oxc_language_server` - [ ] Tests pass: `cargo test -p oxc_language_server` 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1 parent 739d7ff commit b1e1531

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use rustc_hash::FxBuildHasher;
2+
3+
mod backend;
4+
mod capabilities;
5+
mod code_actions;
6+
mod commands;
7+
mod file_system;
8+
mod formatter;
9+
mod linter;
10+
mod options;
11+
#[cfg(test)]
12+
mod tester;
13+
mod utils;
14+
mod worker;
15+
16+
pub use crate::backend::Backend;
17+
pub use crate::linter::server_linter::ServerLinter;
18+
pub use crate::worker::WorkspaceWorker;
19+
20+
pub type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;
21+
22+
pub const LINT_CONFIG_FILE: &str = ".oxlintrc.json";
23+
pub const FORMAT_CONFIG_FILES: &[&str; 2] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];

crates/oxc_language_server/src/linter/server_linter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ impl ServerLinterDiagnostics {
8686
}
8787

8888
impl ServerLinter {
89+
/// # Panics
90+
/// Panics if the root URI cannot be converted to a file path.
8991
pub fn new(root_uri: &Uri, options: &LSPLintOptions) -> Self {
9092
let root_path = root_uri.to_file_path().unwrap();
9193
let mut nested_ignore_patterns = Vec::new();

crates/oxc_language_server/src/main.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
1-
use rustc_hash::FxBuildHasher;
1+
use oxc_language_server::Backend;
22
use tower_lsp_server::{LspService, Server};
33

4-
mod backend;
5-
mod capabilities;
6-
mod code_actions;
7-
mod commands;
8-
mod file_system;
9-
mod formatter;
10-
mod linter;
11-
mod options;
12-
#[cfg(test)]
13-
mod tester;
14-
mod utils;
15-
mod worker;
16-
17-
use crate::backend::Backend;
18-
19-
type ConcurrentHashMap<K, V> = papaya::HashMap<K, V, FxBuildHasher>;
20-
21-
const LINT_CONFIG_FILE: &str = ".oxlintrc.json";
22-
const FORMAT_CONFIG_FILES: &[&str; 2] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];
23-
244
#[tokio::main]
255
async fn main() {
266
env_logger::init();

crates/oxc_language_server/src/worker.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ impl WorkspaceWorker {
5656
/// e.g. root URI: file:///path/to/root
5757
/// responsible for: file:///path/to/root/file.js
5858
/// not responsible for: file:///path/to/other/file.js
59+
///
60+
/// # Panics
61+
/// Panics if the root URI cannot be converted to a file path.
5962
pub fn is_responsible_for_uri(&self, uri: &Uri) -> bool {
6063
if let Some(path) = uri.to_file_path() {
6164
return path.starts_with(self.root_uri.to_file_path().unwrap());
@@ -336,6 +339,9 @@ impl WorkspaceWorker {
336339
}
337340

338341
/// Handle server configuration changes from the client
342+
///
343+
/// # Panics
344+
/// Panics if the root URI cannot be converted to a file path.
339345
pub async fn did_change_configuration(
340346
&self,
341347
changed_options: &Options,

0 commit comments

Comments
 (0)