Skip to content

Commit

Permalink
refactor: unify CDP types in a single module (#21094)
Browse files Browse the repository at this point in the history
This commit moves all Chrome Devtools Protocol messages to `cli/cdp.rs`
and refactors all places using these types to pull them from a common
place.

No functional changes.
  • Loading branch information
bartlomieju authored Nov 5, 2023
1 parent 68a9643 commit fdb4953
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 240 deletions.
78 changes: 78 additions & 0 deletions cli/tools/repl/cdp.rs → cli/cdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,81 @@ pub type UnserializableValue = String;

/// <https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-UniqueDebuggerId>
pub type UniqueDebuggerId = String;

/// <https://chromedevtools.github.io/devtools-protocol/tot/Debugger/#method-setScriptSource>
#[derive(Debug, Deserialize)]
pub struct SetScriptSourceResponse {
pub status: Status,
}

#[derive(Debug, Deserialize)]
pub enum Status {
Ok,
CompileError,
BlockedByActiveGenerator,
BlockedByActiveFunction,
BlockedByTopLevelEsModuleChange,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Debugger/#event-scriptParsed>
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScriptParsed {
pub script_id: String,
pub url: String,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-CoverageRange>
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CoverageRange {
/// Start character index.
#[serde(rename = "startOffset")]
pub start_char_offset: usize,
/// End character index.
#[serde(rename = "endOffset")]
pub end_char_offset: usize,
pub count: i64,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-FunctionCoverage>
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FunctionCoverage {
pub function_name: String,
pub ranges: Vec<CoverageRange>,
pub is_block_coverage: bool,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#type-ScriptCoverage>
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ScriptCoverage {
pub script_id: String,
pub url: String,
pub functions: Vec<FunctionCoverage>,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#method-startPreciseCoverage>
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StartPreciseCoverageArgs {
pub call_count: bool,
pub detailed: bool,
pub allow_triggered_updates: bool,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#method-startPreciseCoverage>
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StartPreciseCoverageResponse {
pub timestamp: f64,
}

/// <https://chromedevtools.github.io/devtools-protocol/tot/Profiler/#method-takePreciseCoverage>
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TakePreciseCoverageResponse {
pub result: Vec<ScriptCoverage>,
pub timestamp: f64,
}
1 change: 1 addition & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
mod args;
mod auth_tokens;
mod cache;
mod cdp;
mod deno_std;
mod emit;
mod errors;
Expand Down
60 changes: 0 additions & 60 deletions cli/tools/coverage/json_types.rs

This file was deleted.

Loading

0 comments on commit fdb4953

Please sign in to comment.