diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-09-12 02:55:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-12 00:55:57 +0000 |
commit | 82c28640658df400e5bed2e208912247b1e83d0f (patch) | |
tree | df8e55c5c311ab5306818761ff5efccb1b33fb1c /cli/lsp | |
parent | 950e0e9cd65bd634d59fe60d5a0cb8651958c7fb (diff) |
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.
Diffstat (limited to 'cli/lsp')
-rw-r--r-- | cli/lsp/tsc.rs | 28 |
1 files changed, 15 insertions, 13 deletions
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<str>, + script_kind: i32, + version: Option<String>, +} + #[op] fn op_load( state: &mut OpState, args: SpecifierArgs, -) -> Result<Value, AnyError> { +) -> Result<Option<LoadResponse>, AnyError> { let state = state.borrow_mut::<State>(); 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>(); state.response = Some(args); - true } #[op] |