fix: a lot of small things and adds more customization for caret (#554)

Attention:
prompt_prefix will no longer add a space at the end. So if you still want a space at the end make sure your configuration has one.
The default should not be changed. So if you haven't copied prompt_prefix in your config this doesn't affect you.

Feat:
- prompt prefix does no longer always end with space
- selection_caret configurable. Default: `> `
- result_prefix configurable. Default: `  `
- more actions for git_branches
  - <c-t> does track the branch
  - <c-r> does rebase branch
  - also added delete branch action but not configured. See readme on how to do that

Fixes:
- fix docgen ci
- Better error for lsp_workspace_symbols
- better formatting for CONTRIBUTING.md
- move from systemlist to plenary.job
- git branch now supports checkout on remote branches
This commit is contained in:
Simon Hauser
2021-02-27 16:26:25 +01:00
committed by GitHub
parent 84732d1d78
commit ca92ec1a83
12 changed files with 209 additions and 112 deletions

View File

@@ -16,12 +16,6 @@ jobs:
path: build path: build
key: ${{ runner.os }}-appimage-${{ hashFiles('todays-date') }} key: ${{ runner.os }}-appimage-${{ hashFiles('todays-date') }}
- name: Restore cache for tree-sitter
uses: actions/cache@v2
with:
path: _ts
key: ${{ runner.os }}-ts-${{ hashFiles('todays-date') }}
- name: Prepare - name: Prepare
run: | run: |
test -d build || { test -d build || {
@@ -30,41 +24,36 @@ jobs:
chmod +x nvim.appimage chmod +x nvim.appimage
mv nvim.appimage ./build/nvim mv nvim.appimage ./build/nvim
} }
test -d _ts || {
# Pining version. Not sure if we should actually do that
mkdir -p _ts
wget https://github.com/tree-sitter/tree-sitter/releases/download/0.17.3/tree-sitter-linux-x64.gz
gzip -d tree-sitter-linux-x64
chmod +x tree-sitter-linux-x64
mv tree-sitter-linux-x64 ./_ts/tree-sitter
}
mkdir -p ~/.local/share/nvim/site/pack/vendor/start 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 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 ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- name: Build parser - name: Build parser
run: | run: |
# We have to build the parser every single time to keep up with parser changes # We have to build the parser every single time to keep up with parser changes
export PATH="${PWD}/_ts/:${PATH}"
cd ~/.local/share/nvim/site/pack/vendor/start/tree-sitter-lua cd ~/.local/share/nvim/site/pack/vendor/start/tree-sitter-lua
mkdir -p build parser mkdir -p build parser
make build_parser cc -o ./build/parser.so -I./src src/parser.c src/scanner.cc -shared -Os -lstdc++ -fPIC
ln -s ../build/parser.so parser/lua.so ln -s ../build/parser.so parser/lua.so
cd cd -
- name: Generating docs
run: |
export PATH="${PWD}/build/:${PATH}"
make docgen
# inspired by nvim-lspconfigs # inspired by nvim-lspconfigs
- name: Generating docs - name: Update documentation
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMIT_MSG: | COMMIT_MSG: |
[Actions] Generate Documentation [docgen] Update doc/telescope.txt
skip-checks: true skip-checks: true
run: | run: |
export PATH="${PWD}/build/:${PATH}"
git config user.email "actions@github" git config user.email "actions@github"
git config user.name "Github Actions" git config user.name "Github Actions"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
make docgen
git add doc/ git add doc/
# Only commit and push if we have changes # 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}) git diff --quiet && git diff --staged --quiet || (git commit -m "${COMMIT_MSG}"; git push origin HEAD:${GITHUB_REF})

View File

@@ -2,47 +2,58 @@
is generating docs based on the tree sitter syntax tree. TJ wrote a grammar that includes the documentation in this syntax tree so we can do take this function header documentation and transform it into vim documentation. All documentation will be exported that is part of the returning module. So example: is generating docs based on the tree sitter syntax tree. TJ wrote a grammar that includes the documentation in this syntax tree so we can do take this function header documentation and transform it into vim documentation. All documentation will be exported that is part of the returning module. So example:
```lua
local m = {} local m = {}
--- Test Header --- Test Header
--@return 1: Returns always 1 --@return 1: Returns always 1
function m.a() function m.a() -- or m:a()
return 1 return 1
end end
return m --- Documentation
function m.__b() -- or m:__b()
return 2
end
Something like this. --- Documentation
What is missing? local c = function()
return 2
end
return m
```
This will export function `a` with header documentation and the return value. Module function `b` and local function `c` will not be exported.
## What is missing?
The docgen has some problems on which people can work. This would happen in https://github.com/tjdevries/tree-sitter-lua and documentation of some modules here. The docgen has some problems on which people can work. This would happen in https://github.com/tjdevries/tree-sitter-lua and documentation of some modules here.
I would suggest we are documenting lua/telescope/builtin/init.lua rather than the files itself. We can use that init.lua file as "header" file, so we are not cluttering the other files. I would suggest we are documenting lua/telescope/builtin/init.lua rather than the files itself. We can use that init.lua file as "header" file, so we are not cluttering the other files.
How to do it: How to help out with documentation:
## Auto-updates from CI ## Auto-updates from CI
The easy way would be after this PR is merged The easy way would be:
write some docs - write some docs
commit and push - commit, push and create draft PR
wait a minute until the CI generates a new commit with the changes - wait a minute until the CI generates a new commit with the changes
Look at this commit and the changes - Look at this commit and the changes
And apply new changes with git commit --amend and git push --force to remove that github ci commit again. - Modify documentation until its perfect. You can do `git commit --amend` and `git push --force` to remove the github ci commit again
Repeat until done
## Generate on your local machine ## Generate on your local machine
The other option would be setting up https://github.com/tjdevries/tree-sitter-lua The other option would be setting up https://github.com/tjdevries/tree-sitter-lua
Install Treesitter, either with package manager or with github release - Install Treesitter, either with package manager or with github release
Install plugin as usual - Install plugin as usual
cd to plugin - cd to plugin
mkdir -p build parser Sadly does doesn't exist laughing - `mkdir -p build parser` sadly does doesn't exist
make build_parser - `make build_parser`
ln -s ../build/parser.so parser/lua.so We need the so in parser/ so it gets picked up by neovim. Either copy or symbolic link - `ln -s ../build/parser.so parser/lua.so` We need the shared object in parser/ so it gets picked up by neovim. Either copy or symbolic link
Make sure that nvim-treesitter lua parser is not installed and also delete the lua queries in that repository. queries/lua/*. If you are not doing that you will have a bad time - Make sure that nvim-treesitter lua parser is not installed and also delete the lua queries in that repository. `queries/lua/*`. If you are not doing that you will have a bad time!
cd into this project - cd into this project
Write doc - Write doc
Run make docgen - Run `make docgen`
Repeat last two steps - Repeat last two steps

View File

@@ -139,7 +139,9 @@ require('telescope').setup{
'--smart-case' '--smart-case'
}, },
prompt_position = "bottom", prompt_position = "bottom",
prompt_prefix = ">", prompt_prefix = "> ",
selection_caret = "> ",
entry_prefix = " ",
initial_mode = "insert", initial_mode = "insert",
selection_strategy = "reset", selection_strategy = "reset",
sorting_strategy = "descending", sorting_strategy = "descending",
@@ -191,6 +193,8 @@ EOF
|------------------------|-------------------------------------------------------|----------------------------| |------------------------|-------------------------------------------------------|----------------------------|
| `prompt_position` | Where the prompt should be located. | top/bottom | | `prompt_position` | Where the prompt should be located. | top/bottom |
| `prompt_prefix` | What should the prompt prefix be. | string | | `prompt_prefix` | What should the prompt prefix be. | string |
| `selection_caret` | What should the selection caret be. | string |
| `entry_prefix` | What should be shown in front of every entry. (current selection excluded) | string|
| `initial_mode` | The initial mode when a prompt is opened. | insert/normal | | `initial_mode` | The initial mode when a prompt is opened. | insert/normal |
| `sorting_strategy` | Where first selection should be located. | descending/ascending | | `sorting_strategy` | Where first selection should be located. | descending/ascending |
| `layout_strategy` | How the telescope is drawn. | [supported layouts](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts) | | `layout_strategy` | How the telescope is drawn. | [supported layouts](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts) |
@@ -202,7 +206,7 @@ EOF
| `results_width` | TODO | NUM | | `results_width` | TODO | NUM |
| `borderchars` | The border chars, it gives border telescope window | dict | | `borderchars` | The border chars, it gives border telescope window | dict |
| `color_devicons` | Whether to color devicons or not | boolean | | `color_devicons` | Whether to color devicons or not | boolean |
| `use_less` | Whether to use less with bat or less/cat if bat not installed | boolean | | `use_less` | Whether to use less with bat or less/cat if bat not installed | boolean |
| `set_env` | Set environment variables for previewer | dict | | `set_env` | Set environment variables for previewer | dict |
| `scroll_strategy` | How to behave when the when there are no more item next/prev | cycle, nil | | `scroll_strategy` | How to behave when the when there are no more item next/prev | cycle, nil |
| `file_previewer` | What telescope previewer to use for files. | [Previewers](#previewers) | | `file_previewer` | What telescope previewer to use for files. | [Previewers](#previewers) |
@@ -333,6 +337,14 @@ require('telescope.builtin').fd({ -- or new custom picker's attach_mappings fiel
return true return true
end, end,
}) })
------------------------------
-- More practical example of adding a new mapping
require'telescope.builtin'.git_branches({ attach_mappings = function(_, map)
map('i', '<c-d>', actions.git_delete_branch) -- this action already exist
map('n', '<c-d>', actions.git_delete_branch) -- this action already exist
-- for more actions look at lua/telescope/actions/init.lua
return true
end})
``` ```
For more info, see [./developers.md](./developers.md) For more info, see [./developers.md](./developers.md)
@@ -400,7 +412,7 @@ Built-in functions. Ready to be bound to any key you like. :smile:
|-------------------------------------|---------------------------------------------------------------------------------------------| |-------------------------------------|---------------------------------------------------------------------------------------------|
| `builtin.git_commits` | Lists git commits with diff preview and on enter checkout the commit. | | `builtin.git_commits` | Lists git commits with diff preview and on enter checkout the commit. |
| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checkouts it out on enter. | | `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checkouts it out on enter. |
| `builtin.git_branches` | Lists all branches with log preview and checkout action. | | `builtin.git_branches` | Lists all branches with log preview, checkout action (<cr>), track action (<c-t>) and rebase action(<c-r>). |
| `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multiselection still WIP) | | `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multiselection still WIP) |
| .................................. | Your next awesome picker function here :D | | .................................. | Your next awesome picker function here :D |

View File

@@ -7,6 +7,11 @@ filter, find and pick things in Lua.
To find out more: To find out more:
https://github.com/nvim-telescope/telescope.nvim https://github.com/nvim-telescope/telescope.nvim
:h telescope.setup
:h telescope.builtin
:h telescope.layout
:h telescope.actions
telescope.extensions() *telescope.extensions()* telescope.extensions() *telescope.extensions()*
Use telescope.extensions to reference any extensions within your Use telescope.extensions to reference any extensions within your
@@ -43,6 +48,18 @@ telescope.setup({opts}) *telescope.setup()*
Valid keys for {opts.defaults} Valid keys for {opts.defaults}
*telescope.defaults.entry_prefix*
entry_prefix: ~
Prefix in front of each result entry. Current selection not included.
Default: ' '
*telescope.defaults.prompt_prefix*
prompt_prefix: ~
Will be shown in front of the prompt.
Default: '> '
*telescope.defaults.scroll_strategy* *telescope.defaults.scroll_strategy*
scroll_strategy: ~ scroll_strategy: ~
Determines what happens you try to scroll past view of the picker. Determines what happens you try to scroll past view of the picker.
@@ -51,6 +68,12 @@ telescope.setup({opts}) *telescope.setup()*
- "cycle" (default) - "cycle" (default)
- "limit" - "limit"
*telescope.defaults.selection_caret*
selection_caret: ~
Will be shown in front of the selection.
Default: '> '
*telescope.defaults.selection_strategy* *telescope.defaults.selection_strategy*
selection_strategy: ~ selection_strategy: ~
Determines how the cursor acts after each sort iteration. Determines how the cursor acts after each sort iteration.

View File

@@ -264,7 +264,72 @@ actions.git_checkout = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
utils.get_os_command_output({ 'git', 'checkout', selection.value }, cwd) local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', selection.value }, cwd)
if ret == 0 then
print("Checked out: " .. selection.value)
else
print(string.format(
'Error when checking out: %s. Git returned: "%s"',
selection.value,
table.concat(stderr, ' ')
))
end
end
actions.git_track_branch = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
actions.close(prompt_bufnr)
local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '--track', selection.value }, cwd)
if ret == 0 then
print("Tracking branch: " .. selection.value)
else
print(string.format(
'Error when tracking branch: %s. Git returned: "%s"',
selection.value,
table.concat(stderr, ' ')
))
end
end
actions.git_delete_branch = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
local confirmation = vim.fn.input('Do you really wanna delete branch ' .. selection.value .. '? [Y/n] ')
if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end
actions.close(prompt_bufnr)
local _, ret, stderr = utils.get_os_command_output({ 'git', 'branch', '-D', selection.value }, cwd)
if ret == 0 then
print("Deleted branch: " .. selection.value)
else
print(string.format(
'Error when deleting branch: %s. Git returned: "%s"',
selection.value,
table.concat(stderr, ' ')
))
end
end
actions.git_rebase_branch = function(prompt_bufnr)
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
local selection = action_state.get_selected_entry()
local confirmation = vim.fn.input('Do you really wanna delete branch ' .. selection.value .. '? [Y/n] ')
if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end
actions.close(prompt_bufnr)
local _, ret, stderr = utils.get_os_command_output({ 'git', 'rebase', selection.value }, cwd)
if ret == 0 then
print("Rebased branch: " .. selection.value)
else
print(string.format(
'Error when rebasing branch: %s. Git returned: "%s"',
selection.value,
table.concat(stderr, ' ')
))
end
end end
actions.git_staging_toggle = function(prompt_bufnr) actions.git_staging_toggle = function(prompt_bufnr)

View File

@@ -79,20 +79,15 @@ end
git.branches = function(opts) git.branches = function(opts)
local output = utils.get_os_command_output({ 'git', 'branch', '--all' }, opts.cwd) local output = utils.get_os_command_output({ 'git', 'branch', '--all' }, opts.cwd)
local tmp_results = {} local results = {}
for _, v in ipairs(output) do for _, v in ipairs(output) do
if not string.match(v, 'HEAD') and v ~= '' then if not string.match(v, 'HEAD') and v ~= '' then
v = string.gsub(v, '.* ', '') v = string.gsub(v, '.* ', '')
v = string.gsub(v, '^remotes/[^/]*/', '') v = string.gsub(v, '^remotes/', '')
tmp_results[v] = true table.insert(results, v)
end end
end end
local results = {}
for k, _ in pairs(tmp_results) do
table.insert(results, k)
end
pickers.new(opts, { pickers.new(opts, {
prompt_title = 'Git Branches', prompt_title = 'Git Branches',
finder = finders.new_table { finder = finders.new_table {
@@ -103,8 +98,13 @@ git.branches = function(opts)
}, },
previewer = previewers.git_branch_log.new(opts), previewer = previewers.git_branch_log.new(opts),
sorter = conf.file_sorter(opts), sorter = conf.file_sorter(opts),
attach_mappings = function() attach_mappings = function(_, map)
actions.select_default:replace(actions.git_checkout) actions.select_default:replace(actions.git_checkout)
map('i', '<c-t>', actions.git_track_branch)
map('n', '<c-t>', actions.git_track_branch)
map('i', '<c-r>', actions.git_rebase_branch)
map('n', '<c-r>', actions.git_rebase_branch)
return true return true
end end
}):find() }):find()
@@ -155,14 +155,14 @@ local set_opts_cwd = function(opts)
end end
-- Find root of git directory and remove trailing newline characters -- Find root of git directory and remove trailing newline characters
local git_root = vim.fn.systemlist("git -C " .. opts.cwd .. " rev-parse --show-toplevel")[1] local git_root, ret = utils.get_os_command_output({ "git", "rev-parse", "--show-toplevel" }, opts.cwd)
local use_git_root = utils.get_default(opts.use_git_root, true) local use_git_root = utils.get_default(opts.use_git_root, true)
if vim.v.shell_error ~= 0 then if ret ~= 0 then
error(opts.cwd .. ' is not a git directory') error(opts.cwd .. ' is not a git directory')
else else
if use_git_root then if use_git_root then
opts.cwd = git_root opts.cwd = git_root[1]
end end
end end
end end

View File

@@ -151,8 +151,11 @@ lsp.workspace_symbols = function(opts)
local params = {query = opts.query or ''} local params = {query = opts.query or ''}
local results_lsp = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000) local results_lsp = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000)
if not results_lsp or vim.tbl_isempty(results_lsp) then -- Clangd returns { { result = {} } } for query=''
print("No results from workspace/symbol") if not results_lsp or vim.tbl_isempty(results_lsp) or
vim.tbl_isempty(results_lsp[1]) or vim.tbl_isempty(results_lsp[1].result) then
print("No results from workspace/symbol. Maybe try a different query: " ..
"Telescope lsp_workspace_symbols query=example")
return return
end end
@@ -167,7 +170,6 @@ lsp.workspace_symbols = function(opts)
return return
end end
opts.ignore_filename = utils.get_default(opts.ignore_filename, false) opts.ignore_filename = utils.get_default(opts.ignore_filename, false)
opts.hide_filename = utils.get_default(opts.hide_filename, false) opts.hide_filename = utils.get_default(opts.hide_filename, false)

View File

@@ -75,7 +75,21 @@ function config.set_defaults(defaults)
set("results_height", 1) set("results_height", 1)
set("results_width", 0.8) set("results_width", 0.8)
set("prompt_prefix", ">") set("prompt_prefix", "> ", [[
Will be shown in front of the prompt.
Default: '> '
]])
set("selection_caret", "> ", [[
Will be shown in front of the selection.
Default: '> '
]])
set("entry_prefix", " ", [[
Prefix in front of each result entry. Current selection not included.
Default: ' '
]])
set("initial_mode", "insert") set("initial_mode", "insert")
set("border", {}) set("border", {})

View File

@@ -14,12 +14,11 @@ local telescope = {}
--- ---
--- To find out more: --- To find out more:
--- https://github.com/nvim-telescope/telescope.nvim --- https://github.com/nvim-telescope/telescope.nvim
-- ---
-- :h telescope.setup --- :h telescope.setup
-- :h telescope.builtin --- :h telescope.builtin
-- :h telescope.layout --- :h telescope.layout
-- :h telescope.actions --- :h telescope.actions
--
---@brief ]] ---@brief ]]
---@tag telescope.nvim ---@tag telescope.nvim

View File

@@ -57,6 +57,8 @@ function Picker:new(opts)
preview_title = get_default(opts.preview_title, "Preview"), preview_title = get_default(opts.preview_title, "Preview"),
prompt_prefix = get_default(opts.prompt_prefix, config.values.prompt_prefix), prompt_prefix = get_default(opts.prompt_prefix, config.values.prompt_prefix),
selection_caret = get_default(opts.selection_caret, config.values.selection_caret),
entry_prefix = get_default(opts.entry_prefix, config.values.entry_prefix),
initial_mode = get_default(opts.initial_mode, config.values.initial_mode), initial_mode = get_default(opts.initial_mode, config.values.initial_mode),
default_text = opts.default_text, default_text = opts.default_text,
@@ -112,7 +114,6 @@ function Picker:new(opts)
preview_cutoff = get_default(opts.preview_cutoff, config.values.preview_cutoff), preview_cutoff = get_default(opts.preview_cutoff, config.values.preview_cutoff),
}, self) }, self)
obj.scroller = p_scroller.create( obj.scroller = p_scroller.create(
get_default(opts.scroll_strategy, config.values.scroll_strategy), get_default(opts.scroll_strategy, config.values.scroll_strategy),
obj.sorting_strategy obj.sorting_strategy
@@ -375,10 +376,6 @@ function Picker:find()
local prompt_prefix = self.prompt_prefix local prompt_prefix = self.prompt_prefix
if prompt_prefix ~= '' then if prompt_prefix ~= '' then
a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt') a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt')
if not vim.endswith(prompt_prefix, " ") then
prompt_prefix = prompt_prefix .. " "
end
vim.fn.prompt_setprompt(prompt_bufnr, prompt_prefix) vim.fn.prompt_setprompt(prompt_bufnr, prompt_prefix)
end end
self.prompt_prefix = prompt_prefix self.prompt_prefix = prompt_prefix
@@ -655,9 +652,6 @@ function Picker:change_prompt_prefix(new_prefix, hl_group)
if not new_prefix then return end if not new_prefix then return end
if new_prefix ~= '' then if new_prefix ~= '' then
if not vim.endswith(new_prefix, " ") then
new_prefix = new_prefix .. " "
end
vim.fn.prompt_setprompt(self.prompt_bufnr, new_prefix) vim.fn.prompt_setprompt(self.prompt_bufnr, new_prefix)
else else
vim.api.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, #self.prompt_prefix, {}) vim.api.nvim_buf_set_text(self.prompt_bufnr, 0, 0, 0, #self.prompt_prefix, {})
@@ -733,21 +727,21 @@ function Picker:set_selection(row)
local display, display_highlights = entry_display.resolve(self, self._selection_entry) local display, display_highlights = entry_display.resolve(self, self._selection_entry)
if display then if display then
display = ' ' .. display display = self.entry_prefix .. display
a.nvim_buf_set_lines(results_bufnr, self._selection_row, self._selection_row + 1, false, {display}) a.nvim_buf_set_lines(results_bufnr, self._selection_row, self._selection_row + 1, false, {display})
self.highlighter:hi_display(self._selection_row, ' ', display_highlights) self.highlighter:hi_display(self._selection_row, self.entry_prefix, display_highlights)
self.highlighter:hi_sorter(self._selection_row, prompt, display) self.highlighter:hi_sorter(self._selection_row, prompt, display)
self.highlighter:hi_multiselect(self._selection_row, self._selection_entry) self.highlighter:hi_multiselect(self._selection_row, self._selection_entry)
end end
end end
local caret = '>' local caret = self.selection_caret
-- local display = string.format('%s %s', caret, -- local display = string.format('%s %s', caret,
-- (a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1] or ''):sub(3) -- (a.nvim_buf_get_lines(results_bufnr, row, row + 1, false)[1] or ''):sub(3)
-- ) -- )
local display, display_highlights = entry_display.resolve(self, entry) local display, display_highlights = entry_display.resolve(self, entry)
display = caret .. ' ' .. display display = caret .. display
-- TODO: You should go back and redraw the highlights for this line from the sorter. -- TODO: You should go back and redraw the highlights for this line from the sorter.
-- That's the only smart thing to do. -- That's the only smart thing to do.
@@ -757,8 +751,9 @@ function Picker:set_selection(row)
end end
a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {display}) a.nvim_buf_set_lines(results_bufnr, row, row + 1, false, {display})
self.highlighter:hi_selection(row, caret) -- don't highlight the ' ' at the end of caret
self.highlighter:hi_display(row, ' ', display_highlights) self.highlighter:hi_selection(row, caret:sub(1, -2))
self.highlighter:hi_display(row, caret, display_highlights)
self.highlighter:hi_sorter(row, prompt, display) self.highlighter:hi_sorter(row, prompt, display)
self.highlighter:hi_multiselect(row, entry) self.highlighter:hi_multiselect(row, entry)
end) end)
@@ -809,7 +804,7 @@ function Picker:entry_adder(index, entry, _, insert)
-- This is the two spaces to manage the '> ' stuff. -- This is the two spaces to manage the '> ' stuff.
-- Maybe someday we can use extmarks or floaty text or something to draw this and not insert here. -- Maybe someday we can use extmarks or floaty text or something to draw this and not insert here.
-- until then, insert two spaces -- until then, insert two spaces
local prefix = ' ' local prefix = self.entry_prefix
display = prefix .. display display = prefix .. display
self:_increment("displayed") self:_increment("displayed")
@@ -1109,7 +1104,7 @@ end
function Picker:_get_prompt() function Picker:_get_prompt()
return vim.trim( return vim.trim(
vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]:sub(#self.prompt_prefix) vim.api.nvim_buf_get_lines(self.prompt_bufnr, 0, 1, false)[1]:sub(#self.prompt_prefix + 1)
) )
end end

View File

@@ -466,40 +466,23 @@ previewers.git_branch_log = defaulter(function(opts)
end end
end end
local remotes = utils.get_os_command_output({ 'git', 'remote' }, opts.cwd)
return previewers.new_buffer_previewer { return previewers.new_buffer_previewer {
get_buffer_by_name = function(_, entry) get_buffer_by_name = function(_, entry)
return entry.value return entry.value
end, end,
define_preview = function(self, entry, status) define_preview = function(self, entry, status)
local current_remote = 1 local cmd = { 'git', '--no-pager', 'log', '--graph', '--pretty=format:%h -%d %s (%cr)',
'--abbrev-commit', '--date=relative', entry.value }
local gen_cmd = function(v) putils.job_maker(cmd, self.state.bufnr, {
return { 'git', '--no-pager', 'log', '--graph', '--pretty=format:%h -%d %s (%cr)',
'--abbrev-commit', '--date=relative', v }
end
local handle_results
handle_results = function(bufnr, content)
if content and table.getn(content) == 0 then
if current_remote <= table.getn(remotes) then
local value = 'remotes/' .. remotes[current_remote] .. '/' .. entry.value
current_remote = current_remote + 1
putils.job_maker(gen_cmd(value), bufnr, { cwd = opts.cwd, callback = handle_results })
else
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, { "No log found for branch: " .. entry.value })
end
elseif content and table.getn(content) > 1 then
highlight_buffer(bufnr, content)
end
end
putils.job_maker(gen_cmd(entry.value), self.state.bufnr, {
value = entry.value, value = entry.value,
bufname = self.state.bufname, bufname = self.state.bufname,
cwd = opts.cwd, cwd = opts.cwd,
callback = handle_results callback = function(bufnr, content)
if not content then return end
highlight_buffer(bufnr, content)
end
}) })
end end
} }

View File

@@ -199,7 +199,11 @@ function utils.get_os_command_output(cmd, cwd)
return {} return {}
end end
local command = table.remove(cmd, 1) local command = table.remove(cmd, 1)
return Job:new({ command = command, args = cmd, cwd = cwd }):sync() local stderr = {}
local stdout, ret = Job:new({ command = command, args = cmd, cwd = cwd, on_stderr = function(_, data)
table.insert(stderr, data)
end }):sync()
return stdout, ret, stderr
end end
utils.strdisplaywidth = (function() utils.strdisplaywidth = (function()