folds.scm 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [
  2. (switch_body)
  3. (class_body)
  4. (object)
  5. (template_string)
  6. (named_imports)
  7. ] @fold
  8. ; When we've got
  9. ;
  10. ; function foo(
  11. ; bar,
  12. ; baz,
  13. ; thud
  14. ; )
  15. ;
  16. ; we want to be able to fold up the group of function parameters while
  17. ; preserving the ability to collapse the function body.
  18. ([(arguments) (formal_parameters)] @fold
  19. (#set! fold.adjustToEndOfPreviousRow true))
  20. ; When we've got
  21. ;
  22. ; if (foo) {
  23. ; // something
  24. ; } else {
  25. ; // something else
  26. ; }
  27. ;
  28. ; we want the folds to work a little differently so that collapsing the `if`
  29. ; fold doesn't interfere with our ability to collapse the `else` fold.
  30. ((if_statement
  31. consequence: (statement_block) @fold
  32. alternative: (else_clause)
  33. (#set! fold.adjustToEndOfPreviousRow true)
  34. ))
  35. (else_clause (statement_block) @fold)
  36. (statement_block) @fold
  37. ((comment) @fold
  38. (#set! fold.endAt endPosition)
  39. (#set! fold.offsetEnd -2))
  40. ; When you have…
  41. ;
  42. ; <Element
  43. ; foo="bar"
  44. ; baz="thud">
  45. ;
  46. ; </Element>
  47. ;
  48. ; …this will put the fold on line 3 and let you fold up the contents separately
  49. ; from the opening tag's attributes.
  50. ;
  51. (jsx_element
  52. (jsx_opening_element ">" @fold)
  53. (#set! fold.endAt parent.parent.lastChild.startPosition)
  54. (#set! fold.adjustToEndOfPreviousRow true)
  55. )
  56. ; When you have…
  57. ;
  58. ; <Element
  59. ; foo="bar"
  60. ; baz="thud"
  61. ; >
  62. ;
  63. ; </Element>
  64. ;
  65. ; …the presence of the `>` on its own line will let you treat the opening tag's
  66. ; attributes and the element's contents as separate folds.
  67. ;
  68. (jsx_element
  69. (jsx_opening_element) @fold
  70. (#set! fold.endAt lastChild.previousSibling.endPosition))
  71. ((jsx_self_closing_element) @fold
  72. ; Exclude both the slash and angle bracket `/>` from the fold.
  73. (#set! fold.endAt lastChild.startPosition))