Skip to content

Commit cd5ca5f

Browse files
authored
Historic inline values (#55)
* Refactored variable display moved variable value extraction to "app" * Show historic values * Do not show `undefined` variables * .. and update tests
1 parent 2d9fa24 commit cd5ca5f

File tree

8 files changed

+167
-85
lines changed

8 files changed

+167
-85
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ main
77
- Introduce eval feature
88
- Improve scrolling performance on large files and contexts
99
- Fix position of closing braces in context view
10+
- Show historic inline values
11+
- Do not show "undefined" variables
1012

1113
0.1.1
1214
-----

src/app.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::analyzer::Analyser;
22
use crate::analyzer::Analysis;
3+
use crate::analyzer::VariableRef;
34
use crate::config::Config;
45
use crate::dbgp::client::ContextGetResponse;
56
use crate::dbgp::client::ContinuationResponse;
@@ -54,10 +55,33 @@ pub struct StackFrame {
5455
pub source: SourceContext,
5556
pub context: Option<ContextGetResponse>,
5657
}
58+
#[derive(Clone,Debug)]
59+
pub struct Variable {
60+
pub var_ref: VariableRef,
61+
pub value: Property,
62+
}
63+
#[derive(Default)]
64+
pub struct DocumentVariables {
65+
doclinemap: HashMap<String,Vec<Variable>>
66+
}
67+
impl DocumentVariables {
68+
pub fn put(&mut self, context: &SourceContext, variables: Vec<Variable>) {
69+
let entry = self.doclinemap.entry(format!("{}:{}", context.filename, context.line_no));
70+
entry.insert_entry(variables);
71+
}
72+
73+
pub fn get(&self, source_file: &String, line_no: u32) -> Vec<Variable> {
74+
match self.doclinemap.get(&format!("{}:{}", source_file, line_no)) {
75+
Some(v) => v.to_vec(),
76+
None => vec![],
77+
}
78+
79+
}
80+
}
5781
impl StackFrame {
5882
pub(crate) fn get_property(&self, name: &str) -> Option<&Property> {
5983
match &self.context {
60-
Some(c) => c.properties.iter().find(|&property| property.name == name),
84+
Some(c) => c.properties.get(name),
6185
None => None,
6286
}
6387
}
@@ -221,6 +245,7 @@ pub struct App {
221245
pub workspace: Workspace,
222246

223247
pub history: History,
248+
pub document_variables: DocumentVariables,
224249

225250
pub view_current: SelectedView,
226251
pub focus_view: bool,
@@ -252,6 +277,7 @@ impl App {
252277
sender: sender.clone(),
253278
quit: false,
254279
history: History::default(),
280+
document_variables: DocumentVariables::default(),
255281
client: Arc::clone(&client),
256282
workspace: Workspace::new(Arc::clone(&client)),
257283

@@ -704,11 +730,30 @@ impl App {
704730
}
705731
};
706732

707-
entry.push(StackFrame {
733+
let analysis = self.analyzed_files.get(&filename.clone());
734+
735+
let stack = StackFrame {
708736
level: (level as u16),
709737
source,
710738
context,
711-
});
739+
};
740+
741+
{
742+
// populate inline variables with values
743+
let mut vars = vec![];
744+
if let Some(analysis) = analysis {
745+
for (_, var) in analysis.row(line_no as usize - 1) {
746+
let property = stack.get_property(var.name.as_str());
747+
if let Some(property) = property {
748+
vars.push(Variable{ var_ref: var, value: property.clone() });
749+
}
750+
}
751+
752+
self.document_variables.put(&stack.source, vars);
753+
}
754+
}
755+
756+
entry.push(stack);
712757
}
713758

714759
// *xdebug* only evalutes expressions on the current stack frame

src/dbgp/client.rs

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,45 @@ pub struct DbgpError {
4242

4343
#[derive(Debug, Clone, PartialEq)]
4444
pub struct ContextGetResponse {
45+
pub properties: Properties,
46+
}
47+
impl ContextGetResponse {
48+
}
49+
#[derive(Debug, Clone, PartialEq, Default)]
50+
pub struct Properties {
4551
pub properties: Vec<Property>,
4652
}
53+
impl Properties {
54+
pub fn is_empty(&self) -> bool {
55+
self.properties.is_empty()
56+
}
57+
pub fn none() -> Self {
58+
Self{properties:vec![]}
59+
}
60+
pub fn defined_properties(&self) -> Vec<&Property> {
61+
let mut props = vec![];
62+
for property in &self.properties {
63+
if property.property_type == PropertyType::Undefined {
64+
continue;
65+
}
66+
props.push(property);
67+
}
68+
props
69+
}
70+
71+
pub(crate) fn get(&self, name: &str) -> Option<&Property> {
72+
for property in self.defined_properties() {
73+
if property.name == name {
74+
return Some(property)
75+
}
76+
}
77+
None
78+
}
79+
80+
pub fn from_properties(vec: Vec<Property>) -> Properties {
81+
Self{properties:vec}
82+
}
83+
}
4784

4885
#[derive(PartialEq, Clone, Debug, Default)]
4986
pub enum PropertyType {
@@ -108,7 +145,7 @@ pub struct Property {
108145
pub property_type: PropertyType,
109146
pub facet: Option<String>,
110147
pub size: Option<u32>,
111-
pub children: Vec<Property>,
148+
pub children: Properties,
112149
pub key: Option<String>,
113150
pub address: Option<String>,
114151
pub encoding: Option<String>,
@@ -146,7 +183,7 @@ pub struct ContinuationResponse {
146183
pub struct EvalResponse {
147184
pub success: bool,
148185
pub error: Option<DbgpError>,
149-
pub properties: Vec<Property>,
186+
pub properties: Properties,
150187
}
151188

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

412449

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

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

436-
Ok(EvalResponse { success: true, properties: parse_properties(element)?, error })
473+
Ok(EvalResponse { success: true, properties: Properties::from_properties(parse_properties(element)?), error})
437474
}
438475

439476
fn parse_properties(element: &mut Element) -> Result<Vec<Property>, anyhow::Error> {
@@ -481,7 +518,7 @@ fn parse_properties(element: &mut Element) -> Result<Vec<Property>, anyhow::Erro
481518
key: child.attributes.get("key").map(|name| name.to_string()),
482519
address: child.attributes.get("address").map(|name| name.to_string()),
483520
encoding: encoding.clone(),
484-
children: parse_properties(&mut child)?,
521+
children: Properties::from_properties(parse_properties(&mut child)?),
485522
value: decode_element(Some(&child)),
486523
};
487524
properties.push(p);
@@ -669,7 +706,7 @@ function call_function(string $hello) {
669706
let expected = EvalResponse {
670707
success: true,
671708
error: None,
672-
properties: vec![
709+
properties: Properties::from_properties(vec![
673710
Property {
674711
name: "".to_string(),
675712
fullname: "".to_string(),
@@ -679,13 +716,13 @@ function call_function(string $hello) {
679716
property_type: PropertyType::Int,
680717
facet: None,
681718
size: None,
682-
children: vec![],
719+
children: Properties::none(),
683720
key: None,
684721
address: None,
685722
encoding: None,
686723
value: Some(2.to_string()),
687724
},
688-
],
725+
]),
689726
};
690727
assert_eq!(expected, response)
691728
}
@@ -715,7 +752,7 @@ function call_function(string $hello) {
715752
message: "error evaluating code: Undefined constant \"asda\"".to_string(),
716753
code: "206".to_string()
717754
}),
718-
properties: vec![],
755+
properties: Properties::none(),
719756
};
720757
assert_eq!(expected, response)
721758
}
@@ -750,7 +787,7 @@ function call_function(string $hello) {
750787
match r.command {
751788
CommandResponse::ContextGet(response) => {
752789
let expected = ContextGetResponse {
753-
properties: vec![
790+
properties: Properties::from_properties(vec![
754791
Property {
755792
name: "$bar".to_string(),
756793
fullname: "$bar".to_string(),
@@ -760,7 +797,7 @@ function call_function(string $hello) {
760797
property_type: PropertyType::String,
761798
facet: None,
762799
size: Some(3),
763-
children: vec![],
800+
children: Properties::none(),
764801
key: None,
765802
address: None,
766803
encoding: Some("base64".to_string()),
@@ -775,7 +812,7 @@ function call_function(string $hello) {
775812
property_type: PropertyType::Float,
776813
facet: None,
777814
size: None,
778-
children: vec![],
815+
children: Properties::none(),
779816
key: None,
780817
address: None,
781818
encoding: None,
@@ -790,7 +827,7 @@ function call_function(string $hello) {
790827
property_type: PropertyType::Int,
791828
facet: None,
792829
size: None,
793-
children: vec![],
830+
children: Properties::none(),
794831
key: None,
795832
address: None,
796833
encoding: None,
@@ -805,7 +842,7 @@ function call_function(string $hello) {
805842
property_type: PropertyType::Bool,
806843
facet: None,
807844
size: None,
808-
children: vec![],
845+
children: Properties::none(),
809846
key: None,
810847
address: None,
811848
encoding: None,
@@ -820,7 +857,7 @@ function call_function(string $hello) {
820857
property_type: PropertyType::Object,
821858
facet: None,
822859
size: None,
823-
children: vec![
860+
children: Properties::from_properties(vec![
824861
Property {
825862
name: "true".to_string(),
826863
fullname: "$this->true".to_string(),
@@ -830,7 +867,7 @@ function call_function(string $hello) {
830867
property_type: PropertyType::Bool,
831868
facet: Some("public".to_string()),
832869
size: None,
833-
children: vec![],
870+
children: Properties::none(),
834871
key: None,
835872
address: None,
836873
encoding: None,
@@ -845,7 +882,7 @@ function call_function(string $hello) {
845882
property_type: PropertyType::String,
846883
facet: Some("public".to_string()),
847884
size: Some(3),
848-
children: vec![],
885+
children: Properties::none(),
849886
key: None,
850887
address: None,
851888
encoding: Some("base64".to_string()),
@@ -860,13 +897,13 @@ function call_function(string $hello) {
860897
property_type: PropertyType::Resource,
861898
facet: Some("private".to_string()),
862899
size: None,
863-
children: vec![],
900+
children: Properties::none(),
864901
key: None,
865902
address: None,
866903
encoding: None,
867904
value: Some("resource id='18' type='stream'".to_string()),
868905
},
869-
],
906+
]),
870907
key: None,
871908
address: None,
872909
encoding: None,
@@ -881,14 +918,14 @@ function call_function(string $hello) {
881918
property_type: PropertyType::Array,
882919
facet: None,
883920
size: None,
884-
children: vec![],
921+
children: Properties::none(),
885922
key: None,
886923
address: None,
887924
encoding: None,
888925
value: None,
889926
},
890-
],
891-
};
927+
]),
928+
};
892929
assert_eq!(expected, response)
893930
}
894931
_ => panic!("Could not parse context_get"),

src/theme.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ impl Theme {
5656
source_line_no: Style::default().fg(Solarized::Yellow.to_color()),
5757
source_line_highlight: Style::default().bg(Solarized::Base02.to_color()).fg(Solarized::Base3.to_color()),
5858
source_annotation: Style::default().fg(Solarized::Magenta.to_color()),
59+
source_annotation_historic: Style::default().fg(Solarized::Base01.to_color()),
5960
stack_line: Style::default().fg(Solarized::Base1.to_color()),
6061

6162
widget_active: Style::default().fg(Solarized::Base02.to_color()).bg(Solarized::Green.to_color()),
@@ -87,7 +88,8 @@ impl Theme {
8788
source_line: Style::default().fg(Color::White),
8889
source_line_no: Style::default().fg(Color::Yellow),
8990
source_line_highlight: Style::default().bg(Color::Blue),
90-
source_annotation: Style::default().fg(Color::DarkGray),
91+
source_annotation: Style::default().fg(Color::Cyan),
92+
source_annotation_historic: Style::default().fg(Color::DarkGray),
9193

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

@@ -124,6 +126,7 @@ pub struct Scheme {
124126
pub source_line_no: Style,
125127
pub source_line_highlight: Style,
126128
pub source_annotation: Style,
129+
pub source_annotation_historic: Style,
127130

128131
pub stack_line: Style,
129132

src/view/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl View for ContextComponent {
8181
let truncate_from = app.session_view.context_scroll.0 as u32;
8282
draw_properties(
8383
&app.theme(),
84-
&context.properties,
84+
context.properties.defined_properties(),
8585
&mut lines,
8686
0,
8787
&mut filter_path,

0 commit comments

Comments
 (0)