Merge branch 'NotAShelf:main' into feature/ruby

This commit is contained in:
Yoni Firroloni 2023-07-25 15:46:51 +02:00 committed by GitHub
commit adf027b154
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 511 additions and 139 deletions

View file

@ -21,16 +21,21 @@ with builtins; let
'';
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"copilot-lua"
cfg.copilotNodePackage
];
vim.startPlugins =
[
"copilot-lua"
cfg.copilotNodePackage
]
++ lib.optionals (cfg.cmp.enable) [
"copilot-cmp"
];
vim.luaConfigRC.copilot = nvim.dag.entryAnywhere ''
require("copilot").setup({
-- available options: https://github.com/zbirenbaum/copilot.lua
copilot_node_command = "${cfg.copilot_node_command}",
copilot_node_command = "${cfg.copilotNodeCommand}",
panel = {
enabled = ${lib.boolToString (!cfg.cmp.enable)},
keymap = {
jump_prev = false,
jump_next = false,
@ -44,6 +49,7 @@ in {
},
},
suggestion = {
enabled = ${lib.boolToString (!cfg.cmp.enable)},
keymap = {
accept = false,
accept_word = false,
@ -54,6 +60,10 @@ in {
},
},
})
${lib.optionalString (cfg.cmp.enable) ''
require("copilot_cmp").setup()
''}
'';
vim.maps.normal = mkMerge [

View file

@ -10,6 +10,7 @@ with builtins; let
in {
options.vim.assistant.copilot = {
enable = mkEnableOption "GitHub Copilot AI assistant";
cmp.enable = mkEnableOption "nvim-cmp integration for GitHub Copilot";
panel = {
position = mkOption {
@ -91,16 +92,22 @@ in {
};
};
copilot_node_command = mkOption {
copilotNodeCommand = mkOption {
type = types.str;
default = "${lib.getExe cfg.copilotNodePackage}";
description = "Path to nodejs";
description = ''
The command that will be executed to initiate nodejs for GitHub Copilot.
Recommended to leave as default.
'';
};
copilotNodePackage = mkOption {
type = with types; nullOr package; # TODO - maybe accept a path as well? imperative users might want to use something like nvm
default = pkgs.nodejs-slim; # this will likely need to be downgraded because Copilot does not stay up to date with NodeJS
description = "The package that will be used for Copilot. NodeJS v18 is recommended.";
type = with types; nullOr package;
default = pkgs.nodejs-slim;
description = ''
The nodeJS package that will be used for GitHub Copilot. If you are using a custom node command
you may want to set this option to null so that the package is not pulled from nixpkgs.
'';
};
};
}

View file

@ -49,6 +49,7 @@ in {
"buffer" = "[Buffer]";
"crates" = "[Crates]";
"path" = "[Path]";
"copilot" = "[Copilot]";
};
vim.maps.insert = mkMerge [
@ -106,17 +107,13 @@ in {
end
'')
(mkSetLuaBinding mappings.close ''
require('cmp').mapping.abort
require('cmp').mapping.abort()
'')
(mkSetLuaBinding mappings.scrollDocsUp ''
function()
require('cmp').mapping.scroll_docs(-4)
end
require('cmp').mapping.scroll_docs(-4)
'')
(mkSetLuaBinding mappings.scrollDocsDown ''
function()
require('cmp').mapping.scroll_docs(4)
end
require('cmp').mapping.scroll_docs(4)
'')
];
@ -125,17 +122,13 @@ in {
require('cmp').complete
'')
(mkSetLuaBinding mappings.close ''
require('cmp').mapping.close
require('cmp').mapping.close()
'')
(mkSetLuaBinding mappings.scrollDocsUp ''
function()
require('cmp').mapping.scroll_docs(-4)
end
require('cmp').mapping.scroll_docs(-4)
'')
(mkSetLuaBinding mappings.scrollDocsDown ''
function()
require('cmp').mapping.scroll_docs(4)
end
require('cmp').mapping.scroll_docs(4)
'')
];
@ -182,6 +175,8 @@ in {
'')
];
# TODO: alternative snippet engines to vsnip
# https://github.com/hrsh7th/nvim-cmp/blob/main/doc/cmp.txt#L82
vim.luaConfigRC.completion = mkIf (cfg.type == "nvim-cmp") (dagPlacement ''
local nvim_cmp_menu_map = function(entry, vim_item)
-- name for each source
@ -195,19 +190,30 @@ in {
${optionalString lspkindEnabled ''
lspkind_opts.before = ${cfg.formatting.format}
''}
local cmp = require'cmp'
cmp.setup({
window = {
-- TODO: at some point, those need to be optional
-- but first nvim cmp module needs to be detached from "cfg.autocomplete"
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
sources = {
${builtSources}
},
completion = {
completeopt = 'menu,menuone,noinsert',
},
formatting = {
format =
${

View file

@ -23,7 +23,7 @@ with builtins; let
};
# TODO: specify packages
defaultFormat = "prettierd";
defaultFormat = "prettier";
formats = {
prettier = {
package = pkgs.nodePackages.prettier;

View file

@ -23,6 +23,18 @@ in {
if (auto.type == "nvim-cmp")
then "true"
else "false"
}
},
daily_notes = {
folder = ${
if (cfg.daily-notes.folder == "")
then "nil,"
else "'${cfg.daily-notes.folder}',"
}
date_format = ${
if (cfg.daily-notes.date-format == "")
then "nil,"
else "'${cfg.daily-notes.date-format}',"
}
}
})

View file

@ -14,6 +14,19 @@ with builtins; {
description = "Obsidian vault directory";
};
daily-notes = {
folder = mkOption {
type = types.str;
default = "";
description = "Directory in which daily notes should be created";
};
date-format = mkOption {
type = types.str;
default = "";
description = "Date format used for creating daily notes";
};
};
completion = {
nvim_cmp = mkOption {
# if using nvim-cmp, otherwise set to false

View file

@ -22,9 +22,10 @@ with builtins; {
client_id = mkOption {
type = types.str;
default = "859194972255989790";
default = "79327144129396737";
description = "Client ID of the application";
};
auto_update = mkOption {
type = types.bool;
default = true;

View file

@ -18,6 +18,9 @@
style ? "night",
transparent,
}: ''
require('tokyonight').setup {
transparent = ${lib.boolToString transparent};
}
vim.cmd[[colorscheme tokyonight-${style}]]
'';
styles = ["day" "night" "storm" "moon"];

View file

@ -23,8 +23,17 @@ in {
DEBUG = "${cfg.icons.DEBUG}",
TRACE = "${cfg.icons.TRACE}",
},
}
-- required to fix offset_encoding errors
local notify = vim.notify
vim.notify = function(msg, ...)
if msg:match("warning: multiple different client offset_encodings") then
return
end
notify(msg, ...)
end
'';
};
}