injections.scm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. ((function_call
  2. name: [
  3. (identifier) @_cdef_identifier
  4. (_
  5. _
  6. (identifier) @_cdef_identifier)
  7. ]
  8. arguments: (arguments
  9. (string
  10. content: _ @injection.content)))
  11. (#set! injection.language "c")
  12. (#eq? @_cdef_identifier "cdef"))
  13. ((function_call
  14. name: (_) @_vimcmd_identifier
  15. arguments: (arguments
  16. (string
  17. content: _ @injection.content)))
  18. (#set! injection.language "vim")
  19. (#any-of? @_vimcmd_identifier
  20. "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_command" "vim.api.nvim_exec2"))
  21. ((function_call
  22. name: (_) @_vimcmd_identifier
  23. arguments: (arguments
  24. (string
  25. content: _ @injection.content) .))
  26. (#set! injection.language "query")
  27. (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse"))
  28. ((function_call
  29. name: (_) @_vimcmd_identifier
  30. arguments: (arguments
  31. .
  32. (_)
  33. .
  34. (string
  35. content: _ @_method)
  36. .
  37. (string
  38. content: _ @injection.content)))
  39. (#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify")
  40. (#eq? @_method "nvim_exec_lua")
  41. (#set! injection.language "lua"))
  42. ; exec_lua [[ ... ]] in functionaltests
  43. ((function_call
  44. name: (identifier) @_function
  45. arguments: (arguments
  46. (string
  47. content: (string_content) @injection.content)))
  48. (#eq? @_function "exec_lua")
  49. (#set! injection.language "lua"))
  50. ; vim.api.nvim_create_autocmd("FileType", { command = "injected here" })
  51. (function_call
  52. name: (_) @_vimcmd_identifier
  53. arguments: (arguments
  54. .
  55. (_)
  56. .
  57. (table_constructor
  58. (field
  59. name: (identifier) @_command
  60. value: (string
  61. content: (_) @injection.content))) .)
  62. ; limit so only 2-argument functions gets matched before pred handle
  63. (#eq? @_vimcmd_identifier "vim.api.nvim_create_autocmd")
  64. (#eq? @_command "command")
  65. (#set! injection.language "vim"))
  66. (function_call
  67. name: (_) @_user_cmd
  68. arguments: (arguments
  69. .
  70. (_)
  71. .
  72. (string
  73. content: (_) @injection.content)
  74. .
  75. (_) .)
  76. (#eq? @_user_cmd "vim.api.nvim_create_user_command")
  77. (#set! injection.language "vim"))
  78. (function_call
  79. name: (_) @_user_cmd
  80. arguments: (arguments
  81. .
  82. (_)
  83. .
  84. (_)
  85. .
  86. (string
  87. content: (_) @injection.content)
  88. .
  89. (_) .)
  90. ; Limiting predicate handling to only functions with 4 arguments
  91. (#eq? @_user_cmd "vim.api.nvim_buf_create_user_command")
  92. (#set! injection.language "vim"))
  93. ; rhs highlighting for vim.keymap.set/vim.api.nvim_set_keymap/vim.api.nvim_buf_set_keymap
  94. ; (function_call
  95. ; name: (_) @_map
  96. ; arguments:
  97. ; (arguments
  98. ; . (_)
  99. ; . (_)
  100. ; .
  101. ; (string
  102. ; content: (_) @injection.content))
  103. ; (#any-of? @_map "vim.api.nvim_set_keymap" "vim.keymap.set")
  104. ; (#set! injection.language "vim"))
  105. ;
  106. ; (function_call
  107. ; name: (_) @_map
  108. ; arguments:
  109. ; (arguments
  110. ; . (_)
  111. ; . (_)
  112. ; . (_)
  113. ; .
  114. ; (string
  115. ; content: (_) @injection.content)
  116. ; . (_) .)
  117. ; (#eq? @_map "vim.api.nvim_buf_set_keymap")
  118. ; (#set! injection.language "vim"))
  119. ; highlight string as query if starts with `;; query`
  120. (string
  121. content: _ @injection.content
  122. (#lua-match? @injection.content "^%s*;+%s?query")
  123. (#set! injection.language "query"))