From 82c28640658df400e5bed2e208912247b1e83d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 12 Sep 2023 02:55:57 +0200 Subject: refactor: strongly typed TSC ops (#20466) Removes usage of `serde_json::Value` in several ops used in TSC, in favor of using strongly typed structs. This will unblock more changes in https://github.com/denoland/deno/pull/20462. --- cli/lsp/tsc.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index ae4a00e6a..425856d52 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -3252,26 +3252,29 @@ fn op_is_node_file(state: &mut OpState, path: String) -> bool { } } +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +struct LoadResponse { + data: Arc, + script_kind: i32, + version: Option, +} + #[op] fn op_load( state: &mut OpState, args: SpecifierArgs, -) -> Result { +) -> Result, AnyError> { let state = state.borrow_mut::(); let mark = state.performance.mark("op_load", Some(&args)); let specifier = state.normalize_specifier(args.specifier)?; let asset_or_document = state.get_asset_or_document(&specifier); state.performance.measure(mark); - Ok(match asset_or_document { - Some(doc) => { - json!({ - "data": doc.text(), - "scriptKind": crate::tsc::as_ts_script_kind(doc.media_type()), - "version": state.script_version(&specifier), - }) - } - None => Value::Null, - }) + Ok(asset_or_document.map(|doc| LoadResponse { + data: doc.text(), + script_kind: crate::tsc::as_ts_script_kind(doc.media_type()), + version: state.script_version(&specifier), + })) } #[op] @@ -3312,10 +3315,9 @@ fn op_resolve( } #[op] -fn op_respond(state: &mut OpState, args: Response) -> bool { +fn op_respond(state: &mut OpState, args: Response) { let state = state.borrow_mut::(); state.response = Some(args); - true } #[op] -- cgit v1.2.3