From 367836c01323c22cd3fa07bc88f5195014a2cf52 Mon Sep 17 00:00:00 2001 From: phajw Date: Wed, 4 Oct 2023 06:04:43 -0400 Subject: Move from github --- lua/config/lsp.lua | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 lua/config/lsp.lua (limited to 'lua/config/lsp.lua') 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 @@ +-- local lsp = require('lsp-zero') + +local lsp_zero = require('lsp-zero') +local cmp = require('cmp') +require("luasnip.loaders.from_vscode").lazy_load() + +lsp_zero.preset('recommended') +lsp_zero.setup() +lsp_zero.on_attach(function(client, bufnr) + -- see :help lsp-zero-keybindings + -- to learn the available actions + lsp_zero.default_keymaps({buffer = bufnr}) +end) + +require('mason').setup({}) +require('mason-lspconfig').setup({ + -- Replace the language servers listed here + -- with the ones you want to install + ensure_installed = {'tsserver', 'rust_analyzer', 'eslint'}, + handlers = { + lsp_zero.default_setup, + }, +}) + + + +require('tabnine').setup({ + disable_auto_comment=true, + accept_keymap="", + dismiss_keymap = "", + debounce_ms = 800, + suggestion_color = {gui = "#808080", cterm = 244}, + execlude_filetypes = {"TelescopePrompt"} +}) + +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + window = { + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) +}) + +function PrintDiagnostics(opts, bufnr, line_nr, client_id) + bufnr = bufnr or 0 + line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1) + opts = opts or { ['lnum'] = line_nr } + + local line_diagnostics = vim.diagnostic.get(bufnr, opts) + if vim.tbl_isempty(line_diagnostics) then return end + + local diagnostic_message = "" + for i, diagnostic in ipairs(line_diagnostics) do + diagnostic_message = diagnostic_message .. string.format("%d: %s", i, diagnostic.message or "") + print(diagnostic_message) + if i ~= #line_diagnostics then + diagnostic_message = diagnostic_message .. "\n" + end + end + vim.api.nvim_echo({ { diagnostic_message, "Normal" } }, false, {}) +end + +vim.cmd [[ autocmd! CursorHold * lua PrintDiagnostics() ]] -- cgit v1.2.3