123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- require('nvim-treesitter.configs').setup {
- highlight = {
- enable = true,
- },
- }
- local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
- function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
- opts = opts or {}
- opts.border = opts.border or 'single'
- return orig_util_open_floating_preview(contents, syntax, opts, ...)
- end
- vim.diagnostic.config({
- virtual_text = { severity = { min = vim.diagnostic.severity.WARN } }
- })
- local opts = { noremap=true, silent=true }
- vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
- vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
- vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
- vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setqflist({ severity = { min = vim.diagnostic.severity.WARN } })<CR>', opts)
- function on_attach(client, bufnr)
- -- Enable completion triggered by <c-x><c-o>
- vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
- -- Mappings.
- -- See `:help vim.lsp.*` for documentation on any of the below functions
- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
- end
- require'nvim-treesitter.configs'.setup {
- highlight = {
- enable = true,
- },
- }
- local nvim_lsp = require('lspconfig')
- local null_ls = require('null-ls')
- local null_ls_sources = {}
- if vim.fn.executable("node_modules/.bin/eslint") then
- table.insert(null_ls_sources, null_ls.builtins.formatting.eslint_d)
- table.insert(null_ls_sources, null_ls.builtins.diagnostics.eslint_d)
- table.insert(null_ls_sources, null_ls.builtins.code_actions.eslint_d)
- end
- if vim.fn.executable("gofmt") == 1 then
- table.insert(null_ls_sources, null_ls.builtins.formatting.gofmt)
- end
- if vim.fn.executable("shellcheck") == 1 then
- table.insert(null_ls_sources, null_ls.builtins.diagnostics.shellcheck)
- table.insert(null_ls_sources, null_ls.builtins.code_actions.shellcheck)
- end
- if vim.fn.executable("deno") == 1 then
- nvim_lsp.denols.setup({
- capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
- on_attach = on_attach,
- });
- table.insert(null_ls_sources, null_ls.builtins.formatting.deno_fmt);
- end
- if vim.fn.executable("node_modules/.bin/tsc") == 1 then
- local ts_utils = require("nvim-lsp-ts-utils")
- ts_utils.setup({
- debug = false,
- disable_commands = false,
- enable_import_on_completion = true,
- -- import all
- import_all_timeout = 5000, -- ms
- -- lower numbers = higher priority
- import_all_priorities = {
- same_file = 1, -- add to existing import statement
- local_files = 2, -- git files or files with relative path markers
- buffer_content = 3, -- loaded buffer content
- buffers = 4, -- loaded buffer names
- },
- import_all_scan_buffers = 100,
- import_all_select_source = false,
- -- filter diagnostics
- filter_out_diagnostics_by_severity = {},
- filter_out_diagnostics_by_code = {},
- -- inlay hints
- auto_inlay_hints = true,
- inlay_hints_highlight = "Comment",
- -- update imports on file move
- update_imports_on_move = false,
- require_confirmation_on_move = false,
- watch_dir = nil,
- })
- nvim_lsp.tsserver.setup({
- init_options = ts_utils.init_options,
- capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
- flags = {
- debounce_text_changes = 150,
- },
- on_attach = function(client, bufnr)
- client.resolved_capabilities.document_formatting = false
- client.resolved_capabilities.document_range_formatting = false
- on_attach(client, bufnr)
- -- required to fix code action ranges and filter diagnostics
- ts_utils.setup_client(client)
- end,
- })
- end
- null_ls.setup({
- sources = null_ls_sources,
- on_attach = function(client, bufnr)
- if client.resolved_capabilities.document_formatting then
- vim.cmd([[
- augroup LspFormatting
- autocmd! * <buffer>
- autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()
- augroup END
- ]])
- end
- on_attach(client, bufnr)
- end,
- });
- -- Setup nvim-cmp.
- local cmp = require'cmp'
- cmp.setup({
- completion = {
- autocomplete = false,
- },
- snippet = {
- expand = function(args)
- vim.fn["vsnip#anonymous"](args.body)
- end,
- },
- mapping = {
- ['<C-d>'] = cmp.mapping.scroll_docs(-4),
- ['<C-f>'] = cmp.mapping.scroll_docs(4),
- ['<C-Space>'] = cmp.mapping.complete(),
- ['<C-e>'] = cmp.mapping.close(),
- ['<CR>'] = cmp.mapping.confirm({ select = true }),
- },
- sources = {
- { name = 'nvim_lsp' },
- { name = 'vsnip' },
- { name = 'buffer' },
- }
- })
|