diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2022-03-14 23:38:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-14 23:38:53 +0100 |
commit | 88d0f01948b68f4a4d87e02a5138e94ac0a6eaea (patch) | |
tree | 2b50e5d2c6990c94f47e604281f3557b3efd9736 /cli | |
parent | 9f494dc405afc4b1b29fa4c813bd5751f26aaa36 (diff) |
feat(ops): custom arity (#13949)
Also cleanup & drop ignored wildcard op-args
Diffstat (limited to 'cli')
-rw-r--r-- | cli/build.rs | 19 | ||||
-rw-r--r-- | cli/lsp/tsc.rs | 22 | ||||
-rw-r--r-- | cli/ops/bench.rs | 11 | ||||
-rw-r--r-- | cli/ops/errors.rs | 3 | ||||
-rw-r--r-- | cli/ops/runtime_compiler.rs | 1 | ||||
-rw-r--r-- | cli/ops/testing.rs | 9 | ||||
-rw-r--r-- | cli/tsc.rs | 48 |
7 files changed, 17 insertions, 96 deletions
diff --git a/cli/build.rs b/cli/build.rs index f1eb1829c..d118dd5b9 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -192,7 +192,6 @@ fn create_compiler_snapshot( fn op_build_info( state: &mut OpState, _args: Value, - _: (), ) -> Result<Value, AnyError> { let build_specifier = "asset:///bootstrap.ts"; let build_libs = state.borrow::<Vec<&str>>(); @@ -203,31 +202,19 @@ fn create_compiler_snapshot( } #[op] - fn op_cwd( - _state: &mut OpState, - _args: Value, - _: (), - ) -> Result<Value, AnyError> { + fn op_cwd(_state: &mut OpState, _args: Value) -> Result<Value, AnyError> { Ok(json!("cache:///")) } #[op] - fn op_exists( - _state: &mut OpState, - _args: Value, - _: (), - ) -> Result<Value, AnyError> { + fn op_exists(_state: &mut OpState, _args: Value) -> Result<Value, AnyError> { Ok(json!(false)) } #[op] // using the same op that is used in `tsc.rs` for loading modules and reading // files, but a slightly different implementation at build time. - fn op_load( - state: &mut OpState, - args: LoadArgs, - _: (), - ) -> Result<Value, AnyError> { + fn op_load(state: &mut OpState, args: LoadArgs) -> Result<Value, AnyError> { let op_crate_libs = state.borrow::<HashMap<&str, &str>>(); let path_dts = state.borrow::<PathBuf>(); let re_asset = diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 648045f4e..4f3e88e7d 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2515,7 +2515,6 @@ struct SourceSnapshotArgs { fn op_dispose( state: &mut OpState, args: SourceSnapshotArgs, - _: (), ) -> Result<bool, AnyError> { let state = state.borrow_mut::<State>(); let mark = state.performance.mark("op_dispose", Some(&args)); @@ -2535,7 +2534,6 @@ struct SpecifierArgs { fn op_exists( state: &mut OpState, args: SpecifierArgs, - _: (), ) -> Result<bool, AnyError> { let state = state.borrow_mut::<State>(); // we don't measure the performance of op_exists anymore because as of TS 4.5 @@ -2569,7 +2567,6 @@ struct GetChangeRangeArgs { fn op_get_change_range( state: &mut OpState, args: GetChangeRangeArgs, - _: (), ) -> Result<Value, AnyError> { let state = state.borrow_mut::<State>(); let mark = state.performance.mark("op_get_change_range", Some(&args)); @@ -2616,7 +2613,6 @@ fn op_get_change_range( fn op_get_length( state: &mut OpState, args: SourceSnapshotArgs, - _: (), ) -> Result<usize, AnyError> { let state = state.borrow_mut::<State>(); let mark = state.performance.mark("op_get_length", Some(&args)); @@ -2650,7 +2646,6 @@ struct GetTextArgs { fn op_get_text( state: &mut OpState, args: GetTextArgs, - _: (), ) -> Result<String, AnyError> { let state = state.borrow_mut::<State>(); let mark = state.performance.mark("op_get_text", Some(&args)); @@ -2670,11 +2665,7 @@ fn op_get_text( } #[op] -fn op_is_cancelled( - state: &mut OpState, - _: (), - _: (), -) -> Result<bool, AnyError> { +fn op_is_cancelled(state: &mut OpState) -> Result<bool, AnyError> { let state = state.borrow_mut::<State>(); Ok(state.token.is_cancelled()) } @@ -2683,7 +2674,6 @@ fn op_is_cancelled( fn op_load( state: &mut OpState, args: SpecifierArgs, - _: (), ) -> Result<Option<String>, AnyError> { let state = state.borrow_mut::<State>(); let mark = state.performance.mark("op_load", Some(&args)); @@ -2697,7 +2687,6 @@ fn op_load( fn op_resolve( state: &mut OpState, args: ResolveArgs, - _: (), ) -> Result<Vec<Option<(String, String)>>, AnyError> { let state = state.borrow_mut::<State>(); let mark = state.performance.mark("op_resolve", Some(&args)); @@ -2731,11 +2720,7 @@ fn op_resolve( } #[op] -fn op_respond( - state: &mut OpState, - args: Response, - _: (), -) -> Result<bool, AnyError> { +fn op_respond(state: &mut OpState, args: Response) -> Result<bool, AnyError> { let state = state.borrow_mut::<State>(); state.response = Some(args); Ok(true) @@ -2745,7 +2730,6 @@ fn op_respond( fn op_script_names( state: &mut OpState, _args: Value, - _: (), ) -> Result<Vec<ModuleSpecifier>, AnyError> { let state = state.borrow_mut::<State>(); Ok( @@ -2769,7 +2753,6 @@ struct ScriptVersionArgs { fn op_script_version( state: &mut OpState, args: ScriptVersionArgs, - _: (), ) -> Result<Option<String>, AnyError> { let state = state.borrow_mut::<State>(); // this op is very "noisy" and measuring its performance is not useful, so we @@ -3881,7 +3864,6 @@ mod tests { SpecifierArgs { specifier: "/error/unknown:something/index.d.ts".to_string(), }, - (), ); assert!(actual.is_ok()); let actual = actual.unwrap(); diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index ab15a2b4b..4b7d6743f 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -35,7 +35,6 @@ struct PermissionsHolder(Uuid, Permissions); pub fn op_pledge_test_permissions( state: &mut OpState, args: ChildPermissionsArg, - _: (), ) -> Result<Uuid, AnyError> { let token = Uuid::new_v4(); let parent_permissions = state.borrow_mut::<Permissions>(); @@ -54,7 +53,6 @@ pub fn op_pledge_test_permissions( pub fn op_restore_test_permissions( state: &mut OpState, token: Uuid, - _: (), ) -> Result<(), AnyError> { if let Some(permissions_holder) = state.try_take::<PermissionsHolder>() { if token != permissions_holder.0 { @@ -70,11 +68,7 @@ pub fn op_restore_test_permissions( } #[op] -fn op_get_bench_origin( - state: &mut OpState, - _: (), - _: (), -) -> Result<String, AnyError> { +fn op_get_bench_origin(state: &mut OpState) -> Result<String, AnyError> { Ok(state.borrow::<ModuleSpecifier>().to_string()) } @@ -82,7 +76,6 @@ fn op_get_bench_origin( fn op_dispatch_bench_event( state: &mut OpState, event: BenchEvent, - _: (), ) -> Result<(), AnyError> { let sender = state.borrow::<UnboundedSender<BenchEvent>>().clone(); sender.send(event).ok(); @@ -91,7 +84,7 @@ fn op_dispatch_bench_event( } #[op] -fn op_bench_now(state: &mut OpState, _: (), _: ()) -> Result<u64, AnyError> { +fn op_bench_now(state: &mut OpState) -> Result<u64, AnyError> { let ns = state.borrow::<time::Instant>().elapsed().as_nanos(); let ns_u64 = u64::try_from(ns)?; Ok(ns_u64) diff --git a/cli/ops/errors.rs b/cli/ops/errors.rs index c215ade41..5be6e0737 100644 --- a/cli/ops/errors.rs +++ b/cli/ops/errors.rs @@ -46,7 +46,6 @@ struct AppliedSourceMap { fn op_apply_source_map( state: &mut OpState, args: ApplySourceMap, - _: (), ) -> Result<AppliedSourceMap, AnyError> { let mut mappings_map: CachedMaps = HashMap::new(); let ps = state.borrow::<ProcState>().clone(); @@ -71,7 +70,6 @@ fn op_apply_source_map( fn op_format_diagnostic( _state: &mut OpState, args: Value, - _: (), ) -> Result<Value, AnyError> { let diagnostic: Diagnostics = serde_json::from_value(args)?; Ok(json!(diagnostic.to_string())) @@ -81,7 +79,6 @@ fn op_format_diagnostic( fn op_format_file_name( _state: &mut OpState, file_name: String, - _: (), ) -> Result<String, AnyError> { Ok(format_file_name(&file_name)) } diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index 6fb8d688c..8c02190c0 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -144,7 +144,6 @@ fn to_maybe_jsx_import_source_module( async fn op_emit( state: Rc<RefCell<OpState>>, args: EmitArgs, - _: (), ) -> Result<EmitResult, AnyError> { deno_runtime::ops::check_unstable2(&state, "Deno.emit"); let root_specifier = args.root_specifier; diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index ebaa819e1..eb2deb90c 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -33,7 +33,6 @@ struct PermissionsHolder(Uuid, Permissions); pub fn op_pledge_test_permissions( state: &mut OpState, args: ChildPermissionsArg, - _: (), ) -> Result<Uuid, AnyError> { let token = Uuid::new_v4(); let parent_permissions = state.borrow_mut::<Permissions>(); @@ -52,7 +51,6 @@ pub fn op_pledge_test_permissions( pub fn op_restore_test_permissions( state: &mut OpState, token: Uuid, - _: (), ) -> Result<(), AnyError> { if let Some(permissions_holder) = state.try_take::<PermissionsHolder>() { if token != permissions_holder.0 { @@ -68,11 +66,7 @@ pub fn op_restore_test_permissions( } #[op] -fn op_get_test_origin( - state: &mut OpState, - _: (), - _: (), -) -> Result<String, AnyError> { +fn op_get_test_origin(state: &mut OpState) -> Result<String, AnyError> { Ok(state.borrow::<ModuleSpecifier>().to_string()) } @@ -80,7 +74,6 @@ fn op_get_test_origin( fn op_dispatch_test_event( state: &mut OpState, event: TestEvent, - _: (), ) -> Result<(), AnyError> { let sender = state.borrow::<UnboundedSender<TestEvent>>().clone(); sender.send(event).ok(); diff --git a/cli/tsc.rs b/cli/tsc.rs index ddb8a442e..39f78ec9d 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -307,11 +307,7 @@ struct CreateHashArgs { } #[op] -fn op_create_hash( - s: &mut OpState, - args: Value, - _: (), -) -> Result<Value, AnyError> { +fn op_create_hash(s: &mut OpState, args: Value) -> Result<Value, AnyError> { let state = s.borrow_mut::<State>(); let v: CreateHashArgs = serde_json::from_value(args) .context("Invalid request from JavaScript for \"op_create_hash\".")?; @@ -322,7 +318,7 @@ fn op_create_hash( } #[op] -fn op_cwd(s: &mut OpState, _args: Value, _: ()) -> Result<String, AnyError> { +fn op_cwd(s: &mut OpState, _args: Value) -> Result<String, AnyError> { let state = s.borrow_mut::<State>(); if let Some(config_specifier) = &state.maybe_config_specifier { let cwd = config_specifier.join("./")?; @@ -347,11 +343,7 @@ struct EmitArgs { } #[op] -fn op_emit( - state: &mut OpState, - args: EmitArgs, - _: (), -) -> Result<Value, AnyError> { +fn op_emit(state: &mut OpState, args: EmitArgs) -> Result<Value, AnyError> { let state = state.borrow_mut::<State>(); match args.file_name.as_ref() { "deno:///.tsbuildinfo" => state.maybe_tsbuildinfo = Some(args.data), @@ -406,11 +398,7 @@ struct ExistsArgs { } #[op] -fn op_exists( - state: &mut OpState, - args: ExistsArgs, - _: (), -) -> Result<bool, AnyError> { +fn op_exists(state: &mut OpState, args: ExistsArgs) -> Result<bool, AnyError> { let state = state.borrow_mut::<State>(); let graph_data = state.graph_data.read(); if let Ok(specifier) = normalize_specifier(&args.specifier) { @@ -452,7 +440,7 @@ fn as_ts_script_kind(media_type: &MediaType) -> i32 { } #[op] -fn op_load(state: &mut OpState, args: Value, _: ()) -> Result<Value, AnyError> { +fn op_load(state: &mut OpState, args: Value) -> Result<Value, AnyError> { let state = state.borrow_mut::<State>(); let v: LoadArgs = serde_json::from_value(args) .context("Invalid request from JavaScript for \"op_load\".")?; @@ -521,7 +509,6 @@ pub struct ResolveArgs { fn op_resolve( state: &mut OpState, args: ResolveArgs, - _: (), ) -> Result<Value, AnyError> { let state = state.borrow_mut::<State>(); let mut resolved: Vec<(String, String)> = Vec::new(); @@ -629,11 +616,7 @@ struct RespondArgs { } #[op] -fn op_respond( - state: &mut OpState, - args: Value, - _: (), -) -> Result<Value, AnyError> { +fn op_respond(state: &mut OpState, args: Value) -> Result<Value, AnyError> { let state = state.borrow_mut::<State>(); let v: RespondArgs = serde_json::from_value(args) .context("Error converting the result for \"op_respond\".")?; @@ -881,7 +864,6 @@ mod tests { let actual = op_create_hash::call( &mut state, json!({ "data": "some sort of content" }), - (), ) .expect("could not invoke op"); assert_eq!( @@ -934,7 +916,6 @@ mod tests { file_name: "cache:///some/file.js".to_string(), maybe_specifiers: Some(vec!["file:///some/file.ts".to_string()]), }, - (), ) .expect("should have invoked op"); assert_eq!(actual, json!(true)); @@ -966,7 +947,6 @@ mod tests { vec!["file:///some/file.ts?q=.json".to_string()], ), }, - (), ) .expect("should have invoked op"); assert_eq!(actual, json!(true)); @@ -996,7 +976,6 @@ mod tests { file_name: "deno:///.tsbuildinfo".to_string(), maybe_specifiers: None, }, - (), ) .expect("should have invoked op"); assert_eq!(actual, json!(true)); @@ -1019,7 +998,6 @@ mod tests { let actual = op_load::call( &mut state, json!({ "specifier": "https://deno.land/x/mod.ts"}), - (), ) .expect("should have invoked op"); assert_eq!( @@ -1051,7 +1029,6 @@ mod tests { let value = op_load::call( &mut state, json!({ "specifier": "asset:///lib.dom.d.ts" }), - (), ) .expect("should have invoked op"); let actual: LoadResponse = @@ -1070,12 +1047,9 @@ mod tests { Some("some content".to_string()), ) .await; - let actual = op_load::call( - &mut state, - json!({ "specifier": "deno:///.tsbuildinfo"}), - (), - ) - .expect("should have invoked op"); + let actual = + op_load::call(&mut state, json!({ "specifier": "deno:///.tsbuildinfo"})) + .expect("should have invoked op"); assert_eq!( actual, json!({ @@ -1092,7 +1066,6 @@ mod tests { let actual = op_load::call( &mut state, json!({ "specifier": "https://deno.land/x/mod.ts"}), - (), ) .expect("should have invoked op"); assert_eq!( @@ -1119,7 +1092,6 @@ mod tests { base: "https://deno.land/x/a.ts".to_string(), specifiers: vec!["./b.ts".to_string()], }, - (), ) .expect("should have invoked op"); assert_eq!(actual, json!([["https://deno.land/x/b.ts", ".ts"]])); @@ -1139,7 +1111,6 @@ mod tests { base: "https://deno.land/x/a.ts".to_string(), specifiers: vec!["./bad.ts".to_string()], }, - (), ) .expect("should have not errored"); assert_eq!( @@ -1163,7 +1134,6 @@ mod tests { ], "stats": [["a", 12]] }), - (), ) .expect("should have invoked op"); assert_eq!(actual, json!(true)); |