Skip to content

Commit 3a368e9

Browse files
committed
feat(telescope): make mappings customizable, docs synced
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent 9083845 commit 3a368e9

4 files changed

Lines changed: 156 additions & 63 deletions

File tree

README.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ require('lazy').setup({
152152
'nvim-telescope/telescope.nvim',
153153
'ibhagwan/fzf-lua',
154154
},
155-
156155
---@module 'project'
156+
157157
---@type Project.Config.Options
158158
opts = {
159159
-- your configuration comes here
@@ -176,11 +176,11 @@ if vim.fn.has('nvim-0.11') == 1 then
176176
require('pckr').add({
177177
{
178178
'DrKJeff16/project.nvim',
179-
requires = {
179+
requires = { -- OPTIONAL
180180
'nvim-lua/plenary.nvim',
181181
'nvim-telescope/telescope.nvim',
182182
'ibhagwan/fzf-lua',
183-
}, -- OPTIONAL
183+
},
184184
config = function()
185185
require('project').setup({
186186
-- your configuration comes here
@@ -204,11 +204,10 @@ local paq = require('paq')
204204
paq({
205205
'savq/paq-nvim',
206206

207+
'DrKJeff16/project.nvim',
207208
'nvim-lua/plenary.nvim', -- OPTIONAL
208209
'nvim-telescope/telescope.nvim', -- OPTIONAL
209210
'ibhagwan/fzf-lua', -- OPTIONAL
210-
211-
'DrKJeff16/project.nvim',
212211
})
213212
```
214213

@@ -240,6 +239,19 @@ require('project').setup()
240239
> [!NOTE]
241240
> You can find these in [`project/config/defaults.lua`](./lua/project/config/defaults.lua).
242241
242+
> [!NOTE]
243+
> The `Project.Telescope.ActionNames` type is an alias for:
244+
>
245+
> ```lua
246+
> ---@alias Project.Telescope.ActionNames
247+
> ---|'browse_project_files'
248+
> ---|'change_working_directory'
249+
> ---|'delete_project'
250+
> ---|'find_project_files'
251+
> ---|'recent_project_files'
252+
> ---|'search_in_project_files'
253+
> ```
254+
243255
<details>
244256
<summary><b><code>setup()</code><ins>comes with these defaults.</ins></b></summary>
245257
@@ -425,6 +437,33 @@ require('project').setup()
425437
--- ---
426438
---@type boolean
427439
disable_file_picker = false,
440+
441+
---Table of mappings for the Telescope picker.
442+
---
443+
---Only supports Normal and Insert modes.
444+
--- ---
445+
---Default: check the README
446+
--- ---
447+
---@type table<'n'|'i', table<string, Project.Telescope.ActionNames>>
448+
mappings = {
449+
n = {
450+
b = 'browse_project_files',
451+
d = 'delete_project',
452+
f = 'find_project_files',
453+
r = 'recent_project_files',
454+
s = 'search_in_project_files',
455+
w = 'change_working_directory',
456+
},
457+
458+
i = {
459+
['<C-b>'] = 'browse_project_files',
460+
['<C-d>'] = 'delete_project',
461+
['<C-f>'] = 'find_project_files',
462+
['<C-r>'] = 'recent_project_files',
463+
['<C-s>'] = 'search_in_project_files',
464+
['<C-w>'] = 'change_working_directory',
465+
},
466+
},
428467
},
429468
430469
---Make hidden files visible when using any picker.

doc/project-nvim.txt

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ Table of Contents *project-nvim.toc*
2020

2121
1. Installation |project-nvim.install|
2222
1.1 vim-plug |project-nvim.install-vim-plug|
23-
1.2 lazy.nvim |project-nvim.install-lazy-nvim|
24-
1.3 pckr.nvim |project-nvim.install-pckr-nvim|
23+
1.2 lazy.nvim |project-nvim.install-lazy|
24+
1.3 pckr.nvim |project-nvim.install-pckr|
25+
1.4 paq-nvim |project-nvim.install-paq|
2526
2. project-nvim.setup |project-nvim.setup|
2627
2.1. `Project.Config.Options` |Project.Config.Options|
2728
2.2. `Project.Config.Telescope` |Project.Config.Telescope|
@@ -54,13 +55,13 @@ Table of Contents *project-nvim.toc*
5455

5556
------------------------------------------------------------------------------
5657
1.1 vim-plug *project-nvim.install-vim-plug*
57-
5858
>vim
5959
if has('nvim-0.11')
6060
Plug 'DrKJeff16/project.nvim'
6161

6262
" OPTIONAL
6363
Plug 'nvim-telescope/telescope.nvim' | Plug 'nvim-lua/plenary.nvim'
64+
Plug 'ibhagwan/fzf-lua'
6465

6566
lua << EOF
6667
require('project').setup({
@@ -71,8 +72,7 @@ Table of Contents *project-nvim.toc*
7172
endif
7273
<
7374
------------------------------------------------------------------------------
74-
1.2 lazy.nvim *project-nvim.install-lazy-nvim*
75-
75+
1.2 lazy.nvim *project-nvim.install-lazy*
7676
>lua
7777
require('lazy').setup({
7878
spec = {
@@ -82,9 +82,10 @@ Table of Contents *project-nvim.toc*
8282
dependencies = { -- OPTIONAL
8383
'nvim-lua/plenary.nvim',
8484
'nvim-telescope/telescope.nvim',
85+
'ibhagwan/fzf-lua',
8586
},
86-
8787
---@module 'project'
88+
8889
---@type Project.Config.Options
8990
opts = {
9091
-- your configuration comes here
@@ -98,17 +99,17 @@ Table of Contents *project-nvim.toc*
9899
<
99100

100101
------------------------------------------------------------------------------
101-
1.3 pckr.nvim *project-nvim.install-pckr-nvim*
102-
102+
1.3 pckr.nvim *project-nvim.install-pckr*
103103
>lua
104104
if vim.fn.has('nvim-0.11') == 1 then
105105
require('pckr').add({
106106
{
107107
'DrKJeff16/project.nvim',
108-
requires = {
108+
requires = { -- OPTIONAL
109109
'nvim-lua/plenary.nvim',
110110
'nvim-telescope/telescope.nvim',
111-
}, -- OPTIONAL
111+
'ibhagwan/fzf-lua',
112+
},
112113
config = function()
113114
require('project').setup({
114115
-- your configuration comes here
@@ -121,6 +122,22 @@ Table of Contents *project-nvim.toc*
121122
end
122123
<
123124

125+
126+
------------------------------------------------------------------------------
127+
1.4 paq-nvim *project-nvim.install-paq*
128+
>lua
129+
local paq = require('paq')
130+
131+
paq({
132+
'savq/paq-nvim',
133+
134+
'DrKJeff16/project.nvim',
135+
'nvim-lua/plenary.nvim', -- OPTIONAL
136+
'nvim-telescope/telescope.nvim', -- OPTIONAL
137+
'ibhagwan/fzf-lua', -- OPTIONAL
138+
})
139+
<
140+
124141
==============================================================================
125142
2. project-nvim.setup *project-nvim.setup*
126143

@@ -381,6 +398,13 @@ Table of Contents *project-nvim.toc*
381398
Default: `'newest'` ~
382399

383400

401+
* {mappings} (table)
402+
Table of mappings for the Telescope picker.
403+
Only supports Normal and Insert modes ~
404+
405+
Default: check the README ~
406+
407+
384408
* {prefer_file_browser} (boolean)
385409
Toggles `telescope-file-browser.nvim` for the
386410
telescope picker instead of the `find_files`

lua/project/config/defaults.lua

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
local MODSTR = 'project.config.defaults'
22

3+
---@alias Project.Telescope.ActionNames
4+
---|'browse_project_files'
5+
---|'change_working_directory'
6+
---|'delete_project'
7+
---|'find_project_files'
8+
---|'recent_project_files'
9+
---|'search_in_project_files'
10+
311
local validate = vim.validate
412
local in_tbl = vim.tbl_contains
513
local empty = vim.tbl_isempty
614
local WARN = vim.log.levels.WARN
715

8-
local Util = require('project.utils.util')
9-
local is_type = Util.is_type
10-
local dir_exists = Util.dir_exists
11-
1216
---The options available for in `require('project').setup()`.
1317
--- ---
1418
---@class Project.Config.Options
@@ -58,6 +62,33 @@ local DEFAULTS = {
5862
--- ---
5963
---@type boolean
6064
disable_file_picker = false,
65+
66+
---Table of mappings for the Telescope picker.
67+
---
68+
---Only supports Normal and Insert modes.
69+
--- ---
70+
---Default: check the README
71+
--- ---
72+
---@type table<'n'|'i', table<string, Project.Telescope.ActionNames>>
73+
mappings = {
74+
n = {
75+
b = 'browse_project_files',
76+
d = 'delete_project',
77+
f = 'find_project_files',
78+
r = 'recent_project_files',
79+
s = 'search_in_project_files',
80+
w = 'change_working_directory',
81+
},
82+
83+
i = {
84+
['<C-b>'] = 'browse_project_files',
85+
['<C-d>'] = 'delete_project',
86+
['<C-f>'] = 'find_project_files',
87+
['<C-r>'] = 'recent_project_files',
88+
['<C-s>'] = 'search_in_project_files',
89+
['<C-w>'] = 'change_working_directory',
90+
},
91+
},
6192
},
6293

6394
---Table of options used for `fzf-lua` integration
@@ -340,7 +371,7 @@ function DEFAULTS:verify_scope_chdir()
340371
end
341372

342373
function DEFAULTS:verify_datapath()
343-
if not dir_exists(self.datapath) then
374+
if not require('project.utils.util').dir_exists(self.datapath) then
344375
vim.notify('Invalid `datapath`, reverting to default.', WARN)
345376
self.datapath = DEFAULTS.datapath
346377
end
@@ -358,6 +389,8 @@ end
358389
--- ---
359390
---@param self Project.Config.Options
360391
function DEFAULTS:verify_methods()
392+
local is_type = require('project.utils.util').is_type
393+
361394
if not is_type('table', self.detection_methods) then
362395
vim.notify('`detection_methods` option is not a table. Reverting to default option.', WARN)
363396
self.detection_methods = DEFAULTS.detection_methods
@@ -428,24 +461,21 @@ function DEFAULTS:verify()
428461
self:verify_histsize()
429462
self:verify_methods()
430463
self:verify_scope_chdir()
431-
432464
self:verify_logging()
433465
end
434466

435467
---@param opts? Project.Config.Options
436468
---@return Project.Config.Options
437469
function DEFAULTS.new(opts)
438-
if vim.fn.has('nvim-0.11') == 1 then
439-
vim.validate('opts', opts, 'table', true, 'Project.Config.Options')
470+
if require('project.utils.util').vim_has('nvim-0.11') then
471+
validate('opts', opts, 'table', true, 'Project.Config.Options')
440472
else
441-
vim.validate({ opts = { opts, { 'table', 'nil' } } })
473+
validate({ opts = { opts, { 'table', 'nil' } } })
442474
end
443-
444475
opts = opts or {}
445476

446477
---@type Project.Config.Options
447478
local self = setmetatable(opts, { __index = DEFAULTS })
448-
449479
self = vim.tbl_deep_extend('keep', self, DEFAULTS)
450480

451481
return self

0 commit comments

Comments
 (0)