mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Handle getBreakpointPositionsCompressed in source actor
Co-authored-by: atbrakhi <atbrakhi@igalia.com> Signed-off-by: Delan Azabani <dazabani@igalia.com>
This commit is contained in:
parent
cfb66702ca
commit
5f105f69e8
1 changed files with 29 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::net::TcpStream;
|
||||
|
||||
use base::id::PipelineId;
|
||||
|
@ -70,6 +70,12 @@ struct GetBreakableLinesReply {
|
|||
lines: Vec<usize>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct GetBreakpointPositionsCompressedReply {
|
||||
from: String,
|
||||
positions: BTreeMap<usize, Vec<usize>>,
|
||||
}
|
||||
|
||||
impl SourceManager {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
|
@ -181,6 +187,28 @@ impl Actor for SourceActor {
|
|||
let _ = stream.write_json_packet(&reply);
|
||||
ActorMessageStatus::Processed
|
||||
},
|
||||
// Client wants to know which columns in the line can have breakpoints.
|
||||
// Sent when the user tries to set a breakpoint by clicking a line number in a source.
|
||||
"getBreakpointPositionsCompressed" => {
|
||||
// Tell the client that every column is breakable.
|
||||
// TODO: determine which columns are actually breakable.
|
||||
let mut positions = BTreeMap::default();
|
||||
if let Some(content) = self.content.as_ref() {
|
||||
for (line_number, line) in content.lines().enumerate() {
|
||||
// Column numbers are in Unicode scalar values, not UTF-16 code units or grapheme clusters.
|
||||
let column_count = line.chars().count();
|
||||
// Line and column numbers are one-based.
|
||||
// <https://firefox-source-docs.mozilla.org/devtools/backend/protocol.html#source-locations>
|
||||
positions.insert(line_number + 1, (1..=column_count).collect());
|
||||
}
|
||||
}
|
||||
let reply = GetBreakpointPositionsCompressedReply {
|
||||
from: self.name(),
|
||||
positions,
|
||||
};
|
||||
let _ = stream.write_json_packet(&reply);
|
||||
ActorMessageStatus::Processed
|
||||
},
|
||||
_ => ActorMessageStatus::Ignored,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue