From 9e913ac548bfc0d9a2603bb38847cf820aeeabdd Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:13:10 -0400 Subject: [PATCH 1/6] fix(make_entry): fix ordinal basename (#368) extra os_sep was causing a bad basename. eg `/tmp//foo` was turning into `oo` --- lua/telescope/_extensions/file_browser/make_entry.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lua/telescope/_extensions/file_browser/make_entry.lua b/lua/telescope/_extensions/file_browser/make_entry.lua index d312dd8..cf29fbb 100644 --- a/lua/telescope/_extensions/file_browser/make_entry.lua +++ b/lua/telescope/_extensions/file_browser/make_entry.lua @@ -117,9 +117,6 @@ local make_entry = function(opts) local parent_dir = Path:new(opts.cwd):parent():absolute() local mt = {} mt.cwd = opts.cwd - -- +1 to start at first file char; cwd may or may not end in os_sep - local cwd_substr = #mt.cwd + 1 - cwd_substr = mt.cwd:sub(-1, -1) ~= os_sep and cwd_substr + os_sep_len or cwd_substr -- TODO(fdschmidt93): handle VimResized with due to variable width mt.display = function(entry) @@ -245,7 +242,7 @@ local make_entry = function(opts) local e = setmetatable({ absolute_path, ordinal = (absolute_path == opts.cwd and ".") - or (absolute_path == parent_dir and ".." or absolute_path:sub(cwd_substr, -1)), + or (absolute_path == parent_dir and ".." or vim.fs.basename(absolute_path)), Path = path, path = absolute_path, is_dir = is_dir, From 3bece973c5d80e7da447157822d5b0e73558d361 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Tue, 19 Mar 2024 22:22:36 -0400 Subject: [PATCH 2/6] docs(readme): add neovim minimum version (#369) Need 0.9.0 or higher for `vim.fs` access. --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7b50ba5..b4d9e85 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ More demo examples can be found in the [showcase issue](https://github.com/nvim- ### Table of Contents +- [Requirements](#requirements) - [Installation](#installation) - [Setup and Configuration](#setup-and-configuration) - [Usage](#usage) @@ -20,22 +21,27 @@ More demo examples can be found in the [showcase issue](https://github.com/nvim- --- +## Requirements +- Neovim >= **0.9.0** +- [fd](https://github.com/sharkdp/fd) (optional, for faster browser) +- git (optional, for display git status) + ## Installation Install the plugin with your preferred package manager. ```lua --- packer -use { - "nvim-telescope/telescope-file-browser.nvim", - requires = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" } -} - --lazy { "nvim-telescope/telescope-file-browser.nvim", dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" } } + +-- packer +use { + "nvim-telescope/telescope-file-browser.nvim", + requires = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" } +} ```
@@ -49,12 +55,6 @@ Plug 'nvim-telescope/telescope-file-browser.nvim'
-#### Optional Dependencies - -- `telescope-file-browser` optionally leverages [fd](https://github.com/sharkdp/fd) if installed for faster, more async browsing -- [`nvim-web-devicons`](https://github.com/nvim-tree/nvim-web-devicons) for file icons -- `git` to show the status of files directly in the file browser. - ## Setup and Configuration You can configure the `telescope-file-browser` like any other `telescope.nvim` picker. Please see `:h telescope-file-browser.picker` for the full set of options dedicated to the picker. Unless otherwise stated, you can pass these options either to your configuration at extension setup or picker startup. For instance, you can map `theme` and [mappings](#remappings) as you are used to from `telescope.nvim`. From 73a4d6a30e033ed139e1935ff27dde89296acdb2 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Fri, 22 Mar 2024 21:15:47 -0400 Subject: [PATCH 3/6] fix(make_entry): ordinal & display for higher depth search (#373) --- .../_extensions/file_browser/actions.lua | 2 +- .../_extensions/file_browser/make_entry.lua | 25 ++++++++-------- .../file_browser/make_entry_utils.lua | 30 +++++++++++++++++++ .../_extensions/file_browser/utils.lua | 23 ++++++++++---- lua/tests/make_entry_spec.lua | 24 +++++++++++++++ 5 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 lua/telescope/_extensions/file_browser/make_entry_utils.lua create mode 100644 lua/tests/make_entry_spec.lua diff --git a/lua/telescope/_extensions/file_browser/actions.lua b/lua/telescope/_extensions/file_browser/actions.lua index 7f03a16..e81af9e 100755 --- a/lua/telescope/_extensions/file_browser/actions.lua +++ b/lua/telescope/_extensions/file_browser/actions.lua @@ -93,7 +93,7 @@ end local function newly_created_root(path, cwd) local idx local parents = path:parents() - cwd = fb_utils.trim_right_os_sep(cwd) + cwd = fb_utils.sanitize_path_str(cwd) for i, p in ipairs(parents) do if p == cwd then idx = i diff --git a/lua/telescope/_extensions/file_browser/make_entry.lua b/lua/telescope/_extensions/file_browser/make_entry.lua index cf29fbb..f57776b 100644 --- a/lua/telescope/_extensions/file_browser/make_entry.lua +++ b/lua/telescope/_extensions/file_browser/make_entry.lua @@ -1,15 +1,15 @@ -local fb_utils = require "telescope._extensions.file_browser.utils" +local Path = require "plenary.path" +local action_state = require "telescope.actions.state" +local entry_display = require "telescope.pickers.entry_display" local fb_git = require "telescope._extensions.file_browser.git" +local fb_utils = require "telescope._extensions.file_browser.utils" +local fb_make_entry_utils = require "telescope._extensions.file_browser.make_entry_utils" local fs_stat = require "telescope._extensions.file_browser.fs_stat" -local utils = require "telescope.utils" local log = require "telescope.log" -local entry_display = require "telescope.pickers.entry_display" -local action_state = require "telescope.actions.state" +local os_sep = Path.path.sep local state = require "telescope.state" local strings = require "plenary.strings" -local Path = require "plenary.path" -local os_sep = Path.path.sep -local os_sep_len = #os_sep +local utils = require "telescope.utils" local sep = " " @@ -114,9 +114,9 @@ local make_entry = function(opts) }) -- needed since Path:make_relative does not resolve parent dirs - local parent_dir = Path:new(opts.cwd):parent():absolute() + local parent_dir = fb_utils.sanitize_path_str(Path:new(opts.cwd):parent():absolute()) local mt = {} - mt.cwd = opts.cwd + mt.cwd = fb_utils.sanitize_path_str(opts.cwd) -- TODO(fdschmidt93): handle VimResized with due to variable width mt.display = function(entry) @@ -125,7 +125,7 @@ local make_entry = function(opts) local display_array = {} local icon, icon_hl - local tail = fb_utils.trim_right_os_sep(entry.ordinal) + local tail = fb_utils.sanitize_path_str(entry.ordinal) local path_display = utils.transform_path(opts, tail) if entry.is_dir then @@ -235,14 +235,13 @@ local make_entry = function(opts) end return function(absolute_path) - absolute_path = fb_utils.trim_right_os_sep(absolute_path) + absolute_path = fb_utils.sanitize_path_str(absolute_path) local path = Path:new(absolute_path) local is_dir = path:is_dir() local e = setmetatable({ absolute_path, - ordinal = (absolute_path == opts.cwd and ".") - or (absolute_path == parent_dir and ".." or vim.fs.basename(absolute_path)), + ordinal = fb_make_entry_utils.get_ordinal_path(absolute_path, opts.cwd, parent_dir), Path = path, path = absolute_path, is_dir = is_dir, diff --git a/lua/telescope/_extensions/file_browser/make_entry_utils.lua b/lua/telescope/_extensions/file_browser/make_entry_utils.lua new file mode 100644 index 0000000..8f7c752 --- /dev/null +++ b/lua/telescope/_extensions/file_browser/make_entry_utils.lua @@ -0,0 +1,30 @@ +local Path = require "plenary.path" +local fb_utils = require "telescope._extensions.file_browser.utils" + +local os_sep = Path.path.sep +local os_sep_len = #os_sep + +local M = {} + +--- compute ordinal path +--- accounts for `auto_depth` option +---@param path string +---@param cwd string +---@param parent string +---@return string +M.get_ordinal_path = function(path, cwd, parent) + path = fb_utils.sanitize_path_str(path) + if path == cwd then + return "." + elseif path == parent then + return ".." + end + + local cwd_substr = #cwd + 1 + print(cwd_substr) + cwd_substr = cwd:sub(-1, -1) ~= os_sep and cwd_substr + os_sep_len or cwd_substr + + return path:sub(cwd_substr, -1) +end + +return M diff --git a/lua/telescope/_extensions/file_browser/utils.lua b/lua/telescope/_extensions/file_browser/utils.lua index 6bca186..0365e62 100644 --- a/lua/telescope/_extensions/file_browser/utils.lua +++ b/lua/telescope/_extensions/file_browser/utils.lua @@ -10,6 +10,8 @@ local truncate = require("plenary.strings").truncate local fb_utils = {} +local iswin = vim.loop.os_uname().sysname == "Windows_NT" + fb_utils.is_dir = function(path) if Path.is_path(path) then return path:is_dir() @@ -181,17 +183,28 @@ fb_utils.notify = function(funname, opts) end end --- trim the right most os separator from a path string -fb_utils.trim_right_os_sep = function(path) - return path:sub(-1, -1) ~= os_sep and path or path:sub(1, -1 - #os_sep) +--- de-dupe os_sep and right trim os_sep nearly everywhere +--- exception for root dir path (`/` or `C:\`) +---@param path string +---@return string +fb_utils.sanitize_path_str = function(path) + path = path:gsub(os_sep .. os_sep, os_sep) + if iswin then + if path:match "^%w:\\$" then + return path + else + return (path:gsub("(.)\\$", "%1")) + end + end + return (path:gsub("(.)/$", "%1")) end local _get_selection_index = function(path, dir, results) local path_dir = Path:new(path):parent():absolute() - path = fb_utils.trim_right_os_sep(path) + path = fb_utils.sanitize_path_str(path) if dir == path_dir then for i, path_entry in ipairs(results) do - if fb_utils.trim_right_os_sep(path_entry.value) == path then + if fb_utils.sanitize_path_str(path_entry.value) == path then return i end end diff --git a/lua/tests/make_entry_spec.lua b/lua/tests/make_entry_spec.lua new file mode 100644 index 0000000..62dbc9c --- /dev/null +++ b/lua/tests/make_entry_spec.lua @@ -0,0 +1,24 @@ +local me_utils = require "telescope._extensions.file_browser.make_entry_utils" + +describe("get_ordinal_path", function() + it("shows '.' for cwd", function() + assert.are.same(".", me_utils.get_ordinal_path("/home/a/b/c", "/home/a/b/c", "/home/a/b")) + assert.are.same(".", me_utils.get_ordinal_path("/home/a/b/c", "/home/a/b/c", "/home/a/b")) + end) + + it("shows '..' for parent path", function() + assert.are.same("..", me_utils.get_ordinal_path("/home/a/b", "/home/a/b/c", "/home/a/b")) + end) + + it("shows basename for cwd file", function() + assert.are.same("file.txt", me_utils.get_ordinal_path("/home/a/b/c/file.txt", "/home/a/b/c", "/home/a/b")) + end) + + it("handles depths greater than 1", function() + assert.are.same("d/file.txt", me_utils.get_ordinal_path("/home/a/b/c/d/file.txt", "/home/a/b/c", "/home/a/b")) + 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")) + end) +end) From 789558e60c664137b9deed7a69d65ac0a3e5a316 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Fri, 22 Mar 2024 23:39:43 -0400 Subject: [PATCH 4/6] fix: remove print (#374) --- lua/telescope/_extensions/file_browser/make_entry_utils.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/telescope/_extensions/file_browser/make_entry_utils.lua b/lua/telescope/_extensions/file_browser/make_entry_utils.lua index 8f7c752..200c5ca 100644 --- a/lua/telescope/_extensions/file_browser/make_entry_utils.lua +++ b/lua/telescope/_extensions/file_browser/make_entry_utils.lua @@ -21,7 +21,6 @@ M.get_ordinal_path = function(path, cwd, parent) end local cwd_substr = #cwd + 1 - print(cwd_substr) cwd_substr = cwd:sub(-1, -1) ~= os_sep and cwd_substr + os_sep_len or cwd_substr return path:sub(cwd_substr, -1) From fe102e6f6c1af5e7cbba1a0a7b2cd8ee136c2ea0 Mon Sep 17 00:00:00 2001 From: kobylianskii <122800364+kobylianskii@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:37:50 +0100 Subject: [PATCH 5/6] docs(readme): fix setup example (#375) Couldn't load config without these commas --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b4d9e85..0c94a0f 100644 --- a/README.md +++ b/README.md @@ -95,8 +95,8 @@ local fb_actions = require "telescope._extensions.file_browser.actions" require("telescope").setup { extensions = { file_browser = { - path = vim.loop.cwd() - cwd = vim.loop.cwd() + path = vim.loop.cwd(), + cwd = vim.loop.cwd(), cwd_to_path = false, grouped = false, files = true, @@ -105,7 +105,7 @@ require("telescope").setup { auto_depth = false, select_buffer = false, hidden = { file_browser = false, folder_browser = false }, - respect_gitignore = vim.fn.executable "fd" == 1 + respect_gitignore = vim.fn.executable "fd" == 1, no_ignore = false, follow_symlinks = false, browse_files = require("telescope._extensions.file_browser.finders").browse_files, From e7f86603fb28d95054235b0b073a82a384025f70 Mon Sep 17 00:00:00 2001 From: James Trew <66286082+jamestrew@users.noreply.github.com> Date: Sat, 23 Mar 2024 20:40:31 -0400 Subject: [PATCH 6/6] build: rework ci actions (#376) - Add testing github actions workflow - Tweak docgen workflow so it's easier to do locally --- .github/workflows/docgen.yml | 49 +++++--------- .github/workflows/lint.yml | 2 +- .github/workflows/test.yml | 32 +++++++++ .gitignore | 1 + Makefile | 37 ++++++++++- .../_extensions/file_browser/utils.lua | 2 +- lua/tests/fb_git_spec.lua | 65 +++++++++++++++++-- lua/tests/make_entry_spec.lua | 10 ++- scripts/minimal_init.vim | 6 +- 9 files changed, 160 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/docgen.yml b/.github/workflows/docgen.yml index f0a7f74..63dc052 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 774b108..2c45980 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 0000000..313971d --- /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 926ccaa..7aa68e8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ doc/tags +deps/ diff --git a/Makefile b/Makefile index 3dbeb14..183d710 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 0365e62..1f45ce7 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 77c2e05..5d49dbc 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 62dbc9c..2fb1120 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 520d9d5..88a5592 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