Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion apps/oxfmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ doctest = false

[dependencies]
oxc_allocator = { workspace = true, features = ["pool"] }
oxc_data_structures = { workspace = true, features = ["rope"] }
oxc_diagnostics = { workspace = true }
oxc_formatter = { workspace = true }
oxc_language_server = { workspace = true, default-features = false, features = ["formatter"] }
oxc_language_server = { workspace = true, default-features = false }
oxc_napi = { workspace = true }
oxc_parser = { workspace = true }
oxc_span = { workspace = true }
Expand All @@ -40,16 +41,19 @@ cow-utils = { workspace = true }
editorconfig-parser = { workspace = true }
ignore = { workspace = true, features = ["simd-accel"] }
json-strip-comments = { workspace = true }
log = { workspace = true }
miette = { workspace = true }
phf = { workspace = true, features = ["macros"] }
rayon = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
simdutf8 = { workspace = true }
sort-package-json = { workspace = true }
oxc-toml = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = [] } # Omit the `regex` feature
tower-lsp-server = { workspace = true, features = ["proposed"] }

# NAPI dependencies (conditional on napi feature)
napi = { workspace = true, features = ["async", "serde-json"], optional = true }
Expand All @@ -58,6 +62,9 @@ napi-derive = { workspace = true, optional = true }
[build-dependencies]
napi-build = { workspace = true }

[dev-dependencies]
insta = { workspace = true }

[target.'cfg(not(any(target_os = "linux", target_os = "freebsd", target_arch = "arm", target_family = "wasm")))'.dependencies]
mimalloc-safe = { workspace = true, optional = true, features = ["skip_collect_on_exit"] }

Expand Down
10 changes: 8 additions & 2 deletions apps/oxfmt/src/lsp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use oxc_language_server::{ServerFormatterBuilder, run_server};
use oxc_language_server::run_server;

mod options;
mod server_formatter;
#[cfg(test)]
mod tester;
const FORMAT_CONFIG_FILES: &[&str; 2] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];

/// Run the language server
pub async fn run_lsp() {
run_server(
"oxfmt".to_string(),
env!("CARGO_PKG_VERSION").to_string(),
vec![Box::new(ServerFormatterBuilder)],
vec![Box::new(server_formatter::ServerFormatterBuilder)],
)
.await;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ use oxc_formatter::{
use oxc_parser::Parser;
use tower_lsp_server::ls_types::{Pattern, Position, Range, ServerCapabilities, TextEdit, Uri};

use crate::{
capabilities::Capabilities,
formatter::{FORMAT_CONFIG_FILES, options::FormatOptions as LSPFormatOptions},
tool::{Tool, ToolBuilder, ToolRestartChanges},
use crate::lsp::{FORMAT_CONFIG_FILES, options::FormatOptions as LSPFormatOptions};

use oxc_language_server::{
Capabilities,
utils::normalize_path,
{Tool, ToolBuilder, ToolRestartChanges},
};

pub struct ServerFormatterBuilder;
Expand Down Expand Up @@ -370,7 +371,8 @@ fn load_ignore_paths(cwd: &Path) -> Vec<PathBuf> {

#[cfg(test)]
mod tests_builder {
use crate::{ServerFormatterBuilder, ToolBuilder, capabilities::Capabilities};
use crate::lsp::server_formatter::ServerFormatterBuilder;
use oxc_language_server::{Capabilities, ToolBuilder};

#[test]
fn test_server_capabilities() {
Expand All @@ -392,7 +394,7 @@ mod test_watchers {
const FAKE_DIR: &str = "fixtures/formatter/watchers";

mod init_watchers {
use crate::formatter::{server_formatter::test_watchers::FAKE_DIR, tester::Tester};
use crate::lsp::{server_formatter::test_watchers::FAKE_DIR, tester::Tester};
use serde_json::json;

#[test]
Expand Down Expand Up @@ -432,10 +434,8 @@ mod test_watchers {
}

mod handle_configuration_change {
use crate::{
ToolRestartChanges,
formatter::{server_formatter::test_watchers::FAKE_DIR, tester::Tester},
};
use crate::lsp::{server_formatter::test_watchers::FAKE_DIR, tester::Tester};
use oxc_language_server::ToolRestartChanges;
use serde_json::json;

#[test]
Expand Down Expand Up @@ -465,7 +465,7 @@ mod tests {
use serde_json::json;

use super::compute_minimal_text_edit;
use crate::formatter::tester::Tester;
use crate::lsp::tester::Tester;

#[test]
#[should_panic(expected = "assertion failed")]
Expand Down Expand Up @@ -551,7 +551,7 @@ mod tests {
#[test]
fn test_formatter() {
Tester::new(
"fixtures/formatter/basic",
"test/fixtures/lsp/basic",
json!({
"fmt.experimental": true
}),
Expand All @@ -562,7 +562,7 @@ mod tests {
#[test]
fn test_root_config_detection() {
Tester::new(
"fixtures/formatter/root_config",
"test/fixtures/lsp/root_config",
json!({
"fmt.experimental": true
}),
Expand All @@ -573,7 +573,7 @@ mod tests {
#[test]
fn test_custom_config_path() {
Tester::new(
"fixtures/formatter/custom_config_path",
"test/fixtures/lsp/custom_config_path",
json!({
"fmt.experimental": true,
"fmt.configPath": "./format.json",
Expand All @@ -585,7 +585,7 @@ mod tests {
#[test]
fn test_ignore_files() {
Tester::new(
"fixtures/formatter/ignore-file",
"test/fixtures/lsp/ignore-file",
json!({
"fmt.experimental": true
}),
Expand All @@ -596,7 +596,7 @@ mod tests {
#[test]
fn test_ignore_pattern() {
Tester::new(
"fixtures/formatter/ignore-pattern",
"test/fixtures/lsp/ignore-pattern",
json!({
"fmt.experimental": true
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: crates/oxc_language_server/src/formatter/tester.rs
source: apps/oxfmt/src/lsp/tester.rs
---
========================================
File: fixtures/formatter/basic/basic.ts
File: test/fixtures/lsp/basic/basic.ts
========================================
Range: Range {
start: Position {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: crates/oxc_language_server/src/formatter/tester.rs
source: apps/oxfmt/src/lsp/tester.rs
---
========================================
File: fixtures/formatter/root_config/semicolons-as-needed.ts
File: test/fixtures/lsp/custom_config_path/semicolons-as-needed.ts
========================================
Range: Range {
start: Position {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
source: crates/oxc_language_server/src/formatter/tester.rs
source: apps/oxfmt/src/lsp/tester.rs
---
========================================
File: fixtures/formatter/ignore-file/ignored.ts
File: test/fixtures/lsp/ignore-file/ignored.ts
========================================
File is ignored
========================================
File: fixtures/formatter/ignore-file/not-ignored.js
File: test/fixtures/lsp/ignore-file/not-ignored.js
========================================
Range: Range {
start: Position {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---
source: crates/oxc_language_server/src/formatter/tester.rs
source: apps/oxfmt/src/lsp/tester.rs
---
========================================
File: fixtures/formatter/ignore-pattern/ignored.ts
File: test/fixtures/lsp/ignore-pattern/ignored.ts
========================================
File is ignored
========================================
File: fixtures/formatter/ignore-pattern/not-ignored.js
File: test/fixtures/lsp/ignore-pattern/not-ignored.js
========================================
Range: Range {
start: Position {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: crates/oxc_language_server/src/formatter/tester.rs
source: apps/oxfmt/src/lsp/tester.rs
---
========================================
File: fixtures/formatter/custom_config_path/semicolons-as-needed.ts
File: test/fixtures/lsp/root_config/semicolons-as-needed.ts
========================================
Range: Range {
start: Position {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ use std::{fmt::Write, path::PathBuf};

use tower_lsp_server::ls_types::{TextEdit, Uri};

use crate::{
ToolRestartChanges,
formatter::server_formatter::{ServerFormatter, ServerFormatterBuilder},
tool::Tool,
};
use crate::lsp::server_formatter::{ServerFormatter, ServerFormatterBuilder};
use oxc_language_server::{Tool, ToolRestartChanges};

/// Given a file path relative to the crate root directory, return the absolute path of the file.
pub fn get_file_path(relative_file_path: &str) -> PathBuf {
Expand Down
13 changes: 1 addition & 12 deletions crates/oxc_language_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ doctest = false
oxc_allocator = { workspace = true, optional = true }
oxc_data_structures = { workspace = true, features = ["rope"], optional = true }
oxc_diagnostics = { workspace = true, optional = true }
oxc_formatter = { workspace = true, optional = true }
oxc_linter = { workspace = true, optional = true }
oxc_parser = { workspace = true, optional = true }

#
env_logger = { workspace = true, features = ["humantime"] }
futures = { workspace = true }
ignore = { workspace = true, features = ["simd-accel"], optional = true }
json-strip-comments = { workspace = true }
log = { workspace = true }
papaya = { workspace = true }
rustc-hash = { workspace = true }
Expand All @@ -50,7 +47,7 @@ insta = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "io-util", "macros"] }

[features]
default = ["linter", "formatter"]
default = ["linter"]
linter = [
"dep:oxc_allocator",
"dep:oxc_data_structures",
Expand All @@ -59,11 +56,3 @@ linter = [
#
"dep:ignore",
]
formatter = [
"dep:oxc_allocator",
"dep:oxc_data_structures",
"dep:oxc_formatter",
"dep:oxc_parser",
#
"dep:ignore",
]
8 changes: 0 additions & 8 deletions crates/oxc_language_server/src/formatter/mod.rs

This file was deleted.

14 changes: 7 additions & 7 deletions crates/oxc_language_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@ use tower_lsp_server::{LspService, Server, ls_types::ServerInfo};
mod backend;
mod capabilities;
mod file_system;
#[cfg(feature = "formatter")]
mod formatter;
#[cfg(feature = "linter")]
mod linter;
mod options;
#[cfg(test)]
mod tests;
mod tool;
mod utils;
pub mod utils;
mod worker;

use crate::backend::Backend;
#[cfg(feature = "formatter")]
pub use crate::formatter::ServerFormatterBuilder;
pub use crate::capabilities::Capabilities;
#[cfg(feature = "linter")]
pub use crate::linter::ServerLinterBuilder;
pub use crate::tool::{Tool, ToolBuilder, ToolRestartChanges};
Expand All @@ -36,7 +32,11 @@ pub async fn run_server(
let stdout = tokio::io::stdout();

let (service, socket) = LspService::build(|client| {
Backend::new(client, ServerInfo { name: server_name, version: Some(server_version) }, tools)
crate::backend::Backend::new(
client,
ServerInfo { name: server_name, version: Some(server_version) },
tools,
)
})
.finish();

Expand Down
2 changes: 0 additions & 2 deletions crates/oxc_language_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ async fn main() {
#[expect(clippy::vec_init_then_push)]
let tools: Vec<Box<dyn oxc_language_server::ToolBuilder>> = {
let mut v: Vec<Box<dyn oxc_language_server::ToolBuilder>> = Vec::new();
#[cfg(feature = "formatter")]
v.push(Box::new(oxc_language_server::ServerFormatterBuilder));
#[cfg(feature = "linter")]
v.push(Box::new(oxc_language_server::ServerLinterBuilder));
v
Expand Down
Loading