@@ -14,6 +14,15 @@
"(" @context
")" @context)) @item
+(generator_function_declaration
+ "async"? @context
+ "function" @context
+ "*" @context
+ name: (_) @name
+ parameters: (formal_parameters
+ "(" @context
+ ")" @context)) @item
+
(interface_declaration
"interface" @context
name: (_) @name) @item
@@ -18,6 +18,15 @@
"(" @context
")" @context)) @item
+(generator_function_declaration
+ "async"? @context
+ "function" @context
+ "*" @context
+ name: (_) @name
+ parameters: (formal_parameters
+ "(" @context
+ ")" @context)) @item
+
(interface_declaration
"interface" @context
name: (_) @name) @item
@@ -1075,6 +1075,62 @@ mod tests {
);
}
+ #[gpui::test]
+ async fn test_generator_function_outline(cx: &mut TestAppContext) {
+ let language = crate::language("javascript", tree_sitter_typescript::LANGUAGE_TSX.into());
+
+ let text = r#"
+ function normalFunction() {
+ console.log("normal");
+ }
+
+ function* simpleGenerator() {
+ yield 1;
+ yield 2;
+ }
+
+ async function* asyncGenerator() {
+ yield await Promise.resolve(1);
+ }
+
+ function* generatorWithParams(start, end) {
+ for (let i = start; i <= end; i++) {
+ yield i;
+ }
+ }
+
+ class TestClass {
+ *methodGenerator() {
+ yield "method";
+ }
+
+ async *asyncMethodGenerator() {
+ yield "async method";
+ }
+ }
+ "#
+ .unindent();
+
+ let buffer = cx.new(|cx| language::Buffer::local(text, cx).with_language(language, cx));
+ let outline = buffer.read_with(cx, |buffer, _| buffer.snapshot().outline(None).unwrap());
+ assert_eq!(
+ outline
+ .items
+ .iter()
+ .map(|item| (item.text.as_str(), item.depth))
+ .collect::<Vec<_>>(),
+ &[
+ ("function normalFunction()", 0),
+ ("function* simpleGenerator()", 0),
+ ("async function* asyncGenerator()", 0),
+ ("function* generatorWithParams( )", 0),
+ ("class TestClass", 0),
+ ("*methodGenerator()", 1),
+ ("async *asyncMethodGenerator()", 1),
+ ]
+ );
+ }
+
#[gpui::test]
async fn test_package_json_discovery(executor: BackgroundExecutor, cx: &mut TestAppContext) {
cx.update(|cx| {
@@ -18,6 +18,15 @@
"(" @context
")" @context)) @item
+(generator_function_declaration
+ "async"? @context
+ "function" @context
+ "*" @context
+ name: (_) @name
+ parameters: (formal_parameters
+ "(" @context
+ ")" @context)) @item
+
(interface_declaration
"interface" @context
name: (_) @name) @item