nixos/homeConfig/modules/neovim/config/lazyvim/lua/config/autocmds.lua
2023-06-11 23:25:56 -04:00

107 lines
2.5 KiB
Lua

-- Autocmds are automatically loaded on the VeryLazy event
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
-- Add any additional autocmds here
vim.cmd([[
au BufRead,BufNewFile *.purs set filetype=purescript
]])
require("notify").setup({
background_colour = "#000000",
})
local lsp = require("lsp-zero").preset({})
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
require("null-ls").setup({
-- you can reuse a shared lspconfig on_attach callback here
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
bufnr = bufnr,
filter = function(client)
return client.name == "null-ls"
end,
})
vim.lsp.buf.formatting_sync()
end,
})
end
end,
})
--lsp.on_attach(function(client, bufnr)
-- lsp.default_keymaps({ buffer = bufnr })
--end)
lsp.setup_servers({
"tsserver",
"eslint",
"hls",
"pyright",
"nil_ls",
"cssls",
"html",
"jsonls",
"diagnosticls",
"lua_ls",
"marksman",
"purescriptls",
"tailwindcss",
"bashls",
})
require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls())
lsp.setup()
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
sources = {
{ name = "nvim_lsp" },
{ name = "luasnip" },
-- other sources...
},
-- other configurations...
})
cmp.setup({
enabled = function()
-- disable completion in comments
local context = require("cmp.config.context")
-- keep command mode completion enabled when cursor is in a comment
if vim.api.nvim_get_mode().mode == "c" then
return true
else
return not context.in_treesitter_capture("comment") and not context.in_syntax_group("comment")
end
end,
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<Down>"] = cmp.mapping.select_next_item(),
["<Up>"] = cmp.mapping.select_prev_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif cmp.completed then
cmp.confirm({ select = true })
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping.select_prev_item(),
},
})