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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
CHANGELOG
=========

main
----

- Show value of variables on current line
- Support `extended_properties` #5


0.0.2
-----

Expand Down
56 changes: 56 additions & 0 deletions php/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

$arra😸ay = [
'int' => 123,
'float' => 123.4,
'string' => "string",
'bool' => true,
'more' => [
'int' => 123,
'float' => 123.4,
'string' => "string",
'bool' => true,
],
];
$a = 2;
$foo = $a;
$foo = $arra😸ay;

$bar = $foo;


(new Foo(true, "foo"))->method3();
call_function("hello");



function call_function(string $hello) {
$var = 123;
$obj = new Foo(false, 'good day');
another_function($hello);
another_function($hello);
another_function($hello);
}

function another_function(string $goodbye) {
echo $goodbye;


foreach (['one', 'two', 'three', 'four'] as $number) {
if ($number === 'one') {
echo "number";
}
echo $number;
}
}

class Foo {
public function __construct(public bool $true, public string $bar) {}
public function method1() {
}
public function method2() {
}
public function method3() {
}
}

17 changes: 17 additions & 0 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,22 @@ list($var1, $var2) = some_call();
}, line.get(&5).unwrap());
Ok(())
}

#[test]
fn test_cats() -> Result<(), anyhow::Error> {
let source = r#"<?php
$fo😸cat = "12";
"#;
let analysis = Analyser::new().analyze(source)?;
let line = analysis.row(1);
assert_eq!(1, line.values().len());

assert_eq!(&VariableRef{
range: Range::new(Position::new(1,0), Position::new(1,10)),
name: "$fo😸cat".to_string(),
value: None,
}, line.get(&0).unwrap());
Ok(())
}
}

16 changes: 11 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,10 @@ impl App {
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
event: AppEvent,
) -> Result<()> {
info!("Handling event {:?}", event);
match event {
AppEvent::Tick => (),
_ => info!("Handling event {:?}", event),
};
match event {
AppEvent::Tick => (),
AppEvent::Quit => self.quit = true,
Expand Down Expand Up @@ -296,10 +299,13 @@ impl App {
AppEvent::ClientConnected(s) => {
let mut client = self.client.lock().await;
let response = client.deref_mut().connect(s).await?;
client.feature_set(
"max_depth",
self.context_depth.to_string().as_str()
).await?;
for (feature, value) in [
("max_depth",self.context_depth.to_string().as_str()),
("extended_properties","1"),
] {
info!("setting feature {} to {:?}", feature, value);
client.feature_set(feature, value).await?;
}
self.is_connected = true;
self.server_status = None;
self.view_current = CurrentView::Session;
Expand Down
80 changes: 56 additions & 24 deletions src/dbgp/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ impl DbgpClient {
if xml.is_empty() {
return Err(anyhow::anyhow!("Empty XML response"));
}
debug!("[dbgp] << {}", xml);
parse_xml(xml.as_str())
}

Expand Down Expand Up @@ -390,17 +389,24 @@ fn parse_context_get(element: &mut Element) -> Result<ContextGetResponse, anyhow
while let Some(mut child) = element.take_child("property") {
let encoding = child.attributes.get("encoding").map(|s| s.to_string());
let p = Property {
name: child
name: match child
.attributes
.get("name")
.expect("Expected name to be set")
.to_string(),
fullname: child
.get("name") {
Some(name) => name.to_string(),
None => decode_element(child.get_child("name")).unwrap_or("".to_string())
},
fullname: match child
.attributes
.get("name")
.expect("Expected fullname to be set")
.to_string(),
classname: child.attributes.get("classname").map(|s| s.to_string()),
.get("fullname") {
Some(name) => name.to_string(),
None => decode_element(child.get_child("fullname")).unwrap_or("".to_string())
},
classname: match child
.attributes
.get("classname") {
Some(name) => Some(name.to_string()),
None => decode_element(child.get_child("classname"))
},
page: child
.attributes
.get("page")
Expand All @@ -424,23 +430,33 @@ fn parse_context_get(element: &mut Element) -> Result<ContextGetResponse, anyhow
address: child.attributes.get("address").map(|name| name.to_string()),
encoding: encoding.clone(),
children: parse_context_get(&mut child).unwrap().properties,
value: match child.children.first() {
Some(XMLNode::CData(cdata)) => Some(match encoding {
value: decode_element(Some(&child)),
};
properties.push(p);
}
Ok(ContextGetResponse { properties })
}

fn decode_element(element: Option<&Element>) -> Option<String> {
match element {
Some(e) => {
let encoding = e.attributes.get("encoding");
match e.children.first() {
Some(XMLNode::CData(cdata)) => match encoding {
Some(encoding) => match encoding.as_str() {
"base64" => {
String::from_utf8(general_purpose::STANDARD.decode(cdata).unwrap())
.unwrap()
Some(String::from_utf8(general_purpose::STANDARD.decode(cdata).unwrap())
.unwrap())
}
_ => cdata.to_string(),
_ => Some(cdata.to_string()),
},
_ => cdata.to_string(),
}),
_ => Some(cdata.to_string()),
},
_ => None,
},
};
properties.push(p);
}
}
None => None,
}
Ok(ContextGetResponse { properties })
}

fn parse_stack_get(element: &Element) -> StackGetResponse {
Expand Down Expand Up @@ -594,6 +610,7 @@ function call_function(string $hello) {
<property name="bar" fullname="$this-&gt;bar" facet="public" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property>
<property name="handle" fullname="$this-&gt;handle" facet="private" type="resource"><![CDATA[resource id='18' type='stream']]></property>
</property>
<property type="array"><name encoding="base64"><![CDATA[JGFycvCfmLhheQ==]]></name><fullname encoding="base64"><![CDATA[JGFycvCfmLhheQ==]]></fullname></property>
</response>"#,
)?;

Expand Down Expand Up @@ -675,7 +692,7 @@ function call_function(string $hello) {
children: vec![
Property {
name: "true".to_string(),
fullname: "true".to_string(),
fullname: "$this->true".to_string(),
classname: None,
page: None,
pagesize: None,
Expand All @@ -690,7 +707,7 @@ function call_function(string $hello) {
},
Property {
name: "bar".to_string(),
fullname: "bar".to_string(),
fullname: "$this->bar".to_string(),
classname: None,
page: None,
pagesize: None,
Expand All @@ -705,7 +722,7 @@ function call_function(string $hello) {
},
Property {
name: "handle".to_string(),
fullname: "handle".to_string(),
fullname: "$this->handle".to_string(),
classname: None,
page: None,
pagesize: None,
Expand All @@ -724,6 +741,21 @@ function call_function(string $hello) {
encoding: None,
value: None,
},
Property {
name: "$arr😸ay".to_string(),
fullname: "$arr😸ay".to_string(),
classname: None,
page: None,
pagesize: None,
property_type: PropertyType::Array,
facet: None,
size: None,
children: vec![],
key: None,
address: None,
encoding: None,
value: None,
},
],
};
assert_eq!(expected, response)
Expand Down
1 change: 1 addition & 0 deletions src/view/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::app::App;
use crate::dbgp::client::Property;
use crate::dbgp::client::PropertyType;
use crate::event::input::AppEvent;
use log::info;
use ratatui::layout::Constraint;
use ratatui::layout::Layout;
use ratatui::layout::Position;
Expand Down