From a6c979c6590f9e53c69dd6281fe97bdf73345f98 Mon Sep 17 00:00:00 2001 From: Hung Date: Sun, 11 Jun 2023 23:51:47 -0700 Subject: [PATCH] feat: add couple more vim plugins via nixpkgs --- README.md | 1 + native_configs/neovim/init.lua | 26 +------ nix-conf/home-manager/base/neovim.nix | 61 ++++++++++----- scripts/vim_dsl.py | 104 ++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 43 deletions(-) create mode 100755 scripts/vim_dsl.py diff --git a/README.md b/README.md index 0590ee0..f11cddb 100644 --- a/README.md +++ b/README.md @@ -78,3 +78,4 @@ fi - Otherwise, consult [`gh-gist:meeech/a_help-osx-borked-my-nix.md`](https://gist.github.com/meeech/0b97a86f235d10bc4e2a1116eec38e7e) + diff --git a/native_configs/neovim/init.lua b/native_configs/neovim/init.lua index ffab27e..081fed7 100644 --- a/native_configs/neovim/init.lua +++ b/native_configs/neovim/init.lua @@ -34,7 +34,7 @@ end -- Do Plug if plugin not yet linked in `rtp`. This takes care of Nix-compatibility local function WPlug(plugin_path, ...) - local plugin_name = plugin_path:match("/([^/]+)$") + local plugin_name = string.lower(plugin_path:match("/([^/]+)$")) if not installed_plugins[plugin_name] then Plug(plugin_path, ...) end @@ -802,30 +802,6 @@ require('mason-lspconfig').setup_handlers({ }, } end, - -- ["rust_analyzer"] = function() - -- require('lspconfig').rust_analyzer.setup { - -- on_attach = on_attach, - -- capabilities = capabilities, - -- settings = { - -- checkOnSave = { - -- command = "clippy", - -- } - -- } - -- } - -- end, - -- ["astro"] = function() - -- print('configuring astro') - -- require('lspconfig').astro.setup { - -- on_attach = on_attach, - -- capabilities = capabilities, - -- init_options = { - -- configuration = {}, - -- typescript = { - -- serverPath = data_dir - -- } - -- } - -- } - -- end }) require("rust-tools").setup { tools = { diff --git a/nix-conf/home-manager/base/neovim.nix b/nix-conf/home-manager/base/neovim.nix index b8ce466..ecc36ab 100644 --- a/nix-conf/home-manager/base/neovim.nix +++ b/nix-conf/home-manager/base/neovim.nix @@ -1,9 +1,8 @@ -# TODO: vim-plug and Mason supports laziness. Probably worth it to explore -# incremental dependencies based on the project +# TODO: vim-plug and Mason supports laziness. Probably worth it to explore incremental dependencies based on the project # TODO: just install these things, then symlink to mason's bin directory # # One thing to consider, though, /nix/store of `nix-shell` or `nix-develop` -# might be different from `home-manager`'s +# might be different from `home-manager`'s (~/.nix_profile/bin/jq) { pkgs, lib, config, proj_root, ... }: let # NOTE: Add packages to nvim_pkgs instead, so that it's available at userspace @@ -34,7 +33,6 @@ let pkgs.go # doesn't work, Mason installs from runtime path - # Language-specific stuffs pkgs.sumneko-lua-language-server # pkgs.python3Packages.python-lsp-server @@ -78,21 +76,7 @@ in vimAlias = true; withPython3 = true; withNodeJs = true; - # Attempt 4: Correct way to make neovim aware of packages - # homeConfigurations.config.programs.neovim takes UNWRAPPED neovim - # and wraps it. - # Ideally, we build our own neovim and add that to config.home.packages - # to share it with nixOS. But we don't really need to share extraPackages = nvim_pkgs; - # only for here for archive-documentation - # extraPython3Packages = (pypkgs: [ - # # pypkgs.python-lsp-server - # pypkgs.ujson - # ]); - # I use vim-plug, so I probably don't require packaging - # extraConfig actually writes to init-home-manager.vim (not lua) - # https://github.com/nix-community/home-manager/pull/3287 - # extraConfig = builtins.readFile "${proj_root}/neovim/init.lua"; extraLuaConfig = (builtins.readFile "${proj_root.config.path}//neovim/init.lua"); plugins = (let inherit (pkgs.vimPlugins) plenary-nvim @@ -125,6 +109,27 @@ in zk-nvim luasnip fidget-nvim + rust-tools-nvim + + cmp_luasnip + gitsigns-nvim + indent-blankline-nvim + lualine-nvim + mason-lspconfig-nvim + mason-nvim + neogit + nlua-nvim + nvim-jqx + nvim-surround + nvim-web-devicons + playground + todo-comments-nvim + trouble-nvim + vim-dispatch + vim-dispatch-neovim + vim-fugitive + vim-jack-in + ; in [ plenary-nvim nvim-treesitter.withAllGrammars @@ -149,6 +154,26 @@ in luasnip nvim-treesitter-context fidget-nvim + rust-tools-nvim + + cmp_luasnip + gitsigns-nvim + indent-blankline-nvim + lualine-nvim + mason-lspconfig-nvim + mason-nvim + neogit + nlua-nvim + nvim-jqx + nvim-surround + nvim-web-devicons + playground + todo-comments-nvim + trouble-nvim + vim-dispatch + vim-dispatch-neovim + vim-fugitive + vim-jack-in ]); }; # home.packages = nvim_pkgs; diff --git a/scripts/vim_dsl.py b/scripts/vim_dsl.py new file mode 100755 index 0000000..45b1121 --- /dev/null +++ b/scripts/vim_dsl.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 # A simple playground to explore vim plugins that are available in nixpkgs + +import csv +import urllib.request +from io import StringIO +import sqlite3 + +UPSTREAM_CSV = "https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/applications/editors/vim/plugins/vim-plugin-names" + + +def load_csv(url): + with urllib.request.urlopen(url) as response: + data = response.read().decode() + return csv.DictReader(StringIO(data)) + + +class VimPlugins: + def __init__(self, url: str, sqlite: str = ":memory:"): + self.conn = sqlite3.connect(sqlite) + csv_data = load_csv(url) + fieldnames = csv_data.fieldnames or ["repo", "branch", "alias"] + + cur = self.create_table() + for row in csv_data: + fields = ", ".join(f'"{row[field]}"' for field in fieldnames) + cur.execute(f"INSERT INTO {self.table_name()} VALUES ({fields})") + + self.conn.commit() + + def create_table(self, cursor=None): + cur = self.conn.cursor() if not cursor else cursor + cur.execute(f''' + CREATE TABLE {self.table_name()} ( + "repo" TEXT, + "branch" TEXT, + "alias" TEXT + ); + ''') + return cur + + def table_name(self): + return "vim_plugins" + + def query(self, query: str): + return self.conn.cursor().execute(query).fetchall() + + +def vim_plugin_slug(name: str): + return name.replace(".", "-").lower() + + +def name_from_repo(repo: str): + spl = repo.split("/") + return vim_plugin_slug(spl[-1] or spl[-2]) + + +if __name__ == "__main__": + # REPL zone + vp = VimPlugins(UPSTREAM_CSV) + need_install_plugins = """ +tjdevries/nlua.nvim +yioneko/nvim-yati +nathanalderson/yang.vim +numToStr/Comment.nvim +lewis6991/gitsigns.nvim +tpope/vim-fugitive +williamboman/mason.nvim +williamboman/mason-lspconfig.nvim +TimUntersberger/neogit +folke/trouble.nvim +tpope/vim-dispatch +clojure-vim/vim-jack-in +radenling/vim-dispatch-neovim +gennaro-tedesco/nvim-jqx +kylechui/nvim-surround +simrat39/inlay-hints.nvim +gruvbox-community/gruvbox +nvim-lualine/lualine.nvim +lukas-reineke/indent-blankline.nvim +kyazdani42/nvim-web-devicons +m-demare/hlargs.nvim +folke/todo-comments.nvim +nvim-treesitter/playground +saadparwaiz1/cmp_luasnip +L3MON4D3/LuaSnip +arthurxavierx/vim-caser +~/local_repos/ts-ql + """.split() + need_install_plugins = [plugin.strip() for plugin in plugins] + need_install_plugins = [plugin for plugin in plugins if len(plugin) > 0] + need_install_plugins_gh = [ + f"https://github.com/{plugin}/".lower() for plugin in need_install_plugins if plugin[0] not in "~./"] + values = vp.query(f"SELECT LOWER(repo), alias from {vp.table_name()}") + need_install = [] + for repo, alias in values: + if repo in need_install_plugins_gh: + need_install.append(vim_plugin_slug(alias) if len(alias) > 0 else name_from_repo(repo)) + print("need_install", "\n".join(need_install)) + + repos = [repo for repo, _ in values] + not_in_repo = [name_from_repo(gh) for gh in need_install_plugins_gh if gh not in repos] + print("not in repo", not_in_repo) # nvim-yati, yang-vim, Comment-nvim, inlay-hints-nvim, hlargs-nvim, vim-caser, gruvbox-community + +