diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml index f0a7f74f..63dc0527 100644 --- a/.github/workflows/docgen.yml +++ b/.github/workflows/docgen.yml @@ -10,45 +10,29 @@ on: - master jobs: - build-sources: + docgen: name: Generate docs - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: date +%F > todays-date - - name: Restore cache for today's nightly. - uses: actions/cache@v2 - with: - path: build - key: ${{ runner.os }}-appimage-${{ hashFiles('todays-date') }} - - name: Prepare - run: | - test -d build || { - mkdir -p build - wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage - chmod +x nvim.appimage - mv nvim.appimage ./build/nvim - } - mkdir -p ~/.local/share/nvim/site/pack/vendor/start - git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim - git clone --depth 1 https://github.com/tjdevries/tree-sitter-lua ~/.local/share/nvim/site/pack/vendor/start/tree-sitter-lua - ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: stable - - name: Build parser - run: | - # We have to build the parser every single time to keep up with parser changes - cd ~/.local/share/nvim/site/pack/vendor/start/tree-sitter-lua - make dist - cd - + - uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-deps-${{ matrix.version }}-${{ hashFiles('todays-date') }} + restore-keys: | + ${{ runner.os }}-deps-${{ matrix.version }}- - - name: Generating docs - run: | - export PATH="${PWD}/build/:${PATH}" - make docgen + - name: Generating + run: make docgen - # inspired by nvim-lspconfigs - - name: Update documentation + - name: Commit changes env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} COMMIT_MSG: | @@ -61,3 +45,4 @@ jobs: git add 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}) + diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 774b108b..2c459808 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,7 +21,7 @@ jobs: name: stylua runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: JohnnyMorganz/stylua-action@v1 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..313971d4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,32 @@ +name: Tests +on: [push] +jobs: + test: + name: unit tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + version: [v0.9.0, nightly] + + steps: + - uses: actions/checkout@v4 + - run: date +%F > todays-date + + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: ${{ matrix.version }} + + - uses: actions/cache@v3 + with: + path: deps + key: ${{ runner.os }}-deps-${{ matrix.version }}-${{ hashFiles('todays-date') }} + restore-keys: | + ${{ runner.os }}-deps-${{ matrix.version }}- + + - name: Run tests + run: | + nvim --version + make test + diff --git a/.gitignore b/.gitignore index 926ccaaf..7aa68e81 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ doc/tags +deps/ diff --git a/Makefile b/Makefile index 3dbeb140..183d7101 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,37 @@ -docgen: +.PHONY: docgen test clean + +DEPS_DIR := deps +TS_DIR := $(DEPS_DIR)/tree-sitter-lua +PLENARY_DIR := $(DEPS_DIR)/plenary.nvim +TELESCOPE_DIR := $(DEPS_DIR)/telescope.nvim + +define git_clone_or_pull +@mkdir -p $(dir $1) +@if [ ! -d "$1" ]; then \ + git clone --depth 1 $2 $1; \ +else \ + git -C "$1" pull; \ +fi +endef + +$(DEPS_DIR): + @mkdir -p $@ + +plenary: | $(DEPS_DIR) + $(call git_clone_or_pull,$(PLENARY_DIR),https://github.com/nvim-lua/plenary.nvim) + +docgen-deps: plenary | $(DEPS_DIR) + $(call git_clone_or_pull,$(TS_DIR),https://github.com/tjdevries/tree-sitter-lua) + cd "$(TS_DIR)" && make dist + +test-deps: plenary | $(DEPS_DIR) + $(call git_clone_or_pull,$(TELESCOPE_DIR),https://github.com/nvim-telescope/telescope.nvim) + +docgen: docgen-deps nvim --headless --noplugin -u scripts/minimal_init.vim -c "luafile ./scripts/gendocs.lua" -c 'qa' + +test: test-deps + nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/ { minimal_init = './scripts/minimal_init.vim' }" + +clean: + @rm -rf $(DEPS_DIR) diff --git a/lua/telescope/_extensions/file_browser/utils.lua b/lua/telescope/_extensions/file_browser/utils.lua index 0365e622..1f45ce7d 100644 --- a/lua/telescope/_extensions/file_browser/utils.lua +++ b/lua/telescope/_extensions/file_browser/utils.lua @@ -10,7 +10,7 @@ local truncate = require("plenary.strings").truncate local fb_utils = {} -local iswin = vim.loop.os_uname().sysname == "Windows_NT" +fb_utils.iswin = vim.loop.os_uname().sysname == "Windows_NT" fb_utils.is_dir = function(path) if Path.is_path(path) then diff --git a/lua/tests/fb_git_spec.lua b/lua/tests/fb_git_spec.lua index 77c2e05a..5d49dbcc 100644 --- a/lua/tests/fb_git_spec.lua +++ b/lua/tests/fb_git_spec.lua @@ -1,6 +1,10 @@ -local fb_git = require "telescope._extensions.file_browser.git" +local git = require "telescope._extensions.file_browser.git" +local utils = require "telescope._extensions.file_browser.utils" -describe("parse_status_output", function() +describe("parse_status_output unix", function() + if utils.iswin then + return + end local cwd = "/project/root/dir" it("works in the root dir", function() local git_status = { @@ -15,7 +19,7 @@ describe("parse_status_output", function() [cwd .. "/lua/telescope/_extensions/file_browser/finders.lua"] = " M", [cwd .. "/lua/tests/"] = "??", } - local actual = fb_git.parse_status_output(git_status, cwd) + local actual = git.parse_status_output(git_status, cwd) assert.are.same(expect, actual) end) @@ -28,7 +32,7 @@ describe("parse_status_output", function() [cwd .. "/lua/telescope/_extensions/file_browser/finders.lua"] = " M", [cwd .. "/lua/tests/"] = "??", } - local actual = fb_git.parse_status_output(git_status, cwd) + local actual = git.parse_status_output(git_status, cwd) assert.are.same(expect, actual) end) @@ -43,7 +47,58 @@ describe("parse_status_output", function() [cwd .. "/lua/telescope/_extensions/file_browser/fs_stat.lua"] = "C ", [cwd .. "/lua/telescope/_extensions/file_browser/make_entry.lua"] = " M", } - local actual = fb_git.parse_status_output(git_status, cwd) + local actual = git.parse_status_output(git_status, cwd) + assert.are.same(expect, actual) + end) +end) + +describe("parse_status_output windows", function() + if not utils.iswin then + return + end + local cwd = "C:\\project\\root\\dir" + it("works in the root dir", function() + local git_status = { + "M .gitignore", + " M README.md", + " M lua\\telescope\\_extensions\\file_browser\\finders.lua", + "?? lua\\tests\\", + } + local expect = { + [cwd .. "\\.gitignore"] = "M ", + [cwd .. "\\README.md"] = " M", + [cwd .. "\\lua\\telescope\\_extensions\\file_browser\\finders.lua"] = " M", + [cwd .. "\\lua\\tests\\"] = "??", + } + local actual = git.parse_status_output(git_status, cwd) + assert.are.same(expect, actual) + end) + + it("works in a sub dir", function() + local git_status = { + " M lua\\telescope\\_extensions\\file_browser\\finders.lua", + "?? lua\\tests\\", + } + local expect = { + [cwd .. "\\lua\\telescope\\_extensions\\file_browser\\finders.lua"] = " M", + [cwd .. "\\lua\\tests\\"] = "??", + } + local actual = git.parse_status_output(git_status, cwd) + assert.are.same(expect, actual) + end) + + it("parses renamed and copied status", function() + local git_status = { + "R lua\\telescope\\_extensions\\file_browser\\stats.lua -> lua\\telescope\\_extensions\\file_browser\\fs_stat.lua", + "C lua\\telescope\\_extensions\\file_browser\\stats.lua -> lua\\telescope\\_extensions\\file_browser\\fs_stat.lua", + " M lua\\telescope\\_extensions\\file_browser\\make_entry.lua", + } + local expect = { + [cwd .. "\\lua\\telescope\\_extensions\\file_browser\\fs_stat.lua"] = "R ", + [cwd .. "\\lua\\telescope\\_extensions\\file_browser\\fs_stat.lua"] = "C ", + [cwd .. "\\lua\\telescope\\_extensions\\file_browser\\make_entry.lua"] = " M", + } + local actual = git.parse_status_output(git_status, cwd) assert.are.same(expect, actual) end) end) diff --git a/lua/tests/make_entry_spec.lua b/lua/tests/make_entry_spec.lua index 62dbc9cd..2fb1120d 100644 --- a/lua/tests/make_entry_spec.lua +++ b/lua/tests/make_entry_spec.lua @@ -1,3 +1,4 @@ +local utils = require "telescope._extensions.file_browser.utils" local me_utils = require "telescope._extensions.file_browser.make_entry_utils" describe("get_ordinal_path", function() @@ -19,6 +20,13 @@ describe("get_ordinal_path", function() end) it("handles duplicate os_sep", function() - assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c//file.txt", "/home/a/b/c", "/home/a/b")) + if utils.iswin then + assert.are.same( + "file.txt", + me_utils.get_ordinal_path([[C:\\Users\a\b\c\\file.txt]], [[C:\Users\a\b\c]], [[C:\Users\a\b\]]) + ) + else + assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c//file.txt", "/home/a/b/c", "/home/a/b")) + end end) end) diff --git a/scripts/minimal_init.vim b/scripts/minimal_init.vim index 520d9d58..88a55925 100644 --- a/scripts/minimal_init.vim +++ b/scripts/minimal_init.vim @@ -1,6 +1,6 @@ set rtp+=. -set rtp+=../plenary.nvim/ -set rtp+=../popup.nvim/ -set rtp+=../tree-sitter-lua/ +set rtp+=deps/plenary.nvim/ +set rtp+=deps/telescope.nvim/ +set rtp+=deps/tree-sitter-lua/ runtime! plugin/plenary.vim