aboutsummaryrefslogtreecommitdiffstats
path: root/lua/config/lsp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/config/lsp.lua')
-rw-r--r--lua/config/lsp.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/lua/config/lsp.lua b/lua/config/lsp.lua
new file mode 100644
index 0000000..623aab3
--- /dev/null
+++ b/lua/config/lsp.lua
@@ -0,0 +1,78 @@
1-- local lsp = require('lsp-zero')
2
3local lsp_zero = require('lsp-zero')
4local cmp = require('cmp')
5require("luasnip.loaders.from_vscode").lazy_load()
6
7lsp_zero.preset('recommended')
8lsp_zero.setup()
9lsp_zero.on_attach(function(client, bufnr)
10 -- see :help lsp-zero-keybindings
11 -- to learn the available actions
12 lsp_zero.default_keymaps({buffer = bufnr})
13end)
14
15require('mason').setup({})
16require('mason-lspconfig').setup({
17 -- Replace the language servers listed here
18 -- with the ones you want to install
19 ensure_installed = {'tsserver', 'rust_analyzer', 'eslint'},
20 handlers = {
21 lsp_zero.default_setup,
22 },
23})
24
25
26
27require('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
36cmp.setup({
37 snippet = {
38 expand = function(args)
39 require('luasnip').lsp_expand(args.body)
40 end,
41 },
42 window = {
43 },
44 mapping = cmp.mapping.preset.insert({
45 ['<C-b>'] = cmp.mapping.scroll_docs(-4),
46 ['<C-f>'] = cmp.mapping.scroll_docs(4),
47 ['<C-Space>'] = cmp.mapping.complete(),
48 ['<C-e>'] = cmp.mapping.abort(),
49 ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
50 }),
51 sources = cmp.config.sources({
52 { name = 'nvim_lsp' },
53 { name = 'luasnip' },
54 }, {
55 { name = 'buffer' },
56 })
57})
58
59function PrintDiagnostics(opts, bufnr, line_nr, client_id)
60 bufnr = bufnr or 0
61 line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1)
62 opts = opts or { ['lnum'] = line_nr }
63
64 local line_diagnostics = vim.diagnostic.get(bufnr, opts)
65 if vim.tbl_isempty(line_diagnostics) then return end
66
67 local diagnostic_message = ""
68 for i, diagnostic in ipairs(line_diagnostics) do
69 diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "")
70 print(diagnostic_message)
71 if i ~= #line_diagnostics then
72 diagnostic_message = diagnostic_message .. "\n"
73 end
74 end
75 vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {})
76end
77
78vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]]