Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ main
- Introduce eval feature
- Improve scrolling performance on large files and contexts
- Fix position of closing braces in context view
- Show historic inline values
- Do not show "undefined" variables

0.1.1
-----
Expand Down
51 changes: 48 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::analyzer::Analyser;
use crate::analyzer::Analysis;
use crate::analyzer::VariableRef;
use crate::config::Config;
use crate::dbgp::client::ContextGetResponse;
use crate::dbgp::client::ContinuationResponse;
Expand Down Expand Up @@ -54,10 +55,33 @@ pub struct StackFrame {
pub source: SourceContext,
pub context: Option<ContextGetResponse>,
}
#[derive(Clone,Debug)]
pub struct Variable {
pub var_ref: VariableRef,
pub value: Property,
}
#[derive(Default)]
pub struct DocumentVariables {
doclinemap: HashMap<String,Vec<Variable>>
}
impl DocumentVariables {
pub fn put(&mut self, context: &SourceContext, variables: Vec<Variable>) {
let entry = self.doclinemap.entry(format!("{}:{}", context.filename, context.line_no));
entry.insert_entry(variables);
}

pub fn get(&self, source_file: &String, line_no: u32) -> Vec<Variable> {
match self.doclinemap.get(&format!("{}:{}", source_file, line_no)) {
Some(v) => v.to_vec(),
None => vec![],
}

}
}
impl StackFrame {
pub(crate) fn get_property(&self, name: &str) -> Option<&Property> {
match &self.context {
Some(c) => c.properties.iter().find(|&property| property.name == name),
Some(c) => c.properties.get(name),
None => None,
}
}
Expand Down Expand Up @@ -221,6 +245,7 @@ pub struct App {
pub workspace: Workspace,

pub history: History,
pub document_variables: DocumentVariables,

pub view_current: SelectedView,
pub focus_view: bool,
Expand Down Expand Up @@ -252,6 +277,7 @@ impl App {
sender: sender.clone(),
quit: false,
history: History::default(),
document_variables: DocumentVariables::default(),
client: Arc::clone(&client),
workspace: Workspace::new(Arc::clone(&client)),

Expand Down Expand Up @@ -704,11 +730,30 @@ impl App {
}
};

entry.push(StackFrame {
let analysis = self.analyzed_files.get(&filename.clone());

let stack = StackFrame {
level: (level as u16),
source,
context,
});
};

{
// populate inline variables with values
let mut vars = vec![];
if let Some(analysis) = analysis {
for (_, var) in analysis.row(line_no as usize - 1) {
let property = stack.get_property(var.name.as_str());
if let Some(property) = property {
vars.push(Variable{ var_ref: var, value: property.clone() });
}
}

self.document_variables.put(&stack.source, vars);
}
}

entry.push(stack);
}

// *xdebug* only evalutes expressions on the current stack frame
Expand Down
81 changes: 59 additions & 22 deletions src/dbgp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,45 @@ pub struct DbgpError {

#[derive(Debug, Clone, PartialEq)]
pub struct ContextGetResponse {
pub properties: Properties,
}
impl ContextGetResponse {
}
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Properties {
pub properties: Vec<Property>,
}
impl Properties {
pub fn is_empty(&self) -> bool {
self.properties.is_empty()
}
pub fn none() -> Self {
Self{properties:vec![]}
}
pub fn defined_properties(&self) -> Vec<&Property> {
let mut props = vec![];
for property in &self.properties {
if property.property_type == PropertyType::Undefined {
continue;
}
props.push(property);
}
props
}

pub(crate) fn get(&self, name: &str) -> Option<&Property> {
for property in self.defined_properties() {
if property.name == name {
return Some(property)
}
}
None
}

pub fn from_properties(vec: Vec<Property>) -> Properties {
Self{properties:vec}
}
}

#[derive(PartialEq, Clone, Debug, Default)]
pub enum PropertyType {
Expand Down Expand Up @@ -108,7 +145,7 @@ pub struct Property {
pub property_type: PropertyType,
pub facet: Option<String>,
pub size: Option<u32>,
pub children: Vec<Property>,
pub children: Properties,
pub key: Option<String>,
pub address: Option<String>,
pub encoding: Option<String>,
Expand Down Expand Up @@ -146,7 +183,7 @@ pub struct ContinuationResponse {
pub struct EvalResponse {
pub success: bool,
pub error: Option<DbgpError>,
pub properties: Vec<Property>,
pub properties: Properties,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -411,7 +448,7 @@ fn parse_source(element: &Element) -> Result<String, anyhow::Error> {


fn parse_context_get(element: &mut Element) -> Result<ContextGetResponse, anyhow::Error> {
Ok(ContextGetResponse { properties: parse_properties(element)?})
Ok(ContextGetResponse { properties: Properties::from_properties(parse_properties(element)?)})
}

fn parse_eval(element: &mut Element) -> Result<EvalResponse, anyhow::Error> {
Expand All @@ -433,7 +470,7 @@ fn parse_eval(element: &mut Element) -> Result<EvalResponse, anyhow::Error> {
None
};

Ok(EvalResponse { success: true, properties: parse_properties(element)?, error })
Ok(EvalResponse { success: true, properties: Properties::from_properties(parse_properties(element)?), error})
}

fn parse_properties(element: &mut Element) -> Result<Vec<Property>, anyhow::Error> {
Expand Down Expand Up @@ -481,7 +518,7 @@ fn parse_properties(element: &mut Element) -> Result<Vec<Property>, anyhow::Erro
key: child.attributes.get("key").map(|name| name.to_string()),
address: child.attributes.get("address").map(|name| name.to_string()),
encoding: encoding.clone(),
children: parse_properties(&mut child)?,
children: Properties::from_properties(parse_properties(&mut child)?),
value: decode_element(Some(&child)),
};
properties.push(p);
Expand Down Expand Up @@ -669,7 +706,7 @@ function call_function(string $hello) {
let expected = EvalResponse {
success: true,
error: None,
properties: vec![
properties: Properties::from_properties(vec![
Property {
name: "".to_string(),
fullname: "".to_string(),
Expand All @@ -679,13 +716,13 @@ function call_function(string $hello) {
property_type: PropertyType::Int,
facet: None,
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
value: Some(2.to_string()),
},
],
]),
};
assert_eq!(expected, response)
}
Expand Down Expand Up @@ -715,7 +752,7 @@ function call_function(string $hello) {
message: "error evaluating code: Undefined constant \"asda\"".to_string(),
code: "206".to_string()
}),
properties: vec![],
properties: Properties::none(),
};
assert_eq!(expected, response)
}
Expand Down Expand Up @@ -750,7 +787,7 @@ function call_function(string $hello) {
match r.command {
CommandResponse::ContextGet(response) => {
let expected = ContextGetResponse {
properties: vec![
properties: Properties::from_properties(vec![
Property {
name: "$bar".to_string(),
fullname: "$bar".to_string(),
Expand All @@ -760,7 +797,7 @@ function call_function(string $hello) {
property_type: PropertyType::String,
facet: None,
size: Some(3),
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: Some("base64".to_string()),
Expand All @@ -775,7 +812,7 @@ function call_function(string $hello) {
property_type: PropertyType::Float,
facet: None,
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
Expand All @@ -790,7 +827,7 @@ function call_function(string $hello) {
property_type: PropertyType::Int,
facet: None,
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
Expand All @@ -805,7 +842,7 @@ function call_function(string $hello) {
property_type: PropertyType::Bool,
facet: None,
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
Expand All @@ -820,7 +857,7 @@ function call_function(string $hello) {
property_type: PropertyType::Object,
facet: None,
size: None,
children: vec![
children: Properties::from_properties(vec![
Property {
name: "true".to_string(),
fullname: "$this->true".to_string(),
Expand All @@ -830,7 +867,7 @@ function call_function(string $hello) {
property_type: PropertyType::Bool,
facet: Some("public".to_string()),
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
Expand All @@ -845,7 +882,7 @@ function call_function(string $hello) {
property_type: PropertyType::String,
facet: Some("public".to_string()),
size: Some(3),
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: Some("base64".to_string()),
Expand All @@ -860,13 +897,13 @@ function call_function(string $hello) {
property_type: PropertyType::Resource,
facet: Some("private".to_string()),
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
value: Some("resource id='18' type='stream'".to_string()),
},
],
]),
key: None,
address: None,
encoding: None,
Expand All @@ -881,14 +918,14 @@ function call_function(string $hello) {
property_type: PropertyType::Array,
facet: None,
size: None,
children: vec![],
children: Properties::none(),
key: None,
address: None,
encoding: None,
value: None,
},
],
};
]),
};
assert_eq!(expected, response)
}
_ => panic!("Could not parse context_get"),
Expand Down
5 changes: 4 additions & 1 deletion src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Theme {
source_line_no: Style::default().fg(Solarized::Yellow.to_color()),
source_line_highlight: Style::default().bg(Solarized::Base02.to_color()).fg(Solarized::Base3.to_color()),
source_annotation: Style::default().fg(Solarized::Magenta.to_color()),
source_annotation_historic: Style::default().fg(Solarized::Base01.to_color()),
stack_line: Style::default().fg(Solarized::Base1.to_color()),

widget_active: Style::default().fg(Solarized::Base02.to_color()).bg(Solarized::Green.to_color()),
Expand Down Expand Up @@ -87,7 +88,8 @@ impl Theme {
source_line: Style::default().fg(Color::White),
source_line_no: Style::default().fg(Color::Yellow),
source_line_highlight: Style::default().bg(Color::Blue),
source_annotation: Style::default().fg(Color::DarkGray),
source_annotation: Style::default().fg(Color::Cyan),
source_annotation_historic: Style::default().fg(Color::DarkGray),

stack_line: Style::default().fg(Color::White),

Expand Down Expand Up @@ -124,6 +126,7 @@ pub struct Scheme {
pub source_line_no: Style,
pub source_line_highlight: Style,
pub source_annotation: Style,
pub source_annotation_historic: Style,

pub stack_line: Style,

Expand Down
2 changes: 1 addition & 1 deletion src/view/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl View for ContextComponent {
let truncate_from = app.session_view.context_scroll.0 as u32;
draw_properties(
&app.theme(),
&context.properties,
context.properties.defined_properties(),
&mut lines,
0,
&mut filter_path,
Expand Down
Loading