diff --git a/CHANGELOG.md b/CHANGELOG.md index 64e6663..4a5978f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ CHANGELOG ========= +main +---- + +- Show value of variables on current line +- Support `extended_properties` #5 + + 0.0.2 ----- diff --git a/php/test.php b/php/test.php new file mode 100644 index 0000000..cf17f5a --- /dev/null +++ b/php/test.php @@ -0,0 +1,56 @@ + 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() { + } +} + diff --git a/src/analyzer.rs b/src/analyzer.rs index ff6bd70..407ca33 100644 --- a/src/analyzer.rs +++ b/src/analyzer.rs @@ -166,5 +166,22 @@ list($var1, $var2) = some_call(); }, line.get(&5).unwrap()); Ok(()) } + + #[test] + fn test_cats() -> Result<(), anyhow::Error> { + let source = r#">, event: AppEvent, ) -> Result<()> { - info!("Handling event {:?}", event); + match event { + AppEvent::Tick => (), + _ => info!("Handling event {:?}", event), + }; match event { AppEvent::Tick => (), AppEvent::Quit => self.quit = true, @@ -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; diff --git a/src/dbgp/client.rs b/src/dbgp/client.rs index 4a1a0d7..fab8288 100644 --- a/src/dbgp/client.rs +++ b/src/dbgp/client.rs @@ -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()) } @@ -390,17 +389,24 @@ fn parse_context_get(element: &mut Element) -> Result 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") @@ -424,23 +430,33 @@ fn parse_context_get(element: &mut Element) -> Result Some(match encoding { + value: decode_element(Some(&child)), + }; + properties.push(p); + } + Ok(ContextGetResponse { properties }) +} + +fn decode_element(element: Option<&Element>) -> Option { + 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 { @@ -594,6 +610,7 @@ function call_function(string $hello) { + "#, )?; @@ -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, @@ -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, @@ -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, @@ -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) diff --git a/src/view/source.rs b/src/view/source.rs index 665c617..f2f9c10 100644 --- a/src/view/source.rs +++ b/src/view/source.rs @@ -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;