diff options
author | Brahmajit Das <brahmajit.xyz@gmail.com> | 2024-03-17 03:27:41 +0530 |
---|---|---|
committer | Brahmajit Das <brahmajit.xyz@gmail.com> | 2024-03-17 03:27:41 +0530 |
commit | 63a239013389ff362fa19abf4ecd98cc8e355f1a (patch) | |
tree | 9663214ca1e5e82fde28d9e69442e160107250a0 /lua | |
parent | c364e7425b7cf9df8aab0708fd6e54af5b0cd2dd (diff) |
nvim: plugins: lsp: for lsp specific settings
Signed-off-by: Brahmajit Das <brahmajit.xyz@gmail.com>
Diffstat (limited to 'lua')
-rw-r--r-- | lua/plugins/lsp.lua | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua new file mode 100644 index 0000000..43015fd --- /dev/null +++ b/lua/plugins/lsp.lua @@ -0,0 +1,105 @@ +require 'lspconfig'.lua_ls.setup { + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using + -- (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { + 'vim', + 'require' + }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, +} + +-- Global mappings. +-- See `:help vim.diagnostic.*` for documentation on any of the below functions +vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float) +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next) +vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist) + +-- Use LspAttach autocommand to only map the following keys +-- after the language server attaches to the current buffer +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + -- Enable completion triggered by <c-x><c-o> + vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc' + + -- Buffer local mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local opts = { buffer = ev.buf } + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts) + vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts) + vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts) + vim.keymap.set('n', '<leader>wa', vim.lsp.buf.add_workspace_folder, opts) + vim.keymap.set('n', '<leader>wr', vim.lsp.buf.remove_workspace_folder, opts) + vim.keymap.set('n', '<leader>wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, opts) + vim.keymap.set('n', '<leader>D', vim.lsp.buf.type_definition, opts) + vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, opts) + vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts) + vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts) + vim.keymap.set('n', '<leader>f', function() + vim.lsp.buf.format { async = true } + end, opts) + end, +}) + + +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) +end + +vim.o.updatetime = 250 +vim.cmd [[autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]] +vim.cmd [[autocmd! CursorHold,CursorHoldI * lua vim.diagnostic.open_float(nil, {focus=false})]] +vim.cmd [[autocmd! ColorScheme * highlight NormalFloat guibg=#4c4f69]] +vim.cmd [[autocmd! ColorScheme * highlight FloatBorder guifg=white guibg=#1f2335]] + +local border = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, +} + +-- To instead override globally +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 border + return orig_util_open_floating_preview(contents, syntax, opts, ...) +end + +--- In .nvim.lua of your project paste in this +--- +--- require'lspconfig'.clangd.setup{ +--- on_attach = require("plugins.lsp-config").on_attach, +--- cpabilities = require("plugins.lsp-config").cpabilities, +--- lsp_flags = require("plugins.lsp-config").lsp_flags, +--- cmd = {vim.fn.expand('~/esp/esp-clang/bin/clangd')} +--- } |