diff options
| author | phajw <dscr@duck.com> | 2024-01-25 16:31:23 +0100 |
|---|---|---|
| committer | phajw <dscr@duck.com> | 2024-01-25 16:31:23 +0100 |
| commit | a0d4284f53f90fb94430edb5309cee4bc0067e7e (patch) | |
| tree | cad9fdca4c96d4f65b5c6566d3dabc9469afd406 /lua/config/lsp.lua | |
| parent | 8471aeda42ff08420c99955ea785db0f24b5b7a2 (diff) | |
| download | neovim-a0d4284f53f90fb94430edb5309cee4bc0067e7e.tar.gz neovim-a0d4284f53f90fb94430edb5309cee4bc0067e7e.zip | |
Add licence, enable silent formatters execution
Diffstat (limited to 'lua/config/lsp.lua')
| -rw-r--r-- | lua/config/lsp.lua | 108 |
1 files changed, 47 insertions, 61 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua index 3fdc2e0..fdcfe99 100644 --- a/lua/config/lsp.lua +++ b/lua/config/lsp.lua | |||
| @@ -1,78 +1,64 @@ | |||
| 1 | -- local lsp = require('lsp-zero') | 1 | -- local lsp = require('lsp-zero') |
| 2 | 2 | ||
| 3 | local lsp_zero = require('lsp-zero') | 3 | local lsp_zero = require("lsp-zero") |
| 4 | local cmp = require('cmp') | 4 | local cmp = require("cmp") |
| 5 | require("luasnip.loaders.from_vscode").lazy_load() | 5 | require("luasnip.loaders.from_vscode").lazy_load() |
| 6 | 6 | ||
| 7 | lsp_zero.preset('recommended') | 7 | lsp_zero.preset("recommended") |
| 8 | lsp_zero.setup() | 8 | lsp_zero.setup() |
| 9 | lsp_zero.on_attach(function(client, bufnr) | 9 | lsp_zero.on_attach(function(client_id, bufnr) |
| 10 | -- see :help lsp-zero-keybindings | 10 | lsp_zero.default_keymaps({ buffer = bufnr }) |
| 11 | -- to learn the available actions | ||
| 12 | lsp_zero.default_keymaps({buffer = bufnr}) | ||
| 13 | end) | 11 | end) |
| 14 | 12 | ||
| 15 | require('mason').setup({}) | 13 | require("mason").setup({}) |
| 16 | require('mason-lspconfig').setup({ | 14 | require("mason-lspconfig").setup({ |
| 17 | -- Replace the language servers listed here | 15 | ensure_installed = { "tsserver", "rust_analyzer", "eslint" }, |
| 18 | -- with the ones you want to install | 16 | handlers = { |
| 19 | ensure_installed = {'tsserver', 'rust_analyzer', 'eslint'}, | 17 | lsp_zero.default_setup, |
| 20 | handlers = { | 18 | }, |
| 21 | lsp_zero.default_setup, | ||
| 22 | }, | ||
| 23 | }) | 19 | }) |
| 24 | 20 | ||
| 25 | |||
| 26 | |||
| 27 | --require('tabnine').setup({ | ||
| 28 | -- disable_auto_comment=true, | ||
| 29 | -- accept_keymap="<Tab>", | ||
| 30 | -- dismiss_keymap = "<C-]>", | ||
| 31 | -- debounce_ms = 800, | ||
| 32 | -- suggestion_color = {gui = "#808080", cterm = 244}, | ||
| 33 | -- execlude_filetypes = {"TelescopePrompt"} | ||
| 34 | --}) | ||
| 35 | |||
| 36 | cmp.setup({ | 21 | cmp.setup({ |
| 37 | snippet = { | 22 | snippet = { |
| 38 | expand = function(args) | 23 | expand = function(args) |
| 39 | require('luasnip').lsp_expand(args.body) | 24 | require("luasnip").lsp_expand(args.body) |
| 40 | end, | 25 | end, |
| 41 | }, | 26 | }, |
| 42 | window = { | 27 | window = {}, |
| 43 | }, | 28 | mapping = cmp.mapping.preset.insert({ |
| 44 | mapping = cmp.mapping.preset.insert({ | 29 | ["<C-b>"] = cmp.mapping.scroll_docs(-4), |
| 45 | ['<C-b>'] = cmp.mapping.scroll_docs(-4), | 30 | ["<C-f>"] = cmp.mapping.scroll_docs(4), |
| 46 | ['<C-f>'] = cmp.mapping.scroll_docs(4), | 31 | ["<C-Space>"] = cmp.mapping.complete(), |
| 47 | ['<C-Space>'] = cmp.mapping.complete(), | 32 | ["<C-e>"] = cmp.mapping.abort(), |
| 48 | ['<C-e>'] = cmp.mapping.abort(), | 33 | ["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. |
| 49 | ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. | 34 | }), |
| 50 | }), | 35 | sources = cmp.config.sources({ |
| 51 | sources = cmp.config.sources({ | 36 | { name = "nvim_lsp" }, |
| 52 | { name = 'nvim_lsp' }, | 37 | { name = "luasnip" }, |
| 53 | { name = 'luasnip' }, | 38 | }, { |
| 54 | }, { | 39 | { name = "buffer" }, |
| 55 | { name = 'buffer' }, | 40 | }), |
| 56 | }) | ||
| 57 | }) | 41 | }) |
| 58 | 42 | ||
| 59 | function PrintDiagnostics(opts, bufnr, line_nr, client_id) | 43 | function PrintDiagnostics(opts, bufnr, line_nr, client_id) |
| 60 | bufnr = bufnr or 0 | 44 | bufnr = bufnr or 0 |
| 61 | line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) | 45 | line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) |
| 62 | opts = opts or { ['lnum'] = line_nr } | 46 | opts = opts or { ["lnum"] = line_nr } |
| 63 | 47 | ||
| 64 | local line_diagnostics = vim.diagnostic.get(bufnr, opts) | 48 | local line_diagnostics = vim.diagnostic.get(bufnr, opts) |
| 65 | if vim.tbl_isempty(line_diagnostics) then return end | 49 | if vim.tbl_isempty(line_diagnostics) then |
| 50 | return | ||
| 51 | end | ||
| 66 | 52 | ||
| 67 | local diagnostic_message = "" | 53 | local diagnostic_message = "" |
| 68 | for i, diagnostic in ipairs(line_diagnostics) do | 54 | for i, diagnostic in ipairs(line_diagnostics) do |
| 69 | diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") | 55 | diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") |
| 70 | print(diagnostic_message) | 56 | print(diagnostic_message) |
| 71 | if i ~= #line_diagnostics then | 57 | if i ~= #line_diagnostics then |
| 72 | diagnostic_message = diagnostic_message .. "\n" | 58 | diagnostic_message = diagnostic_message .. "\n" |
| 73 | end | 59 | end |
| 74 | end | 60 | end |
| 75 | vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) | 61 | vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) |
| 76 | end | 62 | end |
| 77 | 63 | ||
| 78 | vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]] | 64 | vim.cmd([[ autocmd! CursorHold * lua PrintDiagnostics() ]]) |
