summaryrefslogtreecommitdiff
path: root/cli/tsc
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2023-12-12 10:26:27 +0000
committerGitHub <noreply@github.com>2023-12-12 10:26:27 +0000
commit7d88e48296f2b88c646335b2868ca9e48b08a3d2 (patch)
tree32a2fa31383aaa4c4dd7d0d7a45898290b21e79a /cli/tsc
parent49a6daaa8386f321d23f57fb5f3ae365abf82a80 (diff)
perf(lsp): use null types instead of stub modules (#21541)
Diffstat (limited to 'cli/tsc')
-rw-r--r--cli/tsc/99_main_compiler.js2
-rw-r--r--cli/tsc/mod.rs36
2 files changed, 16 insertions, 22 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index d795e542b..e1b7b462c 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -528,7 +528,7 @@ delete Object.prototype.__proto__;
if (logDebug) {
debug(`host.readFile("${specifier}")`);
}
- return ops.op_load(specifier).data;
+ return ops.op_load(specifier)?.data;
},
getCancellationToken() {
// createLanguageService will call this immediately and cache it
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs
index 6a239c1e9..7ef4bf83a 100644
--- a/cli/tsc/mod.rs
+++ b/cli/tsc/mod.rs
@@ -441,7 +441,7 @@ pub fn as_ts_script_kind(media_type: MediaType) -> i32 {
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
struct LoadResponse {
- data: Option<String>,
+ data: String,
version: Option<String>,
script_kind: i32,
}
@@ -451,7 +451,7 @@ struct LoadResponse {
fn op_load(
state: &mut OpState,
#[string] load_specifier: &str,
-) -> Result<LoadResponse, AnyError> {
+) -> Result<Option<LoadResponse>, AnyError> {
let state = state.borrow_mut::<State>();
let specifier = normalize_specifier(load_specifier, &state.current_dir)
@@ -466,9 +466,7 @@ fn op_load(
// in certain situations we return a "blank" module to tsc and we need to
// handle the request for that module here.
} else if load_specifier == "internal:///missing_dependency.d.ts" {
- hash = Some("1".to_string());
- media_type = MediaType::Dts;
- Some(Cow::Borrowed("declare const __: any;\nexport = __;\n"))
+ None
} else if let Some(name) = load_specifier.strip_prefix("asset:///") {
let maybe_source = get_lazily_loaded_asset(name);
hash = get_maybe_hash(maybe_source, state.hash_data);
@@ -521,18 +519,19 @@ fn op_load(
.with_context(|| format!("Unable to load {}", file_path.display()))?;
Some(Cow::Owned(code))
} else {
- media_type = MediaType::Unknown;
None
};
hash = get_maybe_hash(maybe_source.as_deref(), state.hash_data);
maybe_source
};
-
- Ok(LoadResponse {
- data: data.map(String::from),
+ let Some(data) = data else {
+ return Ok(None);
+ };
+ Ok(Some(LoadResponse {
+ data: data.into_owned(),
version: hash,
script_kind: as_ts_script_kind(media_type),
- })
+ }))
}
#[derive(Debug, Deserialize, Serialize)]
@@ -1079,9 +1078,10 @@ mod tests {
)
.await;
let actual = op_load::call(&mut state, "asset:///lib.dom.d.ts")
- .expect("should have invoked op");
+ .expect("should have invoked op")
+ .expect("load should have succeeded");
let expected = get_lazily_loaded_asset("lib.dom.d.ts").unwrap();
- assert_eq!(actual.data.unwrap(), expected);
+ assert_eq!(actual.data, expected);
assert!(actual.version.is_some());
assert_eq!(actual.script_kind, 3);
}
@@ -1095,7 +1095,8 @@ mod tests {
)
.await;
let actual = op_load::call(&mut state, "internal:///.tsbuildinfo")
- .expect("should have invoked op");
+ .expect("should have invoked op")
+ .expect("load should have succeeded");
assert_eq!(
serde_json::to_value(actual).unwrap(),
json!({
@@ -1111,14 +1112,7 @@ mod tests {
let mut state = setup(None, None, None).await;
let actual = op_load::call(&mut state, "https://deno.land/x/mod.ts")
.expect("should have invoked op");
- assert_eq!(
- serde_json::to_value(actual).unwrap(),
- json!({
- "data": null,
- "version": null,
- "scriptKind": 0,
- })
- )
+ assert_eq!(serde_json::to_value(actual).unwrap(), json!(null));
}
#[tokio::test]