home/nvim: a better require system + type defs

This commit is contained in:
chayleaf 2023-03-16 23:37:57 +07:00
parent 15e7be9a24
commit 049c95bd9f
13 changed files with 406 additions and 9869 deletions

View file

@ -21,7 +21,7 @@ in {
rust-analyzer rust-analyzer
nodePackages.bash-language-server shellcheck nodePackages.bash-language-server shellcheck
nodePackages.typescript-language-server nodePackages.typescript-language-server
clang-tools clang-tools_latest
nodePackages.vscode-langservers-extracted nodePackages.vscode-langservers-extracted
nil nil
marksman marksman

View file

@ -21,7 +21,7 @@ in {
rust-analyzer rust-analyzer
nodePackages.bash-language-server shellcheck nodePackages.bash-language-server shellcheck
nodePackages.typescript-language-server nodePackages.typescript-language-server
clang-tools clang-tools_latest
nodePackages.vscode-langservers-extracted nodePackages.vscode-langservers-extracted
nil nil
marksman marksman

View file

@ -85,7 +85,7 @@
else if func.__kind == "prop" then else if func.__kind == "prop" then
"${wrapExpr (compileExpr sc func.expr)}.${func.name}" "${wrapExpr (compileExpr sc func.expr)}.${func.name}"
else if func.__kind == "call" then else if func.__kind == "call" then
"${wrapExpr (compileExpr sc func.func)}(${builtins.concatStringsSep ", " (map (compileExpr sc) (if builtins.isList func.args then func.args else [func.args]))})" "${wrapExpr (compileExpr sc func._func)}(${builtins.concatStringsSep ", " (map (compileExpr sc) (if builtins.isList func._args then func._args else [func._args]))})"
else if func.__kind == "mcall" then else if func.__kind == "mcall" then
"${wrapExpr (compileExpr sc func.val)}:${func.name}(${builtins.concatStringsSep ", " (map (compileExpr sc) (if builtins.isList func.args then func.args else [func.args]))})" "${wrapExpr (compileExpr sc func.val)}:${func.name}(${builtins.concatStringsSep ", " (map (compileExpr sc) (if builtins.isList func.args then func.args else [func.args]))})"
else if func.__kind == "tableAttr" then else if func.__kind == "tableAttr" then
@ -167,7 +167,7 @@
# Call a function # Call a function
# corresponding lua code: someFunc() # corresponding lua code: someFunc()
# expr -> [args] -> expr | expr -> arg1 -> expr # expr -> [args] -> expr | expr -> arg1 -> expr
call = func: args: { __kind = "call"; inherit func args; }; call = func: args: { __kind = "call"; _func = func; _args = args; };
# Call a method # Call a method
# corresponding lua code: someTable:someFunc() # corresponding lua code: someTable:someFunc()
@ -232,12 +232,14 @@
bindrec = vals: func: if builtins.isList vals then { __kind = "letrec"; inherit vals func; } else bindrec [ vals ] func; bindrec = vals: func: if builtins.isList vals then { __kind = "letrec"; inherit vals func; } else bindrec [ vals ] func;
# "type definitions" for neovim # "type definitions" for neovim
defs = pkgs.callPackage ./vim-opts.nix { inherit raw call; }; defs = pkgs.callPackage ./vim-opts.nix { inherit raw call; plugins = config.programs.neovim.plugins; };
reqbind = name: func: bind [ (defs.require name) ] (result: func (defs._reqbind name result._name));
in with defs; let in with defs; let
require = name: call (var "require") [ name ]; # require = name: call (var "require") [ name ];
setup = plugin: opts: call (prop plugin "setup") [ opts ]; # setup = plugin: opts: call (prop plugin "setup") [ opts ];
# vimfn = name: call (raw "vim.fn.${name}"); # vimfn = name: call (raw "vim.fn.${name}");
vimcmd = name: call (raw "vim.cmd.${name}"); vimcmd = name: call (raw "vim.cmd.${name}");
vimg = name: prop vim.g name;
keymapSetSingle = opts@{ keymapSetSingle = opts@{
mode, mode,
lhs, lhs,
@ -267,12 +269,16 @@
in (lib.mapAttrsToList (k: {rhs, desc}: keymapSetSingle (opts' // { in (lib.mapAttrsToList (k: {rhs, desc}: keymapSetSingle (opts' // {
lhs = k; inherit rhs; lhs = k; inherit rhs;
})) keys) ++ [ })) keys) ++ [
(call (prop (require "which-key") "register") [(lib.mapAttrs (k: v: [v.rhs v.desc]) keys) opts']) (which-key.register [(lib.mapAttrs (k: v: [v.rhs v.desc]) keys) opts'])
]; ];
keymapSetNs = args: keymapSetMulti (args // { mode = "n"; }); keymapSetNs = args: keymapSetMulti (args // { mode = "n"; });
kmSetNs = keys: keymapSetNs { inherit keys; }; kmSetNs = keys: keymapSetNs { inherit keys; };
keymapSetVs = args: keymapSetMulti (args // { mode = "v"; }); keymapSetVs = args: keymapSetMulti (args // { mode = "v"; });
kmSetVs = keys: keymapSetVs { inherit keys; }; kmSetVs = keys: keymapSetVs { inherit keys; };
which-key = req "which-key";
luasnip = req "luasnip";
cmp = req "cmp";
in { in {
enable = true; enable = true;
defaultEditor = true; defaultEditor = true;
@ -282,7 +288,7 @@
nodePackages_latest.bash-language-server shellcheck nodePackages_latest.bash-language-server shellcheck
nodePackages_latest.typescript-language-server nodePackages_latest.typescript-language-server
nodePackages_latest.svelte-language-server nodePackages_latest.svelte-language-server
clang-tools clang-tools_latest
nodePackages_latest.vscode-langservers-extracted nodePackages_latest.vscode-langservers-extracted
nil nil
marksman marksman
@ -298,11 +304,12 @@
]; ];
# extraPython3Packages = pyPkgs: with pyPkgs; [ # extraPython3Packages = pyPkgs: with pyPkgs; [
# ]; # ];
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
extraLuaConfig = (compile "main" [ extraLuaConfig = (compile "main" [
(set vim.g.vimsyn_embed "l") (set (vimg "vimsyn_embed") "l")
(vim.api.nvim_set_hl [ 0 "NormalFloat" {
bg = "NONE";
}])
(bind (vim.api.nvim_create_augroup [ "nvimrc" { clear = true; } ]) (group: (bind (vim.api.nvim_create_augroup [ "nvimrc" { clear = true; } ]) (group:
map (au: let au' = lib.filterAttrs (k: v: k != "event") au; map (au: let au' = lib.filterAttrs (k: v: k != "event") au;
in vim.api.nvim_create_autocmd [ au.event ({ in vim.api.nvim_create_autocmd [ au.event ({
@ -311,10 +318,12 @@
) [ ) [
{ event = "FileType"; { event = "FileType";
pattern = ["markdown" "gitcommit"]; pattern = ["markdown" "gitcommit"];
# must be a string
callback = defun (set vim.o.colorcolumn "73"); } callback = defun (set vim.o.colorcolumn "73"); }
{ event = "FileType"; { event = "FileType";
pattern = ["markdown"]; pattern = ["markdown"];
callback = defun (set vim.o.textwidth "72"); } # must be a number...
callback = defun (set vim.o.textwidth 72); }
{ event = "BufReadPre"; { event = "BufReadPre";
callback = defun (set vim.o.foldmethod "syntax"); } callback = defun (set vim.o.foldmethod "syntax"); }
{ event = "BufWinEnter"; { event = "BufWinEnter";
@ -322,13 +331,13 @@
(bind (vim.filetype.match { inherit buf; }) (filetype: [ (bind (vim.filetype.match { inherit buf; }) (filetype: [
(vimcmd "folddoc" [ "foldopen!" ]) (vimcmd "folddoc" [ "foldopen!" ])
(ifelse [(eq filetype "gitcommit") [ (ifelse [(eq filetype "gitcommit") [
(vim.cmd { (call vim.cmd {
cmd = "normal"; cmd = "normal";
bang = true; bang = true;
args = [ "gg" ]; args = [ "gg" ];
}) })
]] ]]
(vim.cmd { (call vim.cmd {
cmd = "normal"; cmd = "normal";
bang = true; bang = true;
args = [ "g`\"" ]; args = [ "g`\"" ];
@ -337,13 +346,10 @@
])); } ])); }
])) # END ])) # END
]); ]);
viAlias = true; plugins = let ps = pkgs.vimPlugins; in map (x: if x?config && x?plugin then { type = "lua"; } // x else x) [
vimAlias = true; ps.vim-svelte
vimdiffAlias = true;
plugins = with pkgs.vimPlugins; map (x: if x?config && x?plugin then { type = "lua"; } // x else x) [
vim-svelte
# TODO remove on next nvim update (0.8.3/0.9) # TODO remove on next nvim update (0.8.3/0.9)
vim-nix ps.vim-nix
{ plugin = pkgs.vimUtils.buildVimPluginFrom2Nix { { plugin = pkgs.vimUtils.buildVimPluginFrom2Nix {
pname = "vscode-nvim"; pname = "vscode-nvim";
version = "2023-02-10"; version = "2023-02-10";
@ -354,42 +360,47 @@
sha256 = "sha256-X2IgIjO5NNq7vJdl09hBY1TFqHlsfF1xfllKr4osILI="; sha256 = "sha256-X2IgIjO5NNq7vJdl09hBY1TFqHlsfF1xfllKr4osILI=";
}; };
}; };
config = compile "vscode_nvim" (setup (require "vscode") { config = compile "vscode_nvim" [
transparent = true; ((req "vscode").setup {
color_overrides = { transparent = true;
vscGray = "#745b5f"; color_overrides = {
vscViolet = "#${config.colors.magenta}"; vscGray = "#745b5f";
vscBlue = "#6ddfd8"; vscViolet = "#${config.colors.magenta}";
vscDarkBlue = "#${config.colors.blue}"; vscBlue = "#6ddfd8";
vscGreen = "#${config.colors.green}"; vscDarkBlue = "#${config.colors.blue}";
vscBlueGreen = "#73bf88"; vscGreen = "#${config.colors.green}";
vscLightGreen = "#6acf6e"; vscBlueGreen = "#73bf88";
vscRed = "#${config.colors.red}"; vscLightGreen = "#6acf6e";
vscOrange = "#e89666"; vscRed = "#${config.colors.red}";
vscLightRed = "#e64e4e"; vscOrange = "#e89666";
vscYellowOrange = "#e8b166"; vscLightRed = "#e64e4e";
vscYellow = "#${config.colors.yellow}"; vscYellowOrange = "#e8b166";
vscPink = "#cf83c4"; vscYellow = "#${config.colors.yellow}";
}; vscPink = "#cf83c4";
}); } };
{ plugin = nvim-web-devicons; })
config = compile "nvim_web_devicons" (setup (require "nvim-web-devicons") {}); } (vim.api.nvim_set_hl [ 0 "NormalFloat" {
{ plugin = nvim-tree-lua; bg = "NONE";
}])
]; }
{ plugin = ps.nvim-web-devicons;
config = compile "nvim_web_devicons" ((req "nvim-web-devicons").setup {}); }
{ plugin = ps.nvim-tree-lua;
config = compile "nvim_tree_lua" [ config = compile "nvim_tree_lua" [
(set vim.g.loaded_netrw 1) (set (vimg "loaded_netrw") 1)
(set vim.g.loaded_netrwPlugin 1) (set (vimg "loaded_netrwPlugin") 1)
(set vim.opt.termguicolors true) (set vim.o.termguicolors true)
(setup (require "nvim-tree") {}) # :help nvim-tree-setup ((req "nvim-tree").setup {}) # :help nvim-tree-setup
(kmSetNs { (kmSetNs {
"<C-N>" = { "<C-N>" = {
rhs = prop (require "nvim-tree.api") "tree.toggle"; rhs = (req "nvim-tree.api").tree.toggle;
desc = "Toggle NvimTree"; desc = "Toggle NvimTree";
}; };
}) })
]; } ]; }
vim-sleuth ps.vim-sleuth
luasnip ps.luasnip
{ plugin = nvim-cmp; { plugin = ps.nvim-cmp;
config = let config = let
border = (name: [ border = (name: [
[ "" name ] [ "" name ]
@ -401,10 +412,11 @@
[ "" name ] [ "" name ]
[ "" name ] [ "" name ]
]); ]);
in compile "nvim_cmp" (bind (require "cmp") (cmp: in compile "nvim_cmp" (reqbind "cmp" (cmp:
(setup cmp { # call is required because cmp.setup is a table
(call cmp.setup {
snippet = { snippet = {
expand = { body, ... }: call (prop (require "luasnip") "lsp_expand") body; expand = { body, ... }: luasnip.lsp_expand body;
}; };
view = { }; view = { };
window = { window = {
@ -420,85 +432,77 @@
format = _: vim_item: let kind = prop vim_item "kind"; in [ format = _: vim_item: let kind = prop vim_item "kind"; in [
(set (set
kind kind
(string.format ([ (string.format [
"%s %s" "%s %s"
(tableAttr (require "lspkind") kind) (tableAttr (req "lspkind") kind)
kind kind
]))) ]))
(return vim_item) (return vim_item)
]; ];
}; };
mapping = { mapping = {
"<C-p>" = call (prop cmp "mapping.select_prev_item") []; "<C-p>" = cmp.mapping.select_prev_item [];
"<C-n>" = call (prop cmp "mapping.select_next_item") []; "<C-n>" = cmp.mapping.select_next_item [];
"<C-space>" = call (prop cmp "mapping.complete") []; "<C-space>" = cmp.mapping.complete [];
"<C-e>" = call (prop cmp "mapping.close") []; "<C-e>" = cmp.mapping.close [];
"<cr>" = call (prop cmp "mapping.confirm") { "<cr>" = cmp.mapping.confirm {
behavior = prop cmp "ConfirmBehavior.Replace"; behavior = cmp.ConfirmBehavior.Replace;
select = false; select = false;
}; };
"<tab>" = call (prop cmp "mapping") [(fallback: "<tab>" = call cmp.mapping [(fallback:
(ifelse [ (ifelse [[(cmp.visible [])
[(call (prop cmp "visible") []) (cmp.select_next_item [])]
# then /*elseif*/ [(luasnip.expand_or_jumpable [])
(call (prop cmp "select_next_item") [])] (vim.api.nvim_feedkeys [
[(call (prop (require "luasnip") "expand_or_jumpable") []) (vim.api.nvim_replace_termcodes [ "<Plug>luasnip-expand-or-jump" true true true ])
# then ""
(vim.api.nvim_feedkeys [ false
(vim.api.nvim_replace_termcodes [ "<Plug>luasnip-expand-or-jump" true true true ]) ])
"" ]] # else
false (call fallback [])
])
]]
# else
(call fallback [])
)) ))
[ "i" "s" ] [ "i" "s" ]
]; ];
"<S-tab>" = call (prop cmp "mapping") [(fallback: "<S-tab>" = call cmp.mapping [(fallback:
(ifelse [ (ifelse [[(cmp.visible [])
[(call (prop cmp "visible" ) []) (cmp.select_prev_item [])]
# then /*elseif*/ [(luasnip.jumpable [ (-1) ])
(call (prop cmp "select_prev_item") [])] (vim.api.nvim_feedkeys [
[(call (prop (require "luasnip") "jumpable") [ (-1) ]) (vim.api.nvim_replace_termcodes [ "<Plug>luasnip-jump-prev" true true true ])
# then ""
(vim.api.nvim_feedkeys [ false
(vim.api.nvim_replace_termcodes [ "<Plug>luasnip-jump-prev" true true true ]) ])
"" ]] # else
false (call fallback [])
])
]]
# else
(call fallback [])
)) ))
[ "i" "s" ] [ "i" "s" ]
]; ];
}; };
sources = call (prop cmp "config.sources") [[ sources = cmp.config.sources [[
{ name = "nvim_lsp"; } { name = "nvim_lsp"; }
{ name = "luasnip"; } { name = "luasnip"; }
]]; ]];
}) })
)); } )); }
lspkind-nvim ps.lspkind-nvim
cmp_luasnip ps.cmp_luasnip
cmp-nvim-lsp ps.cmp-nvim-lsp
{ plugin = nvim-autopairs; { plugin = ps.nvim-autopairs;
config = compile "nvim_autopairs" (bind (require "nvim-autopairs.completion.cmp") (cmp_autopairs: [ config = compile "nvim_autopairs" (reqbind "nvim-autopairs.completion.cmp" (cmp_autopairs: [
(setup (require "nvim-autopairs") { ((req "nvim-autopairs").setup {
disable_filetype = [ "TelescopePrompt" "vim" ]; disable_filetype = [ "TelescopePrompt" "vim" ];
}) })
(mcall (prop (require "cmp") "event") "on" [ (mcall cmp.event "on" [
"confirm_done" "confirm_done"
(call (prop cmp_autopairs "on_confirm_done") []) (cmp_autopairs.on_confirm_done [])
]) ])
])); } ])); }
{ plugin = comment-nvim; { plugin = ps.comment-nvim;
config = compile "comment_nvim" [ config = compile "comment_nvim" [
(setup (require "Comment") {}) ((req "Comment").setup {})
(kmSetNs { (kmSetNs {
"<space>/" = { "<space>/" = {
rhs = prop (require "Comment.api") "toggle.linewise.current"; rhs = prop (req "Comment.api").toggle "linewise.current";
desc = "Comment current line"; desc = "Comment current line";
}; };
}) })
@ -509,8 +513,8 @@
}; };
}) })
]; } ]; }
{ plugin = nvim-lspconfig; { plugin = ps.nvim-lspconfig;
config = compile "nvim_lspconfig" (let setupLsp = lsp: setup (prop (require "lspconfig") lsp); in [ config = compile "nvim_lspconfig" (let setupLsp = lsp: builtins.seq (req "lspconfig.server_configurations.${lsp}") (call (prop (req "lspconfig") "${lsp}.setup")); in [
# See `:help vim.diagnostic.*` for documentation on any of the below functions # See `:help vim.diagnostic.*` for documentation on any of the below functions
(kmSetNs { (kmSetNs {
"<space>e" = { "<space>e" = {
@ -561,7 +565,7 @@
desc = "Remove a folder from the workspace folders."; }; desc = "Remove a folder from the workspace folders."; };
"<space>wl" = { "<space>wl" = {
rhs = (defun (print [ rhs = (defun (print [
(vim.inspect [(vim.lsp.buf.list_workspace_folders [])]) (call vim.inspect [(vim.lsp.buf.list_workspace_folders [])])
])); ]));
desc = "List workspace folders."; }; desc = "List workspace folders."; };
"<space>D" = { "<space>D" = {
@ -592,7 +596,7 @@
(vim.tbl_extend [ (vim.tbl_extend [
"keep" "keep"
(vim.lsp.protocol.make_client_capabilities []) (vim.lsp.protocol.make_client_capabilities [])
(call (prop (require "cmp_nvim_lsp") "default_capabilities") []) ((req "cmp_nvim_lsp").default_capabilities [])
]) ])
# BEGIN # BEGIN
] (on_attach: rust_settings: capabilities: [ ] (on_attach: rust_settings: capabilities: [
@ -600,12 +604,13 @@
# LETREC on_attach_rust # LETREC on_attach_rust
(on_attach_rust: client: bufnr: [ (on_attach_rust: client: bufnr: [
(vim.api.nvim_create_user_command ["RustAndroid" (opts: [ (vim.api.nvim_create_user_command ["RustAndroid" (opts: [
(vim.lsp.set_log_level "debug")
(setupLsp "rust_analyzer" { (setupLsp "rust_analyzer" {
on_attach = on_attach_rust; on_attach = on_attach_rust;
inherit capabilities; inherit capabilities;
settings = vim.tbl_deep_extend [ settings = vim.tbl_deep_extend [
"keep" "keep"
{ rust-analyzer.cargo.target = "x86_64-linux-android"; } config.rustAnalyzerAndroidSettings
rust_settings rust_settings
]; ];
}) })
@ -642,11 +647,11 @@
]))) # END ]))) # END
])) # END ])) # END
]); } ]); }
{ plugin = which-key-nvim; { plugin = ps.which-key-nvim;
config = compile "which_key_nvim" [ config = compile "which_key_nvim" [
(set vim.o.timeout true) (set vim.o.timeout true)
(set vim.o.timeoutlen 500) (set vim.o.timeoutlen 500)
(setup (require "which-key") {}) (which-key.setup {})
]; } ]; }
]; ];
}; };

View file

@ -1,39 +1,155 @@
-- globals.lua local seen = {}
-- list all global variables
-- :enew|pu=execute('luafile /path/to/file.lua')
-- list vim vars
-- :new | put! =getcompletion('*', 'var')
-- list events
-- :new | put! =getcompletion('*', 'event')
-- list options
-- :new | put! =getcompletion('*', 'option')
local seen={} local result = {}
function dump(t,i) local function dump2(t, path, res)
seen[t]=true seen[t] = path
local s={} if path ~= "" then
local n=0 path = path.."."
for k in pairs(t) do
n=n+1 s[n]=k
end end
local p0 = "package.loaded." for k,v in pairs(t) do
local i1 = (i:sub(0, #p0) == p0) and i:sub(#p0+1) or i k = tostring(k)
local p1 = "package.preload." if path ~= "" or k ~= "package" then
local i2 = (i1:sub(0, #p1) == p1) and i1:sub(#p1+1) or i1 if type(v) == "table" then
for k,v in ipairs(s) do if seen[v] then
local v0=t[v] if not res[k] then
if type(v0)=="table" and not seen[v0] then res[k] = { __kind = "rec", path = seen[v] }
dump(v0,i1..v..".") end
elseif v ~= "vim._meta" and v ~= "vim._init_packages" and v ~= "table.clear" and v ~= "table.new" and type(v0) == "function" and i:sub(0, #p1) == p1 then else
dump(v0(),i2..v..".") if not res[k] then
elseif type(v0) == "function" then res[k] = {}
print("function/"..debug.getinfo(v0).nparams.."/"..i..v) end
elseif type(v0) ~= "table" then res[k].__kind = "var"
print(type(v0).."/"..i..v) res[k]._type = "table"
res[k]._name = path..k
dump2(v, path..k, res[k])
end
elseif type(v) == "function" then
local info = debug.getinfo(v)
res[k] = {
__kind = "var",
_name = path..k,
_type = "function",
_minArity = info.nparams
}
if not info.isvararg then
res[k]["maxArity"] = info.nparams
end
else
res[k] = {
__kind = "var", _name = path..k, _type = type(v)
}
end
end end
end end
end end
dump(_G,"") local function dumpf(t, path, res)
for k,v in pairs(t.funcs) do
if type(v.args) == "table" then
-- 1 value: min bound
-- 2 values: min and max bound
if #v.args == 1 then
res[k] = {
__kind = "var",
_name = path..k,
_type = "function",
_minArity = v.args[1]
}
elseif #v.args == 2 then
res[k] = {
__kind = "var",
_name = path..k,
_type = "function",
_minArity = v.args[1],
_maxArity = v.args[2]
}
else
print("ERROR")
end
elseif type(v.args) == "number" then
-- exact arg count
res[k] = {
__kind = "var",
_name = path..k,
_type = "function",
_minArity = v.args,
_maxArity = v.args
}
else
-- zero args
res[k] = {
__kind = "var",
_name = path..k,
_type = "function",
_minArity = 0,
_maxArity = 0
}
end
end
end
local function dumpo(t, path, opt, res)
local types = {
bool = "boolean",
string = "string",
number = "number",
}
local key_value_options = {
fillchars = true,
listchars = true,
winhighlight = true,
}
for k,v in pairs(t.options) do
if opt and key_value_options[v.full_name] then
-- kv map
res[v.full_name] = {
__kind = "var",
_name = path..v.full_name,
_type = "table"
}
if type(v.abbreviation) == "string" then
res[path..v.full_name] = { __kind = "rec", path = path..v.full_name, }
end
elseif opt and v.list then
-- list
res[v.full_name] = {
__kind = "var",
_name = path..v.full_name,
_type = "table"
}
if type(v.abbreviation) == "string" then
res[v.abbreviation] = { __kind = "rec", path = path..v.full_name, }
end
elseif not opt then
res[v.full_name] = {
__kind = "var",
_name = path..v.full_name,
_type = types[v.type],
}
if type(v.abbreviation) == "string" then
res[v.abbreviation] = { __kind = "rec", path = path..v.full_name, }
end
end
end
end
local json = require "json"
--- DUMPING BUILTINS
result["vim"] = { __kind = "var", _type = "table", _name = "vim" }
for k in pairs(vim._submodules) do
result["vim"][k] = { __kind = "var", _type = "table", _name = "vim."..k }
dump2(vim[k], "vim."..k, result["vim"][k])
end
dump2(package.loaded["vim.shared"], "vim", result["vim"])
-- for main thread only?
dump2(package.loaded["vim._editor"], "vim", result["vim"])
dump2(_G, "", result)
-- eval.lua from https://github.com/neovim/neovim/blob/674e23f19c509381e2476a3990e21272e362e3a4/src/nvim/eval.lua
dumpf(require("eval"), "vim.fn.", result["vim"]["fn"])
-- https://github.com/neovim/neovim/blob/674e23f19c509381e2476a3990e21272e362e3a4/src/nvim/options.lua
dumpo(require("options"), "vim.o.", false, result["vim"]["o"])
dumpo(require("options"), "vim.opt.", true, result["vim"]["opt"])
print(json.encode(result))

View file

@ -0,0 +1,67 @@
local seen = {}
local result = {}
local function mark(t)
seen[t] = true
for k,v in pairs(t) do
if type(v) == "table" and not seen[v] then
mark(v)
end
end
end
local function dump2(t, path, res)
seen[t] = path
if path ~= "" then
path = path.."."
end
for k,v in pairs(t) do
k = tostring(k)
if path ~= "" or k ~= "package" then
if type(v) == "table" then
if seen[v] then
if not res[k] and seen[v] ~= true then
res[k] = { __kind = "rec", path = seen[v] }
end
else
if not res[k] then
res[k] = {}
end
res[k].__kind = "var"
res[k]._type = "table"
res[k]._name = path..k
dump2(v, path..k, res[k])
end
elseif type(v) == "function" then
local info = debug.getinfo(v)
res[k] = {
__kind = "var",
_name = path..k,
_type = "function",
_minArity = info.nparams
}
if not info.isvararg then
res[k]["maxArity"] = info.nparams
end
else
res[k] = {
__kind = "var", _name = path..k, _type = type(v)
}
end
end
end
end
local json = require "cjson"
-- mark globals before requiring package
mark(_G)
local package = "@package@"
result = { __kind = "var", _type = "table", _name = "" }
dump2(require(package), "", result)
print(json.encode(result))

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -1,69 +1,50 @@
{ lib, raw, call }: let defs = map (line: { stdenvNoCC
if lib.hasPrefix "function/" line then let split = lib.splitString "/" (lib.removePrefix "function/" line); in { , lib
type = "function"; , neovim-unwrapped
arity = lib.toInt (builtins.elemAt split 0); , neovimUtils
value = builtins.elemAt split 1; , lua51Packages
} else if lib.hasPrefix "string/" line then { , wrapNeovimUnstable
type = "string"; , call
value = lib.removePrefix "string/" line; , substituteAll
} else if lib.hasPrefix "boolean/" line then { , plugins
type = "boolean"; # , extraLuaPackages ? []
value = lib.removePrefix "boolean/" line; , ... }:
} else if lib.hasPrefix "number/" line then {
type = "number"; let update = self: prefix: lib.mapAttrs (k: v: let
value = lib.removePrefix "number/" line; v' = update self prefix v;
} else { in (if builtins.isAttrs v && v?__kind then (
type = "ignore"; if v.__kind == "rec" then
value = "____ignore.___ignore"; lib.attrByPath (lib.splitString "." v.path) self
}) (lib.splitString "\n" (builtins.readFile ./vim-lua.txt)); else if v.__kind == "var" && v._type == "function" then
process' = val: ( (args: if args == "GET_INFO" then v' else call v' args)
if val.type == "function" then ( else v'
#if val.arity == 0 then ) else if builtins.isAttrs v then v'
args: if args == "GET_INFO" then val else call (raw val.value) args else if prefix != "" && k == "_name" then
#else if val.arity == 1 then (a: if a == "GET_INFO" then val else call (raw val.value) [a]) (if v == "" then prefix else "${prefix}.${v}")
#else (a: if a == "GET_INFO" then val else call (raw val.value) a) else v));
) else raw val.value data = builtins.fromJSON (builtins.readFile ./vim-defs.json);
); result = update result "" data;
process = val: lib.setAttrByPath (lib.splitString "." val.value) (process' val); config = neovimUtils.makeNeovimConfig {
processOpt = o: val: lib.setAttrByPath ["vim" o val] (raw "vim.${o}.${val}"); extraLuaPackages = p: [ p.cjson ];
processVar = val: # inherit extraLuaPackages;
if lib.hasPrefix "b:" val then lib.setAttrByPath ["vim" "b" (lib.removePrefix "b:" val)] (raw "vim.b.${val}") plugins = map (plugin: if plugin?plugin then {plugin=plugin.plugin;} else {inherit plugin;}) plugins;
else if lib.hasPrefix "v:" val then lib.setAttrByPath ["vim" "v" (lib.removePrefix "v:" val)] (raw "vim.v.${val}") };
else if lib.hasPrefix "w:" val then lib.setAttrByPath ["vim" "w" (lib.removePrefix "w:" val)] (raw "vim.w.${val}") neovim = wrapNeovimUnstable neovim-unwrapped config;
else if lib.hasPrefix "t:" val then lib.setAttrByPath ["vim" "t" (lib.removePrefix "t:" val)] (raw "vim.t.${val}") getReqAttrs = name: builtins.fromJSON (builtins.readFile (stdenvNoCC.mkDerivation {
else if lib.hasPrefix "v:" val then lib.setAttrByPath ["vim" "v" (lib.removePrefix "v:" val)] (raw "vim.v.${val}") phases = [ "installPhase" ];
else lib.setAttrByPath ["vim" "g" val] (raw "vim.g.${val}"); name = "neovim-require-${name}.json";
setPath = path: key: val: if builtins.isAttrs val dumpPlugin = substituteAll {
then (builtins.mapAttrs (setPath "${path}${key}.") val) // { __kind = "var"; _name = "${path}${key}"; } src = ./dump_plugin.lua;
else val; package = name;
opts = (lib.splitString "\n" (builtins.readFile ./vim-opts.txt)); };
vars = (lib.splitString "\n" (builtins.readFile ./vim-vars.txt)); nativeBuildInputs = [ neovim ];
zip = x: if x == [] then {} else lib.recursiveUpdate (zip (builtins.tail x)) (builtins.head x); installPhase = ''
patch = builtins.mapAttrs (k: v: if k == "vim" then v // { export HOME="$TMPDIR"
inspect = process' { nvim --headless -S $dumpPlugin -i NONE -u NONE -n -c 'echo""|qall!' 2>$out
type = "function"; '';
arity = 2; }));
value = "vim.inspect"; req = name: let result = update result "require(\"${name}\")" (getReqAttrs name); in result;
}; _reqbind = name: varname: let result = update result "${varname}" (getReqAttrs name); in result;
cmd = process' { in result // {
type = "function"; inherit req _reqbind;
arity = 1; }
value = "vim.cmd";
};
fn = (if v?fn then v.fn else {}) // {
visualmode = {
type = "function";
arity = 0;
value = "vim.fn.visualmode";
};
};
} else v);
in
patch (builtins.mapAttrs (setPath "")
(zip (
(map process defs)
++ (map process (map (x: x // {value = "vim" + (lib.removePrefix "vim.shared" x.value); }) (builtins.filter ({value,...}: lib.hasPrefix "vim.shared" value) defs)))
++ (map (processOpt "o") opts)
++ (map (processOpt "opt") opts)
++ (map processVar vars)
)))

View file

@ -1,354 +0,0 @@
all
aleph
arabic
arabicshape
allowrevins
ambiwidth
autochdir
autoindent
autoread
autowrite
autowriteall
background
backspace
backup
backupcopy
backupdir
backupext
backupskip
belloff
binary
bomb
breakat
breakindent
breakindentopt
bufhidden
buflisted
buftype
casemap
cdhome
cdpath
cedit
channel
charconvert
cindent
cinkeys
cinoptions
cinwords
cinscopedecls
clipboard
cmdheight
cmdwinheight
colorcolumn
columns
comments
commentstring
compatible
complete
concealcursor
conceallevel
completefunc
completeopt
confirm
copyindent
cpoptions
cscopepathcomp
cscopeprg
cscopequickfix
cscoperelative
cscopetag
cscopetagorder
cscopeverbose
cursorbind
cursorcolumn
cursorline
cursorlineopt
debug
define
delcombine
dictionary
diff
diffexpr
diffopt
digraph
directory
display
eadirection
edcompatible
emoji
encoding
endofline
equalalways
equalprg
errorbells
errorfile
errorformat
eventignore
expandtab
exrc
fileencoding
fileencodings
fileformat
fileformats
fileignorecase
filetype
fillchars
fixendofline
foldclose
foldcolumn
foldenable
foldexpr
foldignore
foldlevel
foldlevelstart
foldmarker
foldmethod
foldminlines
foldnestmax
foldopen
foldtext
formatexpr
formatoptions
formatlistpat
formatprg
fsync
gdefault
grepformat
grepprg
guicursor
guifont
guifontwide
helpfile
helpheight
helplang
hidden
highlight
history
hkmap
hkmapp
hlsearch
icon
iconstring
ignorecase
iminsert
imsearch
inccommand
include
includeexpr
incsearch
indentexpr
indentkeys
infercase
insertmode
isfname
isident
iskeyword
isprint
joinspaces
jumpoptions
keymap
keymodel
keywordprg
langmap
langmenu
langnoremap
langremap
laststatus
lazyredraw
linebreak
lines
linespace
lisp
lispwords
list
listchars
loadplugins
magic
makeef
makeencoding
makeprg
matchpairs
matchtime
maxcombine
maxfuncdepth
maxmapdepth
maxmempattern
menuitems
mkspellmem
modeline
modelineexpr
modelines
modifiable
modified
more
mouse
mousefocus
mousemodel
mousemoveevent
mousescroll
mousetime
nrformats
number
numberwidth
omnifunc
operatorfunc
packpath
paragraphs
paste
pastetoggle
patchexpr
patchmode
path
preserveindent
previewheight
previewwindow
printdevice
printencoding
printexpr
printfont
printheader
printmbcharset
printmbfont
printoptions
prompt
pumblend
pumheight
pumwidth
pyxversion
quickfixtextfunc
quoteescape
readonly
redrawdebug
redrawtime
regexpengine
relativenumber
remap
report
revins
rightleft
rightleftcmd
ruler
rulerformat
runtimepath
scroll
scrollback
scrollbind
scrolljump
scrolloff
scrollopt
sections
secure
selection
selectmode
sessionoptions
shada
shadafile
shell
shellcmdflag
shellpipe
shellquote
shellredir
shelltemp
shellxquote
shellxescape
shiftround
shiftwidth
shortmess
showbreak
showcmd
showfulltag
showmatch
showmode
showtabline
sidescroll
sidescrolloff
signcolumn
smartcase
smartindent
smarttab
softtabstop
spell
spellcapcheck
spellfile
spelllang
spellsuggest
spelloptions
splitbelow
splitright
startofline
statusline
suffixes
suffixesadd
swapfile
switchbuf
synmaxcol
syntax
tagfunc
tabline
tabpagemax
tabstop
tagbsearch
tagcase
taglength
tagrelative
tags
tagstack
termbidi
termguicolors
termpastefilter
terse
textwidth
thesaurus
thesaurusfunc
tildeop
timeout
timeoutlen
title
titlelen
titleold
titlestring
ttimeout
ttimeoutlen
ttyfast
undodir
undofile
undolevels
undoreload
updatecount
updatetime
varsofttabstop
vartabstop
verbose
verbosefile
viewdir
viewoptions
virtualedit
visualbell
warn
whichwrap
wildchar
wildcharm
wildignore
wildignorecase
wildmenu
wildmode
wildoptions
winaltkeys
winbar
winblend
winhighlight
window
winheight
winfixheight
winfixwidth
winminheight
winminwidth
winwidth
wrap
wrapmargin
wrapscan
write
writeany
writebackup
writedelay

View file

@ -1,140 +0,0 @@
NvimTreeRequired
NvimTreeSetup
b:autopairs_keymaps
b:changedtick
b:nvim-autopairs
colors_name
did_indent_on
did_load_filetypes
did_load_ftplugin
ft_ignore_pat
loaded_2html_plugin
loaded_clipboard_provider
loaded_cmp
loaded_devicons
loaded_gzip
loaded_man
loaded_matchit
loaded_matchparen
loaded_netrw
loaded_netrwPlugin
loaded_node_provider
loaded_python_provider
loaded_remote_plugins
loaded_shada_plugin
loaded_sleuth
loaded_spellfile_plugin
loaded_tarPlugin
loaded_tutor_mode_plugin
loaded_zipPlugin
lspconfig
lua_subversion
lua_version
markdown_fenced_languages
markdown_minlines
matchparen_insert_timeout
matchparen_timeout
nvim_web_devicons
python3_host_prog
ruby_host_prog
syntax_on
system_remote_plugins
v:_null_blob
v:_null_dict
v:_null_list
v:_null_string
v:argv
v:beval_bufnr
v:beval_col
v:beval_lnum
v:beval_text
v:beval_winid
v:beval_winnr
v:char
v:charconvert_from
v:charconvert_to
v:cmdarg
v:cmdbang
v:collate
v:completed_item
v:count
v:count1
v:ctype
v:dying
v:echospace
v:errmsg
v:errors
v:event
v:exception
v:exiting
v:false
v:fcs_choice
v:fcs_reason
v:fname
v:fname_diff
v:fname_in
v:fname_new
v:fname_out
v:folddashes
v:foldend
v:foldlevel
v:foldstart
v:hlsearch
v:insertmode
v:key
v:lang
v:lc_time
v:lnum
v:lua
v:mouse_col
v:mouse_lnum
v:mouse_win
v:mouse_winid
v:msgpack_types
v:null
v:numbermax
v:numbermin
v:numbersize
v:oldfiles
v:operator
v:option_command
v:option_new
v:option_old
v:option_oldglobal
v:option_oldlocal
v:option_type
v:prevcount
v:profiling
v:progname
v:progpath
v:register
v:scrollstart
v:searchforward
v:servername
v:shell_error
v:statusmsg
v:stderr
v:swapchoice
v:swapcommand
v:swapname
v:t_blob
v:t_bool
v:t_dict
v:t_float
v:t_func
v:t_list
v:t_number
v:t_string
v:termresponse
v:testing
v:this_session
v:throwpoint
v:true
v:val
v:version
v:vim_did_enter
v:warningmsg
v:windowid
vimsyn_embed
zipPlugin_ext

View file

@ -1,5 +1,15 @@
{ lib, config, ... }: { lib, config, ... }:
with lib; { with lib; {
options.rustAnalyzerAndroidSettings = mkOption {
type = with types; attrs;
description = "Additional cargo arguments for rust-analyzer's RustAndroid command";
# TODO: create a neovim plugin or edit an existing one for workspace-specific config
default = {
rust-analyzer = {
cargo.target = "x86_64-linux-android";
};
};
};
options.terminals = mkOption { options.terminals = mkOption {
type = with types; listOf str; type = with types; listOf str;
description = "terminal kinds (possible values are alacritty, urxvt, kitty, foot)"; description = "terminal kinds (possible values are alacritty, urxvt, kitty, foot)";

View file

@ -26,7 +26,13 @@
pkgs = nixpkgs.legacyPackages."x86_64-linux"; pkgs = nixpkgs.legacyPackages."x86_64-linux";
modules = [ modules = [
nur.nixosModules.nur nur.nixosModules.nur
{ nixpkgs.overlays = [ nix-gaming.overlays.default ]; } { nixpkgs.overlays = [
nix-gaming.overlays.default
(self: super: {
clang_latest = super.clang_15;
clang-tools_latest = super.clang-tools_15;
})
]; }
./hosts/nixmsi.nix ./hosts/nixmsi.nix
(getPriv "nixmsi") (getPriv "nixmsi")
]; ];

View file

@ -49,8 +49,14 @@
''; '';
}; in { }; in {
STEAM_EXTRA_COMPAT_TOOLS_PATHS = "${proton-ge}"; STEAM_EXTRA_COMPAT_TOOLS_PATHS = "${proton-ge}";
CARGO_PROFILE_DEV_INCREMENTAL = "true";
RUSTC_LINKER = "${pkgs.clang_latest}/bin/clang";
RUSTFLAGS = "-C link-arg=--ld-path=${pkgs.mold}/bin/mold";
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = "${pkgs.clang_latest}/bin/clang";
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS = "-C link-arg=--ld-path=${pkgs.mold}/bin/mold";
}; };
home.packages = with pkgs; [ home.packages = with pkgs; [
mold
(ghidra.overrideAttrs (old: { (ghidra.overrideAttrs (old: {
patches = old.patches ++ [ ../common/ghidra-stdcall.patch ]; patches = old.patches ++ [ ../common/ghidra-stdcall.patch ];
})) cutter })) cutter
@ -65,7 +71,7 @@
virtmanager virtmanager
gimp krita blender gimp krita blender
tdesktop tdesktop
clang rustc rustfmt cargo clippy clang_latest rustc rustfmt cargo clippy
# waiting until the PR gets merged # waiting until the PR gets merged
(looking-glass-client.overrideAttrs (old: { (looking-glass-client.overrideAttrs (old: {
version = "B6"; version = "B6";