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
30 changes: 23 additions & 7 deletions crates/oxc_language_server/src/formatter/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@ pub fn get_file_uri(relative_file_path: &str) -> Uri {
}

fn get_snapshot_from_text_edits(edits: &[TextEdit]) -> String {
edits
.iter()
.map(|edit| format!("{:#?},\n\n{:?}", edit.range, edit.new_text))
.collect::<Vec<_>>()
.join("\n")
if edits.len() == 1 {
// Single edit - show range and the actual formatted content with proper indentation
let edit = &edits[0];
let indent = " ".repeat(edit.range.start.character as usize);
let indented_content = format!("{}{}", indent, edit.new_text);

format!("Range: {:#?}\n\n{}", edit.range, indented_content)
} else {
// Multiple edits - show each edit separately
edits
.iter()
.enumerate()
.map(|(i, edit)| {
let indent = " ".repeat(edit.range.start.character as usize);
let indented_content = format!("{}{}", indent, edit.new_text);

format!("Edit {}: Range: {:#?}\n{}", i + 1, edit.range, indented_content)
})
.collect::<Vec<_>>()
.join("\n----------\n")
}
}

/// Testing struct for the [formatter server][crate::formatter::server_formatter::ServerFormatter].
Expand Down Expand Up @@ -71,8 +87,8 @@ impl Tester<'_> {

let _ = write!(
snapshot_result,
"########## \nfile: {}/{relative_file_path}\n----------\n{snapshot}\n",
self.relative_root_dir
"========================================\nFile: {}/{}\n========================================\n{}\n",
self.relative_root_dir, relative_file_path, snapshot
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
source: crates/oxc_language_server/src/formatter/tester.rs
---
##########
file: fixtures/formatter/basic/basic.ts
----------
Range {
========================================
File: fixtures/formatter/basic/basic.ts
========================================
Range: Range {
start: Position {
line: 1,
character: 2,
Expand All @@ -13,6 +13,30 @@ Range {
line: 26,
character: 0,
},
},
}

"#name: string;\n\n public get name() {\n return this.#name;\n }\n\n private set name(name: string) {\n this.#name = name;\n }\n}\n\nclass C2 {\n #name: string;\n\n private set name(name: string) {\n this.#name = name;\n }\n\n public get name() {\n return this.#name;\n }\n}\n\nconst c1 = new C1();\nconst c2 = new C2();"
#name: string;

public get name() {
return this.#name;
}

private set name(name: string) {
this.#name = name;
}
}

class C2 {
#name: string;

private set name(name: string) {
this.#name = name;
}

public get name() {
return this.#name;
}
}

const c1 = new C1();
const c2 = new C2();
Loading