1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 02:05:40 +08:00

chore(telescope): update telescope to 0.1.2

This commit is contained in:
wsdjeg 2023-06-15 11:55:36 +08:00
parent 9be79c8e5a
commit a7194fbafa
46 changed files with 934 additions and 928 deletions

View File

@ -10,30 +10,38 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: nightly/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-linux64.tar.gz
- os: ubuntu-22.04
rev: v0.7.2/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
- os: macos-10.15
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz
- os: ubuntu-22.04
rev: v0.8.1/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
- os: macos-12
rev: nightly/nvim-macos.tar.gz
manager: brew
packages: ripgrep
- os: macos-10.15
url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-macos.tar.gz
- os: macos-12
rev: v0.7.2/nvim-macos.tar.gz
manager: brew
packages: ripgrep
- os: macos-12
rev: v0.8.1/nvim-macos.tar.gz
manager: brew
packages: ripgrep
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore from todays cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }}
key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}
- name: Prepare
run: |
@ -41,11 +49,11 @@ jobs:
${{ matrix.manager }} install ${{ matrix.packages }}
test -d _neovim || {
mkdir -p _neovim
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
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/kyazdani42/nvim-web-devicons ~/.local/share/nvim/site/pack/vendor/start/nvim-web-devicons
git clone --depth 1 https://github.com/nvim-tree/nvim-web-devicons ~/.local/share/nvim/site/pack/vendor/start/nvim-web-devicons
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
- name: Run tests

View File

@ -13,13 +13,13 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }}
@ -32,13 +32,14 @@ jobs:
}
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 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
- 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
git checkout 86f74dfb69c570f0749b241f8f5489f8f50adbea
make dist
cd -

View File

@ -7,7 +7,7 @@ jobs:
name: Luacheck
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Prepare
run: |
@ -22,9 +22,10 @@ jobs:
name: stylua
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: JohnnyMorganz/stylua-action@v1
- uses: actions/checkout@v3
- uses: JohnnyMorganz/stylua-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: latest
# CLI arguments
args: --color always --check lua/

View File

@ -0,0 +1,29 @@
name: "release"
on:
push:
tags:
- '*'
jobs:
luarocks-upload:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: LuaRocks Upload
uses: nvim-neorocks/luarocks-tag-release@v1.0.2
env:
LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }}
with:
summary: "Find, Filter, Preview, Pick. All lua, all the time."
detailed_description: |
A highly extendable fuzzy finder over lists.
Built on the latest awesome features from neovim core.
Telescope is centered around modularity, allowing for easy customization.
dependencies: |
plenary.nvim
copy_directories: |
doc
ftplugin
plugin
scripts
autoload
data

View File

@ -17,10 +17,17 @@ globals = {
"TelescopeGlobalState",
"_TelescopeConfigurationValues",
"_TelescopeConfigurationPickers",
"__TelescopeKeymapStore",
}
-- Global objects defined by the C code
read_globals = {
"vim",
}
files = {
["lua/telescope/builtin/init.lua"] = {
ignore = {
"631", -- allow line len > 120
}
},
}

View File

@ -1,6 +1,7 @@
# telescope.nvim
[![Gitter](https://badges.gitter.im/nvim-telescope/community.svg)](https://gitter.im/nvim-telescope/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![LuaRocks](https://img.shields.io/luarocks/v/Conni2461/telescope.nvim?logo=lua&color=purple)](https://luarocks.org/modules/Conni2461/telescope.nvim)
Gaze deeply into unknown regions using the power of the moon.
@ -51,7 +52,7 @@ latest neovim nightly commit is required for `telescope.nvim` to work.
### Suggested dependencies
- [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) is required for
`live_grep` and `grep_string` and is the first priority for `find_files`.
`live_grep` and `grep_string`
We also suggest you install one native telescope sorter to significantly improve
sorting performance. Take a look at either
@ -67,7 +68,7 @@ wiki.
- [sharkdp/fd](https://github.com/sharkdp/fd) (finder)
- [nvim-treesitter/nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) (finder/preview)
- [neovim LSP]( https://neovim.io/doc/user/lsp.html) (picker)
- [devicons](https://github.com/kyazdani42/nvim-web-devicons) (icons)
- [devicons](https://github.com/nvim-tree/nvim-web-devicons) (icons)
### Installation
@ -82,7 +83,7 @@ Using [vim-plug](https://github.com/junegunn/vim-plug)
```viml
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.0' }
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.1' }
" or , { 'branch': '0.1.x' }
```
@ -90,19 +91,37 @@ Using [dein](https://github.com/Shougo/dein.vim)
```viml
call dein#add('nvim-lua/plenary.nvim')
call dein#add('nvim-telescope/telescope.nvim', { 'rev': '0.1.0' })
call dein#add('nvim-telescope/telescope.nvim', { 'rev': '0.1.1' })
" or , { 'rev': '0.1.x' })
```
Using [packer.nvim](https://github.com/wbthomason/packer.nvim)
```lua
use {
'nvim-telescope/telescope.nvim', tag = '0.1.0',
'nvim-telescope/telescope.nvim', tag = '0.1.1',
-- or , branch = '0.1.x',
requires = { {'nvim-lua/plenary.nvim'} }
}
```
Using [lazy.nvim](https://github.com/folke/lazy.nvim)
```lua
-- init.lua:
{
'nvim-telescope/telescope.nvim', tag = '0.1.1',
-- or , branch = '0.1.1',
dependencies = { 'nvim-lua/plenary.nvim' }
}
-- plugins/telescope.lua:
return {
'nvim-telescope/telescope.nvim', tag = '0.1.1',
-- or , branch = '0.1.1',
dependencies = { 'nvim-lua/plenary.nvim' }
}
```
### checkhealth
Make sure you call `:checkhealth telescope` after installing telescope to ensure
@ -279,12 +298,12 @@ Built-in functions. Ready to be bound to any key you like.
### File Pickers
| Functions | Description |
|-------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|
| `builtin.find_files` | Lists files in your current working directory, respects .gitignore |
| `builtin.git_files` | Fuzzy search through the output of `git ls-files` command, respects .gitignore |
| `builtin.grep_string` | Searches for the string under your cursor in your current working directory |
| `builtin.live_grep` | Search for a string in your current working directory and get results live as you type, respects .gitignore |
| Functions | Description |
|-------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `builtin.find_files` | Lists files in your current working directory, respects .gitignore |
| `builtin.git_files` | Fuzzy search through the output of `git ls-files` command, respects .gitignore |
| `builtin.grep_string` | Searches for the string under your cursor in your current working directory |
| `builtin.live_grep` | Search for a string in your current working directory and get results live as you type, respects .gitignore. (Requires [ripgrep](https://github.com/BurntSushi/ripgrep)) |
### Vim Pickers
@ -338,7 +357,7 @@ Built-in functions. Ready to be bound to any key you like.
|-------------------------------------|------------------------------------------------------------------------------------------------------------|
| `builtin.git_commits` | Lists git commits with diff preview, checkout action `<cr>`, reset mixed `<C-r>m`, reset soft `<C-r>s` and reset hard `<C-r>h` |
| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checks them out on `<cr>` |
| `builtin.git_branches` | Lists all branches with log preview, checkout action `<cr>`, track action `<C-t>` and rebase action`<C-r>` |
| `builtin.git_branches` | Lists all branches with log preview, checkout action `<cr>`, track action `<C-t>`, rebase action`<C-r>`, create action `<C-a>`, switch action `<C-s>`, delete action `<C-d>` and merge action `<C-y>` |
| `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multi-selection still WIP) |
| `builtin.git_stash` | Lists stash items in current repository with ability to apply them on `<cr>` |
@ -524,7 +543,7 @@ Telescope user autocmds:
## Extensions
Telescope provides the capabilities to create & register extensions, which
improve telescope in a variety of ways.
improves telescope in a variety of ways.
Some extensions provide integration with external tools, outside of the scope of
`builtins`. Others provide performance enhancements by using compiled C and

View File

@ -264,7 +264,7 @@ find results and call `entry_maker` for each entry. An example usage would be
`find`.
```lua
finder = finders.new_oneshot_job({ "find" }, opts ),
finder = finders.new_oneshot_job { "find", opts },
```
### More examples

View File

@ -6,9 +6,9 @@ filter, find and pick things in Lua.
Getting started with telescope:
1. Run `:checkhealth telescope` to make sure everything is installed.
2. Evaluate it working with `:Telescope find_files` or `:lua
2. Evaluate it is working with `:Telescope find_files` or `:lua
require("telescope.builtin").find_files()`
3. Put a `require("telescope").setup() call somewhere in your neovim config.
3. Put a `require("telescope").setup()` call somewhere in your neovim config.
4. Read |telescope.setup| to check what config keys are available and what
you can put inside the setup call
5. Read |telescope.builtin| to check which builtin pickers are offered and
@ -24,14 +24,14 @@ The below flow chart illustrates a simplified telescope architecture:
│ │ ┌───│Manager│────│ Sorter │┐ └───┬───* │
│ ▼ ▼ └───────* └────────┘│ │ │
│ 1────────┐ 2───┴──┐ │ │
│ ┌─────│ Picker │ │Finder│────┘ │
│ ┌─────│ Picker │ │Finder│────┘ │
│ ▼ └───┬────┘ └──────* │
│ ┌────────┐ │ 3────────+ ▲ │
│ │Selected│ └───────│ Prompt │─────────┘ │
│ │ Entry │ └───┬────┘ │
│ └────────* ┌───┴────┐ ┌────────┐ ┌────────┐ │
│ │ ▲ 4─────────┐│ Prompt │ │(Attach)│ │Actions │ │
│ ▼ └──► │ Results ││ Buffer │◄─┤Mappings│◄─┤User Fn │ │
│ ▼ └──▶ │ Results ││ Buffer │◀─┤Mappings│◀─┤User Fn │ │
│5─────────┐ └─────────┘└────────┘ └────────┘ └────────┘ │
││Previewer│ │
│└─────────┘ telescope.nvim architecture │
@ -192,13 +192,13 @@ telescope.setup({opts}) *telescope.setup()*
*telescope.defaults.cycle_layout_list*
cycle_layout_list: ~
Determines the layouts to cycle through when using `actions.cycle_layout_next`
and `actions.cycle_layout_prev`.
Determines the layouts to cycle through when using `actions.layout.cycle_layout_next`
and `actions.layout.cycle_layout_prev`.
Should be a list of "layout setups".
Each "layout setup" can take one of two forms:
1. string <br>
1. string
This is interpreted as the name of a `layout_strategy`
2. table <br>
2. table
A table with possible keys `layout_strategy`, `layout_config` and `previewer`
Default: { "horizontal", "vertical" }
@ -227,7 +227,6 @@ telescope.setup({opts}) *telescope.setup()*
selection_caret: ~
The character(s) that will be shown in front of the current selection.
Default: '> '
*telescope.defaults.entry_prefix*
@ -260,7 +259,7 @@ telescope.setup({opts}) *telescope.setup()*
*telescope.defaults.path_display*
path_display: ~
Determines how file paths are displayed
Determines how file paths are displayed.
path_display can be set to an array with a combination of:
- "hidden" hide file names
@ -273,7 +272,7 @@ telescope.setup({opts}) *telescope.setup()*
- "shorten" only display the first character of each directory in
the path
- "truncate" truncates the start of the path when the whole path will
not fit. To increase the the gap between the path and the edge.
not fit. To increase the gap between the path and the edge,
set truncate to number `truncate = 3`
You can also specify the number of characters of each directory name
@ -352,7 +351,7 @@ telescope.setup({opts}) *telescope.setup()*
prompt_title: ~
Defines the default title of the prompt window. A false value
can be used to hide the title altogether. Most of the times builtins
define a prompt_title which will be prefered over this default.
define a prompt_title which will be preferred over this default.
Default: "Prompt"
@ -371,6 +370,8 @@ telescope.setup({opts}) *telescope.setup()*
Will allow you to completely remove all of telescope's default maps
and use your own.
Default: nil
*telescope.defaults.history*
history: ~
@ -388,11 +389,11 @@ telescope.setup({opts}) *telescope.setup()*
Fields:
- path: The path to the telescope history as string.
default: stdpath("data")/telescope_history
Default: stdpath("data")/telescope_history
- limit: The amount of entries that will be written in the
history.
Warning: If limit is set to nil it will grow unbound.
default: 100
Default: 100
- handler: A lua function that implements the history.
This is meant as a developer setting for extensions to
override the history handling, e.g.,
@ -420,7 +421,8 @@ telescope.setup({opts}) *telescope.setup()*
indices larger than `cache_picker.num_pickers` will
be cleared.
Default: 1
- limit_entries: The amount of entries that will be written in the
- limit_entries: The amount of entries that will be saved for each
picker.
Default: 1000
@ -514,7 +516,7 @@ telescope.setup({opts}) *telescope.setup()*
- msg_bg_fillchar: Character to fill background of unpreviewable buffers with
Default: ""
- hide_on_startup: Hide previewer when picker starts. Previewer can be toggled
with actions.toggle_preview.
with actions.layout.toggle_preview.
Default: false
@ -565,7 +567,7 @@ telescope.setup({opts}) *telescope.setup()*
file_sorter: ~
A function pointer that specifies the file_sorter. This sorter will
be used for find_files, git_files and similar.
Hint: If you load a native sorter, you dont need to change this value,
Hint: If you load a native sorter, you don't need to change this value,
the native sorter will override it anyway.
Default: require("telescope.sorters").get_fzy_sorter
@ -574,7 +576,7 @@ telescope.setup({opts}) *telescope.setup()*
generic_sorter: ~
A function pointer to the generic sorter. The sorter that should be
used for everything that is not a file.
Hint: If you load a native sorter, you dont need to change this value,
Hint: If you load a native sorter, you don't need to change this value,
the native sorter will override it anyway.
Default: require("telescope.sorters").get_fzy_sorter
@ -583,7 +585,7 @@ telescope.setup({opts}) *telescope.setup()*
prefilter_sorter: ~
This points to a wrapper sorter around the generic_sorter that is able
to do prefiltering.
Its usually used for lsp_*_symbols and lsp_*_diagnostics
It's usually used for lsp_*_symbols and lsp_*_diagnostics
Default: require("telescope.sorters").prefilter
@ -794,6 +796,8 @@ builtin.live_grep({opts}) *telescope.builtin.live_grep()*
{max_results} (number) define a upper result value
{disable_coordinates} (boolean) don't show the line & row
numbers (default: false)
{file_encoding} (string) file encoding for the entry &
previewer
builtin.grep_string({opts}) *telescope.builtin.grep_string()*
@ -828,6 +832,8 @@ builtin.grep_string({opts}) *telescope.builtin.grep_string()*
{only_sort_text} (boolean) only sort the text, not the
file, line or row (default:
false)
{file_encoding} (string) file encoding for the entry &
previewer
builtin.find_files({opts}) *telescope.builtin.find_files()*
@ -857,6 +863,7 @@ builtin.find_files({opts}) *telescope.builtin.find_files()*
{search_dirs} (table) directory/directories/files to
search
{search_file} (string) specify a filename to search for
{file_encoding} (string) file encoding for the previewer
builtin.fd() *telescope.builtin.fd()*
@ -879,6 +886,7 @@ builtin.treesitter() *telescope.builtin.treesitter()*
current buffer)
{symbol_highlights} (table) string -> string. Matches symbol with
hl_group
{file_encoding} (string) file encoding for the previewer
builtin.current_buffer_fuzzy_find({opts}) *telescope.builtin.current_buffer_fuzzy_find()*
@ -889,8 +897,9 @@ builtin.current_buffer_fuzzy_find({opts}) *telescope.builtin.current_buffer_fuzz
{opts} (table) options to pass to the picker
Options: ~
{skip_empty_lines} (boolean) if true we dont display empty lines
{skip_empty_lines} (boolean) if true we don't display empty lines
(default: false)
{file_encoding} (string) file encoding for the previewer
builtin.tags({opts}) *telescope.builtin.tags()*
@ -958,8 +967,9 @@ builtin.git_files({opts}) *telescope.builtin.git_files()*
{recurse_submodules} (boolean) if true, adds the
`--recurse-submodules` flag to command
(default: false)
{git_command} (table) command that will be exectued.
{git_command} (table) command that will be executed.
{"git","ls-files","--exclude-standard","--cached"}
{file_encoding} (string) file encoding for the previewer
builtin.git_commits({opts}) *telescope.builtin.git_commits()*
@ -978,13 +988,13 @@ builtin.git_commits({opts}) *telescope.builtin.git_commits()*
{cwd} (string) specify the path of the repo
{use_git_root} (boolean) if we should use git root as cwd or the cwd
(important for submodule) (default: true)
{git_command} (table) command that will be exectued.
{git_command} (table) command that will be executed.
{"git","log","--pretty=oneline","--abbrev-commit","--","."}
builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()*
Lists commits for current buffer with diff preview
- Default keymaps or your overriden `select_` keys:
- Default keymaps or your overridden `select_` keys:
- `<cr>`: checks out the currently selected commit
- `<c-v>`: opens a diff in a vertical split
- `<c-x>`: opens a diff in a horizontal split
@ -1000,7 +1010,7 @@ builtin.git_bcommits({opts}) *telescope.builtin.git_bcommits()*
(important for submodule) (default: true)
{current_file} (string) specify the current file that should be used
for bcommits (default: current buffer)
{git_command} (table) command that will be exectued.
{git_command} (table) command that will be executed.
{"git","log","--pretty=oneline","--abbrev-commit"}
@ -1115,9 +1125,9 @@ builtin.planets({opts}) *telescope.builtin.planets()*
{opts} (table) options to pass to the picker
Options: ~
{show_pluto} (boolean) we love pluto (default: false, because its a
{show_pluto} (boolean) we love Pluto (default: false, because its a
hidden feature)
{show_moon} (boolean) we love the moon (default: false, because its
{show_moon} (boolean) we love the Moon (default: false, because its
a hidden feature)
@ -1199,8 +1209,9 @@ builtin.oldfiles({opts}) *telescope.builtin.oldfiles()*
{opts} (table) options to pass to the picker
Options: ~
{only_cwd} (boolean) show only files in the cwd (default: false)
{cwd_only} (boolean) alias for only_cwd
{only_cwd} (boolean) show only files in the cwd (default: false)
{cwd_only} (boolean) alias for only_cwd
{file_encoding} (string) file encoding for the previewer
builtin.command_history({opts}) *telescope.builtin.command_history()*
@ -1300,6 +1311,7 @@ builtin.buffers({opts}) *telescope.builtin.buffers()*
{bufnr_width} (number) Defines the width of the buffer
numbers in front of the filenames
(default: dynamic)
{file_encoding} (string) file encoding for the previewer
builtin.colorscheme({opts}) *telescope.builtin.colorscheme()*
@ -1320,6 +1332,9 @@ builtin.marks({opts}) *telescope.builtin.marks()*
Parameters: ~
{opts} (table) options to pass to the picker
Options: ~
{file_encoding} (string) file encoding for the previewer
builtin.registers({opts}) *telescope.builtin.registers()*
Lists vim registers, pastes the contents of the register on `<cr>`
@ -1424,6 +1439,7 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*
section (default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{file_encoding} (string) file encoding for the previewer
builtin.lsp_incoming_calls({opts}) *telescope.builtin.lsp_incoming_calls()*
@ -1435,10 +1451,11 @@ builtin.lsp_incoming_calls({opts}) *telescope.builtin.lsp_incoming_calls()*
{opts} (table) options to pass to the picker
Options: ~
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{file_encoding} (string) file encoding for the previewer
builtin.lsp_outgoing_calls({opts}) *telescope.builtin.lsp_outgoing_calls()*
@ -1450,10 +1467,11 @@ builtin.lsp_outgoing_calls({opts}) *telescope.builtin.lsp_outgoing_calls()*
{opts} (table) options to pass to the picker
Options: ~
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{file_encoding} (string) file encoding for the previewer
builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()*
@ -1465,12 +1483,15 @@ builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()*
{opts} (table) options to pass to the picker
Options: ~
{jump_type} (string) how to goto definition if there is only one,
values: "tab", "split", "vsplit", "never"
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{jump_type} (string) how to goto definition if there is only one
and the definition file is different from
the current file, values: "tab", "split",
"vsplit", "never"
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{file_encoding} (string) file encoding for the previewer
builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()*
@ -1482,12 +1503,15 @@ builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()*
{opts} (table) options to pass to the picker
Options: ~
{jump_type} (string) how to goto definition if there is only one,
values: "tab", "split", "vsplit", "never"
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{jump_type} (string) how to goto definition if there is only one
and the definition file is different from
the current file, values: "tab", "split",
"vsplit", "never"
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{file_encoding} (string) file encoding for the previewer
builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
@ -1499,13 +1523,15 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
{opts} (table) options to pass to the picker
Options: ~
{jump_type} (string) how to goto implementation if there is only
one, values: "tab", "split", "vsplit",
"never"
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{jump_type} (string) how to goto implementation if there is only
one and the definition file is different
from the current file, values: "tab",
"split", "vsplit", "never"
{fname_width} (number) defines the width of the filename section
(default: 30)
{show_line} (boolean) show results text (default: true)
{trim_text} (boolean) trim results text (default: false)
{file_encoding} (string) file encoding for the previewer
builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
@ -1521,6 +1547,10 @@ builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
Options: ~
{fname_width} (number) defines the width of the filename
section (default: 30)
{symbol_width} (number) defines the width of the symbol
section (default: 25)
{symbol_type_width} (number) defines the width of the symbol
type section (default: 8)
{show_line} (boolean) if true, shows the content of the
line the tag is found on (default:
false)
@ -1528,6 +1558,7 @@ builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
{ignore_symbols} (string|table) list of symbols to ignore
{symbol_highlights} (table) string -> string. Matches symbol
with hl_group
{file_encoding} (string) file encoding for the previewer
builtin.lsp_workspace_symbols({opts}) *telescope.builtin.lsp_workspace_symbols()*
@ -1545,6 +1576,10 @@ builtin.lsp_workspace_symbols({opts}) *telescope.builtin.lsp_workspace_symbols()
(default: "")
{fname_width} (number) defines the width of the filename
section (default: 30)
{symbol_width} (number) defines the width of the symbol
section (default: 25)
{symbol_type_width} (number) defines the width of the symbol
type section (default: 8)
{show_line} (boolean) if true, shows the content of the
line the tag is found on (default:
false)
@ -1552,6 +1587,7 @@ builtin.lsp_workspace_symbols({opts}) *telescope.builtin.lsp_workspace_symbols()
{ignore_symbols} (string|table) list of symbols to ignore
{symbol_highlights} (table) string -> string. Matches symbol
with hl_group
{file_encoding} (string) file encoding for the previewer
builtin.lsp_dynamic_workspace_symbols({opts}) *telescope.builtin.lsp_dynamic_workspace_symbols()*
@ -1574,6 +1610,7 @@ builtin.lsp_dynamic_workspace_symbols({opts}) *telescope.builtin.lsp_dynamic_wor
{ignore_symbols} (string|table) list of symbols to ignore
{symbol_highlights} (table) string -> string. Matches symbol
with hl_group
{file_encoding} (string) file encoding for the previewer
builtin.diagnostics({opts}) *telescope.builtin.diagnostics()*
@ -1628,9 +1665,10 @@ themes.get_dropdown() *telescope.themes.get_dropdown()*
Usage:
>
`local builtin = require('telescope.builtin')`
`local themes = require('telescope.themes')`
`builtin.find_files(themes.get_dropdown())`
local opts = {...} -- picker options
local builtin = require('telescope.builtin')
local themes = require('telescope.themes')
builtin.find_files(themes.get_dropdown(opts))
<
@ -1640,10 +1678,10 @@ themes.get_cursor() *telescope.themes.get_cursor()*
Usage:
>
`local builtin = require('telescope.builtin')`
`local themes = require('telescope.themes')`
`builtin.lsp_references(themes.get_cursor())`
local opts = {...} -- picker options
local builtin = require('telescope.builtin')
local themes = require('telescope.themes')
builtin.find_files(themes.get_cursor(opts))
<
@ -1653,9 +1691,10 @@ themes.get_ivy() *telescope.themes.get_ivy()*
Usage:
>
`local builtin = require('telescope.builtin')`
`local themes = require('telescope.themes')`
`builtin.find_files(themes.get_ivy())`
local opts = {...} -- picker options
local builtin = require('telescope.builtin')
local themes = require('telescope.themes')
builtin.find_files(themes.get_ivy(opts))
<
@ -1665,12 +1704,11 @@ themes.get_ivy() *telescope.themes.get_ivy()*
MAPPINGS *telescope.mappings*
|telescope.mappings| is used to configure the keybindings within a telescope
picker. These keybinds are only local to the picker window and will be cleared
picker. These key binds are only local to the picker window and will be cleared
once you exit the picker.
We provide multiple different ways of configuring, as described below, to
provide an easy to use experience for changing the default behavior of
telescope or extending for your own purposes.
We provide multiple configuration options to make it easy for you to adjust
telescope's default key bindings and create your own custom key binds.
To see many of the builtin actions that you can use as values for this table,
see |telescope.actions|
@ -1703,7 +1741,6 @@ For example:
...,
}
<
Into your config.
To override behavior of a key, simply set the value to be a function (either by
requiring an action or by writing your own function)
@ -1716,7 +1753,8 @@ requiring an action or by writing your own function)
<
If the function you want is part of `telescope.actions`, then you can simply
give a string. For example, the previous option is equivalent to:
supply the function name as a string. For example, the previous option is
equivalent to:
>
{
...,
@ -1775,6 +1813,11 @@ ordered from the lowest priority to the highest priority.
map("i", "asdf", function(_prompt_bufnr)
print "You typed asdf"
end)
map({"i", "n"}, "<C-r>", function(_prompt_bufnr)
print "You typed <C-r>"
end)
-- needs to return true if you want to map default_mappings and
-- false if not
return true
@ -1823,7 +1866,6 @@ All layout strategies are functions with the following signature:
- lines : (number) Lines in the vim window
- layout_config : (table) The configuration values specific to the picker.
This means you can create your own layout strategy if you want! Just be aware
for now that we may change some APIs or interfaces, so they may break if you
create your own.
@ -1892,14 +1934,14 @@ layout_strategies.center() *telescope.layout.center()*
┌──────────────────────────────────────────────────┐
│ ┌────────────────────────────────────────┐ │
| Preview |
| Preview |
│ Preview │
│ Preview │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
| Prompt |
│ Prompt │
│ ├────────────────────────────────────────┤ │
| Result |
| Result |
│ Result │
│ Result │
│ └────────────────────────────────────────┘ │
│ │
│ │
@ -1948,6 +1990,20 @@ layout_strategies.cursor() *telescope.layout.cursor()*
│ │
└──────────────────────────────────────────────────┘
`picker.layout_config` shared options:
- height:
- How tall to make Telescope's entire layout
- See |resolver.resolve_height()|
- scroll_speed: The number of lines to scroll through the previewer
- width:
- How wide to make Telescope's entire layout
- See |resolver.resolve_width()|
`picker.layout_config` unique options:
- preview_cutoff: When columns are less than this value, the preview will be disabled
- preview_width:
- Change the width of Telescope's preview window
- See |resolver.resolve_width()|
layout_strategies.vertical() *telescope.layout.vertical()*
@ -1957,16 +2013,16 @@ layout_strategies.vertical() *telescope.layout.vertical()*
┌──────────────────────────────────────────────────┐
│ │
│ ┌────────────────────────────────────────┐ │
| Preview |
| Preview |
| Preview |
│ Preview │
│ Preview │
│ Preview │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
| Result |
| Result |
│ Result │
│ Result │
│ └────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────┐ │
| Prompt |
│ Prompt │
│ └────────────────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────┘
@ -2103,33 +2159,33 @@ MAKE_ENTRY *telescope.make_entry*
Each picker has a finder made up of two parts, the results which are the data
to be displayed, and the entry_maker. These entry_makers are functions returned
from make_entry functions. These will be referrd to as entry_makers in the
from make_entry functions. These will be referred to as entry_makers in the
following documentation.
Every entry maker returns a function which accepts the data to be used for an
Every entry maker returns a function that accepts the data to be used for an
entry. This function will return an entry table (or nil, meaning skip this
entry) which contains of the - following important keys:
entry) which contains the following important keys:
- value any: value key can be anything but still required
- valid bool: is an optional key because it defaults to true but if the key is
set to false it will not be displayed by the picker. (optional)
- ordinal string: is the text that is used for filtering (required)
- valid bool (optional): is an optional key because it defaults to true but if
the key is set to false it will not be displayed by the picker
- ordinal string: is the text that is used for filtering
- display string|function: is either a string of the text that is being
displayed or a function receiving the entry at a later stage, when the entry
is actually being displayed. A function can be useful here if complex
calculation have to be done. `make_entry` can also return a second value a
is actually being displayed. A function can be useful here if a complex
calculation has to be done. `make_entry` can also return a second value - a
highlight array which will then apply to the line. Highlight entry in this
array has the following signature `{ { start_col, end_col }, hl_group }`
(required).
- filename string: will be interpreted by the default `<cr>` action as open
this file (optional)
- bufnr number: will be interpreted by the default `<cr>` action as open this
buffer (optional)
- lnum number: lnum value which will be interpreted by the default `<cr>`
action as a jump to this line (optional)
- col number: col value which will be interpreted by the default `<cr>` action
as a jump to this column (optional)
- filename string (optional): will be interpreted by the default `<cr>` action
as open this file
- bufnr number (optional): will be interpreted by the default `<cr>` action as
open this buffer
- lnum number (optional): lnum value which will be interpreted by the default
`<cr>` action as a jump to this line
- col number (optional): col value which will be interpreted by the default
`<cr>` action as a jump to this column
More information on easier displaying, see |telescope.pickers.entry_display|
For more information on easier displaying, see
|telescope.pickers.entry_display|
TODO: Document something we call `entry_index`
@ -2148,11 +2204,11 @@ every single entry. So it is suggested to do this outside of `make_display` for
the best performance.
The create function will use the column widths passed to it in
configaration.items. Each item in that table is the number of characters in the
configuration.items. Each item in that table is the number of characters in the
column. It's also possible for the final column to not have a fixed width, this
will be shown in the configuartion as 'remaining = true'.
will be shown in the configuration as 'remaining = true'.
An example of this configuration is shown for the buffers picker
An example of this configuration is shown for the buffers picker:
>
local displayer = entry_display.create {
separator = " ",
@ -2166,10 +2222,10 @@ local displayer = entry_display.create {
<
This shows 4 columns, the first is defined in the opts as the width we'll use
when display_string the number of the buffer. The second has a fixed width of 4
and the 3rd column's widht will be decided by the width of the icons we use.
The fourth column will use the remaining space. Finally we have also defined
the seperator between each column will be the space " ".
when display_string is the number of the buffer. The second has a fixed width
of 4 and the third column's width will be decided by the width of the icons we
use. The fourth column will use the remaining space. Finally, we have also
defined the separator between each column will be the space " ".
An example of how the display reference will be used is shown, again for the
buffers picker:
@ -2185,11 +2241,12 @@ return displayer {
There are two types of values each column can have. Either a simple String or a
table containing the String as well as the hl_group.
The displayer can return values, string and an optional highlights. String is
all the text to be displayed for this entry as a single string. If parts of the
string are to be highlighted they will be described in the highlights table.
The displayer can return values, string and an optional highlights. The string
is all the text to be displayed for this entry as a single string. If parts of
the string are to be highlighted they will be described in the highlights
table.
For better understanding of how create() and displayer are used it's best to
For a better understanding of how create() and displayer are used it's best to
look at the code in make_entry.lua.
@ -2210,7 +2267,7 @@ utils.transform_path({opts}, {path}) *telescope.utils.transform_path()*
Parameters: ~
{opts} (table) The opts the users passed into the picker. Might
contains a path_display key
{path} (string) The path that should be formated
{path} (string) The path that should be formatted
Return: ~
string: The transformed path ready to be displayed
@ -2229,9 +2286,9 @@ utils.notify({funname}, {opts}) *telescope.utils.notify()*
================================================================================
ACTIONS *telescope.actions*
Actions functions that are useful for people creating their own mappings.
These functions are useful for people creating their own mappings.
Actions can be either normal functions that expect the prompt_bufnr as first
Actions can be either normal functions that expect the `prompt_bufnr` as first
argument (1) or they can be a custom telescope type called "action" (2).
(1) The `prompt_bufnr` of a normal function denotes the identifier of your
@ -2272,8 +2329,8 @@ do the following:
action(bufnr)
<
Another interesing thing to do is that these actions now have functions you can
call. These functions include `:replace(f)`, `:replace_if(f, c)`,
Another interesting thing to do is that these actions now have functions you
can call. These functions include `:replace(f)`, `:replace_if(f, c)`,
`replace_map(tbl)` and `enhance(tbl)`. More information on these functions can
be found in the `developers.md` and `lua/tests/automated/action_spec.lua` file.
@ -2359,8 +2416,8 @@ actions.toggle_selection({prompt_bufnr}) *telescope.actions.toggle_selection()*
actions.select_all({prompt_bufnr}) *telescope.actions.select_all()*
Multi select all entries.
- Note: selected entries may include results not visible in the results
popup.
- Note: selected entries may include results not visible in the results pop
up.
Parameters: ~
@ -2377,8 +2434,8 @@ actions.drop_all({prompt_bufnr}) *telescope.actions.drop_all()*
actions.toggle_all({prompt_bufnr}) *telescope.actions.toggle_all()*
Toggle multi selection for all entries.
- Note: toggled entries may include results not visible in the results
popup.
- Note: toggled entries may include results not visible in the results pop
up.
Parameters: ~
@ -2470,28 +2527,6 @@ actions.select_tab({prompt_bufnr}) *telescope.actions.select_tab()*
{prompt_bufnr} (number) The prompt bufnr
actions.select_drop({prompt_bufnr}) *telescope.actions.select_drop()*
Perform 'drop' action on selection, usually something like
`:drop <selection>`
i.e. open the selection in a window
Parameters: ~
{prompt_bufnr} (number) The prompt bufnr
actions.select_tab_drop({prompt_bufnr}) *telescope.actions.select_tab_drop()*
Perform 'tab drop' action on selection, usually something like
`:tab drop <selection>`
i.e. open the selection in a new tab
Parameters: ~
{prompt_bufnr} (number) The prompt bufnr
actions.file_edit({prompt_bufnr}) *telescope.actions.file_edit()*
Perform file edit on selection, usually something like
`:edit <selection>`
@ -2547,7 +2582,7 @@ actions._close({prompt_bufnr}) *telescope.actions._close()*
actions.edit_command_line({prompt_bufnr}) *telescope.actions.edit_command_line()*
Set a value in the command line and dont run it, making it editable.
Set a value in the command line and don't run it, making it editable.
Parameters: ~
@ -2563,7 +2598,7 @@ actions.set_command_line({prompt_bufnr}) *telescope.actions.set_command_line()*
actions.edit_search_line({prompt_bufnr}) *telescope.actions.edit_search_line()*
Set a value in the search line and dont search for it, making it editable.
Set a value in the search line and don't search for it, making it editable.
Parameters: ~
@ -3087,7 +3122,7 @@ utils.map_entries({prompt_bufnr}, {f}) *telescope.actions.utils.map_entries()*
Apply `f` to the entries of the current picker.
- Notes:
- Mapped entries include all currently filtered results, not just the
visible onces.
visible ones.
- Indices are 1-indexed, whereas rows are 0-indexed.
- Warning: `map_entries` has no return value.
- The below example showcases how to collect results
@ -3100,7 +3135,7 @@ utils.map_entries({prompt_bufnr}, {f}) *telescope.actions.utils.map_entries()*
local prompt_bufnr = vim.api.nvim_get_current_buf()
local current_picker = action_state.get_current_picker(prompt_bufnr)
local results = {}
action_utils.map_entries(prompt_bufnr, function(entry, index, row)
action_utils.map_entries(prompt_bufnr, function(entry, index, row)
results[row] = entry.value
end)
return results
@ -3119,7 +3154,8 @@ utils.map_selections({prompt_bufnr}, {f}) *telescope.actions.utils.map_selection
Apply `f` to the multi selections of the current picker and return a table
of mapped selections.
- Notes:
- Mapped selections may include results not visible in the results popup.
- Mapped selections may include results not visible in the results pop
up.
- Selected entries are returned in order of their selection.
- Warning: `map_selections` has no return value.
- The below example showcases how to collect results
@ -3132,7 +3168,7 @@ utils.map_selections({prompt_bufnr}, {f}) *telescope.actions.utils.map_selection
local prompt_bufnr = vim.api.nvim_get_current_buf()
local current_picker = action_state.get_current_picker(prompt_bufnr)
local results = {}
action_utils.map_selections(prompt_bufnr, function(entry, index)
action_utils.map_selections(prompt_bufnr, function(entry, index)
results[index] = entry.value
end)
return results
@ -3239,7 +3275,7 @@ PREVIEWERS *telescope.previewers*
Provides a Previewer table that has to be implemented by each previewer. To
achieve this, this module also provides two wrappers that abstract most of the
work and make it really easy create new previewers.
work and make it really easy to create new previewers.
- `previewers.new_termopen_previewer`
- `previewers.new_buffer_previewer`
@ -3268,7 +3304,7 @@ previewers.Previewer() *telescope.previewers.Previewer()*
What `:new` expects is listed below
The interface provides following set of functions. All of them, besides
The interface provides the following set of functions. All of them, besides
`new`, will be handled by telescope pickers.
- `:new(opts)`
- `:preview(entry, status)`
@ -3279,7 +3315,7 @@ previewers.Previewer() *telescope.previewers.Previewer()*
`Previewer:new()` expects a table as input with following keys:
- `setup` function(self): Will be called the first time preview will be
called.
- `teardown` function(self): Will be called on cleanup.
- `teardown` function(self): Will be called on clean up.
- `preview_fn` function(self, entry, status): Will be called each time a
new entry was selected.
- `title` function(self): Will return the static title of the previewer.
@ -3389,9 +3425,9 @@ previewers.new_buffer_previewer() *telescope.previewers.new_buffer_previewer()*
table of vars that will be available in `self.state` in each
`define_preview` call.
- `teardown = function(self)` (optional) Will be called at the end, when
the picker is being closed and is meant to cleanup everything that was
the picker is being closed and is meant to clean up everything that was
allocated by the previewer. The `buffer_previewer` will automatically
cleanup all created buffers. So you only need to handle things that
clean up all created buffers. So you only need to handle things that
were introduced by you.
- `keep_last_buf = true` (optional) Will not delete the last selected
buffer. This would allow you to reuse that buffer in the select action.
@ -3399,7 +3435,7 @@ previewers.new_buffer_previewer() *telescope.previewers.new_buffer_previewer()*
recreating that buffer in an action. To access the last buffer number:
`require('telescope.state').get_global_key("last_preview_bufnr")`
- `get_buffer_by_name = function(self, entry)` Allows you to set a unique
name for each buffer. This is used for caching purpose.
name for each buffer. This is used for caching purposes.
`self.state.bufname` will be nil if the entry was never loaded or the
unique name when it was loaded once. For example, useful if you have
one file but multiple entries. This happens for grep and lsp builtins.
@ -3450,8 +3486,8 @@ previewers.new_buffer_previewer() *telescope.previewers.new_buffer_previewer()*
vim.api.nvim_buf_call(bufnr, function()
-- for example `search` and `matchadd`
end)
to achieve that.
<
to achieve that.
- If you want to read a file into the buffer it's best to use
`buffer_previewer_maker`. But access this function with
`require('telescope.config').values.buffer_previewer_maker` because it
@ -3495,7 +3531,7 @@ previewers.vim_buffer_vimgrep() *telescope.previewers.vim_buffer_vimgrep()*
previewers.vim_buffer_qflist() *telescope.previewers.vim_buffer_qflist()*
Is the same as `vim_buffer_vimgrep` and only exist for consistency with
Is the same as `vim_buffer_vimgrep` and only exists for consistency with
`term_previewers`.
The preferred way of using this previewer is like this
@ -3566,7 +3602,7 @@ HISTORY *telescope.actions.history*
A base implementation of a prompt history that provides a simple history and
can be replaced with a custom implementation.
For example: We provide a extension for a smart history that uses sql.nvim to
For example: We provide an extension for a smart history that uses sql.nvim to
map histories to metadata, like the calling picker or cwd.
So you have a history for:

View File

@ -21,7 +21,7 @@ function AsyncJob.new(opts)
self.stderr = opts.stderr or M.NullPipe()
if opts.cwd and opts.cwd ~= "" then
self.uv_opts.cwd = vim.fn.expand(opts.cwd)
self.uv_opts.cwd = vim.fn.expand(vim.fn.escape(opts.cwd, "$"))
-- this is a "illegal" hack for windows. E.g. If the git command returns `/` rather than `\` as delimiter,
-- vim.fn.expand might just end up returning an empty string. Weird
-- Because empty string is not allowed in libuv the job will not spawn. Solution is we just set it to opts.cwd

View File

@ -62,7 +62,7 @@ action_generate.refine = function(prompt_bufnr, opts)
opts = opts or {}
opts.prompt_to_prefix = vim.F.if_nil(opts.prompt_to_prefix, false)
opts.prefix_hl_group = vim.F.if_nil(opts.prompt_hl_group, "TelescopePromptPrefix")
opts.prompt_prefix = vim.F.if_nil(opts.promt_prefix, config.values.prompt_prefix)
opts.prompt_prefix = vim.F.if_nil(opts.prompt_prefix, config.values.prompt_prefix)
opts.reset_multi_selection = vim.F.if_nil(opts.reset_multi_selection, false)
opts.reset_prompt = vim.F.if_nil(opts.reset_prompt, true)
opts.sorter = vim.F.if_nil(opts.sorter, config.values.generic_sorter {})
@ -75,11 +75,11 @@ action_generate.refine = function(prompt_bufnr, opts)
end
-- title
if opts.prompt_title then
if opts.prompt_title and current_picker.prompt_border then
current_picker.prompt_border:change_title(opts.prompt_title)
end
if opts.results_title then
if opts.results_title and current_picker.results_border then
current_picker.results_border:change_title(opts.results_title)
end

View File

@ -11,7 +11,7 @@ local uv = vim.loop
--- A base implementation of a prompt history that provides a simple history
--- and can be replaced with a custom implementation.
---
--- For example: We provide a extension for a smart history that uses sql.nvim
--- For example: We provide an extension for a smart history that uses sql.nvim
--- to map histories to metadata, like the calling picker or cwd.
---
--- So you have a history for:

View File

@ -2,9 +2,9 @@
---@config { ["module"] = "telescope.actions" }
---@brief [[
--- Actions functions that are useful for people creating their own mappings.
--- These functions are useful for people creating their own mappings.
---
--- Actions can be either normal functions that expect the prompt_bufnr as
--- Actions can be either normal functions that expect the `prompt_bufnr` as
--- first argument (1) or they can be a custom telescope type called "action" (2).
---
--- (1) The `prompt_bufnr` of a normal function denotes the identifier of your
@ -45,7 +45,7 @@
--- action(bufnr)
--- </code>
---
--- Another interesing thing to do is that these actions now have functions you
--- Another interesting thing to do is that these actions now have functions you
--- can call. These functions include `:replace(f)`, `:replace_if(f, c)`,
--- `replace_map(tbl)` and `enhance(tbl)`. More information on these functions
--- can be found in the `developers.md` and `lua/tests/automated/action_spec.lua`
@ -75,6 +75,12 @@ local actions = setmetatable({}, {
end,
})
local append_to_history = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end
--- Move the selection to the next entry
---@param prompt_bufnr number: The prompt bufnr
actions.move_selection_next = function(prompt_bufnr)
@ -150,7 +156,7 @@ actions.toggle_selection = function(prompt_bufnr)
end
--- Multi select all entries.
--- - Note: selected entries may include results not visible in the results popup.
--- - Note: selected entries may include results not visible in the results pop up.
---@param prompt_bufnr number: The prompt bufnr
actions.select_all = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
@ -187,7 +193,7 @@ actions.drop_all = function(prompt_bufnr)
end
--- Toggle multi selection for all entries.
--- - Note: toggled entries may include results not visible in the results popup.
--- - Note: toggled entries may include results not visible in the results pop up.
---@param prompt_bufnr number: The prompt bufnr
actions.toggle_all = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
@ -241,11 +247,7 @@ end
--- i.e. open the selection in the current buffer
---@param prompt_bufnr number: The prompt bufnr
actions.select_default = {
pre = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end,
pre = append_to_history,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "default")
end,
@ -257,11 +259,7 @@ actions.select_default = {
--- i.e. open the selection in a new horizontal split
---@param prompt_bufnr number: The prompt bufnr
actions.select_horizontal = {
pre = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end,
pre = append_to_history,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "horizontal")
end,
@ -273,11 +271,7 @@ actions.select_horizontal = {
--- i.e. open the selection in a new vertical split
---@param prompt_bufnr number: The prompt bufnr
actions.select_vertical = {
pre = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end,
pre = append_to_history,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "vertical")
end,
@ -289,48 +283,12 @@ actions.select_vertical = {
--- i.e. open the selection in a new tab
---@param prompt_bufnr number: The prompt bufnr
actions.select_tab = {
pre = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end,
pre = append_to_history,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "tab")
end,
}
--- Perform 'drop' action on selection, usually something like<br>
---`:drop <selection>`
---
--- i.e. open the selection in a window
---@param prompt_bufnr number: The prompt bufnr
actions.select_drop = {
pre = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "drop")
end,
}
--- Perform 'tab drop' action on selection, usually something like<br>
---`:tab drop <selection>`
---
--- i.e. open the selection in a new tab
---@param prompt_bufnr number: The prompt bufnr
actions.select_tab_drop = {
pre = function(prompt_bufnr)
action_state
.get_current_history()
:append(action_state.get_current_line(), action_state.get_current_picker(prompt_bufnr))
end,
action = function(prompt_bufnr)
return action_set.select(prompt_bufnr, "tab drop")
end,
}
-- TODO: consider adding float!
-- https://github.com/nvim-telescope/telescope.nvim/issues/365
@ -394,16 +352,17 @@ end
local set_edit_line = function(prompt_bufnr, fname, prefix, postfix)
postfix = vim.F.if_nil(postfix, "")
postfix = a.nvim_replace_termcodes(postfix, true, false, true)
local selection = action_state.get_selected_entry()
if selection == nil then
utils.__warn_no_selection(fname)
return
end
actions.close(prompt_bufnr)
a.nvim_feedkeys(a.nvim_replace_termcodes(prefix .. selection.value .. postfix, true, false, true), "t", true)
a.nvim_feedkeys(prefix .. selection.value .. postfix, "n", true)
end
--- Set a value in the command line and dont run it, making it editable.
--- Set a value in the command line and don't run it, making it editable.
---@param prompt_bufnr number: The prompt bufnr
actions.edit_command_line = function(prompt_bufnr)
set_edit_line(prompt_bufnr, "actions.edit_command_line", ":")
@ -422,7 +381,7 @@ actions.set_command_line = function(prompt_bufnr)
vim.cmd(selection.value)
end
--- Set a value in the search line and dont search for it, making it editable.
--- Set a value in the search line and don't search for it, making it editable.
---@param prompt_bufnr number: The prompt bufnr
actions.edit_search_line = function(prompt_bufnr)
set_edit_line(prompt_bufnr, "actions.edit_search_line", "/")
@ -781,7 +740,7 @@ actions.git_checkout_current_buffer = function(prompt_bufnr)
return
end
actions.close(prompt_bufnr)
utils.get_os_command_output({ "git", "checkout", selection.value, "--", selection.file }, cwd)
utils.get_os_command_output({ "git", "checkout", selection.value, "--", selection.current_file }, cwd)
vim.cmd "checktime"
end
@ -864,51 +823,68 @@ end
--- Sends the selected entries to the quickfix list, replacing the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.send_selected_to_qflist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, " ")
end
actions.send_selected_to_qflist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, " ")
end,
}
--- Adds the selected entries to the quickfix list, keeping the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.add_selected_to_qflist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, "a")
end
actions.add_selected_to_qflist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, "a")
end,
}
--- Sends all entries to the quickfix list, replacing the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.send_to_qflist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, " ")
end
actions.send_to_qflist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, " ")
end,
}
--- Adds all entries to the quickfix list, keeping the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.add_to_qflist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, "a")
end
actions.add_to_qflist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, "a")
end,
}
--- Sends the selected entries to the location list, replacing the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.send_selected_to_loclist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, " ", "loclist")
end
actions.send_selected_to_loclist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, " ", "loclist")
end,
}
--- Adds the selected entries to the location list, keeping the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.add_selected_to_loclist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, "a", "loclist")
end
actions.add_selected_to_loclist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, "a", "loclist")
end,
}
--- Sends all entries to the location list, replacing the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.send_to_loclist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, " ", "loclist")
end
actions.send_to_loclist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, " ", "loclist")
end,
}
--- Adds all entries to the location list, keeping the previous entries.
---@param prompt_bufnr number: The prompt bufnr
actions.add_to_loclist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, "a", "loclist")
end
actions.add_to_loclist = {
pre = append_to_history,
action = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, "a", "loclist")
end,
}
local smart_send = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
@ -922,31 +898,39 @@ end
--- Sends the selected entries to the quickfix list, replacing the previous entries.
--- If no entry was selected, sends all entries.
---@param prompt_bufnr number: The prompt bufnr
actions.smart_send_to_qflist = function(prompt_bufnr)
smart_send(prompt_bufnr, " ")
end
actions.smart_send_to_qflist = {
pre = append_to_history,
action = function(prompt_bufnr)
smart_send(prompt_bufnr, " ")
end,
}
--- Adds the selected entries to the quickfix list, keeping the previous entries.
--- If no entry was selected, adds all entries.
---@param prompt_bufnr number: The prompt bufnr
actions.smart_add_to_qflist = function(prompt_bufnr)
smart_send(prompt_bufnr, "a")
end
actions.smart_add_to_qflist = {
pre = append_to_history,
action = function(prompt_bufnr)
smart_send(prompt_bufnr, "a")
end,
}
--- Sends the selected entries to the location list, replacing the previous entries.
--- If no entry was selected, sends all entries.
---@param prompt_bufnr number: The prompt bufnr
actions.smart_send_to_loclist = function(prompt_bufnr)
smart_send(prompt_bufnr, " ", "loclist")
end
actions.smart_send_to_loclist = {
pre = append_to_history,
action = function(prompt_bufnr)
smart_send(prompt_bufnr, " ", "loclist")
end,
}
--- Adds the selected entries to the location list, keeping the previous entries.
--- If no entry was selected, adds all entries.
---@param prompt_bufnr number: The prompt bufnr
actions.smart_add_to_loclist = function(prompt_bufnr)
smart_send(prompt_bufnr, "a", "loclist")
end
actions.smart_add_to_loclist = {
pre = append_to_history,
action = function(prompt_bufnr)
smart_send(prompt_bufnr, "a", "loclist")
end,
}
--- Open completion menu containing the tags which can be used to filter the results in a faster way
---@param prompt_bufnr number: The prompt bufnr
actions.complete_tag = function(prompt_bufnr)
@ -1037,7 +1021,7 @@ end
--- `actions.smart_send_to_qflist + actions.open_qflist`
---@param prompt_bufnr number: The prompt bufnr
actions.open_qflist = function(prompt_bufnr)
vim.cmd [[copen]]
vim.cmd [[botright copen]]
end
--- Open the location list. It makes sense to use this in combination with one of the send_to_loclist actions
@ -1154,26 +1138,10 @@ actions.which_key = function(prompt_bufnr, opts)
local mappings = {}
local mode = a.nvim_get_mode().mode
for _, v in pairs(action_utils.get_registered_mappings(prompt_bufnr)) do
-- holds true for registered keymaps
if type(v.func) == "table" then
local name = ""
for _, action in ipairs(v.func) do
if type(action) == "string" then
name = name == "" and action or name .. " + " .. action
end
end
if name and name ~= "which_key" and name ~= "nop" then
if not opts.only_show_current_mode or mode == v.mode then
table.insert(mappings, { mode = v.mode, keybind = v.keybind, name = name })
end
end
elseif type(v.func) == "function" then
if v.desc and v.desc ~= "which_key" and v.desc ~= "nop" then
if not opts.only_show_current_mode or mode == v.mode then
local fname = action_utils._get_anon_function_name(v.func)
-- telescope.setup mappings might result in function names that reflect the keys
fname = fname:lower() == v.keybind:lower() and "<anonymous>" or fname
table.insert(mappings, { mode = v.mode, keybind = v.keybind, name = fname })
if fname == "<anonymous>" then
table.insert(mappings, { mode = v.mode, keybind = v.keybind, name = v.desc })
if v.desc == "<anonymous>" then
utils.notify("actions.which_key", {
msg = "No name available for anonymous functions.",
level = "INFO",

View File

@ -67,8 +67,6 @@ end
local edit_buffer
do
local map = {
drop = "drop",
["tab drop"] = "tab drop",
edit = "buffer",
new = "sbuffer",
vnew = "vert sbuffer",
@ -80,11 +78,7 @@ do
if command == nil then
error "There was no associated buffer command"
end
if command ~= "drop" and command ~= "tab drop" then
vim.cmd(string.format("%s %d", command, bufnr))
else
vim.cmd(string.format("%s %s", command, vim.api.nvim_buf_get_name(bufnr)))
end
vim.cmd(string.format("%s %d", command, bufnr))
end
end
@ -110,7 +104,7 @@ action_set.edit = function(prompt_bufnr, command)
-- TODO: Check for off-by-one
row = entry.row or entry.lnum
col = vim.F.if_nil(entry.col, 1)
col = entry.col
elseif not entry.bufnr then
-- TODO: Might want to remove this and force people
-- to put stuff into `filename`
@ -164,8 +158,19 @@ action_set.edit = function(prompt_bufnr, command)
-- check if we didn't pick a different buffer
-- prevents restarting lsp server
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
filename = Path:new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd())
pcall(vim.cmd, string.format("%s %s", command, filename))
filename = Path:new(filename):normalize(vim.loop.cwd())
pcall(vim.cmd, string.format("%s %s", command, vim.fn.fnameescape(filename)))
end
end
local pos = vim.api.nvim_win_get_cursor(0)
if col == nil then
if row == pos[1] then
col = pos[2] + 1
elseif row == nil then
row, col = pos[1], pos[2] + 1
else
col = 1
end
end

View File

@ -33,8 +33,6 @@ local select_to_edit_map = {
horizontal = "new",
vertical = "vnew",
tab = "tabedit",
drop = "drop",
["tab drop"] = "tab drop",
}
function action_state.select_key_to_edit_key(type)
return select_to_edit_map[type]

View File

@ -13,7 +13,7 @@ local utils = {}
--- Apply `f` to the entries of the current picker.
--- - Notes:
--- - Mapped entries include all currently filtered results, not just the visible onces.
--- - Mapped entries include all currently filtered results, not just the visible ones.
--- - Indices are 1-indexed, whereas rows are 0-indexed.
--- - Warning: `map_entries` has no return value.
--- - The below example showcases how to collect results
@ -26,7 +26,7 @@ local utils = {}
--- local prompt_bufnr = vim.api.nvim_get_current_buf()
--- local current_picker = action_state.get_current_picker(prompt_bufnr)
--- local results = {}
--- action_utils.map_entries(prompt_bufnr, function(entry, index, row)
--- action_utils.map_entries(prompt_bufnr, function(entry, index, row)
--- results[row] = entry.value
--- end)
--- return results
@ -50,7 +50,7 @@ end
--- Apply `f` to the multi selections of the current picker and return a table of mapped selections.
--- - Notes:
--- - Mapped selections may include results not visible in the results popup.
--- - Mapped selections may include results not visible in the results pop up.
--- - Selected entries are returned in order of their selection.
--- - Warning: `map_selections` has no return value.
--- - The below example showcases how to collect results
@ -63,7 +63,7 @@ end
--- local prompt_bufnr = vim.api.nvim_get_current_buf()
--- local current_picker = action_state.get_current_picker(prompt_bufnr)
--- local results = {}
--- action_utils.map_selections(prompt_bufnr, function(entry, index)
--- action_utils.map_selections(prompt_bufnr, function(entry, index)
--- results[index] = entry.value
--- end)
--- return results
@ -81,25 +81,25 @@ function utils.map_selections(prompt_bufnr, f)
end
end
local findnth = function(str, nth)
local array = {}
for i in string.gmatch(str, "%d+") do
table.insert(array, tonumber(i))
end
return array[nth]
end
--- Utility to collect mappings of prompt buffer in array of `{mode, keybind, name}`.
---@param prompt_bufnr number: The prompt bufnr
function utils.get_registered_mappings(prompt_bufnr)
local ret = {}
for _, mode in ipairs { "n", "i" } do
local mode_mappings = vim.api.nvim_buf_get_keymap(prompt_bufnr, mode)
for _, mapping in ipairs(mode_mappings) do
for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(prompt_bufnr, mode)) do
-- ensure only telescope mappings
if mapping.rhs and string.find(mapping.rhs, [[require%('telescope.mappings'%).execute_keymap]]) then
local funcid = findnth(mapping.rhs, 2)
table.insert(ret, { mode = mode, keybind = mapping.lhs, func = __TelescopeKeymapStore[prompt_bufnr][funcid] })
if mapping.desc then
if mapping.desc:sub(1, 10) == "telescope|" then
table.insert(ret, { mode = mode, keybind = mapping.lhs, desc = mapping.desc:sub(11) })
elseif mapping.desc:sub(1, 11) == "telescopej|" then
local fname = utils._get_anon_function_name(vim.json.decode(mapping.desc:sub(12)))
fname = fname:lower() == mapping.lhs:lower() and "<anonymous>" or fname
table.insert(ret, {
mode = mode,
keybind = mapping.lhs,
desc = fname,
})
end
end
end
end
@ -107,9 +107,8 @@ function utils.get_registered_mappings(prompt_bufnr)
end
-- Best effort to infer function names for actions.which_key
function utils._get_anon_function_name(func_ref)
function utils._get_anon_function_name(info)
local Path = require "plenary.path"
local info = debug.getinfo(func_ref)
local fname
-- if fn defined in string (ie loadstring) source is string
-- if fn defined in file, source is file name prefixed with a `@´

View File

@ -59,6 +59,36 @@ local get_open_filelist = function(grep_open_files, cwd)
return filelist
end
local opts_contain_invert = function(args)
local invert = false
local files_with_matches = false
for _, v in ipairs(args) do
if v == "--invert-match" then
invert = true
elseif v == "--files-with-matches" or v == "--files-without-match" then
files_with_matches = true
end
if #v >= 2 and v:sub(1, 1) == "-" and v:sub(2, 2) ~= "-" then
local non_option = false
for i = 2, #v do
local vi = v:sub(i, i)
if vi == "=" then -- ignore option -g=xxx
break
elseif vi == "g" or vi == "f" or vi == "m" or vi == "e" or vi == "r" or vi == "t" or vi == "T" then
non_option = true
elseif non_option == false and vi == "v" then
invert = true
elseif non_option == false and vi == "l" then
files_with_matches = true
end
end
end
end
return invert, files_with_matches
end
-- Special keys:
-- opts.search_dirs -- list of directory to search in
-- opts.grep_open_files -- boolean to restrict search to open files
@ -96,9 +126,10 @@ files.live_grep = function(opts)
end
end
local live_grepper = finders.new_job(function(prompt)
-- TODO: Probably could add some options for smart case and whatever else rg offers.
local args = flatten { vimgrep_arguments, additional_args }
opts.__inverted, opts.__matches = opts_contain_invert(args)
local live_grepper = finders.new_job(function(prompt)
if not prompt or prompt == "" then
return nil
end
@ -111,7 +142,7 @@ files.live_grep = function(opts)
search_list = search_dirs
end
return flatten { vimgrep_arguments, additional_args, "--", prompt, search_list }
return flatten { args, "--", prompt, search_list }
end, opts.entry_maker or make_entry.gen_from_vimgrep(opts), opts.max_results, opts.cwd)
pickers
@ -148,7 +179,6 @@ files.grep_string = function(opts)
if search == "" then
search = { "-v", "--", "^[[:space:]]*$" }
opts.__inverted = true
else
search = { "--", search }
end
@ -159,6 +189,7 @@ files.grep_string = function(opts)
opts.word_match,
search,
}
opts.__inverted, opts.__matches = opts_contain_invert(args)
if opts.grep_open_files then
for _, file in ipairs(get_open_filelist(opts.grep_open_files, opts.cwd)) do
@ -401,13 +432,11 @@ files.current_buffer_fuzzy_find = function(opts)
local _, ts_configs = pcall(require, "nvim-treesitter.configs")
local parser_ok, parser = pcall(vim.treesitter.get_parser, opts.bufnr, filetype)
local query_ok, query = pcall(vim.treesitter.get_query, filetype, "highlights")
local get_query = vim.treesitter.query.get or vim.treesitter.get_query
local query_ok, query = pcall(get_query, filetype, "highlights")
if parser_ok and query_ok and ts_ok and ts_configs.is_enabled("highlight", filetype, opts.bufnr) then
local root = parser:parse()[1]:root()
local highlighter = vim.treesitter.highlighter.new(parser)
local highlighter_query = highlighter:get_query(filetype)
local line_highlights = setmetatable({}, {
__index = function(t, k)
local obj = {}
@ -418,9 +447,23 @@ files.current_buffer_fuzzy_find = function(opts)
-- update to changes on Neovim master, see https://github.com/neovim/neovim/pull/19931
-- TODO(clason): remove when dropping support for Neovim 0.7
local on_nvim_master = vim.fn.has "nvim-0.8" == 1
local get_hl_from_capture = (function()
if vim.fn.has "nvim-0.8" == 1 then
return function(q, id)
return "@" .. q.captures[id]
end
else
local highlighter = vim.treesitter.highlighter.new(parser)
local highlighter_query = highlighter:get_query(filetype)
return function(_, id)
return highlighter_query:_get_hl_from_capture(id)
end
end
end)()
for id, node in query:iter_captures(root, opts.bufnr, 0, -1) do
local hl = on_nvim_master and query.captures[id] or highlighter_query:_get_hl_from_capture(id)
local hl = get_hl_from_capture(query, id)
if hl and type(hl) ~= "number" then
local row1, col1, row2, col2 = node:range()
@ -469,6 +512,7 @@ files.current_buffer_fuzzy_find = function(opts)
return true
end,
push_cursor_on_edit = true,
})
:find()
end

View File

@ -71,12 +71,9 @@ git.commits = function(opts)
sorter = conf.file_sorter(opts),
attach_mappings = function(_, map)
actions.select_default:replace(actions.git_checkout)
map("i", "<c-r>m", actions.git_reset_mixed)
map("n", "<c-r>m", actions.git_reset_mixed)
map("i", "<c-r>s", actions.git_reset_soft)
map("n", "<c-r>s", actions.git_reset_soft)
map("i", "<c-r>h", actions.git_reset_hard)
map("n", "<c-r>h", actions.git_reset_hard)
map({ "i", "n" }, "<c-r>m", actions.git_reset_mixed)
map({ "i", "n" }, "<c-r>s", actions.git_reset_soft)
map({ "i", "n" }, "<c-r>h", actions.git_reset_hard)
return true
end,
})
@ -293,23 +290,12 @@ git.branches = function(opts)
sorter = conf.file_sorter(opts),
attach_mappings = function(_, map)
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)
map("i", "<c-a>", actions.git_create_branch)
map("n", "<c-a>", actions.git_create_branch)
map("i", "<c-s>", actions.git_switch_branch)
map("n", "<c-s>", actions.git_switch_branch)
map("i", "<c-d>", actions.git_delete_branch)
map("n", "<c-d>", actions.git_delete_branch)
map("i", "<c-y>", actions.git_merge_branch)
map("n", "<c-y>", actions.git_merge_branch)
map({ "i", "n" }, "<c-t>", actions.git_track_branch)
map({ "i", "n" }, "<c-r>", actions.git_rebase_branch)
map({ "i", "n" }, "<c-a>", actions.git_create_branch)
map({ "i", "n" }, "<c-s>", actions.git_switch_branch)
map({ "i", "n" }, "<c-d>", actions.git_delete_branch)
map({ "i", "n" }, "<c-y>", actions.git_merge_branch)
return true
end,
})
@ -327,7 +313,7 @@ git.status = function(opts)
local gen_new_finder = function()
local expand_dir = vim.F.if_nil(opts.expand_dir, true)
local git_cmd = { "git", "status", "-s", "--", "." }
local git_cmd = { "git", "status", "-z", "--", "." }
if expand_dir then
table.insert(git_cmd, #git_cmd - 1, "-u")
@ -345,7 +331,7 @@ git.status = function(opts)
end
return finders.new_table {
results = output,
results = vim.split(output[1], "", { trimempty = true }),
entry_maker = vim.F.if_nil(opts.entry_maker, make_entry.gen_from_git_status(opts)),
}
end
@ -368,8 +354,7 @@ git.status = function(opts)
end,
}
map("i", "<tab>", actions.git_staging_toggle)
map("n", "<tab>", actions.git_staging_toggle)
map({ "i", "n" }, "<tab>", actions.git_staging_toggle)
return true
end,
})
@ -392,11 +377,7 @@ local set_opts_cwd = function(opts)
local in_bare = utils.get_os_command_output({ "git", "rev-parse", "--is-bare-repository" }, opts.cwd)
if in_worktree[1] ~= "true" and in_bare[1] ~= "true" then
utils.notify("builtin.git", {
msg = opts.cwd .. " is not a git directory",
level = "ERROR",
})
return false
error(opts.cwd .. " is not a git directory")
elseif in_worktree[1] ~= "true" and in_bare[1] == "true" then
opts.is_bare = true
end
@ -405,8 +386,6 @@ local set_opts_cwd = function(opts)
opts.cwd = git_root[1]
end
end
return true
end
local function apply_checks(mod)
@ -414,10 +393,8 @@ local function apply_checks(mod)
mod[k] = function(opts)
opts = vim.F.if_nil(opts, {})
local ok = set_opts_cwd(opts)
if ok then
v(opts)
end
set_opts_cwd(opts)
v(opts)
end
end

View File

@ -62,6 +62,10 @@ internal.builtin = function(opts)
end
end
table.sort(objs, function(a, b)
return a.text < b.text
end)
opts.bufnr = vim.api.nvim_get_current_buf()
opts.winnr = vim.api.nvim_get_current_win()
pickers
@ -198,8 +202,7 @@ internal.pickers = function(opts)
opts["initial_mode"] = cached_pickers[selection_index].initial_mode
internal.resume(opts)
end)
map("i", "<C-x>", actions.remove_selected_picker)
map("n", "<C-x>", actions.remove_selected_picker)
map({ "i", "n" }, "<C-x>", actions.remove_selected_picker)
return true
end,
})
@ -368,6 +371,7 @@ internal.commands = function(opts)
if val.nargs == "0" then
vim.cmd(cmd)
vim.fn.histadd("cmd", val.name)
else
vim.cmd [[stopinsert]]
vim.fn.feedkeys(cmd, "n")
@ -512,13 +516,14 @@ internal.oldfiles = function(opts)
end
for _, file in ipairs(vim.v.oldfiles) do
if vim.loop.fs_stat(file) and not vim.tbl_contains(results, file) and file ~= current_file then
local file_stat = vim.loop.fs_stat(file)
if file_stat and file_stat.type == "file" and not vim.tbl_contains(results, file) and file ~= current_file then
table.insert(results, file)
end
end
if opts.cwd_only then
local cwd = vim.loop.cwd()
local cwd = vim.loop.cwd() .. utils.get_separator()
cwd = cwd:gsub([[\]], [[\\]])
results = vim.tbl_filter(function(file)
return vim.fn.matchstrpos(file, cwd)[2] ~= -1
@ -556,10 +561,8 @@ internal.command_history = function(opts)
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
map("i", "<CR>", actions.set_command_line)
map("n", "<CR>", actions.set_command_line)
map("n", "<C-e>", actions.edit_command_line)
map("i", "<C-e>", actions.edit_command_line)
actions.select_default:replace(actions.set_command_line)
map({ "i", "n" }, "<C-e>", actions.edit_command_line)
-- TODO: Find a way to insert the text... it seems hard.
-- map('i', '<C-i>', actions.insert_value, { expr = true })
@ -588,10 +591,8 @@ internal.search_history = function(opts)
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
map("i", "<CR>", actions.set_search_line)
map("n", "<CR>", actions.set_search_line)
map("n", "<C-e>", actions.edit_search_line)
map("i", "<C-e>", actions.edit_search_line)
actions.select_default:replace(actions.set_search_line)
map({ "i", "n" }, "<C-e>", actions.edit_search_line)
-- TODO: Find a way to insert the text... it seems hard.
-- map('i', '<C-i>', actions.insert_value, { expr = true })
@ -755,8 +756,16 @@ internal.man_pages = function(opts)
opts.sections = vim.F.if_nil(opts.sections, { "1" })
assert(vim.tbl_islist(opts.sections), "sections should be a list")
opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function()
local is_darwin = vim.loop.os_uname().sysname == "Darwin"
return is_darwin and { "apropos", " " } or { "apropos", "" }
local uname = vim.loop.os_uname()
local sysname = string.lower(uname.sysname)
if sysname == "darwin" then
local major_version = tonumber(vim.fn.matchlist(uname.release, [[^\(\d\+\)\..*]])[2]) or 0
return major_version >= 22 and { "apropos", "." } or { "apropos", " " }
elseif sysname == "freebsd" then
return { "apropos", "." }
else
return { "apropos", "" }
end
end)
opts.entry_maker = opts.entry_maker or make_entry.gen_from_apropos(opts)
opts.env = { PATH = vim.env.PATH, MANPATH = vim.env.MANPATH }
@ -1069,7 +1078,7 @@ internal.marks = function(opts)
end
internal.registers = function(opts)
local registers_table = { '"', "_", "#", "=", "_", "/", "*", "+", ":", ".", "%" }
local registers_table = { '"', "-", "#", "=", "/", "*", "+", ":", ".", "%" }
-- named
for i = 0, 9 do
@ -1091,7 +1100,7 @@ internal.registers = function(opts)
sorter = conf.generic_sorter(opts),
attach_mappings = function(_, map)
actions.select_default:replace(actions.paste_register)
map("i", "<C-e>", actions.edit_register)
map({ "i", "n" }, "<C-e>", actions.edit_register)
return true
end,
@ -1335,7 +1344,7 @@ internal.jumplist = function(opts)
local sorted_jumplist = {}
for i = #jumplist, 1, -1 do
if vim.api.nvim_buf_is_valid(jumplist[i].bufnr) then
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum, jumplist[i].lnum + 1, false)[1]
jumplist[i].text = vim.api.nvim_buf_get_lines(jumplist[i].bufnr, jumplist[i].lnum - 1, jumplist[i].lnum, false)[1]
or ""
table.insert(sorted_jumplist, jumplist[i])
end

View File

@ -25,7 +25,7 @@ lsp.references = function(opts)
local locations = {}
if result then
local results = vim.lsp.util.locations_to_items(result, vim.lsp.get_client_by_id(ctx.client_id).offset_encoding)
if not include_current_line then
if include_current_line then
locations = vim.tbl_filter(function(v)
-- Remove current line from result
return not (v.filename == filepath and v.lnum == lnum)
@ -165,12 +165,15 @@ local function list_or_jump(action, title, opts)
if #flattened_results == 0 then
return
elseif #flattened_results == 1 and opts.jump_type ~= "never" then
if opts.jump_type == "tab" then
vim.cmd "tabedit"
elseif opts.jump_type == "split" then
vim.cmd "new"
elseif opts.jump_type == "vsplit" then
vim.cmd "vnew"
local uri = params.textDocument.uri
if uri ~= flattened_results[1].uri and uri ~= flattened_results[1].targetUri then
if opts.jump_type == "tab" then
vim.cmd "tabedit"
elseif opts.jump_type == "split" then
vim.cmd "new"
elseif opts.jump_type == "vsplit" then
vim.cmd "vnew"
end
end
vim.lsp.util.jump_to_location(flattened_results[1], offset_encoding)
else

View File

@ -55,6 +55,7 @@ end
---@field additional_args function|table: additional arguments to be passed on. Can be fn(opts) -> tbl
---@field max_results number: define a upper result value
---@field disable_coordinates boolean: don't show the line & row numbers (default: false)
---@field file_encoding string: file encoding for the entry & previewer
builtin.live_grep = require_on_exported_call("telescope.builtin.__files").live_grep
--- Searches for the string under your cursor in your current working directory
@ -68,6 +69,7 @@ builtin.live_grep = require_on_exported_call("telescope.builtin.__files").live_g
---@field additional_args function|table: additional arguments to be passed on. Can be fn(opts) -> tbl
---@field disable_coordinates boolean: don't show the line and row numbers (default: false)
---@field only_sort_text boolean: only sort the text, not the file, line or row (default: false)
---@field file_encoding string: file encoding for the entry & previewer
builtin.grep_string = require_on_exported_call("telescope.builtin.__files").grep_string
--- Search for files (respecting .gitignore)
@ -80,6 +82,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.__files").grep
---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false)
---@field search_dirs table: directory/directories/files to search
---@field search_file string: specify a filename to search for
---@field file_encoding string: file encoding for the previewer
builtin.find_files = require_on_exported_call("telescope.builtin.__files").find_files
--- This is an alias for the `find_files` picker
@ -91,11 +94,13 @@ builtin.fd = builtin.find_files
---@field show_line boolean: if true, shows the row:column that the result is found at (default: true)
---@field bufnr number: specify the buffer number where treesitter should run. (default: current buffer)
---@field symbol_highlights table: string -> string. Matches symbol with hl_group
---@field file_encoding string: file encoding for the previewer
builtin.treesitter = require_on_exported_call("telescope.builtin.__files").treesitter
--- Live fuzzy search inside of the currently open buffer
---@param opts table: options to pass to the picker
---@field skip_empty_lines boolean: if true we dont display empty lines (default: false)
---@field skip_empty_lines boolean: if true we don't display empty lines (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.current_buffer_fuzzy_find = require_on_exported_call("telescope.builtin.__files").current_buffer_fuzzy_find
--- Lists tags in current directory with tag location file preview (users are required to run ctags -R to generate tags
@ -132,7 +137,8 @@ builtin.current_buffer_tags = require_on_exported_call("telescope.builtin.__file
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field show_untracked boolean: if true, adds `--others` flag to command and shows untracked files (default: false)
---@field recurse_submodules boolean: if true, adds the `--recurse-submodules` flag to command (default: false)
---@field git_command table: command that will be exectued. {"git","ls-files","--exclude-standard","--cached"}
---@field git_command table: command that will be executed. {"git","ls-files","--exclude-standard","--cached"}
---@field file_encoding string: file encoding for the previewer
builtin.git_files = require_on_exported_call("telescope.builtin.__git").files
--- Lists commits for current directory with diff preview
@ -144,11 +150,11 @@ builtin.git_files = require_on_exported_call("telescope.builtin.__git").files
---@param opts table: options to pass to the picker
---@field cwd string: specify the path of the repo
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field git_command table: command that will be exectued. {"git","log","--pretty=oneline","--abbrev-commit","--","."}
---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit","--","."}
builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commits
--- Lists commits for current buffer with diff preview
--- - Default keymaps or your overriden `select_` keys:
--- - Default keymaps or your overridden `select_` keys:
--- - `<cr>`: checks out the currently selected commit
--- - `<c-v>`: opens a diff in a vertical split
--- - `<c-x>`: opens a diff in a horizontal split
@ -157,7 +163,7 @@ builtin.git_commits = require_on_exported_call("telescope.builtin.__git").commit
---@field cwd string: specify the path of the repo
---@field use_git_root boolean: if we should use git root as cwd or the cwd (important for submodule) (default: true)
---@field current_file string: specify the current file that should be used for bcommits (default: current buffer)
---@field git_command table: command that will be exectued. {"git","log","--pretty=oneline","--abbrev-commit"}
---@field git_command table: command that will be executed. {"git","log","--pretty=oneline","--abbrev-commit"}
builtin.git_bcommits = require_on_exported_call("telescope.builtin.__git").bcommits
--- List branches for current directory, with output from `git log --oneline` shown in the preview window
@ -222,8 +228,8 @@ builtin.pickers = require_on_exported_call("telescope.builtin.__internal").picke
--- Use the telescope...
---@param opts table: options to pass to the picker
---@field show_pluto boolean: we love pluto (default: false, because its a hidden feature)
---@field show_moon boolean: we love the moon (default: false, because its a hidden feature)
---@field show_pluto boolean: we love Pluto (default: false, because its a hidden feature)
---@field show_moon boolean: we love the Moon (default: false, because its a hidden feature)
builtin.planets = require_on_exported_call("telescope.builtin.__internal").planets
--- Lists symbols inside of `data/telescope-sources/*.json` found in your runtime path
@ -265,6 +271,7 @@ builtin.loclist = require_on_exported_call("telescope.builtin.__internal").locli
---@param opts table: options to pass to the picker
---@field only_cwd boolean: show only files in the cwd (default: false)
---@field cwd_only boolean: alias for only_cwd
---@field file_encoding string: file encoding for the previewer
builtin.oldfiles = require_on_exported_call("telescope.builtin.__internal").oldfiles
--- Lists commands that were executed recently, and reruns them on `<cr>`
@ -309,6 +316,7 @@ builtin.reloader = require_on_exported_call("telescope.builtin.__internal").relo
---@field sort_lastused boolean: Sorts current and last buffer to the top and selects the lastused (default: false)
---@field sort_mru boolean: Sorts all buffers after most recent used. Not just the current and last one (default: false)
---@field bufnr_width number: Defines the width of the buffer numbers in front of the filenames (default: dynamic)
---@field file_encoding string: file encoding for the previewer
builtin.buffers = require_on_exported_call("telescope.builtin.__internal").buffers
--- Lists available colorschemes and applies them on `<cr>`
@ -318,6 +326,7 @@ builtin.colorscheme = require_on_exported_call("telescope.builtin.__internal").c
--- Lists vim marks and their value, jumps to the mark on `<cr>`
---@param opts table: options to pass to the picker
---@field file_encoding string: file encoding for the previewer
builtin.marks = require_on_exported_call("telescope.builtin.__internal").marks
--- Lists vim registers, pastes the contents of the register on `<cr>`
@ -375,6 +384,7 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.__internal").jump
---@field fname_width number: defines the width of the filename section (default: 30)
---@field show_line boolean: show results text (default: true)
---@field trim_text boolean: trim results text (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.lsp_references = require_on_exported_call("telescope.builtin.__lsp").references
--- Lists LSP incoming calls for word under the cursor, jumps to reference on `<cr>`
@ -382,6 +392,7 @@ builtin.lsp_references = require_on_exported_call("telescope.builtin.__lsp").ref
---@field fname_width number: defines the width of the filename section (default: 30)
---@field show_line boolean: show results text (default: true)
---@field trim_text boolean: trim results text (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.lsp_incoming_calls = require_on_exported_call("telescope.builtin.__lsp").incoming_calls
--- Lists LSP outgoing calls for word under the cursor, jumps to reference on `<cr>`
@ -389,31 +400,35 @@ builtin.lsp_incoming_calls = require_on_exported_call("telescope.builtin.__lsp")
---@field fname_width number: defines the width of the filename section (default: 30)
---@field show_line boolean: show results text (default: true)
---@field trim_text boolean: trim results text (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.lsp_outgoing_calls = require_on_exported_call("telescope.builtin.__lsp").outgoing_calls
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
---@param opts table: options to pass to the picker
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
---@field jump_type string: how to goto definition if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
---@field fname_width number: defines the width of the filename section (default: 30)
---@field show_line boolean: show results text (default: true)
---@field trim_text boolean: trim results text (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.lsp_definitions = require_on_exported_call("telescope.builtin.__lsp").definitions
--- Goto the definition of the type of the word under the cursor, if there's only one,
--- otherwise show all options in Telescope
---@param opts table: options to pass to the picker
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
---@field jump_type string: how to goto definition if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
---@field fname_width number: defines the width of the filename section (default: 30)
---@field show_line boolean: show results text (default: true)
---@field trim_text boolean: trim results text (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.lsp_type_definitions = require("telescope.builtin.__lsp").type_definitions
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
---@param opts table: options to pass to the picker
---@field jump_type string: how to goto implementation if there is only one, values: "tab", "split", "vsplit", "never"
---@field jump_type string: how to goto implementation if there is only one and the definition file is different from the current file, values: "tab", "split", "vsplit", "never"
---@field fname_width number: defines the width of the filename section (default: 30)
---@field show_line boolean: show results text (default: true)
---@field trim_text boolean: trim results text (default: false)
---@field file_encoding string: file encoding for the previewer
builtin.lsp_implementations = require_on_exported_call("telescope.builtin.__lsp").implementations
--- Lists LSP document symbols in the current buffer
@ -421,10 +436,13 @@ builtin.lsp_implementations = require_on_exported_call("telescope.builtin.__lsp"
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
---@param opts table: options to pass to the picker
---@field fname_width number: defines the width of the filename section (default: 30)
---@field symbol_width number: defines the width of the symbol section (default: 25)
---@field symbol_type_width number: defines the width of the symbol type section (default: 8)
---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false)
---@field symbols string|table: filter results by symbol kind(s)
---@field ignore_symbols string|table: list of symbols to ignore
---@field symbol_highlights table: string -> string. Matches symbol with hl_group
---@field file_encoding string: file encoding for the previewer
builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.__lsp").document_symbols
--- Lists LSP document symbols in the current workspace
@ -433,10 +451,13 @@ builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.__lsp
---@param opts table: options to pass to the picker
---@field query string: for what to query the workspace (default: "")
---@field fname_width number: defines the width of the filename section (default: 30)
---@field symbol_width number: defines the width of the symbol section (default: 25)
---@field symbol_type_width number: defines the width of the symbol type section (default: 8)
---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false)
---@field symbols string|table: filter results by symbol kind(s)
---@field ignore_symbols string|table: list of symbols to ignore
---@field symbol_highlights table: string -> string. Matches symbol with hl_group
---@field file_encoding string: file encoding for the previewer
builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.__lsp").workspace_symbols
--- Dynamically lists LSP for all workspace symbols
@ -448,6 +469,7 @@ builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.__ls
---@field symbols string|table: filter results by symbol kind(s)
---@field ignore_symbols string|table: list of symbols to ignore
---@field symbol_highlights table: string -> string. Matches symbol with hl_group
---@field file_encoding string: file encoding for the previewer
builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.builtin.__lsp").dynamic_workspace_symbols
--
@ -474,9 +496,10 @@ builtin.lsp_dynamic_workspace_symbols = require_on_exported_call("telescope.buil
builtin.diagnostics = require_on_exported_call("telescope.builtin.__diagnostics").get
local apply_config = function(mod)
local pickers_conf = require("telescope.config").pickers
for k, v in pairs(mod) do
mod[k] = function(opts)
local pickers_conf = require("telescope.config").pickers
opts = opts or {}
opts.bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
opts.winnr = opts.winnr or vim.api.nvim_get_current_win()

View File

@ -194,13 +194,13 @@ append(
"cycle_layout_list",
{ "horizontal", "vertical" },
[[
Determines the layouts to cycle through when using `actions.cycle_layout_next`
and `actions.cycle_layout_prev`.
Determines the layouts to cycle through when using `actions.layout.cycle_layout_next`
and `actions.layout.cycle_layout_prev`.
Should be a list of "layout setups".
Each "layout setup" can take one of two forms:
1. string <br>
1. string
This is interpreted as the name of a `layout_strategy`
2. table <br>
2. table
A table with possible keys `layout_strategy`, `layout_config` and `previewer`
Default: { "horizontal", "vertical" }
@ -241,7 +241,6 @@ append(
[[
The character(s) that will be shown in front of the current selection.
Default: '> ']]
)
@ -289,7 +288,7 @@ append(
"path_display",
{},
[[
Determines how file paths are displayed
Determines how file paths are displayed.
path_display can be set to an array with a combination of:
- "hidden" hide file names
@ -302,7 +301,7 @@ append(
- "shorten" only display the first character of each directory in
the path
- "truncate" truncates the start of the path when the whole path will
not fit. To increase the the gap between the path and the edge.
not fit. To increase the gap between the path and the edge,
set truncate to number `truncate = 3`
You can also specify the number of characters of each directory name
@ -418,7 +417,7 @@ append(
[[
Defines the default title of the prompt window. A false value
can be used to hide the title altogether. Most of the times builtins
define a prompt_title which will be prefered over this default.
define a prompt_title which will be preferred over this default.
Default: "Prompt"]]
)
@ -442,6 +441,8 @@ append(
Will allow you to completely remove all of telescope's default maps
and use your own.
Default: nil
]]
)
@ -469,11 +470,11 @@ append(
Fields:
- path: The path to the telescope history as string.
default: stdpath("data")/telescope_history
Default: stdpath("data")/telescope_history
- limit: The amount of entries that will be written in the
history.
Warning: If limit is set to nil it will grow unbound.
default: 100
Default: 100
- handler: A lua function that implements the history.
This is meant as a developer setting for extensions to
override the history handling, e.g.,
@ -507,7 +508,8 @@ append(
indices larger than `cache_picker.num_pickers` will
be cleared.
Default: 1
- limit_entries: The amount of entries that will be written in the
- limit_entries: The amount of entries that will be saved for each
picker.
Default: 1000
]]
)
@ -611,7 +613,7 @@ append(
- msg_bg_fillchar: Character to fill background of unpreviewable buffers with
Default: ""
- hide_on_startup: Hide previewer when picker starts. Previewer can be toggled
with actions.toggle_preview.
with actions.layout.toggle_preview.
Default: false
]]
)
@ -677,7 +679,7 @@ append(
[[
A function pointer that specifies the file_sorter. This sorter will
be used for find_files, git_files and similar.
Hint: If you load a native sorter, you dont need to change this value,
Hint: If you load a native sorter, you don't need to change this value,
the native sorter will override it anyway.
Default: require("telescope.sorters").get_fzy_sorter]]
@ -689,7 +691,7 @@ append(
[[
A function pointer to the generic sorter. The sorter that should be
used for everything that is not a file.
Hint: If you load a native sorter, you dont need to change this value,
Hint: If you load a native sorter, you don't need to change this value,
the native sorter will override it anyway.
Default: require("telescope.sorters").get_fzy_sorter]]
@ -702,7 +704,7 @@ append(
[[
This points to a wrapper sorter around the generic_sorter that is able
to do prefiltering.
Its usually used for lsp_*_symbols and lsp_*_diagnostics
It's usually used for lsp_*_symbols and lsp_*_diagnostics
Default: require("telescope.sorters").prefilter]]
)

View File

@ -140,23 +140,27 @@ end
_resolve_map[function(val)
return type(val) == "table" and val["max"] ~= nil and val[1] ~= nil and val[1] >= 0 and val[1] < 1
end] =
function(selector, val)
return function(...)
local selected = select(selector, ...)
return math.min(math.floor(val[1] * selected), val["max"])
end
end] = function(
selector,
val
)
return function(...)
local selected = select(selector, ...)
return math.min(math.floor(val[1] * selected), val["max"])
end
end
_resolve_map[function(val)
return type(val) == "table" and val["min"] ~= nil and val[1] ~= nil and val[1] >= 0 and val[1] < 1
end] =
function(selector, val)
return function(...)
local selected = select(selector, ...)
return math.max(math.floor(val[1] * selected), val["min"])
end
end] = function(
selector,
val
)
return function(...)
local selected = select(selector, ...)
return math.max(math.floor(val[1] * selected), val["min"])
end
end
-- Add padding option
_resolve_map[function(val)

View File

@ -65,16 +65,24 @@ function JobFinder:_find(prompt, process_result, process_complete)
self.job:shutdown()
end
local line_num = 0
local on_output = function(_, line, _)
line_num = line_num + 1
if not line or line == "" then
return
end
local entry
if self.entry_maker then
line = self.entry_maker(line)
entry = self.entry_maker(line)
if entry then
entry.index = line_num
end
else
entry = line
end
process_result(line)
process_result(entry)
end
local opts = self:fn_command(prompt)
@ -131,8 +139,14 @@ end
function DynamicFinder:_find(prompt, process_result, process_complete)
local results = self.fn(prompt)
local result_num = 0
for _, result in ipairs(results) do
if process_result(self.entry_maker(result)) then
result_num = result_num + 1
local entry = self.entry_maker(result)
if entry then
entry.index = result_num
end
if process_result(entry) then
return
end
end
@ -204,8 +218,13 @@ finders.new_table = function(t)
return async_static_finder(t)
end
finders.new_dynamic = function(t)
return DynamicFinder:new(t)
--- Used to create a finder from a function.
--
---@param opts table: stuff
-- @key fn function() => list[string]
-- @key entry_maker function Optional: function(line: string) => table
finders.new_dynamic = function(opts)
return DynamicFinder:new(opts)
end
return finders

View File

@ -56,8 +56,14 @@ return function(opts)
stdout = stdout,
}
local line_num = 0
for line in stdout:iter(true) do
if process_result(entry_maker(line)) then
line_num = line_num + 1
local entry = entry_maker(line)
if entry then
entry.index = line_num
end
if process_result(entry) then
return
end
end

View File

@ -70,9 +70,12 @@ return function(opts)
async.util.scheduler()
end
local v = entry_maker(line)
results[num_results] = v
process_result(v)
local entry = entry_maker(line)
if entry then
entry.index = num_results
end
results[num_results] = entry
process_result(entry)
end
process_complete()

View File

@ -30,7 +30,7 @@ function from_entry.path(entry, validate, escape)
-- TODO(conni2461): we are not going to return the expanded path because
-- this would lead to cache misses in the perviewer.
-- Requires overall refactoring in previewer interface
local expanded = vim.fn.expand(path)
local expanded = vim.fn.expand(vim.fn.escape(path, "$?*[]"))
if (vim.fn.filereadable(expanded) + vim.fn.isdirectory(expanded)) == 0 then
return
end

View File

@ -1,4 +1,10 @@
local health = vim.health or require "health"
local start = health.start or health.report_start
local ok = health.ok or health.report_ok
local warn = health.warn or health.report_warn
local error = health.error or health.report_error
local info = health.info or health.report_info
local extension_module = require "telescope._extensions"
local extension_info = require("telescope").extensions
local is_win = vim.api.nvim_call_function("has", { "win32" }) == 1
@ -60,23 +66,23 @@ local M = {}
M.check = function()
-- Required lua libs
health.report_start "Checking for required plugins"
start "Checking for required plugins"
for _, plugin in ipairs(required_plugins) do
if lualib_installed(plugin.lib) then
health.report_ok(plugin.lib .. " installed.")
ok(plugin.lib .. " installed.")
else
local lib_not_installed = plugin.lib .. " not found."
if plugin.optional then
health.report_warn(("%s %s"):format(lib_not_installed, plugin.info))
warn(("%s %s"):format(lib_not_installed, plugin.info))
else
health.report_error(lib_not_installed)
error(lib_not_installed)
end
end
end
-- external dependencies
-- TODO: only perform checks if user has enabled dependency in their config
health.report_start "Checking external dependencies"
start "Checking external dependencies"
for _, opt_dep in pairs(optional_dependencies) do
for _, package in ipairs(opt_dep.package) do
@ -84,9 +90,9 @@ M.check = function()
if not installed then
local err_msg = ("%s: not found."):format(package.name)
if package.optional then
health.report_warn(("%s %s"):format(err_msg, ("Install %s for extended capabilities"):format(package.url)))
warn(("%s %s"):format(err_msg, ("Install %s for extended capabilities"):format(package.url)))
else
health.report_error(
error(
("%s %s"):format(
err_msg,
("`%s` finder will not function without %s installed."):format(opt_dep.finder_name, package.url)
@ -95,13 +101,13 @@ M.check = function()
end
else
local eol = version:find "\n"
health.report_ok(("%s: found %s"):format(package.name, version:sub(0, eol - 1) or "(unknown version)"))
ok(("%s: found %s"):format(package.name, version:sub(0, eol - 1) or "(unknown version)"))
end
end
end
-- Extensions
health.report_start "===== Installed extensions ====="
start "===== Installed extensions ====="
local installed = {}
for extension_name, _ in pairs(extension_info) do
@ -112,11 +118,11 @@ M.check = function()
for _, installed_ext in ipairs(installed) do
local extension_healthcheck = extension_module._health[installed_ext]
health.report_start(string.format("Telescope Extension: `%s`", installed_ext))
start(string.format("Telescope Extension: `%s`", installed_ext))
if extension_healthcheck then
extension_healthcheck()
else
health.report_info "No healthcheck provided"
info "No healthcheck provided"
end
end
end

View File

@ -13,10 +13,10 @@ local telescope = {}
---
--- Getting started with telescope:
--- 1. Run `:checkhealth telescope` to make sure everything is installed.
--- 2. Evaluate it working with
--- 2. Evaluate it is working with
--- `:Telescope find_files` or
--- `:lua require("telescope.builtin").find_files()`
--- 3. Put a `require("telescope").setup() call somewhere in your neovim config.
--- 3. Put a `require("telescope").setup()` call somewhere in your neovim config.
--- 4. Read |telescope.setup| to check what config keys are available and what you can put inside the setup call
--- 5. Read |telescope.builtin| to check which builtin pickers are offered and what options these implement
--- 6. Profit
@ -31,14 +31,14 @@ local telescope = {}
--- │ │ ┌───│Manager│────│ Sorter │┐ └───┬───* │
--- │ ▼ ▼ └───────* └────────┘│ │ │
--- │ 1────────┐ 2───┴──┐ │ │
--- │ ┌─────│ Picker │ │Finder│────┘ │
--- │ ┌─────│ Picker │ │Finder│────┘ │
--- │ ▼ └───┬────┘ └──────* │
--- │ ┌────────┐ │ 3────────+ ▲ │
--- │ │Selected│ └───────│ Prompt │─────────┘ │
--- │ │ Entry │ └───┬────┘ │
--- │ └────────* ┌───┴────┐ ┌────────┐ ┌────────┐ │
--- │ │ ▲ 4─────────┐│ Prompt │ │(Attach)│ │Actions │ │
--- │ ▼ └──► │ Results ││ Buffer │◄─┤Mappings│◄─┤User Fn │ │
--- │ ▼ └──▶ │ Results ││ Buffer │◀─┤Mappings│◀─┤User Fn │ │
--- │5─────────┐ └─────────┘└────────┘ └────────┘ └────────┘ │
--- ││Previewer│ │
--- │└─────────┘ telescope.nvim architecture │

View File

@ -4,33 +4,32 @@
---
--- Each picker has a finder made up of two parts, the results which are the
--- data to be displayed, and the entry_maker. These entry_makers are functions
--- returned from make_entry functions. These will be referrd to as
--- returned from make_entry functions. These will be referred to as
--- entry_makers in the following documentation.
---
--- Every entry maker returns a function which accepts the data to be used for
--- Every entry maker returns a function that accepts the data to be used for
--- an entry. This function will return an entry table (or nil, meaning skip
--- this entry) which contains of the - following important keys:
--- this entry) which contains the following important keys:
--- - value any: value key can be anything but still required
--- - valid bool: is an optional key because it defaults to true but if the key
--- is set to false it will not be displayed by the picker. (optional)
--- - ordinal string: is the text that is used for filtering (required)
--- - valid bool (optional): is an optional key because it defaults to true but if the key
--- is set to false it will not be displayed by the picker
--- - ordinal string: is the text that is used for filtering
--- - display string|function: is either a string of the text that is being
--- displayed or a function receiving the entry at a later stage, when the entry
--- is actually being displayed. A function can be useful here if complex
--- calculation have to be done. `make_entry` can also return a second value
--- is actually being displayed. A function can be useful here if a complex
--- calculation has to be done. `make_entry` can also return a second value -
--- a highlight array which will then apply to the line. Highlight entry in
--- this array has the following signature `{ { start_col, end_col }, hl_group }`
--- (required).
--- - filename string: will be interpreted by the default `<cr>` action as
--- open this file (optional)
--- - bufnr number: will be interpreted by the default `<cr>` action as open
--- this buffer (optional)
--- - lnum number: lnum value which will be interpreted by the default `<cr>`
--- action as a jump to this line (optional)
--- - col number: col value which will be interpreted by the default `<cr>`
--- action as a jump to this column (optional)
--- - filename string (optional): will be interpreted by the default `<cr>` action as
--- open this file
--- - bufnr number (optional): will be interpreted by the default `<cr>` action as open
--- this buffer
--- - lnum number (optional): lnum value which will be interpreted by the default `<cr>`
--- action as a jump to this line
--- - col number (optional): col value which will be interpreted by the default `<cr>`
--- action as a jump to this column
---
--- More information on easier displaying, see |telescope.pickers.entry_display|
--- For more information on easier displaying, see |telescope.pickers.entry_display|
---
--- TODO: Document something we call `entry_index`
---@brief ]]
@ -158,13 +157,13 @@ do
mt_file_entry.cwd = cwd
mt_file_entry.display = function(entry)
local hl_group
local hl_group, icon
local display = utils.transform_path(opts, entry.value)
display, hl_group = utils.transform_devicons(entry.value, display, disable_devicons)
display, hl_group, icon = utils.transform_devicons(entry.value, display, disable_devicons)
if hl_group then
return display, { { { 1, 3 }, hl_group } }
return display, { { { 0, #icon }, hl_group } }
else
return display
end
@ -244,12 +243,23 @@ do
return { filename, lnum, nil, text }
end
local parse_only_filename = function(t)
t.filename = t.value
t.lnum = nil
t.col = nil
t.text = ""
return { t.filename, nil, nil, "" }
end
function make_entry.gen_from_vimgrep(opts)
opts = opts or {}
local mt_vimgrep_entry
local parse = parse_with_col
if opts.__inverted == true then
if opts.__matches == true then
parse = parse_only_filename
elseif opts.__inverted == true then
parse = parse_without_col
end
@ -290,7 +300,7 @@ do
end
end
local display_string = "%s:%s%s"
local display_string = "%s%s%s"
mt_vimgrep_entry = {
cwd = vim.fn.expand(opts.cwd or vim.loop.cwd()),
@ -298,23 +308,26 @@ do
display = function(entry)
local display_filename = utils.transform_path(opts, entry.filename)
local coordinates = ""
local coordinates = ":"
if not disable_coordinates then
if entry.col then
coordinates = string.format("%s:%s:", entry.lnum, entry.col)
else
coordinates = string.format("%s:", entry.lnum)
if entry.lnum then
if entry.col then
coordinates = string.format(":%s:%s:", entry.lnum, entry.col)
else
coordinates = string.format(":%s:", entry.lnum)
end
end
end
local display, hl_group = utils.transform_devicons(
local text = opts.file_encoding and vim.iconv(entry.text, opts.file_encoding, "utf8") or entry.text
local display, hl_group, icon = utils.transform_devicons(
entry.filename,
string.format(display_string, display_filename, coordinates, entry.text),
string.format(display_string, display_filename, coordinates, text),
disable_devicons
)
if hl_group then
return display, { { { 1, 3 }, hl_group } }
return display, { { { 0, #icon }, hl_group } }
else
return display
end
@ -611,7 +624,18 @@ function make_entry.gen_from_buffer(opts)
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
local changed = entry.info.changed == 1 and "+" or " "
local indicator = entry.flag .. hidden .. readonly .. changed
local line_count = vim.api.nvim_buf_line_count(entry.bufnr)
local lnum = 1
-- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker
if entry.info.lnum ~= 0 then
-- but make sure the buffer is loaded, otherwise line_count is 0
if vim.api.nvim_buf_is_loaded(entry.bufnr) then
local line_count = vim.api.nvim_buf_line_count(entry.bufnr)
lnum = math.max(math.min(entry.info.lnum, line_count), 1)
else
lnum = entry.info.lnum
end
end
return make_entry.set_default_entry_mt({
value = bufname,
@ -620,8 +644,7 @@ function make_entry.gen_from_buffer(opts)
bufnr = entry.bufnr,
filename = bufname,
-- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker
lnum = entry.info.lnum ~= 0 and math.max(math.min(entry.info.lnum, line_count), 1) or 1,
lnum = lnum,
indicator = indicator,
}, opts)
end
@ -667,8 +690,7 @@ function make_entry.gen_from_treesitter(opts)
local get_filename = get_filename_fn()
return function(entry)
local ts_utils = require "nvim-treesitter.ts_utils"
local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node)
local start_row, start_col, end_row, _ = vim.treesitter.get_node_range(entry.node)
local node_text = vim.treesitter.get_node_text(entry.node, bufnr)
return make_entry.set_default_entry_mt({
value = entry.node,
@ -792,7 +814,7 @@ function make_entry.gen_from_registers(opts)
end
return function(entry)
local contents = vim.fn.getreg(entry)
local contents = vim.fn.getreg(entry, 1)
return make_entry.set_default_entry_mt({
value = entry,
ordinal = string.format("%s %s", entry, contents),
@ -805,7 +827,7 @@ end
function make_entry.gen_from_keymaps(opts)
local function get_desc(entry)
if entry.callback and not entry.desc then
return require("telescope.actions.utils")._get_anon_function_name(entry.callback)
return require("telescope.actions.utils")._get_anon_function_name(debug.getinfo(entry.callback))
end
return vim.F.if_nil(entry.desc, entry.rhs)
end
@ -1227,7 +1249,7 @@ function make_entry.gen_from_commands(opts)
attrs,
entry.nargs,
entry.complete or "",
entry.definition,
entry.definition:gsub("\n", " "),
}
end
@ -1299,7 +1321,13 @@ function make_entry.gen_from_git_status(opts)
if entry == "" then
return nil
end
local mod, file = string.match(entry, "(..).*%s[->%s]?(.+)")
local mod, file = entry:match "^(..) (.+)$"
-- Ignore entries that are the PATH in XY ORIG_PATH PATH
-- (renamed or copied files)
if not mod then
return nil
end
return setmetatable({
value = file,

View File

@ -2,12 +2,11 @@
---@brief [[
--- |telescope.mappings| is used to configure the keybindings within
--- a telescope picker. These keybinds are only local to the picker window
--- a telescope picker. These key binds are only local to the picker window
--- and will be cleared once you exit the picker.
---
--- We provide multiple different ways of configuring, as described below,
--- to provide an easy to use experience for changing the default behavior
--- of telescope or extending for your own purposes.
--- We provide multiple configuration options to make it easy for you to adjust
--- telescope's default key bindings and create your own custom key binds.
---
--- To see many of the builtin actions that you can use as values for this
--- table, see |telescope.actions|
@ -39,7 +38,6 @@
--- ...,
--- }
--- </code>
--- Into your config.
---
--- To override behavior of a key, simply set the value
--- to be a function (either by requiring an action or by writing
@ -53,7 +51,7 @@
--- </code>
---
--- If the function you want is part of `telescope.actions`, then you can
--- simply give a string.
--- simply supply the function name as a string.
--- For example, the previous option is equivalent to:
--- <code>
--- {
@ -112,6 +110,11 @@
--- map("i", "asdf", function(_prompt_bufnr)
--- print "You typed asdf"
--- end)
---
--- map({"i", "n"}, "<C-r>", function(_prompt_bufnr)
--- print "You typed <C-r>"
--- end)
---
--- -- needs to return true if you want to map default_mappings and
--- -- false if not
--- return true
@ -196,28 +199,21 @@ mappings.default_mappings = config.values.default_mappings
},
}
__TelescopeKeymapStore = __TelescopeKeymapStore
or setmetatable({}, {
__index = function(t, k)
rawset(t, k, {})
return rawget(t, k)
end,
})
local keymap_store = __TelescopeKeymapStore
local _mapping_key_id = 0
local get_next_id = function()
_mapping_key_id = _mapping_key_id + 1
return _mapping_key_id
end
local assign_function = function(prompt_bufnr, func)
local func_id = get_next_id()
keymap_store[prompt_bufnr][func_id] = func
return func_id
-- normal names are prefixed with telescope|
-- encoded objects are prefixed with telescopej|
local get_desc_for_keyfunc = function(v)
if type(v) == "table" then
local name = ""
for _, action in ipairs(v) do
if type(action) == "string" then
name = name == "" and action or name .. " + " .. action
end
end
return "telescope|" .. name
elseif type(v) == "function" then
local info = debug.getinfo(v)
return "telescopej|" .. vim.json.encode { source = info.source, linedefined = info.linedefined }
end
end
local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts)
@ -237,9 +233,14 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts)
key_func = actions[key_func]
elseif type(key_func) == "table" then
if key_func.type == "command" then
a.nvim_buf_set_keymap(prompt_bufnr, mode, key_bind, key_func[1], opts or {
silent = true,
})
vim.keymap.set(
mode,
key_bind,
key_func[1],
vim.tbl_extend("force", opts or {
silent = true,
}, { buffer = prompt_bufnr })
)
return
elseif key_func.type == "action_key" then
key_func = actions[key_func[1]]
@ -248,27 +249,11 @@ local telescope_map = function(prompt_bufnr, mode, key_bind, key_func, opts)
end
end
local key_id = assign_function(prompt_bufnr, key_func)
local prefix
local map_string
if opts.expr then
map_string =
string.format([[luaeval("require('telescope.mappings').execute_keymap(%s, %s)")]], prompt_bufnr, key_id)
else
if mode == "i" and not opts.expr then
prefix = "<cmd>"
elseif mode == "n" then
prefix = ":<C-U>"
else
prefix = ":"
end
map_string =
string.format("%slua require('telescope.mappings').execute_keymap(%s, %s)<CR>", prefix, prompt_bufnr, key_id)
end
a.nvim_buf_set_keymap(prompt_bufnr, mode, key_bind, map_string, opts)
vim.keymap.set(mode, key_bind, function()
local ret = key_func(prompt_bufnr)
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeKeymap" })
return ret
end, vim.tbl_extend("force", opts, { buffer = prompt_bufnr, desc = get_desc_for_keyfunc(key_func) }))
end
local extract_keymap_opts = function(key_func)
@ -284,12 +269,18 @@ end
mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap)
local applied_mappings = { n = {}, i = {} }
local map = function(mode, key_bind, key_func, opts)
mode = string.lower(mode)
local key_bind_internal = a.nvim_replace_termcodes(key_bind, true, true, true)
applied_mappings[mode][key_bind_internal] = true
local map = function(modes, key_bind, key_func, opts)
if type(modes) == "string" then
modes = { modes }
end
telescope_map(prompt_bufnr, mode, key_bind, key_func, opts)
for _, mode in pairs(modes) do
mode = string.lower(mode)
local key_bind_internal = a.nvim_replace_termcodes(key_bind, true, true, true)
applied_mappings[mode][key_bind_internal] = true
telescope_map(prompt_bufnr, mode, key_bind, key_func, opts)
end
end
if attach_mappings then
@ -333,17 +324,4 @@ mappings.apply_keymap = function(prompt_bufnr, attach_mappings, buffer_keymap)
end
end
mappings.execute_keymap = function(prompt_bufnr, keymap_identifier)
local key_func = keymap_store[prompt_bufnr][keymap_identifier]
assert(key_func, string.format("Unsure of how we got this failure: %s %s", prompt_bufnr, keymap_identifier))
key_func(prompt_bufnr)
vim.api.nvim_exec_autocmds("User TelescopeKeymap", {})
end
mappings.clear = function(prompt_bufnr)
keymap_store[prompt_bufnr] = nil
end
return mappings

View File

@ -90,7 +90,7 @@ function Picker:new(opts)
sorter = opts.sorter or require("telescope.sorters").empty(),
all_previewers = opts.previewer,
current_previewer_index = 1,
current_previewer_index = opts.current_previewer_index or 1,
default_selection_index = opts.default_selection_index,
@ -147,8 +147,8 @@ function Picker:new(opts)
if obj.all_previewers[1] == nil then
obj.all_previewers = { obj.all_previewers }
end
obj.previewer = obj.all_previewers[1]
if obj.preview_title == nil then
obj.previewer = obj.all_previewers[obj.current_previewer_index]
if obj.preview_title == nil or #obj.all_previewers > 1 then
obj.preview_title = obj.previewer:title(nil, config.values.dynamic_preview_title)
else
obj.fix_preview_title = true
@ -344,7 +344,7 @@ function Picker:find()
self.original_win_id = a.nvim_get_current_win()
-- User autocmd run it before create Telescope window
vim.api.nvim_exec_autocmds("User TelescopeFindPre", {})
vim.api.nvim_exec_autocmds("User", { pattern = "TelescopeFindPre" })
-- Create three windows:
-- 1. Prompt window
@ -749,7 +749,9 @@ function Picker.close_windows(status)
utils.win_delete("preview_border_win", status.preview_border_win, true, true)
-- we cant use win_delete. We first need to close and then delete the buffer
vim.api.nvim_win_close(status.prompt_win, true)
if vim.api.nvim_win_is_valid(status.prompt_win) then
vim.api.nvim_win_close(status.prompt_win, true)
end
utils.buf_delete(status.prompt_bufnr)
state.clear_status(status.prompt_bufnr)
@ -853,7 +855,7 @@ end
function Picker:_reset_prefix_color(hl_group)
self._current_prefix_hl_group = hl_group or nil
if self.prompt_prefix ~= "" then
if self.prompt_prefix ~= "" and a.nvim_buf_is_valid(self.prompt_bufnr) then
vim.api.nvim_buf_add_highlight(
self.prompt_bufnr,
ns_telescope_prompt_prefix,
@ -1327,6 +1329,11 @@ function Picker:get_result_completor(results_bufnr, find_id, prompt, status_upda
self:clear_extra_rows(results_bufnr)
self.sorter:_finish(prompt)
if self.wrap_results and self.sorting_strategy == "descending" then
local visible_result_rows = vim.api.nvim_win_get_height(self.results_win)
vim.api.nvim_win_set_cursor(self.results_win, { self.max_results - visible_result_rows, 1 })
vim.api.nvim_win_set_cursor(self.results_win, { self.max_results, 1 })
end
self:_on_complete()
end)
end
@ -1415,6 +1422,8 @@ pickers.new = function(opts, defaults)
if result["previewer"] == false then
result["previewer"] = defaults["previewer"]
result["__hide_previewer"] = true
elseif result["previewer"] == true then
result["previewer"] = defaults["previewer"]
elseif type(opts["preview"]) == "table" and opts["preview"]["hide_on_startup"] then
result["__hide_previewer"] = true
end
@ -1485,7 +1494,6 @@ function pickers.on_close_prompt(prompt_bufnr)
buffer = prompt_bufnr,
}
picker.close_windows(status)
mappings.clear(prompt_bufnr)
end
function pickers.on_resize_window(prompt_bufnr)

View File

@ -1,244 +0,0 @@
local assert = require "luassert"
local builtin = require "telescope.builtin"
local log = require "telescope.log"
local Job = require "plenary.job"
local Path = require "plenary.path"
local tester = {}
tester.debug = false
local replace_terms = function(input)
return vim.api.nvim_replace_termcodes(input, true, false, true)
end
local nvim_feed = function(text, feed_opts)
feed_opts = feed_opts or "m"
vim.api.nvim_feedkeys(text, feed_opts, true)
end
local writer = function(val)
if type(val) == "table" then
val = vim.json.encode(val) .. "\n"
end
if tester.debug then
print(val)
else
io.stderr:write(val)
end
end
local execute_test_case = function(location, key, spec)
local ok, actual = pcall(spec[2])
if not ok then
writer {
location = "Error: " .. location,
case = key,
expected = "To succeed and return: " .. tostring(spec[1]),
actual = actual,
_type = spec._type,
}
else
writer {
location = location,
case = key,
expected = spec[1],
actual = actual,
_type = spec._type,
}
end
end
local end_test_cases = function()
vim.cmd [[qa!]]
end
local invalid_test_case = function(k)
writer { case = k, expected = "<a valid key>", actual = k }
end_test_cases()
end
tester.picker_feed = function(input, test_cases)
input = replace_terms(input)
return coroutine.wrap(function()
for i = 1, #input do
local char = input:sub(i, i)
nvim_feed(char, "")
-- TODO: I'm not 100% sure this is a hack or not...
-- it's possible these characters could still have an on_complete... but i'm not sure.
if string.match(char, "%g") then
coroutine.yield()
end
if tester.debug then
vim.wait(200)
end
end
vim.wait(10)
if tester.debug then
coroutine.yield()
end
vim.defer_fn(function()
if test_cases.post_typed then
for k, v in ipairs(test_cases.post_typed) do
execute_test_case("post_typed", k, v)
end
end
nvim_feed(replace_terms "<CR>", "")
end, 20)
vim.defer_fn(function()
if test_cases.post_close then
for k, v in ipairs(test_cases.post_close) do
execute_test_case("post_close", k, v)
end
end
if tester.debug then
return
end
vim.defer_fn(end_test_cases, 20)
end, 40)
coroutine.yield()
end)
end
local _VALID_KEYS = {
post_typed = true,
post_close = true,
}
tester.builtin_picker = function(builtin_key, input, test_cases, opts)
opts = opts or {}
tester.debug = opts.debug or false
for k, _ in pairs(test_cases) do
if not _VALID_KEYS[k] then
return invalid_test_case(k)
end
end
opts.on_complete = {
tester.picker_feed(input, test_cases),
}
builtin[builtin_key](opts)
end
local get_results_from_file = function(file)
local j = Job:new {
command = "nvim",
args = {
"--noplugin",
"-u",
"scripts/minimal_init.vim",
"-c",
string.format([[lua require("telescope.pickers._test")._execute("%s")]], file),
},
}
j:sync(10000)
local results = j:stderr_result()
local result_table = {}
for _, v in ipairs(results) do
table.insert(result_table, vim.json.decode(v))
end
return result_table
end
local asserters = {
_default = assert.are.same,
are = assert.are.same,
are_not = assert.are_not.same,
}
local check_results = function(results)
-- TODO: We should get all the test cases here that fail, not just the first one.
for _, v in ipairs(results) do
local assertion = asserters[v._type or "default"]
assertion(v.expected, v.actual, string.format("Test Case: %s // %s", v.location, v.case))
end
end
tester.run_string = function(contents)
local tempname = vim.fn.tempname()
contents = [[
local tester = require('telescope.pickers._test')
local helper = require('telescope.pickers._test_helpers')
helper.make_globals()
]] .. contents
vim.fn.writefile(vim.split(contents, "\n"), tempname)
local result_table = get_results_from_file(tempname)
vim.fn.delete(tempname)
check_results(result_table)
end
tester.run_file = function(filename)
local file = "./lua/tests/pickers/" .. filename .. ".lua"
if not Path:new(file):exists() then
assert.are.same("<An existing file>", file)
end
local result_table = get_results_from_file(file)
check_results(result_table)
end
tester.not_ = function(val)
val._type = "are_not"
return val
end
tester._execute = function(filename)
-- Important so that the outputs don't get mixed
log.use_console = false
vim.cmd(string.format("luafile %s", filename))
local f = loadfile(filename)
if not f then
writer {
location = "Error: " .. filename,
case = filename,
expected = "To succeed",
actual = nil,
}
end
local ok, msg = pcall(f)
if not ok then
writer {
location = "Error: " .. msg,
case = msg,
expected = msg,
}
end
end_test_cases()
end
return tester

View File

@ -12,11 +12,11 @@
--- for the best performance.
---
--- The create function will use the column widths passed to it in
--- configaration.items. Each item in that table is the number of characters in
--- configuration.items. Each item in that table is the number of characters in
--- the column. It's also possible for the final column to not have a fixed
--- width, this will be shown in the configuartion as 'remaining = true'.
--- width, this will be shown in the configuration as 'remaining = true'.
---
--- An example of this configuration is shown for the buffers picker
--- An example of this configuration is shown for the buffers picker:
--- <code>
--- local displayer = entry_display.create {
--- separator = " ",
@ -30,10 +30,10 @@
--- </code>
---
--- This shows 4 columns, the first is defined in the opts as the width we'll
--- use when display_string the number of the buffer. The second has a fixed
--- width of 4 and the 3rd column's widht will be decided by the width of the
--- icons we use. The fourth column will use the remaining space. Finally we
--- have also defined the seperator between each column will be the space " ".
--- use when display_string is the number of the buffer. The second has a fixed
--- width of 4 and the third column's width will be decided by the width of the
--- icons we use. The fourth column will use the remaining space. Finally, we
--- have also defined the separator between each column will be the space " ".
---
--- An example of how the display reference will be used is shown, again for
--- the buffers picker:
@ -49,12 +49,12 @@
--- There are two types of values each column can have. Either a simple String
--- or a table containing the String as well as the hl_group.
---
--- The displayer can return values, string and an optional highlights.
--- String is all the text to be displayed for this entry as a single string. If
--- parts of the string are to be highlighted they will be described in the
--- highlights table.
--- The displayer can return values, string and an optional highlights. The string
--- is all the text to be displayed for this entry as a single string. If parts of
--- the string are to be highlighted they will be described in the highlights
--- table.
---
--- For better understanding of how create() and displayer are used it's best to look
--- For a better understanding of how create() and displayer are used it's best to look
--- at the code in make_entry.lua.
---@brief ]]

View File

@ -38,7 +38,6 @@
--- - columns : (number) Columns in the vim window
--- - lines : (number) Lines in the vim window
--- - layout_config : (table) The configuration values specific to the picker.
---
--- </pre>
---
--- This means you can create your own layout strategy if you want! Just be aware
@ -411,14 +410,14 @@ layout_strategies.horizontal = make_documented_layout(
--- <pre>
--- ┌──────────────────────────────────────────────────┐
--- │ ┌────────────────────────────────────────┐ │
--- │ | Preview |
--- │ | Preview |
--- │ │ Preview │
--- │ │ Preview │
--- │ └────────────────────────────────────────┘ │
--- │ ┌────────────────────────────────────────┐ │
--- │ | Prompt |
--- │ │ Prompt │
--- │ ├────────────────────────────────────────┤ │
--- │ | Result |
--- │ | Result |
--- │ │ Result │
--- │ │ Result │
--- │ └────────────────────────────────────────┘ │
--- │ │
--- │ │
@ -550,6 +549,7 @@ layout_strategies.center = make_documented_layout(
--- │ │
--- └──────────────────────────────────────────────────┘
--- </pre>
---@eval { ["description"] = require("telescope.pickers.layout_strategies")._format("cursor") }
layout_strategies.cursor = make_documented_layout(
"cursor",
vim.tbl_extend("error", {
@ -647,16 +647,16 @@ layout_strategies.cursor = make_documented_layout(
--- ┌──────────────────────────────────────────────────┐
--- │ │
--- │ ┌────────────────────────────────────────┐ │
--- │ | Preview |
--- │ | Preview |
--- │ | Preview |
--- │ │ Preview │
--- │ │ Preview │
--- │ │ Preview │
--- │ └────────────────────────────────────────┘ │
--- │ ┌────────────────────────────────────────┐ │
--- │ | Result |
--- │ | Result |
--- │ │ Result │
--- │ │ Result │
--- │ └────────────────────────────────────────┘ │
--- │ ┌────────────────────────────────────────┐ │
--- │ | Prompt |
--- │ │ Prompt │
--- │ └────────────────────────────────────────┘ │
--- │ │
--- └──────────────────────────────────────────────────┘
@ -775,9 +775,13 @@ layout_strategies.flex = make_documented_layout(
if max_columns < flip_columns and max_lines > flip_lines then
self.__flex_strategy = "vertical"
self.layout_config.flip_columns = nil
self.layout_config.flip_lines = nil
return layout_strategies.vertical(self, max_columns, max_lines, layout_config.vertical)
else
self.__flex_strategy = "horizontal"
self.layout_config.flip_columns = nil
self.layout_config.flip_lines = nil
return layout_strategies.horizontal(self, max_columns, max_lines, layout_config.horizontal)
end
end
@ -898,6 +902,9 @@ layout_strategies.bottom_pane = make_documented_layout(
if type(results.title) == "string" then
results.title = { { pos = "S", text = results.title } }
end
if type(preview.title) == "string" then
preview.title = { { pos = "S", text = preview.title } }
end
elseif layout_config.prompt_position == "bottom" then
results.line = max_lines - results.height - (1 + bs) + 1
preview.line = results.line

View File

@ -60,7 +60,8 @@ local function split(s, sep, plain, opts)
opts = opts or {}
local t = {}
for c in vim.gsplit(s, sep, plain) do
table.insert(t, c)
local line = opts.file_encoding and vim.iconv(c, opts.file_encoding, "utf8") or c
table.insert(t, line)
if opts.preview.timeout then
local diff_time = (vim.loop.hrtime() - opts.start_time) / 1e6
if diff_time > opts.preview.timeout then
@ -192,8 +193,8 @@ previewers.file_maker = function(filepath, bufnr, opts)
if opts.preview.check_mime_type == true and has_file and opts.ft == "" then
-- avoid SIGABRT in buffer previewer happening with utils.get_os_command_output
local output = capture(string.format([[file --mime-type -b "%s"]], filepath))
local mime_type = vim.split(output, "/")[1]
if mime_type ~= "text" and mime_type ~= "inode" then
local mime_type = vim.split(output, "/")
if mime_type[1] ~= "text" and mime_type[1] ~= "inode" and mime_type[2] ~= "json" then
if type(opts.preview.mime_hook) == "function" then
vim.schedule_wrap(opts.preview.mime_hook)(filepath, bufnr, opts)
else
@ -206,6 +207,9 @@ previewers.file_maker = function(filepath, bufnr, opts)
end
return
end
if mime_type[2] == "json" then
opts.ft = "json"
end
end
if opts.preview.filesize_limit then
@ -433,6 +437,7 @@ previewers.cat = defaulter(function(opts)
bufname = self.state.bufname,
winid = self.state.winid,
preview = opts.preview,
file_encoding = opts.file_encoding,
})
end,
}
@ -487,6 +492,7 @@ previewers.vimgrep = defaulter(function(opts)
callback = function(bufnr)
jump_to_line(self, bufnr, entry.lnum)
end,
file_encoding = opts.file_encoding,
})
end
end,
@ -881,7 +887,7 @@ previewers.git_file_diff = defaulter(function(opts)
winid = self.state.winid,
})
else
putils.job_maker({ "git", "--no-pager", "diff", entry.value }, self.state.bufnr, {
putils.job_maker({ "git", "--no-pager", "diff", "HEAD", "--", entry.value }, self.state.bufnr, {
value = entry.value,
bufname = self.state.bufname,
cwd = opts.cwd,

View File

@ -4,7 +4,7 @@
---@brief [[
--- Provides a Previewer table that has to be implemented by each previewer.
--- To achieve this, this module also provides two wrappers that abstract most
--- of the work and make it really easy create new previewers.
--- of the work and make it really easy to create new previewers.
--- - `previewers.new_termopen_previewer`
--- - `previewers.new_buffer_previewer`
---
@ -40,7 +40,7 @@ local previewers = {}
---
--- What `:new` expects is listed below
---
--- The interface provides following set of functions. All of them, besides
--- The interface provides the following set of functions. All of them, besides
--- `new`, will be handled by telescope pickers.
--- - `:new(opts)`
--- - `:preview(entry, status)`
@ -51,7 +51,7 @@ local previewers = {}
--- `Previewer:new()` expects a table as input with following keys:
--- - `setup` function(self): Will be called the first time preview will be
--- called.
--- - `teardown` function(self): Will be called on cleanup.
--- - `teardown` function(self): Will be called on clean up.
--- - `preview_fn` function(self, entry, status): Will be called each time
--- a new entry was selected.
--- - `title` function(self): Will return the static title of the previewer.
@ -156,8 +156,8 @@ previewers.qflist = term_previewer.qflist
--- available in `self.state` in each `define_preview` call.
--- - `teardown = function(self)` (optional)
--- Will be called at the end, when the picker is being closed and is
--- meant to cleanup everything that was allocated by the previewer.
--- The `buffer_previewer` will automatically cleanup all created buffers.
--- meant to clean up everything that was allocated by the previewer.
--- The `buffer_previewer` will automatically clean up all created buffers.
--- So you only need to handle things that were introduced by you.
--- - `keep_last_buf = true` (optional)
--- Will not delete the last selected buffer. This would allow you to
@ -167,7 +167,7 @@ previewers.qflist = term_previewer.qflist
--- `require('telescope.state').get_global_key("last_preview_bufnr")`
--- - `get_buffer_by_name = function(self, entry)`
--- Allows you to set a unique name for each buffer. This is used for
--- caching purpose. `self.state.bufname` will be nil if the entry was
--- caching purposes. `self.state.bufname` will be nil if the entry was
--- never loaded or the unique name when it was loaded once. For example,
--- useful if you have one file but multiple entries. This happens for grep
--- and lsp builtins. So to make the cache work only load content if
@ -221,8 +221,8 @@ previewers.qflist = term_previewer.qflist
--- vim.api.nvim_buf_call(bufnr, function()
--- -- for example `search` and `matchadd`
--- end)
--- to achieve that.
--- </code>
--- to achieve that.
--- - If you want to read a file into the buffer it's best to use
--- `buffer_previewer_maker`. But access this function with
--- `require('telescope.config').values.buffer_previewer_maker`
@ -258,7 +258,7 @@ previewers.vim_buffer_cat = buffer_previewer.cat
--- case it's configured that way.
previewers.vim_buffer_vimgrep = buffer_previewer.vimgrep
--- Is the same as `vim_buffer_vimgrep` and only exist for consistency with
--- Is the same as `vim_buffer_vimgrep` and only exists for consistency with
--- `term_previewers`.
---
--- The preferred way of using this previewer is like this

View File

@ -126,8 +126,7 @@ end
--- Attach regex highlighter
utils.regex_highlighter = function(bufnr, ft)
if has_filetype(ft) then
vim.api.nvim_buf_set_option(bufnr, "syntax", ft)
return true
return pcall(vim.api.nvim_buf_set_option, bufnr, "syntax", ft)
end
return false
end

View File

@ -19,9 +19,10 @@ local themes = {}
---
--- Usage:
--- <code>
--- `local builtin = require('telescope.builtin')`
--- `local themes = require('telescope.themes')`
--- `builtin.find_files(themes.get_dropdown())`
--- local opts = {...} -- picker options
--- local builtin = require('telescope.builtin')
--- local themes = require('telescope.themes')
--- builtin.find_files(themes.get_dropdown(opts))
--- </code>
function themes.get_dropdown(opts)
opts = opts or {}
@ -67,10 +68,10 @@ end
---
--- Usage:
--- <code>
---
--- `local builtin = require('telescope.builtin')`
--- `local themes = require('telescope.themes')`
--- `builtin.lsp_references(themes.get_cursor())`
--- local opts = {...} -- picker options
--- local builtin = require('telescope.builtin')
--- local themes = require('telescope.themes')
--- builtin.find_files(themes.get_cursor(opts))
--- </code>
function themes.get_cursor(opts)
opts = opts or {}
@ -99,9 +100,10 @@ end
---
--- Usage:
--- <code>
--- `local builtin = require('telescope.builtin')`
--- `local themes = require('telescope.themes')`
--- `builtin.find_files(themes.get_ivy())`
--- local opts = {...} -- picker options
--- local builtin = require('telescope.builtin')
--- local themes = require('telescope.themes')
--- builtin.find_files(themes.get_ivy(opts))
--- </code>
function themes.get_ivy(opts)
opts = opts or {}

View File

@ -211,7 +211,7 @@ end
--- this function outside of telescope might yield to undefined behavior and will
--- not be addressed by us
---@param opts table: The opts the users passed into the picker. Might contains a path_display key
---@param path string: The path that should be formated
---@param path string: The path that should be formatted
---@return string: The transformed path ready to be displayed
utils.transform_path = function(opts, path)
if path == nil then
@ -432,6 +432,16 @@ local load_once = function(f)
end
end
utils.file_extension = function(filename)
local parts = vim.split(filename, "%.")
-- this check enables us to get multi-part extensions, like *.test.js for example
if #parts > 2 then
return table.concat(vim.list_slice(parts, #parts - 1), ".")
else
return table.concat(vim.list_slice(parts, #parts), ".")
end
end
utils.transform_devicons = load_once(function()
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
@ -446,13 +456,18 @@ utils.transform_devicons = load_once(function()
return display
end
local icon, icon_highlight = devicons.get_icon(utils.path_tail(filename), nil, { default = true })
local icon_display = (icon or " ") .. " " .. (display or "")
local basename = utils.path_tail(filename)
local icon, icon_highlight = devicons.get_icon(basename, utils.file_extension(basename), { default = false })
if not icon then
icon, icon_highlight = devicons.get_icon(basename, nil, { default = true })
icon = icon or " "
end
local icon_display = icon .. " " .. (display or "")
if conf.color_devicons then
return icon_display, icon_highlight
return icon_display, icon_highlight, icon
else
return icon_display, nil
return icon_display, nil, icon
end
end
else
@ -476,7 +491,11 @@ utils.get_devicons = load_once(function()
return ""
end
local icon, icon_highlight = devicons.get_icon(utils.path_tail(filename), nil, { default = true })
local basename = utils.path_tail(filename)
local icon, icon_highlight = devicons.get_icon(basename, utils.file_extension(basename), { default = false })
if not icon then
icon, icon_highlight = devicons.get_icon(basename, nil, { default = true })
end
if conf.color_devicons then
return icon, icon_highlight
else

View File

@ -1,4 +1,3 @@
-- local tester = require('telescope.pickers._test')
local config = require "telescope.config"
local resolve = require "telescope.config.resolve"
local layout_strats = require "telescope.pickers.layout_strategies"

View File

@ -14,6 +14,10 @@ describe("builtin.find_files", function()
tester.run_file "find_files__readme"
end)
it("should handle cycling for full list", function()
tester.run_file "find_files__scrolling_descending_cycle"
end)
for _, configuration in ipairs {
{ sorting_strategy = "descending" },
{ sorting_strategy = "ascending" },
@ -107,12 +111,12 @@ describe("builtin.find_files", function()
it("should be able to c-n the items", function()
tester.run_string [[
runner.picker('find_files', 'fixtures/file<c-n>', {
runner.picker('find_files', 'fixtures/find_files/file<c-n>', {
post_typed = {
{
{
" lua/tests/fixtures/file_a.txt",
"> lua/tests/fixtures/file_abc.txt",
" lua/tests/fixtures/find_files/file_a.txt",
"> lua/tests/fixtures/find_files/file_abc.txt",
}, GetResults
},
},
@ -129,9 +133,9 @@ describe("builtin.find_files", function()
it("should be able to get the current selection", function()
tester.run_string [[
runner.picker('find_files', 'fixtures/file_abc', {
runner.picker('find_files', 'fixtures/find_files/file_abc', {
post_typed = {
{ 'lua/tests/fixtures/file_abc.txt', GetSelectionValue },
{ 'lua/tests/fixtures/find_files/file_abc.txt', GetSelectionValue },
}
})
]]

View File

@ -1,12 +0,0 @@
require("plenary.reload").reload_module "telescope"
local tester = require "telescope.pickers._test"
local log = require "telescope.log"
log.use_console = false
describe("scrolling strategies", function()
it("should handle cycling for full list", function()
tester.run_file [[find_files__scrolling_descending_cycle]]
end)
end)

View File

@ -116,9 +116,12 @@ end, {
local n = #l - 2
if n == 0 then
local commands = vim.tbl_flatten { builtin_list, extensions_list }
table.sort(commands)
return vim.tbl_filter(function(val)
return vim.startswith(val, l[2])
end, vim.tbl_extend("force", builtin_list, extensions_list))
end, commands)
end
if n == 1 then
@ -128,13 +131,18 @@ end, {
if #is_extension > 0 then
local extensions_subcommand_dict = require("telescope.command").get_extensions_subcommand()
local commands = extensions_subcommand_dict[l[2]]
table.sort(commands)
return vim.tbl_filter(function(val)
return vim.startswith(val, l[3])
end, extensions_subcommand_dict[l[2]])
end, commands)
end
end
local options_list = vim.tbl_keys(require("telescope.config").values)
table.sort(options_list)
return vim.tbl_filter(function(val)
return vim.startswith(val, l[#l])
end, options_list)

View File

@ -0,0 +1,37 @@
local MODREV, SPECREV = 'scm', '-1'
rockspec_format = '3.0'
package = 'telescope.nvim'
version = MODREV .. SPECREV
description = {
summary = 'Find, Filter, Preview, Pick. All lua, all the time.',
detailed = [[
A highly extendable fuzzy finder over lists.
Built on the latest awesome features from neovim core.
Telescope is centered around modularity, allowing for easy customization.
]],
labels = { 'neovim', 'plugin', },
homepage = 'https://github.com/nvim-telescope/telescope.nvim',
license = 'MIT',
}
dependencies = {
'lua == 5.1',
'plenary.nvim',
}
source = {
url = 'git://github.com/nvim-telescope/telescope.nvim',
}
build = {
type = 'builtin',
copy_directories = {
'doc',
'ftplugin',
'plugin',
'scripts',
'autoload',
'data',
}
}