diff options
Diffstat (limited to 'cli/lsp/tsc.rs')
-rw-r--r-- | cli/lsp/tsc.rs | 75 |
1 files changed, 50 insertions, 25 deletions
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index d5cedfd51..c345b705d 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -1832,7 +1832,7 @@ where }) } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct SourceSnapshotArgs { specifier: String, @@ -1846,14 +1846,17 @@ fn op_dispose( state: &mut State, args: SourceSnapshotArgs, ) -> Result<bool, AnyError> { - let mark = state.state_snapshot.performance.mark("op_dispose"); + let mark = state + .state_snapshot + .performance + .mark("op_dispose", Some(&args)); let specifier = resolve_url(&args.specifier)?; state.snapshots.remove(&(specifier, args.version.into())); state.state_snapshot.performance.measure(mark); Ok(true) } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct GetChangeRangeArgs { specifier: String, @@ -1868,10 +1871,13 @@ fn op_get_change_range( state: &mut State, args: GetChangeRangeArgs, ) -> Result<Value, AnyError> { - let mark = state.state_snapshot.performance.mark("op_get_change_range"); + let mark = state + .state_snapshot + .performance + .mark("op_get_change_range", Some(&args)); let specifier = resolve_url(&args.specifier)?; cache_snapshot(state, &specifier, args.version.clone())?; - if let Some(current) = state + let r = if let Some(current) = state .snapshots .get(&(specifier.clone(), args.version.clone().into())) { @@ -1879,11 +1885,9 @@ fn op_get_change_range( .snapshots .get(&(specifier, args.old_version.clone().into())) { - state.state_snapshot.performance.measure(mark); Ok(text::get_range_change(prev, current)) } else { let new_length = current.encode_utf16().count(); - state.state_snapshot.performance.measure(mark); // when a local file is opened up in the editor, the compiler might // already have a snapshot of it in memory, and will request it, but we // now are working off in memory versions of the document, and so need @@ -1897,7 +1901,6 @@ fn op_get_change_range( })) } } else { - state.state_snapshot.performance.measure(mark); Err(custom_error( "MissingSnapshot", format!( @@ -1905,16 +1908,23 @@ fn op_get_change_range( args ), )) - } + }; + + state.state_snapshot.performance.measure(mark); + r } fn op_get_length( state: &mut State, args: SourceSnapshotArgs, ) -> Result<usize, AnyError> { - let mark = state.state_snapshot.performance.mark("op_get_length"); + let mark = state + .state_snapshot + .performance + .mark("op_get_length", Some(&args)); let specifier = resolve_url(&args.specifier)?; - if let Some(Some(asset)) = state.state_snapshot.assets.get(&specifier) { + let r = if let Some(Some(asset)) = state.state_snapshot.assets.get(&specifier) + { Ok(asset.length) } else { cache_snapshot(state, &specifier, args.version.clone())?; @@ -1922,12 +1932,13 @@ fn op_get_length( .snapshots .get(&(specifier, args.version.into())) .unwrap(); - state.state_snapshot.performance.measure(mark); Ok(content.encode_utf16().count()) - } + }; + state.state_snapshot.performance.measure(mark); + r } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct GetTextArgs { specifier: String, @@ -1940,7 +1951,10 @@ fn op_get_text( state: &mut State, args: GetTextArgs, ) -> Result<String, AnyError> { - let mark = state.state_snapshot.performance.mark("op_get_text"); + let mark = state + .state_snapshot + .performance + .mark("op_get_text", Some(&args)); let specifier = resolve_url(&args.specifier)?; let content = if let Some(Some(content)) = state.state_snapshot.assets.get(&specifier) { @@ -1961,7 +1975,10 @@ fn op_resolve( state: &mut State, args: ResolveArgs, ) -> Result<Vec<Option<(String, String)>>, AnyError> { - let mark = state.state_snapshot.performance.mark("op_resolve"); + let mark = state + .state_snapshot + .performance + .mark("op_resolve", Some(&args)); let mut resolved = Vec::new(); let referrer = resolve_url(&args.base)?; let sources = &mut state.state_snapshot.sources; @@ -2069,7 +2086,7 @@ fn op_script_names( ) } -#[derive(Debug, Deserialize)] +#[derive(Debug, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct ScriptVersionArgs { specifier: String, @@ -2079,27 +2096,32 @@ fn op_script_version( state: &mut State, args: ScriptVersionArgs, ) -> Result<Option<String>, AnyError> { - let mark = state.state_snapshot.performance.mark("op_script_version"); + let mark = state + .state_snapshot + .performance + .mark("op_script_version", Some(&args)); let specifier = resolve_url(&args.specifier)?; - if specifier.scheme() == "asset" { - return if state.state_snapshot.assets.contains_key(&specifier) { + let r = if specifier.scheme() == "asset" { + if state.state_snapshot.assets.contains_key(&specifier) { Ok(Some("1".to_string())) } else { Ok(None) - }; + } } else if let Some(version) = state.state_snapshot.documents.version(&specifier) { - return Ok(Some(version.to_string())); + Ok(Some(version.to_string())) } else { let sources = &mut state.state_snapshot.sources; if let Some(version) = sources.get_script_version(&specifier) { - return Ok(Some(version)); + Ok(Some(version)) + } else { + Ok(None) } - } + }; state.state_snapshot.performance.measure(mark); - Ok(None) + r } /// Create and setup a JsRuntime based on a snapshot. It is expected that the @@ -2498,6 +2520,7 @@ pub fn request( state_snapshot: StateSnapshot, method: RequestMethod, ) -> Result<Value, AnyError> { + let performance = state_snapshot.performance.clone(); let id = { let op_state = runtime.op_state(); let mut op_state = op_state.borrow_mut(); @@ -2507,6 +2530,7 @@ pub fn request( state.last_id }; let request_params = method.to_value(id); + let mark = performance.mark("request", Some(request_params.clone())); let request_src = format!("globalThis.serverRequest({});", request_params); runtime.execute("[native_code]", &request_src)?; @@ -2514,6 +2538,7 @@ pub fn request( let mut op_state = op_state.borrow_mut(); let state = op_state.borrow_mut::<State>(); + performance.measure(mark); if let Some(response) = state.response.clone() { state.response = None; Ok(response.data) |