2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-09-05 20:34:02 -04:00
|
|
|
|
2020-09-12 05:53:57 -04:00
|
|
|
use crate::diagnostics::Diagnostics;
|
2021-09-18 09:40:04 -04:00
|
|
|
use crate::fmt_errors::format_file_name;
|
2020-09-14 12:48:57 -04:00
|
|
|
use deno_core::error::AnyError;
|
2022-03-14 13:44:15 -04:00
|
|
|
use deno_core::op;
|
2020-09-21 12:36:37 -04:00
|
|
|
use deno_core::serde_json;
|
|
|
|
use deno_core::serde_json::json;
|
|
|
|
use deno_core::serde_json::Value;
|
2021-12-29 08:30:08 -05:00
|
|
|
use deno_core::Extension;
|
2019-08-14 11:03:02 -04:00
|
|
|
|
2021-12-29 08:30:08 -05:00
|
|
|
pub fn init() -> Extension {
|
|
|
|
Extension::builder()
|
|
|
|
.ops(vec![
|
2022-03-14 13:44:15 -04:00
|
|
|
op_format_diagnostic::decl(),
|
|
|
|
op_format_file_name::decl(),
|
2021-12-29 08:30:08 -05:00
|
|
|
])
|
|
|
|
.build()
|
2019-10-11 14:41:54 -04:00
|
|
|
}
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
#[op]
|
2022-03-15 19:33:46 -04:00
|
|
|
fn op_format_diagnostic(args: Value) -> Result<Value, AnyError> {
|
2020-09-12 05:53:57 -04:00
|
|
|
let diagnostic: Diagnostics = serde_json::from_value(args)?;
|
2020-08-28 11:08:24 -04:00
|
|
|
Ok(json!(diagnostic.to_string()))
|
2020-02-24 14:48:14 -05:00
|
|
|
}
|
2021-09-18 09:40:04 -04:00
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
#[op]
|
2022-03-15 19:33:46 -04:00
|
|
|
fn op_format_file_name(file_name: String) -> Result<String, AnyError> {
|
2021-09-18 09:40:04 -04:00
|
|
|
Ok(format_file_name(&file_name))
|
|
|
|
}
|