replace efm with none-ls

enable black formatter for black
enable stylua formatter for lua
update nix flake inputs
format lua files
This commit is contained in:
Pim Kunis 2023-11-30 16:59:49 +01:00
parent 421a05a82f
commit 3b9b7d3c01
10 changed files with 219 additions and 133 deletions

View file

@ -101,11 +101,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1700678569, "lastModified": 1700851152,
"narHash": "sha256-2Ki+2UvOidxEb3xB4ADqlbPQ2BZOF4uZMR094O8or2I=", "narHash": "sha256-3PWITNJZyA3jz5IGREJRfSykM6xSLmD8u5A3WpBCyDM=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "8f1180704ac35baded1a74164365ac7cdfba6f38", "rev": "1216a5ba22a93a4a3a3bfdb4bff0f4727c576fcc",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -115,13 +115,29 @@
"type": "github" "type": "github"
} }
}, },
"nixpkgs-unstable": {
"locked": {
"lastModified": 1701040486,
"narHash": "sha256-vawYwoHA5CwvjfqaT3A5CT9V36Eq43gxdwpux32Qkjw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "45827faa2132b8eade424f6bdd48d8828754341a",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nur": { "nur": {
"locked": { "locked": {
"lastModified": 1700855055, "lastModified": 1700923974,
"narHash": "sha256-QKjcrEntfghcXBsrenDE46OxaF/4YQVStAQfyDOQcPA=", "narHash": "sha256-3SWdqep5XzFEuK+5iJkDe/mTIvidS3Gs47W/DVXuRnE=",
"owner": "nix-community", "owner": "nix-community",
"repo": "NUR", "repo": "NUR",
"rev": "ebf2c68214f10ee5b9372ae4960a7b54af514bd3", "rev": "2644c4a32642a32ea01dc63fd780404c21c82d7a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -137,6 +153,7 @@
"homeage": "homeage", "homeage": "homeage",
"nixos-hardware": "nixos-hardware", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable",
"nur": "nur" "nur": "nur"
} }
} }

View file

@ -3,6 +3,7 @@
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nur.url = "github:nix-community/NUR"; nur.url = "github:nix-community/NUR";
home-manager = { home-manager = {
url = url =
@ -21,14 +22,24 @@
nixos-hardware.url = "github:NixOS/nixos-hardware/master"; nixos-hardware.url = "github:NixOS/nixos-hardware/master";
}; };
outputs = outputs = { nixpkgs, nixpkgs-unstable, home-manager, homeage, agenix, nur
{ nixpkgs, home-manager, homeage, agenix, nur, nixos-hardware, ... }: { , nixos-hardware, ... }: {
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt; formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt;
nixosConfigurations.pim = nixpkgs.lib.nixosSystem { nixosConfigurations.pim = nixpkgs.lib.nixosSystem rec {
system = "x86_64-linux"; system = "x86_64-linux";
modules = [ modules = [
{ nixpkgs.overlays = [ nur.overlay ]; } {
nixpkgs.overlays = [
nur.overlay
(final: _prev: {
unstable = import nixpkgs-unstable {
inherit system;
config.allowUnfree = true;
};
})
];
}
./nixos ./nixos
agenix.nixosModules.default agenix.nixosModules.default
nixos-hardware.nixosModules.lenovo-thinkpad-x260 nixos-hardware.nixosModules.lenovo-thinkpad-x260

View file

@ -1,13 +1,13 @@
require("bufferline").setup { require("bufferline").setup({
options = { options = {
diagnostics = 'nvim_lsp', diagnostics = "nvim_lsp",
diagnostics_indicator = function(count, level, diagnostics_dict, context) diagnostics_indicator = function(count, level, diagnostics_dict, context)
local icon = level:match("error") and "" or "" local icon = level:match("error") and "" or ""
return " " .. icon .. count return " " .. icon .. count
end, end,
separator_style = "slant", separator_style = "slant",
hover = {enabled = true, reveal = {'close'}} hover = { enabled = true, reveal = { "close" } },
} },
} })
vim.keymap.set('n', '<leader>ft', ":BufferLinePick<CR>", {}) vim.keymap.set("n", "<leader>ft", ":BufferLinePick<CR>", {})

View file

@ -1,39 +1,43 @@
local cmp = require('cmp') local cmp = require("cmp")
local luasnip = require('luasnip') local luasnip = require("luasnip")
require('luasnip.loaders.from_vscode').lazy_load() require("luasnip.loaders.from_vscode").lazy_load()
luasnip.config.setup {} luasnip.config.setup({})
cmp.setup { cmp.setup({
snippet = {expand = function(args) luasnip.lsp_expand(args.body) end}, snippet = {
mapping = cmp.mapping.preset.insert { expand = function(args)
['<C-n>'] = cmp.mapping.select_next_item(), luasnip.lsp_expand(args.body)
['<C-p>'] = cmp.mapping.select_prev_item(), end,
['<C-d>'] = cmp.mapping.scroll_docs(-4), },
['<C-f>'] = cmp.mapping.scroll_docs(4), mapping = cmp.mapping.preset.insert({
['<C-Space>'] = cmp.mapping.complete {}, ["<C-n>"] = cmp.mapping.select_next_item(),
['<CR>'] = cmp.mapping.confirm { ["<C-p>"] = cmp.mapping.select_prev_item(),
behavior = cmp.ConfirmBehavior.Replace, ["<C-d>"] = cmp.mapping.scroll_docs(-4),
select = true ["<C-f>"] = cmp.mapping.scroll_docs(4),
}, ["<C-Space>"] = cmp.mapping.complete({}),
['<Tab>'] = cmp.mapping(function(fallback) ["<CR>"] = cmp.mapping.confirm({
if cmp.visible() then behavior = cmp.ConfirmBehavior.Replace,
cmp.select_next_item() select = true,
elseif luasnip.expand_or_locally_jumpable() then }),
luasnip.expand_or_jump() ["<Tab>"] = cmp.mapping(function(fallback)
else if cmp.visible() then
fallback() cmp.select_next_item()
end elseif luasnip.expand_or_locally_jumpable() then
end, {'i', 's'}), luasnip.expand_or_jump()
['<S-Tab>'] = cmp.mapping(function(fallback) else
if cmp.visible() then fallback()
cmp.select_prev_item() end
elseif luasnip.locally_jumpable(-1) then end, { "i", "s" }),
luasnip.jump(-1) ["<S-Tab>"] = cmp.mapping(function(fallback)
else if cmp.visible() then
fallback() cmp.select_prev_item()
end elseif luasnip.locally_jumpable(-1) then
end, {'i', 's'}) luasnip.jump(-1)
}, else
sources = {{name = 'nvim_lsp'}, {name = 'luasnip'}} fallback()
} end
end, { "i", "s" }),
}),
sources = { { name = "nvim_lsp" }, { name = "luasnip" } },
})

View file

@ -14,9 +14,9 @@
neofetch neofetch
gopls gopls
terraform-ls terraform-ls
luaformatter
efm-langserver
nixfmt nixfmt
stylua
black
]; ];
plugins = with pkgs.vimPlugins; [ plugins = with pkgs.vimPlugins; [
@ -69,6 +69,11 @@
} }
nvim-web-devicons nvim-web-devicons
lsp-format-nvim lsp-format-nvim
{
plugin = pkgs.unstable.vimPlugins.none-ls-nvim;
type = "lua";
config = builtins.readFile ./none-ls.lua;
}
]; ];
}; };

View file

@ -1,4 +1,4 @@
require('leap').add_default_mappings() require("leap").add_default_mappings()
-- Don't remap 'x' in visual mode. -- Don't remap 'x' in visual mode.
vim.keymap.del({'x', 'o'}, 'x') vim.keymap.del({ "x", "o" }, "x")
vim.keymap.del({'x', 'o'}, 'X') vim.keymap.del({ "x", "o" }, "X")

View file

@ -1,59 +1,58 @@
require("lsp-format").setup {} require("lsp-format").setup({})
local on_attach = function(client, bufnr) local on_attach = function(client, bufnr)
local bufmap = function(keys, func) local bufmap = function(keys, func)
vim.keymap.set('n', keys, func, {buffer = bufnr}) vim.keymap.set("n", keys, func, { buffer = bufnr })
end end
bufmap('<leader>r', vim.lsp.buf.rename) bufmap("<leader>r", vim.lsp.buf.rename)
bufmap('<leader>a', vim.lsp.buf.code_action) bufmap("<leader>a", vim.lsp.buf.code_action)
bufmap('gd', vim.lsp.buf.definition) bufmap("gd", vim.lsp.buf.definition)
bufmap('gD', vim.lsp.buf.declaration) bufmap("gD", vim.lsp.buf.declaration)
bufmap('gI', vim.lsp.buf.implementation) bufmap("gI", vim.lsp.buf.implementation)
bufmap('<leader>D', vim.lsp.buf.type_definition) bufmap("<leader>D", vim.lsp.buf.type_definition)
bufmap('gr', require('telescope.builtin').lsp_references) bufmap("gr", require("telescope.builtin").lsp_references)
bufmap('<leader>s', require('telescope.builtin').lsp_document_symbols) bufmap("<leader>s", require("telescope.builtin").lsp_document_symbols)
bufmap('<leader>S', bufmap("<leader>S", require("telescope.builtin").lsp_dynamic_workspace_symbols)
require('telescope.builtin').lsp_dynamic_workspace_symbols)
bufmap('K', vim.lsp.buf.hover) bufmap("K", vim.lsp.buf.hover)
vim.api.nvim_buf_create_user_command(bufnr, 'Format', vim.api.nvim_buf_create_user_command(bufnr, "Format", function(_)
function(_) vim.lsp.buf.format() end, vim.lsp.buf.format()
{}) end, {})
end end
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities) capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities)
require('neodev').setup() require("neodev").setup()
require'lspconfig'.nil_ls.setup { require("lspconfig").nil_ls.setup({
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities capabilities = capabilities,
} })
require'lspconfig'.pyright.setup { require("lspconfig").pyright.setup({
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities capabilities = capabilities,
} })
require'lspconfig'.gopls.setup { require("lspconfig").gopls.setup({
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities capabilities = capabilities,
} })
require'lspconfig'.terraformls.setup { require("lspconfig").terraformls.setup({
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities capabilities = capabilities,
} })
require'lspconfig'.efm.setup { -- require'lspconfig'.efm.setup {
on_attach = require("lsp-format").on_attach, -- on_attach = require("lsp-format").on_attach,
init_options = {documentFormatting = true}, -- init_options = {documentFormatting = true},
settings = { -- settings = {
languages = { -- languages = {
lua = {{formatCommand = "lua-format -i", formatStdin = true}}, -- lua = {{formatCommand = "lua-format -i", formatStdin = true}},
nix = {{formatCommand = "nixfmt", formatStdin = true}} -- nix = {{formatCommand = "nixfmt", formatStdin = true}}
} -- }
}, -- },
filetypes = {"lua", "nix"} -- filetypes = {"lua", "nix"}
} -- }

View file

@ -0,0 +1,51 @@
-- renamed to none-ls
local null_ls_status_ok, null_ls = pcall(require, "null-ls")
if not null_ls_status_ok then
return
end
local formatting = null_ls.builtins.formatting
local diagnostics = null_ls.builtins.diagnostics
local code_actions = null_ls.builtins.code_actions
-- to setup format on save
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
require("null-ls").setup({
sources = {
formatting.stylua,
formatting.black,
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_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({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end,
})
end
end,
})
-- formatting command
vim.api.nvim_create_user_command("Format", function()
vim.lsp.buf.format(nil, 10000)
end, {})
vim.keymap.set(
"n",
"<leader>fm",
":Format<CR>",
{ desc = "Format current buffer (also done on save)", noremap = true, silent = true }
)

View file

@ -1,17 +1,17 @@
local builtin = require('telescope.builtin') local builtin = require("telescope.builtin")
vim.keymap.set('n', '<leader>ff', builtin.find_files, {}) vim.keymap.set("n", "<leader>ff", builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {}) vim.keymap.set("n", "<leader>fg", builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {}) vim.keymap.set("n", "<leader>fb", builtin.buffers, {})
vim.keymap.set('n', '<leader>fr', builtin.lsp_references, {}) vim.keymap.set("n", "<leader>fr", builtin.lsp_references, {})
vim.keymap.set('n', '<leader>fs', builtin.lsp_document_symbols, {}) vim.keymap.set("n", "<leader>fs", builtin.lsp_document_symbols, {})
require('telescope').setup { require("telescope").setup({
pickers = { pickers = {
find_files = {theme = "dropdown"}, find_files = { theme = "dropdown" },
live_grep = {theme = "dropdown"}, live_grep = { theme = "dropdown" },
buffers = {theme = "dropdown"}, buffers = { theme = "dropdown" },
lsp_references = {theme = "dropdown"}, lsp_references = { theme = "dropdown" },
lsp_document_symbols = {theme = "dropdown"} lsp_document_symbols = { theme = "dropdown" },
} },
} })

View file

@ -1,10 +1,9 @@
require('nvim-treesitter.configs').setup { require("nvim-treesitter.configs").setup({
ensure_installed = {}, ensure_installed = {},
auto_install = false, auto_install = false,
highlight = {enable = true}, highlight = { enable = true },
indent = {enable = true}
}
indent = { enable = true },
})