~cjoly/telescope-repo.nvim

78dedcf656288c196118af9e41d666fac62d57c4 — Clément Joly 1 year, 8 months ago 6b32ac9 + 867f87a
Merge branch 'dev'
A .editorconfig => .editorconfig +14 -0
@@ 0,0 1,14 @@
root                     = true

[*]
end_of_line              = lf
insert_final_newline     = true
trim_trailing_whitespace = true
charset                  = utf-8

[*.lua]
indent_style             = space
indent_size              = 4

[Makefile]
indent_style             = tab

M .github/workflows/lint.yml => .github/workflows/lint.yml +1 -0
@@ 28,3 28,4 @@ jobs:
            token: ${{ secrets.GITHUB_TOKEN }}
            # CLI arguments
            args: --check .
            version: 0.13.1

M README.md => README.md +45 -2
@@ 106,7 106,50 @@ use {

## Usage

### list
### Global Configuration

You can change the default argument given to subcommands (like [`list`](#list) or [`cached_list`](#cached_list)) using the telescope `setup` function with a table like this:

```lua
{
  extensions = {
    repo = {
      <subcommand> = {
        <argument> = {
          "new",
          "default",
          "value",
        },
      },
    },
  },
}
```

for instance, you could do:

```lua
require("telescope").setup {
  extensions = {
    repo = {
      list = {
        fd_opts = {
          "--no-ignore-vcs",
        },
        search_dirs = {
          "~/my_projects",
        },
      },
    },
  },
}

require("telescope").load_extension "repo"
```

**Note**: make sure to have `require("telescope").load_extension "repo"` *after* the call to `require("telescope").setup {…}`, otherwise the global configuration won’t be taken into account.

### `list`

`:Telescope repo list` or `lua require'telescope'.extensions.repo.list{}`



@@ 198,7 241,7 @@ Here is how you can use this plugin with various SCM:

Is your favorite SCM missing? It should be straightforward to support it by changing the pattern parameter. If you want it to be considered for addition here, open a PR!

### cached_list
### `cached_list`

`:Telescope repo cached_list`


M lua/telescope/_extensions/repo.lua => lua/telescope/_extensions/repo.lua +2 -0
@@ 1,10 1,12 @@
local main = require("telescope._extensions.repo.main")
local r_config = require("telescope._extensions.repo.config")
local health = require("telescope._extensions.repo.health")

local fallback_error = { "Falling back to `:Telescope repo list`, but this behavior may change in the future" }

return require("telescope").register_extension({
    health = health.check,
    setup = r_config.setup,
    exports = {
        list = main.list,
        cached_list = main.cached_list,

M lua/telescope/_extensions/repo/cached_list.lua => lua/telescope/_extensions/repo/cached_list.lua +1 -1
@@ 7,7 7,7 @@ local utils = require("telescope._extensions.repo.utils")
M.prepare_command = function(opts)
    opts = opts or {}
    opts.bin = opts.bin or utils.find_locate_binary()
    if opts.bin == "" then
    if not opts.bin then
        error("Please install locate (or one of its alternatives)")
    end
    opts.cwd = vim.env.HOME

A lua/telescope/_extensions/repo/config.lua => lua/telescope/_extensions/repo/config.lua +9 -0
@@ 0,0 1,9 @@
local M = {}

M.values = {}

M.setup = function(opts)
    M.values = opts
end

return M

M lua/telescope/_extensions/repo/health.lua => lua/telescope/_extensions/repo/health.lua +25 -9
@@ 4,7 4,8 @@ local utils = require("telescope._extensions.repo.utils")
local list = require("telescope._extensions.repo.list")
local cached_list = require("telescope._extensions.repo.cached_list")

local health = require("health")
-- TODO Keep only vim.health once nvim 0.8 is required
local health = vim.health or require("health")

local Job = require("plenary.job")
local max_repo = 2


@@ 45,7 46,7 @@ end

local function check_list_cmd()
    local fd_bin = utils.find_fd_binary()
    if fd_bin ~= "" then
    if fd_bin then
        health.report_ok("fd: found `" .. fd_bin .. "`\n" .. get_version(fd_bin))

        local opts = {}


@@ 58,7 59,7 @@ end

local function check_cached_list_cmd()
    local locate_bin = utils.find_locate_binary()
    if locate_bin ~= "" then
    if locate_bin then
        health.report_ok("locate: found `" .. locate_bin .. "`\n" .. get_version(locate_bin))

        local opts = {}


@@ 78,23 79,38 @@ local function check_cached_list_cmd()
    end
end

local function check_previewer()
local function check_previewer_md()
    local markdown_bin = utils.find_markdown_previewer_for_document("test_doc.md")
    if markdown_bin[1] ~= utils._markdown_previewer[1][1] then
        health.report_warn("Install `" .. utils._markdown_previewer[1][1] .. "` for a better preview of markdown files")
    if not markdown_bin then
        health.report_error("No markdown previewer found, the extension will not work properly")
        return
    end
    health.report_ok("Will use `" .. markdown_bin[1] .. "` to preview markdown READMEs")

    local first = utils._markdown_previewer[1][1]
    if markdown_bin[1] ~= first then
        health.report_warn("Install `" .. first .. "` for a better preview of markdown files")
    end
end

local function check_previewer_generic()
    local generic_bin = utils.find_generic_previewer_for_document("test_doc")
    if generic_bin[1] ~= utils._generic_previewer[1][1] then
        health.report_warn("Install `" .. utils._generic_previewer[1][1] .. "` for a better preview of other files")
    if not generic_bin then
        health.report_error("No markdown previewer found, the extension will not work properly")
        return
    end
    health.report_ok("Will use `" .. generic_bin[1] .. "` to preview non-markdown READMEs")

    local first = utils._generic_previewer[1][1]
    if generic_bin[1] ~= first then
        health.report_warn("Install `" .. first .. "` for a better preview of other files")
    end
end

M.check = function()
    -- Ordered from fastest to slowest
    check_previewer()
    check_previewer_generic()
    check_previewer_md()
    check_cached_list_cmd()
    check_list_cmd()
end

M lua/telescope/_extensions/repo/list.lua => lua/telescope/_extensions/repo/list.lua +1 -1
@@ 7,7 7,7 @@ local utils = require("telescope._extensions.repo.utils")
M.prepare_command = function(opts)
    opts = opts or {}
    opts.bin = opts.bin or utils.find_fd_binary()
    if opts.bin == "" then
    if not opts.bin then
        error("fd not found, is fd installed?")
    end
    opts.cwd = vim.env.HOME

M lua/telescope/_extensions/repo/main.lua => lua/telescope/_extensions/repo/main.lua +3 -2
@@ 17,6 17,7 @@ local Path = require("plenary.path")
local utils = require("telescope._extensions.repo.utils")
local list = require("telescope._extensions.repo.list")
local cached_list = require("telescope._extensions.repo.cached_list")
local r_config = require("telescope._extensions.repo.config")

local M = {}



@@ 187,7 188,7 @@ end

-- List of repos built using locate (or variants)
M.cached_list = function(opts)
    opts = opts or {}
    opts = vim.tbl_deep_extend("force", r_config.values.cached_list or {}, opts or {})
    opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_locate_wrapper, opts)
    local locate_command = cached_list.prepare_command(opts)



@@ 196,7 197,7 @@ end

-- Always up to date list of repos built using fd
M.list = function(opts)
    opts = opts or {}
    opts = vim.tbl_deep_extend("force", r_config.values.list or {}, opts or {})
    opts.entry_maker = t_utils.get_lazy_default(opts.entry_maker, gen_from_fd, opts)
    local fd_command = list.prepare_command(opts)


M lua/telescope/_extensions/repo/utils.lua => lua/telescope/_extensions/repo/utils.lua +7 -3
@@ 9,7 9,7 @@ local function find_binary(binaries)
            return vim.deepcopy(binary)
        end
    end
    return ""
    return nil
end

-- Find under what name fd is installed.


@@ 26,7 26,9 @@ M._generic_previewer = { { "bat", "--style", "header,grid" }, { "cat" } }

M.find_generic_previewer_for_document = function(doc)
    local l = find_binary(M._generic_previewer)
    table.insert(l, doc)
    if l then
        table.insert(l, doc)
    end
    return l
end



@@ 35,7 37,9 @@ vim.list_extend(M._markdown_previewer, M._generic_previewer)

M.find_markdown_previewer_for_document = function(doc)
    local l = find_binary(M._markdown_previewer)
    table.insert(l, doc)
    if l then
        table.insert(l, doc)
    end
    return l
end


M lua/tests/automated/list_command_spec.lua => lua/tests/automated/list_command_spec.lua +4 -0
@@ 1,4 1,8 @@
describe("integration tests: ", function()
    it("Telescope repo repo", function()
        vim.cmd([[Telescope repo repo]])
    end)

    it("Telescope repo list", function()
        vim.cmd([[Telescope repo list]])
    end)