Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
fis the method signatures on DiagnosticPrinter
Browse files Browse the repository at this point in the history
  • Loading branch information
leops committed Nov 23, 2022
1 parent f9d3120 commit fabbe82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions crates/rome_wasm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,27 @@ impl DiagnosticPrinter {
}
}

pub fn print(&mut self, diagnostic: IDiagnostic, verbose: bool) -> Result<(), Error> {
pub fn print_simple(&mut self, diagnostic: IDiagnostic) -> Result<(), Error> {
self.print(diagnostic, |err| PrintDiagnostic::simple(err))
}

pub fn print_verbose(&mut self, diagnostic: IDiagnostic) -> Result<(), Error> {
self.print(diagnostic, |err| PrintDiagnostic::verbose(err))
}

fn print(
&mut self,
diagnostic: IDiagnostic,
printer: fn(&rome_diagnostics::Error) -> PrintDiagnostic<rome_diagnostics::Error>,
) -> Result<(), Error> {
let diag: Diagnostic = diagnostic.into_serde().map_err(into_error)?;
let err = diag
.with_file_path(&self.file_name)
.with_file_source_code(&self.file_source);

let mut html = HTML(&mut self.buffer);
Formatter::new(&mut html)
.write_markup(markup!({
if verbose {
PrintDiagnostic::verbose(&err)
} else {
PrintDiagnostic::simple(&err)
}
}))
.write_markup(markup!({ printer(&err) }))
.map_err(into_error)?;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions npm/js-api/tests/wasm/diagnosticPrinter.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(expr()) {
}`;
const printer = new DiagnosticPrinter("file.js", SOURCE_CODE);

printer.print({
printer.print_verbose({
advices: {
advices: [],
},
Expand Down Expand Up @@ -42,7 +42,7 @@ if(expr()) {
},
});

printer.print({
printer.print_verbose({
advices: {
advices: [],
},
Expand Down
2 changes: 1 addition & 1 deletion website/src/playground/workers/romeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ self.addEventListener("message", async (e) => {

const printer = new DiagnosticPrinter(path.path, code);
for (const diag of diagnosticsResult.diagnostics) {
printer.print(diag);
printer.print_verbose(diag);
}

const printed = workspace.formatFile({
Expand Down

0 comments on commit fabbe82

Please sign in to comment.