Skip to content

Commit

Permalink
feat: first working version
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 25, 2023
1 parent 100fd00 commit eb5987e
Show file tree
Hide file tree
Showing 61 changed files with 1,977 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
layout python
python -c 'import pyparsing' 2> /dev/null || pip install pyparsing==3.0.9 black isort mypy
112 changes: 112 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Bug Report
description: File a bug/issue
title: "bug: "
labels: [bug]
body:
- type: markdown
attributes:
value: |
Before reporting a bug, make sure to search [existing issues](https://github.com/stevearc/conform.nvim/issues)
- 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: "Output of :checkhealth conform"
validations:
required: true
- type: textarea
attributes:
label: Describe the bug
description: A clear and concise description of what the bug is.
validations:
required: true
- type: textarea
attributes:
label: Steps To Reproduce
description: Steps to reproduce the behavior.
placeholder: |
1. nvim -u repro.lua
2.
3.
validations:
required: true
- type: textarea
attributes:
label: Expected Behavior
description: A concise description of what you expected to happen.
validations:
required: true
- type: textarea
attributes:
label: Minimal example file
description: A small example file you are editing that produces the issue
validations:
required: false
- type: textarea
attributes:
label: Minimal init.lua
description:
Minimal `init.lua` to reproduce this issue. Save as `repro.lua` and run with `nvim -u repro.lua`
This uses lazy.nvim (a plugin manager).
value: |
-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")
-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end
-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"--single-branch",
"https://github.com/folke/lazy.nvim.git",
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
-- install plugins
local plugins = {
"folke/tokyonight.nvim",
{
"stevearc/conform.nvim",
config = function()
require("conform").setup({
log_level = vim.log.levels.DEBUG,
-- add your config here
})
end,
},
-- add any other plugins here
}
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here
render: Lua
validations:
required: false
- type: textarea
attributes:
label: Additional context
description: Any additional information or screenshots you would like to provide
validations:
required: false
91 changes: 91 additions & 0 deletions .github/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import os
import os.path
import re
from typing import List

from nvim_doc_tools import (
Vimdoc,
VimdocSection,
generate_md_toc,
parse_functions,
read_nvim_json,
render_md_api,
render_vimdoc_api,
replace_section,
)

HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir))
README = os.path.join(ROOT, "README.md")
DOC = os.path.join(ROOT, "doc")
VIMDOC = os.path.join(DOC, "conform.txt")


def update_formatter_list():
formatters = sorted(
[
os.path.splitext(file)[0]
for file in os.listdir(os.path.join(ROOT, "lua", "conform", "formatters"))
]
)
formatter_lines = ["\n"]
for formatter in formatters:
meta = read_nvim_json(f'require("conform.formatters.{formatter}").meta')
formatter_lines.append(
f"- [{formatter}]({meta['url']}) - {meta['description']}\n"
)
replace_section(
README,
r"^<!-- FORMATTERS -->$",
r"^<!-- /FORMATTERS -->$",
formatter_lines,
)


def add_md_link_path(path: str, lines: List[str]) -> List[str]:
ret = []
for line in lines:
ret.append(re.sub(r"(\(#)", "(" + path + "#", line))
return ret


def update_md_api():
funcs = parse_functions(os.path.join(ROOT, "lua", "conform", "init.lua"))
lines = ["\n"] + render_md_api(funcs, 3)[:-1] # trim last newline
replace_section(
README,
r"^<!-- API -->$",
r"^<!-- /API -->$",
lines,
)


def update_readme_toc():
toc = ["\n"] + generate_md_toc(README) + ["\n"]
replace_section(
README,
r"^<!-- TOC -->$",
r"^<!-- /TOC -->$",
toc,
)


def generate_vimdoc():
doc = Vimdoc("conform.txt", "conform")
funcs = parse_functions(os.path.join(ROOT, "lua", "conform", "init.lua"))
doc.sections.extend(
[
VimdocSection("API", "conform-api", render_vimdoc_api("conform", funcs)),
]
)

with open(VIMDOC, "w", encoding="utf-8") as ofile:
ofile.writelines(doc.render())


def main() -> None:
"""Update the README"""
update_formatter_list()
update_md_api()
update_readme_toc()
generate_vimdoc()
31 changes: 31 additions & 0 deletions .github/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
import argparse
import os
import sys

HERE = os.path.dirname(__file__)
ROOT = os.path.abspath(os.path.join(HERE, os.path.pardir))
DOC = os.path.join(ROOT, "doc")


def main() -> None:
"""Generate docs"""
sys.path.append(HERE)
parser = argparse.ArgumentParser(description=main.__doc__)
parser.add_argument("command", choices=["generate", "lint"])
args = parser.parse_args()
if args.command == "generate":
import generate

generate.main()
elif args.command == "lint":
from nvim_doc_tools import lint_md_links

files = [os.path.join(ROOT, "README.md")] + [
os.path.join(DOC, file) for file in os.listdir(DOC) if file.endswith(".md")
]
lint_md_links.main(ROOT, files)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions .github/nvim_doc_tools
Submodule nvim_doc_tools added at 4260b3
5 changes: 5 additions & 0 deletions .github/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e
luacheck lua tests

stylua --check .
7 changes: 7 additions & 0 deletions .github/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
luacheck lua tests

stylua --check .

lua-typecheck lua
12 changes: 12 additions & 0 deletions .github/workflows/install_nvim.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -e
PLUGINS="$HOME/.local/share/nvim/site/pack/plugins/start"
mkdir -p "$PLUGINS"

wget "https://github.com/neovim/neovim/releases/download/${NVIM_TAG}/nvim.appimage"
chmod +x nvim.appimage
./nvim.appimage --appimage-extract >/dev/null
rm -f nvim.appimage
mkdir -p ~/.local/share/nvim
mv squashfs-root ~/.local/share/nvim/appimage
sudo ln -s "$HOME/.local/share/nvim/appimage/AppRun" /usr/bin/nvim
65 changes: 65 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Run tests

on: [push, pull_request]

jobs:
luacheck:
name: Luacheck
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Prepare
run: |
sudo apt-get update
sudo add-apt-repository universe
sudo apt install luarocks -y
sudo luarocks install luacheck
- name: Run Luacheck
run: luacheck .

typecheck:
name: typecheck
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: stevearc/nvim-typecheck-action@v1
with:
path: lua

stylua:
name: StyLua
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Stylua
uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v0.15.2
args: --check .

release:
name: release

if: ${{ github.ref == 'refs/heads/master' }}
needs:
- luacheck
- stylua
- typecheck
runs-on: ubuntu-22.04
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: simple
package-name: conform.nvim
- uses: actions/checkout@v3
- uses: rickstaa/action-create-tag@v1
if: ${{ steps.release.outputs.release_created }}
with:
tag: stable
message: "Current stable release: ${{ steps.release.outputs.tag_name }}"
tag_exists_error: false
force_push_tag: true
35 changes: 35 additions & 0 deletions .github/workflows/update-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Update docs

on: push

jobs:
update-readme:
name: Update docs
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install Neovim and dependencies
env:
NVIM_TAG: v0.8.3
run: |
bash ./.github/workflows/install_nvim.sh
- name: Update docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: |
[docgen] Update docs
skip-checks: true
run: |
git config user.email "actions@github"
git config user.name "Github Actions"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
python -m pip install pyparsing==3.0.9
python .github/main.py generate
python .github/main.py lint
git add README.md doc
# Only commit and push if we have changes
git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push origin HEAD:${GITHUB_REF})
Loading

0 comments on commit eb5987e

Please sign in to comment.