summaryrefslogtreecommitdiff
path: root/.config/nvim/lua
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-12-08 11:52:16 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-12-08 11:52:16 +0100
commit956df69d7496081db5e7b3621a0bcc7b9d7f7dfc (patch)
tree2c1de01541d70d1cbcb59974e42102440359f153 /.config/nvim/lua
parent1eca5dc0fe3648341e1707efc811162fc5056888 (diff)
move to .config folder
Diffstat (limited to '.config/nvim/lua')
-rw-r--r--.config/nvim/lua/git.lua29
-rw-r--r--.config/nvim/lua/lsp_conf.lua77
-rw-r--r--.config/nvim/lua/lualine_style.lua7
3 files changed, 113 insertions, 0 deletions
diff --git a/.config/nvim/lua/git.lua b/.config/nvim/lua/git.lua
new file mode 100644
index 0000000..2f9cbc4
--- /dev/null
+++ b/.config/nvim/lua/git.lua
@@ -0,0 +1,29 @@
+require('gitsigns').setup {
+ signs = {
+ add = {hl = 'GitSignsAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLn'},
+ change = {hl = 'GitSignsChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
+ delete = {hl = 'GitSignsDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
+ topdelete = {hl = 'GitSignsDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLn'},
+ changedelete = {hl = 'GitSignsChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLn'},
+ },
+ keymaps = {
+ -- Default keymap options
+ noremap = true,
+
+ ['n ]c'] = { expr = true, "&diff ? ']c' : '<cmd>lua require\"gitsigns.actions\".next_hunk()<CR>'"},
+ ['n [c'] = { expr = true, "&diff ? '[c' : '<cmd>lua require\"gitsigns.actions\".prev_hunk()<CR>'"},
+
+ ['n hs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
+ ['v hs'] = '<cmd>lua require"gitsigns".stage_hunk({vim.fn.line("."), vim.fn.line("v")})<CR>',
+ ['n hS'] = '<cmd>lua require"gitsigns".stage_buffer()<CR>',
+ ['n hu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
+ ['n hp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
+ ['n hB'] = '<cmd>lua require"gitsigns".blame_line(true)<CR>',
+ },
+ signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
+ numhl = true, -- Toggle with `:Gitsigns toggle_numhl`
+ watch_gitdir = {
+ interval = 1000,
+ follow_files = true
+ },
+}
diff --git a/.config/nvim/lua/lsp_conf.lua b/.config/nvim/lua/lsp_conf.lua
new file mode 100644
index 0000000..e339a5c
--- /dev/null
+++ b/.config/nvim/lua/lsp_conf.lua
@@ -0,0 +1,77 @@
+local nvim_lsp = require('lspconfig')
+local coq = require('coq')
+local null_ls = require("null-ls")
+local trouble = require("trouble")
+
+-- Redefine sign.
+local signs = { Error = 'E', Warning = 'W', Hint = 'H', Information = 'I' }
+
+for type, icon in pairs(signs) do
+ local hl = 'LspDiagnosticsSign' .. type
+ vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
+end
+
+local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
+local opts = { noremap=true, silent=true }
+
+null_ls.config({
+ debug = false,
+ save_after_format = false,
+ sources = {
+ -- Python
+ null_ls.builtins.formatting.black,
+ null_ls.builtins.formatting.isort,
+ null_ls.builtins.diagnostics.flake8,
+ -- Rust
+ null_ls.builtins.formatting.rustfmt,
+ -- C
+ null_ls.builtins.formatting.clang_format,
+ -- JS/TS
+ null_ls.builtins.formatting.prettier,
+ }
+})
+
+-- Setup lspconfig.
+
+--- Use a loop to conveniently call 'setup' on multiple servers and
+-- map buffer local keybindings when the language server attaches
+local servers = { 'pyright', 'rust_analyzer', 'tsserver', 'clangd' }
+for _, lsp in ipairs(servers) do
+ nvim_lsp[lsp].setup {
+ capabilities = coq.lsp_ensure_capabilities(),
+ on_attach = function(client, bufnr)
+ client.resolved_capabilities.document_formatting = false
+
+ require "lsp_signature".on_attach()
+
+ -- Mappings.
+ local opts = { noremap=true, silent=true }
+
+ -- See `:help vim.lsp.*` for documentation on any of the below functions
+ buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
+ buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
+ buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
+ buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
+ buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
+ end,
+ flags = {
+ debounce_text_changes = 150,
+ }
+ }
+end
+
+nvim_lsp["null-ls"].setup({
+ on_attach = function(client)
+ if client.resolved_capabilities.document_formatting then
+ buf_set_keymap('n', '<A-f>', '<cmd>lua vim.lsp.buf.formatting_sync()<cr>', opts)
+ vim.cmd "autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()"
+ end
+ end
+})
+
+trouble.setup({
+ use_lsp_diagnostic_signs = true,
+ auto_close = true,
+ auto_open = true
+})
+
diff --git a/.config/nvim/lua/lualine_style.lua b/.config/nvim/lua/lualine_style.lua
new file mode 100644
index 0000000..bb7738b
--- /dev/null
+++ b/.config/nvim/lua/lualine_style.lua
@@ -0,0 +1,7 @@
+require'lualine'.setup{
+ options = {
+ theme = 'powerline',
+ section_separators = { left = '', right = ''},
+ component_separators = { left = '|', right = '|'},
+ },
+}