init.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. local lv_utils = {}
  2. function lv_utils.define_augroups(definitions) -- {{{1
  3. -- Create autocommand groups based on the passed definitions
  4. --
  5. -- The key will be the name of the group, and each definition
  6. -- within the group should have:
  7. -- 1. Trigger
  8. -- 2. Pattern
  9. -- 3. Text
  10. -- just like how they would normally be defined from Vim itself
  11. for group_name, definition in pairs(definitions) do
  12. vim.cmd('augroup ' .. group_name)
  13. vim.cmd('autocmd!')
  14. for _, def in pairs(definition) do
  15. local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
  16. vim.cmd(command)
  17. end
  18. vim.cmd('augroup END')
  19. end
  20. end
  21. -- lsp
  22. function lv_utils.add_to_workspace_folder()
  23. vim.lsp.buf.add_workspace_folder()
  24. end
  25. function lv_utils.clear_references()
  26. vim.lsp.buf.clear_references()
  27. end
  28. function lv_utils.code_action()
  29. vim.lsp.buf.code_action()
  30. end
  31. function lv_utils.declaration()
  32. vim.lsp.buf.declaration()
  33. vim.lsp.buf.clear_references()
  34. end
  35. function lv_utils.definition()
  36. vim.lsp.buf.definition()
  37. vim.lsp.buf.clear_references()
  38. end
  39. function lv_utils.document_highlight()
  40. vim.lsp.buf.document_highlight()
  41. end
  42. function lv_utils.document_symbol()
  43. vim.lsp.buf.document_symbol()
  44. end
  45. function lv_utils.formatting()
  46. vim.lsp.buf.formatting()
  47. end
  48. function lv_utils.formatting_sync()
  49. vim.lsp.buf.formatting_sync()
  50. end
  51. function lv_utils.hover()
  52. vim.lsp.buf.hover()
  53. end
  54. function lv_utils.implementation()
  55. vim.lsp.buf.implementation()
  56. end
  57. function lv_utils.incoming_calls()
  58. vim.lsp.buf.incoming_calls()
  59. end
  60. function lv_utils.list_workspace_folders()
  61. vim.lsp.buf.list_workspace_folders()
  62. end
  63. function lv_utils.outgoing_calls()
  64. vim.lsp.buf.outgoing_calls()
  65. end
  66. function lv_utils.range_code_action()
  67. vim.lsp.buf.range_code_action()
  68. end
  69. function lv_utils.range_formatting()
  70. vim.lsp.buf.range_formatting()
  71. end
  72. function lv_utils.references()
  73. vim.lsp.buf.references()
  74. vim.lsp.buf.clear_references()
  75. end
  76. function lv_utils.remove_workspace_folder()
  77. vim.lsp.buf.remove_workspace_folder()
  78. end
  79. function lv_utils.rename()
  80. vim.lsp.buf.rename()
  81. end
  82. function lv_utils.signature_help()
  83. vim.lsp.buf.signature_help()
  84. end
  85. function lv_utils.type_definition()
  86. vim.lsp.buf.type_definition()
  87. end
  88. function lv_utils.workspace_symbol()
  89. vim.lsp.buf.workspace_symbol()
  90. end
  91. -- diagnostic
  92. function lv_utils.get_all()
  93. vim.lsp.diagnostic.get_all()
  94. end
  95. function lv_utils.get_next()
  96. vim.lsp.diagnostic.get_next()
  97. end
  98. function lv_utils.get_prev()
  99. vim.lsp.diagnostic.get_prev()
  100. end
  101. function lv_utils.goto_next()
  102. vim.lsp.diagnostic.goto_next()
  103. end
  104. function lv_utils.goto_prev()
  105. vim.lsp.diagnostic.goto_prev()
  106. end
  107. function lv_utils.show_line_diagnostics()
  108. vim.lsp.diagnostic.show_line_diagnostics()
  109. end
  110. -- git signs
  111. function lv_utils.next_hunk()
  112. require('gitsigns').next_hunk()
  113. end
  114. function lv_utils.prev_hunk()
  115. require('gitsigns').prev_hunk()
  116. end
  117. function lv_utils.stage_hunk()
  118. require('gitsigns').stage_hunk()
  119. end
  120. function lv_utils.undo_stage_hunk()
  121. require('gitsigns').undo_stage_hunk()
  122. end
  123. function lv_utils.reset_hunk()
  124. require('gitsigns').reset_hunk()
  125. end
  126. function lv_utils.reset_buffer()
  127. require('gitsigns').reset_buffer()
  128. end
  129. function lv_utils.preview_hunk()
  130. require('gitsigns').preview_hunk()
  131. end
  132. function lv_utils.blame_line()
  133. require('gitsigns').blame_line()
  134. end
  135. -- misc
  136. function lv_utils.file_exists(name)
  137. local f = io.open(name, "r")
  138. if f ~= nil then
  139. io.close(f)
  140. return true
  141. else
  142. return false
  143. end
  144. end
  145. return lv_utils