Skip to content

Commit

Permalink
Improve runnable detection for JavaScript files (zed-industries#21246)
Browse files Browse the repository at this point in the history
Closes zed-industries#21242

![Screenshot 2024-11-27 at 18 52
51](https://github.com/user-attachments/assets/d096197c-33d2-41b9-963d-3e1a9bbdc035)
![Screenshot 2024-11-27 at 18 53
08](https://github.com/user-attachments/assets/b3202b00-3f68-4d9d-acc2-1b86c081fc34)

Release Notes:

- Improved runnable detection for JavaScript/Typescript files.
  • Loading branch information
RemcoSmitsDev authored Nov 27, 2024
1 parent 66ba9d5 commit 04ff9f0
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 34 deletions.
20 changes: 14 additions & 6 deletions crates/languages/src/javascript/outline.scm
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@
name: (_) @name) @item

; Add support for (node:test, bun:test and Jest) runnable
(call_expression
function: (_) @context
(#any-of? @context "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @name
(
(call_expression
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]* @context
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string (string_fragment) @name)
)
)
) @item
Expand Down
15 changes: 11 additions & 4 deletions crates/languages/src/javascript/runnables.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
; Function expression that has `it`, `test` or `describe` as the function name
(
(call_expression
function: (_) @_name
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @run
)
arguments . (string (string_fragment) @run)
)
) @_js-test

(#set! tag js-test)
)
20 changes: 14 additions & 6 deletions crates/languages/src/tsx/outline.scm
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@
name: (_) @name) @item

; Add support for (node:test, bun:test and Jest) runnable
(call_expression
function: (_) @context
(#any-of? @context "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @name
(
(call_expression
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]* @context
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string (string_fragment) @name)
)
)
) @item
Expand Down
19 changes: 13 additions & 6 deletions crates/languages/src/tsx/runnables.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
; Function expression that has `it`, `test` or `describe` as the function name
(
(call_expression
function: (_) @_name
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @run
)
arguments . (string (string_fragment) @run)
)
) @_tsx-test
(#set! tag tsx-test)
) @_js-test

(#set! tag js-test)
)
20 changes: 14 additions & 6 deletions crates/languages/src/typescript/outline.scm
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,20 @@
name: (_) @name) @item

; Add support for (node:test, bun:test and Jest) runnable
(call_expression
function: (_) @context
(#any-of? @context "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @name
(
(call_expression
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]* @context
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string (string_fragment) @name)
)
)
) @item
Expand Down
19 changes: 13 additions & 6 deletions crates/languages/src/typescript/runnables.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
; Function expression that has `it`, `test` or `describe` as the function name
(
(call_expression
function: (_) @_name
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @run
)
arguments . (string (string_fragment) @run)
)
) @_ts-test
(#set! tag ts-test)
) @_js-test

(#set! tag js-test)
)

0 comments on commit 04ff9f0

Please sign in to comment.