init.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. local function_wrapper = {}
  2. function function_wrapper.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. function_wrapper.define_augroups(
  22. {_general_settings = {
  23. {'TextYankPost', '*', 'lua require(\'vim.highlight\').on_yank({higroup = \'QuickScopePrimary\', timeout = 200})'},
  24. {'BufWinEnter', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  25. {'BufRead', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  26. {'BufNewFile', '*', 'setlocal formatoptions-=c formatoptions-=r formatoptions-=o'},
  27. {'FileType', 'java', 'luafile ~/.config/nvim/lua/lsp/java-ls.lua'},
  28. {'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'},
  29. {'FileType', 'java', 'nnoremap ca <Cmd>lua require(\'jdtls\').code_action()<CR>'},
  30. {'User', 'GoyoLeave', 'lua require(\'galaxyline\').disable_galaxyline()'},
  31. {'User', 'GoyoEnter', 'lua require(\'galaxyline\').galaxyline_augroup()'},
  32. },
  33. }
  34. )
  35. -- Add this to lightbulb, java makes this annoying tho
  36. -- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb()
  37. -- lsp
  38. function function_wrapper.add_to_workspace_folder()
  39. vim.lsp.buf.add_workspace_folder()
  40. end
  41. function function_wrapper.clear_references()
  42. vim.lsp.buf.clear_references()
  43. end
  44. function function_wrapper.code_action()
  45. vim.lsp.buf.code_action()
  46. end
  47. function function_wrapper.declaration()
  48. vim.lsp.buf.declaration()
  49. vim.lsp.buf.clear_references()
  50. end
  51. function function_wrapper.definition()
  52. vim.lsp.buf.definition()
  53. vim.lsp.buf.clear_references()
  54. end
  55. function function_wrapper.document_highlight()
  56. vim.lsp.buf.document_highlight()
  57. end
  58. function function_wrapper.document_symbol()
  59. vim.lsp.buf.document_symbol()
  60. end
  61. function function_wrapper.formatting()
  62. vim.lsp.buf.formatting()
  63. end
  64. function function_wrapper.formatting_sync()
  65. vim.lsp.buf.formatting_sync()
  66. end
  67. function function_wrapper.hover()
  68. vim.lsp.buf.hover()
  69. end
  70. function function_wrapper.implementation()
  71. vim.lsp.buf.implementation()
  72. end
  73. function function_wrapper.incoming_calls()
  74. vim.lsp.buf.incoming_calls()
  75. end
  76. function function_wrapper.list_workspace_folders()
  77. vim.lsp.buf.list_workspace_folders()
  78. end
  79. function function_wrapper.outgoing_calls()
  80. vim.lsp.buf.outgoing_calls()
  81. end
  82. function function_wrapper.range_code_action()
  83. vim.lsp.buf.range_code_action()
  84. end
  85. function function_wrapper.range_formatting()
  86. vim.lsp.buf.range_formatting()
  87. end
  88. function function_wrapper.references()
  89. vim.lsp.buf.references()
  90. vim.lsp.buf.clear_references()
  91. end
  92. function function_wrapper.remove_workspace_folder()
  93. vim.lsp.buf.remove_workspace_folder()
  94. end
  95. function function_wrapper.rename()
  96. vim.lsp.buf.rename()
  97. end
  98. function function_wrapper.signature_help()
  99. vim.lsp.buf.signature_help()
  100. end
  101. function function_wrapper.type_definition()
  102. vim.lsp.buf.type_definition()
  103. end
  104. function function_wrapper.workspace_symbol()
  105. vim.lsp.buf.workspace_symbol()
  106. end
  107. -- diagnostic
  108. function function_wrapper.get_all()
  109. vim.lsp.diagnostic.get_all()
  110. end
  111. function function_wrapper.get_next()
  112. vim.lsp.diagnostic.get_next()
  113. end
  114. function function_wrapper.get_prev()
  115. vim.lsp.diagnostic.get_prev()
  116. end
  117. function function_wrapper.goto_next()
  118. vim.lsp.diagnostic.goto_next()
  119. end
  120. function function_wrapper.goto_prev()
  121. vim.lsp.diagnostic.goto_prev()
  122. end
  123. function function_wrapper.show_line_diagnostics()
  124. vim.lsp.diagnostic.show_line_diagnostics()
  125. end
  126. -- git signs
  127. function function_wrapper.next_hunk()
  128. require('gitsigns').next_hunk()
  129. end
  130. function function_wrapper.prev_hunk()
  131. require('gitsigns').prev_hunk()
  132. end
  133. function function_wrapper.stage_hunk()
  134. require('gitsigns').stage_hunk()
  135. end
  136. function function_wrapper.undo_stage_hunk()
  137. require('gitsigns').undo_stage_hunk()
  138. end
  139. function function_wrapper.reset_hunk()
  140. require('gitsigns').reset_hunk()
  141. end
  142. function function_wrapper.reset_buffer()
  143. require('gitsigns').reset_buffer()
  144. end
  145. function function_wrapper.preview_hunk()
  146. require('gitsigns').preview_hunk()
  147. end
  148. function function_wrapper.blame_line()
  149. require('gitsigns').blame_line()
  150. end
  151. -- misc
  152. -- autoformat
  153. -- autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 1000)
  154. return function_wrapper