diff --git a/.busted b/.busted new file mode 100644 index 0000000..8c64018 --- /dev/null +++ b/.busted @@ -0,0 +1,13 @@ +return { + _all = { + coverage = false, + lpath = "lua/?.lua;lua/?/init.lua", + lua = "nlua", + }, + default = { + verbose = true + }, + tests = { + verbose = true + }, +} diff --git a/.github/README.md b/.github/README.md index b874a9e..01ae10e 100644 --- a/.github/README.md +++ b/.github/README.md @@ -7,4 +7,3 @@ Nothing yet :) See [general tips for working with C++ in neovim](../docs/tips.md). - diff --git a/.github/workflows/luarocks.yml b/.github/workflows/luarocks.yml index 8cf6050..e372fed 100644 --- a/.github/workflows/luarocks.yml +++ b/.github/workflows/luarocks.yml @@ -8,11 +8,11 @@ on: workflow_dispatch: jobs: - luarocks-upload: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: LuaRocks Upload - uses: nvim-neorocks/luarocks-tag-release@v5 - env: - LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} + # luarocks-upload: + # runs-on: ubuntu-22.04 + # steps: + # - uses: actions/checkout@v3 + # - name: LuaRocks Upload + # uses: nvim-neorocks/luarocks-tag-release@v5 + # env: + # LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..df1bddf --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +/* + +#GH, git +!.gitignore +!.github/ + +# Meta +!LICENSE + +# Nix +!nix/ +!default.nix +!flake.nix +!flake.lock + +# Plugin +!lua/ +!doc/ +!docs/ +!ftplugin/ +!*.rockspec + +# Plugin test & lint +!spec/ +!.busted +!.luacheckrc diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..2016242 --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,10 @@ +std = "luajit" +cache = true +include_files = {"spec/**.lua", "lua/**.lua", "*.rockspec", ".luacheckrc"} + +read_globals = { + "vim", + "describe", + "it", + "assert" +} diff --git a/cpp-tools.nvim-scm-1.rockspec b/cpp-tools.nvim-scm-1.rockspec index 6c9d310..bb7a8e9 100644 --- a/cpp-tools.nvim-scm-1.rockspec +++ b/cpp-tools.nvim-scm-1.rockspec @@ -1,27 +1,36 @@ -local MODREV, SPECREV = "scm", "-1" +local MODREV, SPECREV = 'scm', '-1' -package = "cpp-tools.nvim" +rockspec_format = '3.0' + +package = 'cpp-tools.nvim' version = MODREV .. SPECREV description = { - summary = "Supercharge your C++ experience in neovim.", - homepage = "http://github.com/Dich0tomy/cpp-tools.nvim", - license = "GPL-3.0" + summary = 'Supercharge your C++ experience in neovim.', + homepage = 'http://github.com/Dich0tomy/cpp-tools.nvim', + license = 'GPL-3.0' } - -dependencies = { } - source = { - url = "http://github.com/Dich0tomy/cpp-tools.nvim/archive/v" .. MODREV .. ".zip", + url = 'http://github.com/Dich0tomy/cpp-tools.nvim/archive/v' .. MODREV .. '.zip', } -if MODREV == "scm" then +if MODREV == 'scm' then source = { - url = "git://github.com/Dich0tomy/cpp-tools.nvim", + url = 'git://github.com/Dich0tomy/cpp-tools.nvim', } end +test_dependencies = { + 'lua >= 5.1', + 'plenary.nvim', + 'nlua', +} + +dependencies = {} build = { - type = "builtin", + type = 'builtin', + copy_directories = { + 'ftplugin' + }, } diff --git a/default.nix b/default.nix index 1d373be..2840540 100644 --- a/default.nix +++ b/default.nix @@ -1,16 +1,17 @@ { - self, - vimUtils, - lib, + self, + vimUtils, + lib, }: vimUtils.buildVimPlugin { pname = "cpp-tools.nvim"; version = self.shortRev or self.dirtyRev or "dirty"; src = lib.fileset.toSource { - root = ./.; - fileset = lib.fileset.unions [ - ./lua - ]; - }; + root = ./.; + fileset = lib.fileset.unions [ + ./ftplugin + ./lua + ]; + }; } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ed8c0b6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,440 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_3": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_4": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_3": { + "inputs": { + "nixpkgs-lib": [ + "neorocks", + "neovim-nightly", + "hercules-ci-effects", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1720524665, + "narHash": "sha256-ni/87oHPZm6Gv0ECYxr1f6uxB0UKBWJ6HvS7lwLU6oY=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "8d6a17d0cdf411c55f12602624df6368ad86fac1", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "git-hooks_2": { + "inputs": { + "flake-compat": "flake-compat_4", + "gitignore": "gitignore_2", + "nixpkgs": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ], + "nixpkgs-stable": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720524665, + "narHash": "sha256-ni/87oHPZm6Gv0ECYxr1f6uxB0UKBWJ6HvS7lwLU6oY=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "8d6a17d0cdf411c55f12602624df6368ad86fac1", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "neorocks", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "neorocks", + "neovim-nightly", + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "hercules-ci-effects": { + "inputs": { + "flake-parts": "flake-parts_3", + "nixpkgs": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1719226092, + "narHash": "sha256-YNkUMcCUCpnULp40g+svYsaH1RbSEj6s4WdZY/SHe38=", + "owner": "hercules-ci", + "repo": "hercules-ci-effects", + "rev": "11e4b8dc112e2f485d7c97e1cee77f9958f498f5", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "hercules-ci-effects", + "type": "github" + } + }, + "neorocks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "git-hooks": "git-hooks", + "neovim-nightly": "neovim-nightly", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1720848250, + "narHash": "sha256-yjfVwL1HIz8SIM+7Gleaw0HNJgE7bafwcoPjZWb6XMQ=", + "owner": "nvim-neorocks", + "repo": "neorocks", + "rev": "e0f7f70cf0664c80f64359dd0881bbfc3992543e", + "type": "github" + }, + "original": { + "owner": "nvim-neorocks", + "repo": "neorocks", + "type": "github" + } + }, + "neovim-nightly": { + "inputs": { + "flake-compat": "flake-compat_3", + "flake-parts": "flake-parts_2", + "git-hooks": "git-hooks_2", + "hercules-ci-effects": "hercules-ci-effects", + "neovim-src": "neovim-src", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1720796317, + "narHash": "sha256-2B4PFl75fFjQkquRCPB5PYeY0bFqF/xvsLy014c+7W4=", + "owner": "nix-community", + "repo": "neovim-nightly-overlay", + "rev": "a07ca86e6922bc2a68ec4c801ab7e05e12397af0", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "neovim-nightly-overlay", + "type": "github" + } + }, + "neovim-src": { + "flake": false, + "locked": { + "lastModified": 1720739431, + "narHash": "sha256-lEgZwuKL1eLsiFqoSiOZgq30jQCFTEYlreL79Txbxu4=", + "owner": "neovim", + "repo": "neovim", + "rev": "a5de650f0eb93a848831f1ba631485437a82d57b", + "type": "github" + }, + "original": { + "owner": "neovim", + "repo": "neovim", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1719876945, + "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + } + }, + "nixpkgs-lib_2": { + "locked": { + "lastModified": 1719876945, + "narHash": "sha256-Fm2rDDs86sHy0/1jxTOKB1118Q0O3Uc7EC0iXvXKpbI=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/5daf0514482af3f97abaefc78a6606365c9108e2.tar.gz" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1720657034, + "narHash": "sha256-nPhbeFdyN8yn+EXmnPcBWisoypndtQbNIhSKmAinv3E=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "212defe037698e18fc9521dfe451779a8979844c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1720750130, + "narHash": "sha256-y2wc7CdK0vVSIbx7MdVoZzuMcUoLvZXm+pQf2RIr1OU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6794d064edc69918bb0fc0e0eda33ece324be17a", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1720542800, + "narHash": "sha256-ZgnNHuKV6h2+fQ5LuqnUaqZey1Lqqt5dTUAiAnqH0QQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "feb2849fdeb70028c70d73b848214b00d324a497", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib_2" + }, + "locked": { + "lastModified": 1719994518, + "narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "root": { + "inputs": { + "neorocks": "neorocks", + "nixpkgs": "nixpkgs_4", + "parts": "parts" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index fb10574..aafe16e 100644 --- a/flake.nix +++ b/flake.nix @@ -1,17 +1,34 @@ { description = "A powerful C++ editing experience for your neovim."; - outputs = inputs@{ parts, ... }: parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + outputs = inputs @ {parts, ...}: + parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; - perSystem = { config, self', inputs', pkgs, system, ... }: { - legacyPackages.vimPlugins = pkgs.callPackage ./default.nix {}; + imports = [ + ./nix/checks.nix + ]; + + perSystem = { + config, + self', + inputs', + pkgs, + system, + ... + }: { + legacyPackages.vimPlugins = pkgs.callPackage ./default.nix {}; + + imports = [ + ./nix/shell.nix + ./nix/formatter.nix + ]; }; }; - inputs = { - parts.url = "github:hercules-ci/flake-parts"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - }; - + inputs = { + parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + neorocks.url = "github:nvim-neorocks/neorocks"; + }; } diff --git a/lua/cpp-tools/health.lua b/lua/cpp-tools/health.lua index ebd8d99..725f791 100644 --- a/lua/cpp-tools/health.lua +++ b/lua/cpp-tools/health.lua @@ -1,16 +1,48 @@ -local health = vim.health +-- Inspired by mrcjkb/haskell-tools.nvim +local h = vim.health +local start = h.start +local ok = h.ok +local error = h.error +local warn = h.warn + +local function dep_exists(name) + return vim.loader.find(name) +end local function validate_config() + start('Checking config') +end + +local function ensure_system_dependencies() + start('Checking system dependencies') +end + +local function ensure_lua_dependencies() + start('Checking lua dependencies') end local function ensure_dependencies() + start('Checking dependencies') + local deps = { + 'lspconfig', + } + + vim + .iter(deps) + :map(function(dep) + return { dep, dep_exists(dep) } + end) + :filter(function(dep) + return dep[1] == false + end) + :each(function(not_found_dep) end) end local M function M.check() - validate_config() - ensure_dependencies() + validate_config() + ensure_dependencies() end return M diff --git a/lua/cpp-tools/lib/README.md b/lua/cpp-tools/lib/README.md new file mode 100644 index 0000000..fe36385 --- /dev/null +++ b/lua/cpp-tools/lib/README.md @@ -0,0 +1,5 @@ +# Lib + +Private library for cpp-tools. + +Generally we opt in for the more performant solutions for obvious reasons, unless it's too much hassle. diff --git a/nix/checks.nix b/nix/checks.nix new file mode 100644 index 0000000..cc54389 --- /dev/null +++ b/nix/checks.nix @@ -0,0 +1,51 @@ +{inputs, ...}: { + perSystem = { + pkgs, + system, + config, + lib, + ... + }: { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [inputs.neorocks.overlays.default]; + }; + + checks.default = pkgs.writeShellApplication { + name = "typos-check"; + + runtimeInputs = [pkgs.typos]; + + text = "typos ."; + }; + + checks.neorocks = pkgs.neorocksTest { + name = "cpp-tools.nvim"; + + src = let + fs = lib.fileset; + root = ../.; + in + fs.toSource { + inherit root; + fileset = fs.unions [ + (root + /ftplugin) + (root + /spec) + (root + /lua) + (root + /.busted) + (fs.fileFilter (f: f.hasExt "rockspec") root) + ]; + }; + + luaPackages = ps: [ps.plenary-nvim]; + }; + + checks.luacheck = pkgs.writeShellApplication { + name = "luacheck"; + + runtimeInputs = [pkgs.luajitPackages.luacheck]; + + text = "luacheck ."; + }; + }; +} diff --git a/nix/formatter.nix b/nix/formatter.nix new file mode 100644 index 0000000..6031aee --- /dev/null +++ b/nix/formatter.nix @@ -0,0 +1,15 @@ +{pkgs, ...}: { + formatter = pkgs.writeShellApplication { + name = "cpp-tools-formatter"; + + runtimeInputs = [ + pkgs.stylua + pkgs.alejandra + ]; + + text = '' + alejandra . + stylua . + ''; + }; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..a17628b --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,8 @@ +{pkgs, ...}: { + devShells.default = pkgs.mkShellNoCC { + packages = [ + pkgs.lua-language-server + pkgs.luajitPackages.luacheck + ]; + }; +} diff --git a/spec/dummy_spec.lua b/spec/dummy_spec.lua new file mode 100644 index 0000000..064a172 --- /dev/null +++ b/spec/dummy_spec.lua @@ -0,0 +1,10 @@ +describe('Test example', function() + it('Test can access vim namespace', function() + assert(vim, 'Cannot access vim namespace') + assert.are.same(vim.trim(' a '), 'a') + end) + + it('Test can access plenary.nvim dependency', function() + assert(require('plenary'), 'Could not access plenary') + end) +end)