From 60e8313e693881778c14baaf8b041947d17e6e83 Mon Sep 17 00:00:00 2001 From: Toshifumi Kiyono Date: Mon, 12 Feb 2024 18:51:15 +0900 Subject: [PATCH] Initial commit --- .github/ISSUE_TEMPLATE/bug_report.yml | 54 +++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.yml | 36 +++++++++++ .github/workflows/docs.yml | 25 ++++++++ .github/workflows/lint-test.yml | 33 ++++++++++ .github/workflows/release.yml | 14 +++++ .gitignore | 1 + .stylua.toml | 6 ++ LICENSE | 21 +++++++ Makefile | 11 ++++ README.md | 47 +++++++++++++++ doc/my-template-docs.txt | 70 ++++++++++++++++++++++ lua/plugin_name.lua | 27 +++++++++ lua/plugin_name/module.lua | 9 +++ plugin/plugin_name.lua | 1 + tests/minimal_init.lua | 11 ++++ tests/plugin_name/plugin_name_spec.lua | 12 ++++ 16 files changed, 378 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/lint-test.yml create mode 100644 .github/workflows/release.yml create mode 100644 .gitignore create mode 100644 .stylua.toml create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 doc/my-template-docs.txt create mode 100644 lua/plugin_name.lua create mode 100644 lua/plugin_name/module.lua create mode 100644 plugin/plugin_name.lua create mode 100644 tests/minimal_init.lua create mode 100644 tests/plugin_name/plugin_name_spec.lua diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..df536b1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,54 @@ +name: Bug Report +description: File a bug/issue +title: "bug: " +labels: [bug] +body: + - type: markdown + attributes: + value: | + **Before** reporting an issue, make sure to read the documentation and search existing issues. Usage questions such as ***"How do I...?"*** belong in Discussions and will be closed. + - type: checkboxes + attributes: + label: Did you check docs and existing issues? + description: Make sure you checked all of the below before submitting an issue + options: + - label: I have read all the plugin docs + required: true + - label: I have searched the existing issues + required: true + - label: I have searched the existing issues of plugins related to this issue + required: true + - type: input + attributes: + label: "Neovim version (nvim -v)" + placeholder: "0.8.0 commit db1b0ee3b30f" + validations: + required: true + - type: input + attributes: + label: "Operating system/version" + placeholder: "MacOS 11.5" + validations: + required: true + - type: textarea + attributes: + label: Describe the bug + description: A clear and concise description of what the bug is. Please include any related errors you see in Neovim. + validations: + required: true + - type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + placeholder: | + 1. + 2. + 3. + validations: + required: true + - type: textarea + attributes: + label: Expected Behavior + description: A concise description of what you expected to happen. + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..f8ce0f9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,36 @@ +name: Feature Request +description: Suggest a new feature +title: "feature: " +labels: [enhancement] +body: + - type: checkboxes + attributes: + label: Did you check the docs? + description: Make sure you read all the docs before submitting a feature request + options: + - label: I have read all the docs + required: true + - type: textarea + validations: + required: true + attributes: + label: Is your feature request related to a problem? Please describe. + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + - type: textarea + validations: + required: true + attributes: + label: Describe the solution you'd like + description: A clear and concise description of what you want to happen. + - type: textarea + validations: + required: true + attributes: + label: Describe alternatives you've considered + description: A clear and concise description of any alternative solutions or features you've considered. + - type: textarea + validations: + required: false + attributes: + label: Additional context + description: Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..0b8d187 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,25 @@ +on: + push: + branches: + - main +name: docs + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: panvimdoc + uses: kdheepak/panvimdoc@main + with: + vimdoc: my-template-docs + version: "Neovim >= 0.8.0" + demojify: true + treesitter: true + - name: Push changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "auto-generate vimdoc" + commit_user_name: "github-actions[bot]" + commit_user_email: "github-actions[bot]@users.noreply.github.com" + commit_author: "github-actions[bot] " diff --git a/.github/workflows/lint-test.yml b/.github/workflows/lint-test.yml new file mode 100644 index 0000000..19a56eb --- /dev/null +++ b/.github/workflows/lint-test.yml @@ -0,0 +1,33 @@ +--- +on: [push, pull_request] +name: lint-test + +jobs: + stylua: + name: stylua + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: JohnnyMorganz/stylua-action@v3 + with: + version: latest + token: ${{ secrets.GITHUB_TOKEN }} + args: --color always --check lua + + test: + runs-on: ubuntu-latest + strategy: + matrix: + nvim-versions: ['stable', 'nightly'] + name: test + steps: + - name: checkout + uses: actions/checkout@v3 + + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: ${{ matrix.nvim-versions }} + + - name: run tests + run: make test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..05db001 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,14 @@ +name: "release" +on: + push: + tags: + - 'v*' +jobs: + luarocks-upload: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + - name: LuaRocks Upload + uses: nvim-neorocks/luarocks-tag-release@v4 + env: + LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..238d11c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vendor/plenary.nvim diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..0fd4cb5 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +no_call_parentheses = false diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..83dc276 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Ellison + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..54bc132 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +TESTS_INIT=tests/minimal_init.lua +TESTS_DIR=tests/ + +.PHONY: test + +test: + @nvim \ + --headless \ + --noplugin \ + -u ${TESTS_INIT} \ + -c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${TESTS_INIT}' }" diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e3a28c --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +# A Neovim Plugin Template + +![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ellisonleao/nvim-plugin-template/lint-test.yml?branch=main&style=for-the-badge) +![Lua](https://img.shields.io/badge/Made%20with%20Lua-blueviolet.svg?style=for-the-badge&logo=lua) + +A template repository for Neovim plugins. + +## Using it + +Via `gh`: + +``` +$ gh repo create my-plugin -p ellisonleao/nvim-plugin-template +``` + +Via github web page: + +Click on `Use this template` + +![](https://docs.github.com/assets/cb-36544/images/help/repository/use-this-template-button.png) + +## Features and structure + +- 100% Lua +- Github actions for: + - running tests using [plenary.nvim](https://github.com/nvim-lua/plenary.nvim) and [busted](https://olivinelabs.com/busted/) + - check for formatting errors (Stylua) + - vimdocs autogeneration from README.md file + - luarocks release (LUAROCKS_API_KEY secret configuration required) + +### Plugin structure + +``` +. +├── lua +│   ├── plugin_name +│   │   └── module.lua +│   └── plugin_name.lua +├── Makefile +├── plugin +│   └── plugin_name.lua +├── README.md +├── tests +│   ├── minimal_init.lua +│   └── plugin_name +│   └── plugin_name_spec.lua +``` diff --git a/doc/my-template-docs.txt b/doc/my-template-docs.txt new file mode 100644 index 0000000..5f5501c --- /dev/null +++ b/doc/my-template-docs.txt @@ -0,0 +1,70 @@ +*my-template-docs.txt* For Neovim >= 0.8.0 Last change: 2024 January 18 + +============================================================================== +Table of Contents *my-template-docs-table-of-contents* + +1. A Neovim Plugin Template |my-template-docs-a-neovim-plugin-template| + - Using it |my-template-docs-a-neovim-plugin-template-using-it| + - Features and structure|my-template-docs-a-neovim-plugin-template-features-and-structure| + +============================================================================== +1. A Neovim Plugin Template *my-template-docs-a-neovim-plugin-template* + + + +A template repository for Neovim plugins. + + +USING IT *my-template-docs-a-neovim-plugin-template-using-it* + +Via `gh` + +> + $ gh repo create my-plugin -p ellisonleao/nvim-plugin-template +< + +Viagithub web page: + +Click on `Use this template` + + + + +FEATURES AND STRUCTURE*my-template-docs-a-neovim-plugin-template-features-and-structure* + +- 100% Lua +- Github actions for: + - running tests using plenary.nvim and busted + - check for formatting errors (Stylua) + - vimdocs autogeneration from README.md file + - luarocks release (LUAROCKS_API_KEY secret configuration required) + + +PLUGIN STRUCTURE ~ + +> + . + ├── lua + │   ├── plugin_name + │   │   └── module.lua + │   └── plugin_name.lua + ├── Makefile + ├── plugin + │   └── plugin_name.lua + ├── README.md + ├── tests + │   ├── minimal_init.lua + │   └── plugin_name + │   └── plugin_name_spec.lua +< + +============================================================================== +2. Links *my-template-docs-links* + +1. *GitHub Workflow Status*: https://img.shields.io/github/actions/workflow/status/ellisonleao/nvim-plugin-template/lint-test.yml?branch=main&style=for-the-badge +2. *Lua*: https://img.shields.io/badge/Made%20with%20Lua-blueviolet.svg?style=for-the-badge&logo=lua +3. **: https://docs.github.com/assets/cb-36544/images/help/repository/use-this-template-button.png + +Generated by panvimdoc + +vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/lua/plugin_name.lua b/lua/plugin_name.lua new file mode 100644 index 0000000..fabecf4 --- /dev/null +++ b/lua/plugin_name.lua @@ -0,0 +1,27 @@ +-- main module file +local module = require("plugin_name.module") + +---@class Config +---@field opt string Your config option +local config = { + opt = "Hello!", +} + +---@class MyModule +local M = {} + +---@type Config +M.config = config + +---@param args Config? +-- you can define your setup function here. Usually configurations can be merged, accepting outside params and +-- you can also put some validation here for those. +M.setup = function(args) + M.config = vim.tbl_deep_extend("force", M.config, args or {}) +end + +M.hello = function() + return module.my_first_function(M.config.opt) +end + +return M diff --git a/lua/plugin_name/module.lua b/lua/plugin_name/module.lua new file mode 100644 index 0000000..78a9962 --- /dev/null +++ b/lua/plugin_name/module.lua @@ -0,0 +1,9 @@ +---@class CustomModule +local M = {} + +---@return string +M.my_first_function = function(greeting) + return greeting +end + +return M diff --git a/plugin/plugin_name.lua b/plugin/plugin_name.lua new file mode 100644 index 0000000..6808ee4 --- /dev/null +++ b/plugin/plugin_name.lua @@ -0,0 +1 @@ +vim.api.nvim_create_user_command("MyFirstFunction", require("plugin_name").hello, {}) diff --git a/tests/minimal_init.lua b/tests/minimal_init.lua new file mode 100644 index 0000000..0841a82 --- /dev/null +++ b/tests/minimal_init.lua @@ -0,0 +1,11 @@ +local plenary_dir = os.getenv("PLENARY_DIR") or "/tmp/plenary.nvim" +local is_not_a_directory = vim.fn.isdirectory(plenary_dir) == 0 +if is_not_a_directory then + vim.fn.system({"git", "clone", "https://github.com/nvim-lua/plenary.nvim", plenary_dir}) +end + +vim.opt.rtp:append(".") +vim.opt.rtp:append(plenary_dir) + +vim.cmd("runtime plugin/plenary.vim") +require("plenary.busted") diff --git a/tests/plugin_name/plugin_name_spec.lua b/tests/plugin_name/plugin_name_spec.lua new file mode 100644 index 0000000..edf409a --- /dev/null +++ b/tests/plugin_name/plugin_name_spec.lua @@ -0,0 +1,12 @@ +local plugin = require("plugin_name") + +describe("setup", function() + it("works with default", function() + assert(plugin.hello() == "Hello!", "my first function with param = Hello!") + end) + + it("works with custom var", function() + plugin.setup({ opt = "custom" }) + assert(plugin.hello() == "custom", "my first function with param = custom") + end) +end)