nixbook: git config, nixd, format

This commit is contained in:
tristan 2024-10-23 22:53:02 +01:00
parent 7322eaeb6f
commit 3bae7dc77c
6 changed files with 91 additions and 66 deletions

View file

@ -1,9 +1,14 @@
{pkgs, ...}: let
{
pkgs,
lib,
...
}: let
lua = cmd: {__raw = cmd;};
luaFunc = cmd: lua ''
function ()
${cmd}
end'';
luaFunc = cmd:
lua ''
function ()
${cmd}
end'';
in {
globals = {
mapleader = " ";
@ -28,6 +33,8 @@ in {
"extends:>"
"precedes:<"
];
foldlevel = 2;
};
extraPlugins = [(pkgs.vimPlugins.actions-preview-nvim)];
extraConfigLua = ''
@ -204,30 +211,32 @@ in {
}
];
autoCmd = [{
event = "BufWritePre";
pattern = "*.go";
# https://github.com/golang/tools/blob/master/gopls/doc/vim.md#imports-and-formatting
callback = luaFunc ''
local params = vim.lsp.util.make_range_params()
params.context = {only = {"source.organizeImports"}}
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
-- machine and codebase, you may want longer. Add an additional
-- argument after params if you find that you have to write the file
-- twice for changes to be saved.
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
for cid, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
vim.lsp.util.apply_workspace_edit(r.edit, enc)
autoCmd = [
{
event = "BufWritePre";
pattern = "*";
# https://github.com/golang/tools/blob/master/gopls/doc/vim.md#imports-and-formatting
callback = luaFunc ''
local params = vim.lsp.util.make_range_params()
params.context = {only = {"source.organizeImports"}}
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
-- machine and codebase, you may want longer. Add an additional
-- argument after params if you find that you have to write the file
-- twice for changes to be saved.
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
for cid, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
vim.lsp.util.apply_workspace_edit(r.edit, enc)
end
end
end
end
vim.lsp.buf.format({async = false})
'';
}];
vim.lsp.buf.format({async = false})
'';
}
];
plugins = {
bufferline.enable = true;
@ -261,7 +270,15 @@ in {
enable = true;
servers = {
ts-ls.enable = true;
nil-ls.enable = true;
nixd = {
enable = true;
settings = {
nixpkgs.expr = ''import <nixpkgs> {}'';
options.zenix.expr = ''(builtins.getFlake "git+https://git.tristans.cloud/tristan/nix").nixosConfigurations.zenix.options'';
options.alpine.expr = ''(builtins.getFlake "git+https://git.tristans.cloud/tristan/nix").nixosConfigurations.alpine.options'';
formatting.command = [(lib.getExe pkgs.alejandra)];
};
};
yamlls.enable = true;
gopls.enable = true;
};