1
0

init.lua 6.9 KB

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