working on null-ls

This commit is contained in:
Bryan Ramos 2023-06-11 22:29:46 -04:00
parent c40cdf87b3
commit a11e955c97
2 changed files with 47 additions and 51 deletions

View file

@ -1,14 +1,44 @@
-- 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({})
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({ buffer = bufnr })
end)
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)
-- When you don't have mason.nvim installed
-- You'll need to list the servers installed in your system
lsp.setup_servers({
"tsserver",
"eslint",
@ -26,7 +56,6 @@ lsp.setup_servers({
"bashls",
})
-- (Optional) Configure lua language server for neovim
require("lspconfig").lua_ls.setup(lsp.nvim_lua_ls())
lsp.setup()
@ -45,19 +74,6 @@ cmp.setup({
},
-- other configurations...
})
vim.cmd([[
au BufRead,BufNewFile *.purs set filetype=purescript
]])
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local luasnip = require("luasnip")
cmp.setup({
enabled = function()
-- disable completion in comments
@ -70,42 +86,22 @@ cmp.setup({
end
end,
mapping = {
["<tab>"] = cmp.mapping(function(fallback)
["<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()
-- you could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
-- they way you will only jump inside the snippet region
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
elseif cmp.completed then
cmp.confirm({ select = true })
else
fallback()
end
end, { "i", "s" }),
["<s-tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<cr>"] = cmp.mapping({
i = function(fallback)
if cmp.visible() and cmp.get_active_entry() then
cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })
else
fallback()
end
end,
}),
["<S-Tab>"] = cmp.mapping.select_prev_item(),
},
})
require("notify").setup({
background_colour = "#000000",
})