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