summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
Diffstat (limited to 'cli')
-rw-r--r--cli/build.rs17
-rw-r--r--cli/lsp/tsc.rs41
-rw-r--r--cli/ops/bench.rs14
-rw-r--r--cli/tsc.rs40
4 files changed, 46 insertions, 66 deletions
diff --git a/cli/build.rs b/cli/build.rs
index 89afe642c..019f8d02d 100644
--- a/cli/build.rs
+++ b/cli/build.rs
@@ -178,26 +178,23 @@ fn create_compiler_snapshot(
}
#[op]
- fn op_build_info(
- state: &mut OpState,
- _args: Value,
- ) -> Result<Value, AnyError> {
+ fn op_build_info(state: &mut OpState) -> Value {
let build_specifier = "asset:///bootstrap.ts";
let build_libs = state.borrow::<Vec<&str>>();
- Ok(json!({
+ json!({
"buildSpecifier": build_specifier,
"libs": build_libs,
- }))
+ })
}
#[op]
- fn op_cwd(_args: Value) -> Result<Value, AnyError> {
- Ok(json!("cache:///"))
+ fn op_cwd() -> String {
+ "cache:///".into()
}
#[op]
- fn op_exists(_args: Value) -> Result<Value, AnyError> {
- Ok(json!(false))
+ fn op_exists() -> bool {
+ false
}
#[op]
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 0557179b6..27d32b2db 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -2489,10 +2489,7 @@ struct SpecifierArgs {
}
#[op]
-fn op_exists(
- state: &mut OpState,
- args: SpecifierArgs,
-) -> Result<bool, AnyError> {
+fn op_exists(state: &mut OpState, args: SpecifierArgs) -> bool {
let state = state.borrow_mut::<State>();
// we don't measure the performance of op_exists anymore because as of TS 4.5
// it is noisy with all the checking for custom libs, that we can't see the
@@ -2504,10 +2501,9 @@ fn op_exists(
// sometimes tsc tries to query invalid specifiers, especially when
// something else isn't quite right, so instead of bubbling up the error
// back to tsc, we simply swallow it and say the file doesn't exist
- Err(_) => return Ok(false),
+ Err(_) => return false,
};
- let result = state.state_snapshot.documents.exists(&specifier);
- Ok(result)
+ state.state_snapshot.documents.exists(&specifier)
}
#[derive(Debug, Deserialize, Serialize)]
@@ -2621,9 +2617,9 @@ fn op_get_text(
}
#[op]
-fn op_is_cancelled(state: &mut OpState) -> Result<bool, AnyError> {
+fn op_is_cancelled(state: &mut OpState) -> bool {
let state = state.borrow_mut::<State>();
- Ok(state.token.is_cancelled())
+ state.token.is_cancelled()
}
#[op]
@@ -2676,27 +2672,22 @@ fn op_resolve(
}
#[op]
-fn op_respond(state: &mut OpState, args: Response) -> Result<bool, AnyError> {
+fn op_respond(state: &mut OpState, args: Response) -> bool {
let state = state.borrow_mut::<State>();
state.response = Some(args);
- Ok(true)
+ true
}
#[op]
-fn op_script_names(
- state: &mut OpState,
- _args: Value,
-) -> Result<Vec<ModuleSpecifier>, AnyError> {
+fn op_script_names(state: &mut OpState) -> Vec<ModuleSpecifier> {
let state = state.borrow_mut::<State>();
- Ok(
- state
- .state_snapshot
- .documents
- .documents(true, true)
- .into_iter()
- .map(|d| d.specifier().clone())
- .collect(),
- )
+ state
+ .state_snapshot
+ .documents
+ .documents(true, true)
+ .into_iter()
+ .map(|d| d.specifier().clone())
+ .collect()
}
#[derive(Debug, Deserialize, Serialize)]
@@ -3844,8 +3835,6 @@ mod tests {
specifier: "/error/unknown:something/index.d.ts".to_string(),
},
);
- assert!(actual.is_ok());
- let actual = actual.unwrap();
assert!(!actual);
}
diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs
index 6f4b80974..e028aa6b1 100644
--- a/cli/ops/bench.rs
+++ b/cli/ops/bench.rs
@@ -45,9 +45,8 @@ fn check_unstable(state: &OpState, api_name: &str) {
}
#[op]
-fn op_bench_check_unstable(state: &mut OpState) -> Result<(), AnyError> {
+fn op_bench_check_unstable(state: &mut OpState) {
check_unstable(state, "Deno.bench");
- Ok(())
}
#[derive(Clone)]
@@ -94,19 +93,14 @@ pub fn op_restore_test_permissions(
}
#[op]
-fn op_get_bench_origin(state: &mut OpState) -> Result<String, AnyError> {
- Ok(state.borrow::<ModuleSpecifier>().to_string())
+fn op_get_bench_origin(state: &mut OpState) -> String {
+ state.borrow::<ModuleSpecifier>().to_string()
}
#[op]
-fn op_dispatch_bench_event(
- state: &mut OpState,
- event: BenchEvent,
-) -> Result<(), AnyError> {
+fn op_dispatch_bench_event(state: &mut OpState, event: BenchEvent) {
let sender = state.borrow::<UnboundedSender<BenchEvent>>().clone();
sender.send(event).ok();
-
- Ok(())
}
#[op]
diff --git a/cli/tsc.rs b/cli/tsc.rs
index c39ed6c0d..aba289d8c 100644
--- a/cli/tsc.rs
+++ b/cli/tsc.rs
@@ -344,7 +344,7 @@ struct EmitArgs {
}
#[op]
-fn op_emit(state: &mut OpState, args: EmitArgs) -> Result<Value, AnyError> {
+fn op_emit(state: &mut OpState, args: EmitArgs) -> bool {
let state = state.borrow_mut::<State>();
match args.file_name.as_ref() {
"deno:///.tsbuildinfo" => state.maybe_tsbuildinfo = Some(args.data),
@@ -389,7 +389,7 @@ fn op_emit(state: &mut OpState, args: EmitArgs) -> Result<Value, AnyError> {
}
}
- Ok(json!(true))
+ true
}
#[derive(Debug, Deserialize)]
@@ -399,20 +399,20 @@ struct ExistsArgs {
}
#[op]
-fn op_exists(state: &mut OpState, args: ExistsArgs) -> Result<bool, AnyError> {
+fn op_exists(state: &mut OpState, args: ExistsArgs) -> bool {
let state = state.borrow_mut::<State>();
let graph_data = state.graph_data.read();
if let Ok(specifier) = normalize_specifier(&args.specifier) {
if specifier.scheme() == "asset" || specifier.scheme() == "data" {
- Ok(true)
+ true
} else {
- Ok(matches!(
+ matches!(
graph_data.get(&graph_data.follow_redirect(&specifier)),
Some(ModuleEntry::Module { .. })
- ))
+ )
}
} else {
- Ok(false)
+ false
}
}
@@ -510,7 +510,7 @@ pub struct ResolveArgs {
fn op_resolve(
state: &mut OpState,
args: ResolveArgs,
-) -> Result<Value, AnyError> {
+) -> Result<Vec<(String, String)>, AnyError> {
let state = state.borrow_mut::<State>();
let mut resolved: Vec<(String, String)> = Vec::new();
let referrer = if let Some(remapped_specifier) =
@@ -607,7 +607,7 @@ fn op_resolve(
}
}
- Ok(json!(resolved))
+ Ok(resolved)
}
#[derive(Debug, Deserialize, Eq, PartialEq)]
@@ -917,9 +917,8 @@ 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));
+ );
+ assert!(actual);
let state = state.borrow::<State>();
assert_eq!(state.emitted_files.len(), 1);
assert!(state.maybe_tsbuildinfo.is_none());
@@ -948,9 +947,8 @@ mod tests {
vec!["file:///some/file.ts?q=.json".to_string()],
),
},
- )
- .expect("should have invoked op");
- assert_eq!(actual, json!(true));
+ );
+ assert!(actual);
let state = state.borrow::<State>();
assert_eq!(state.emitted_files.len(), 1);
assert!(state.maybe_tsbuildinfo.is_none());
@@ -977,9 +975,8 @@ mod tests {
file_name: "deno:///.tsbuildinfo".to_string(),
maybe_specifiers: None,
},
- )
- .expect("should have invoked op");
- assert_eq!(actual, json!(true));
+ );
+ assert!(actual);
let state = state.borrow::<State>();
assert_eq!(state.emitted_files.len(), 0);
assert_eq!(
@@ -1095,7 +1092,10 @@ mod tests {
},
)
.expect("should have invoked op");
- assert_eq!(actual, json!([["https://deno.land/x/b.ts", ".ts"]]));
+ assert_eq!(
+ actual,
+ vec![("https://deno.land/x/b.ts".into(), ".ts".into())]
+ );
}
#[tokio::test]
@@ -1116,7 +1116,7 @@ mod tests {
.expect("should have not errored");
assert_eq!(
actual,
- json!([["deno:///missing_dependency.d.ts", ".d.ts"]])
+ vec![("deno:///missing_dependency.d.ts".into(), ".d.ts".into())]
);
}