init.lua 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. require('telescope').setup({
  2. defaults = {
  3. mappings = {
  4. i = {
  5. ['jj'] = 'close',
  6. ['<C-j>'] = 'move_selection_next',
  7. ['<C-k>'] = 'move_selection_previous',
  8. },
  9. },
  10. layout_config = {
  11. prompt_position = 'top',
  12. },
  13. sorting_strategy = 'ascending',
  14. },
  15. })
  16. require('telescope').load_extension('fzf')
  17. require('onedark').setup({
  18. term_colors = false,
  19. transparent = true,
  20. highlights = {
  21. MiniStatuslineModeNormal = { bg = '$blue', fg = '$black' },
  22. MiniStatuslineModeCommand = { bg = '$grey', fg = '$black' },
  23. MiniStatuslineModeInsert = { bg = '$green', fg = '$black' },
  24. MiniStatuslineModeVisual = { bg = '$orange', fg = '$black' },
  25. MiniStatuslineModeReplace = { bg = '$red', fg = '$black' },
  26. MiniStatuslineModeOther = { bg = '$green', fg = '$black' },
  27. MiniIndentscopeSymbol = { fg = '$bg3' },
  28. },
  29. })
  30. require('onedark').load()
  31. require('gitsigns').setup()
  32. require('mini.statusline').setup({
  33. content = {
  34. active = function()
  35. local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
  36. local git = MiniStatusline.section_git({ trunc_width = 75, icon = '' })
  37. local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75, icon = '' })
  38. local filename = MiniStatusline.section_filename({ trunc_width = 140 })
  39. local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
  40. local location = MiniStatusline.section_location({ trunc_width = 75 })
  41. return MiniStatusline.combine_groups({
  42. { hl = mode_hl, strings = { mode } },
  43. { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } },
  44. '%<', -- Mark general truncate point
  45. { hl = 'MiniStatuslineFilename', strings = { filename } },
  46. '%=', -- End left alignment
  47. { hl = 'MiniStatuslineFileinfo', strings = { fileinfo } },
  48. { hl = mode_hl, strings = { location } },
  49. })
  50. end
  51. },
  52. })
  53. require('mini.bufremove').setup()
  54. require('mini.indentscope').setup()
  55. require('nvim-treesitter.configs').setup {
  56. highlight = {
  57. enable = true,
  58. },
  59. }
  60. vim.diagnostic.config({
  61. virtual_text = { severity = { min = vim.diagnostic.severity.WARN } }
  62. })
  63. local opts = { noremap=true, silent=true }
  64. vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
  65. vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
  66. vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
  67. vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
  68. vim.api.nvim_set_keymap('n', '<Leader>q', '<cmd>lua MiniBufremove.delete()<CR>', opts)
  69. vim.api.nvim_set_keymap('n', '<C-P>', '<cmd>Telescope find_files<CR>', opts)
  70. vim.api.nvim_set_keymap('n', '<C-O>', '<cmd>Telescope buffers<CR>', opts)
  71. vim.api.nvim_set_keymap('n', '<Leader>ff', '<cmd>Telescope live_grep<CR>', opts)
  72. vim.api.nvim_set_keymap('n', '<Leader>fs', '<cmd>Telescope lsp_document_symbols<CR>', opts)
  73. -- Allow pressing enter to autocomplete
  74. vim.api.nvim_set_keymap('i', '<CR>', 'pumvisible() ? "\\<C-y>" : "\\<CR>"', { noremap = true, expr = true })
  75. function on_attach(client, bufnr)
  76. -- Enable completion triggered by <c-x><c-o>
  77. vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.MiniCompletion.completefunc_lsp')
  78. -- Mappings.
  79. -- See `:help vim.lsp.*` for documentation on any of the below functions
  80. vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  81. vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
  82. vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
  83. vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  84. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  85. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  86. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  87. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  88. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  89. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  90. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
  91. vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>Telescope lsp_references<CR>', opts)
  92. vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
  93. end
  94. require'nvim-treesitter.configs'.setup {
  95. highlight = {
  96. enable = true,
  97. },
  98. }
  99. require('mini.completion').setup({
  100. delay = {
  101. -- disable autocomplete
  102. completion = 100000000,
  103. info = 100,
  104. signature = 50,
  105. },
  106. lsp_completion = {
  107. source_func = 'omnifunc',
  108. auto_setup = false,
  109. },
  110. });
  111. local nvim_lsp = require('lspconfig')
  112. local null_ls = require('null-ls')
  113. local null_ls_sources = {}
  114. if vim.fn.executable("node_modules/.bin/eslint") == 1 then
  115. table.insert(null_ls_sources, null_ls.builtins.formatting.eslint_d)
  116. table.insert(null_ls_sources, null_ls.builtins.diagnostics.eslint_d)
  117. table.insert(null_ls_sources, null_ls.builtins.code_actions.eslint_d)
  118. end
  119. if vim.fn.executable("gofmt") == 1 then
  120. table.insert(null_ls_sources, null_ls.builtins.formatting.gofmt)
  121. end
  122. if vim.fn.executable("shellcheck") == 1 then
  123. table.insert(null_ls_sources, null_ls.builtins.diagnostics.shellcheck)
  124. table.insert(null_ls_sources, null_ls.builtins.code_actions.shellcheck)
  125. end
  126. if vim.fn.executable("deno") == 1 then
  127. nvim_lsp.denols.setup({
  128. capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
  129. on_attach = on_attach,
  130. });
  131. table.insert(null_ls_sources, null_ls.builtins.formatting.deno_fmt);
  132. end
  133. if vim.fn.executable("node_modules/.bin/tsc") == 1 then
  134. local ts_utils = require("nvim-lsp-ts-utils")
  135. nvim_lsp.tsserver.setup({
  136. init_options = ts_utils.init_options,
  137. flags = {
  138. debounce_text_changes = 150,
  139. },
  140. on_attach = function(client, bufnr)
  141. client.resolved_capabilities.document_formatting = false
  142. client.resolved_capabilities.document_range_formatting = false
  143. on_attach(client, bufnr)
  144. ts_utils.setup({
  145. debug = false,
  146. disable_commands = false,
  147. enable_import_on_completion = true,
  148. -- import all
  149. import_all_timeout = 5000, -- ms
  150. -- lower numbers = higher priority
  151. import_all_priorities = {
  152. same_file = 1, -- add to existing import statement
  153. local_files = 2, -- git files or files with relative path markers
  154. buffer_content = 3, -- loaded buffer content
  155. buffers = 4, -- loaded buffer names
  156. },
  157. import_all_scan_buffers = 100,
  158. import_all_select_source = false,
  159. -- filter diagnostics
  160. filter_out_diagnostics_by_severity = {},
  161. filter_out_diagnostics_by_code = {},
  162. -- inlay hints
  163. auto_inlay_hints = false,
  164. inlay_hints_highlight = "Comment",
  165. -- update imports on file move
  166. update_imports_on_move = false,
  167. require_confirmation_on_move = false,
  168. watch_dir = nil,
  169. })
  170. -- required to fix code action ranges and filter diagnostics
  171. ts_utils.setup_client(client)
  172. end,
  173. })
  174. end
  175. null_ls.setup({
  176. sources = null_ls_sources,
  177. on_attach = function(client, bufnr)
  178. if client.resolved_capabilities.document_formatting then
  179. vim.cmd([[
  180. augroup LspFormatting
  181. autocmd! * <buffer>
  182. autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
  183. augroup END
  184. ]])
  185. end
  186. end,
  187. });