|
1 | 1 | local MODSTR = 'project.config.defaults' |
2 | 2 |
|
| 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 | + |
3 | 11 | local validate = vim.validate |
4 | 12 | local in_tbl = vim.tbl_contains |
5 | 13 | local empty = vim.tbl_isempty |
6 | 14 | local WARN = vim.log.levels.WARN |
7 | 15 |
|
8 | | -local Util = require('project.utils.util') |
9 | | -local is_type = Util.is_type |
10 | | -local dir_exists = Util.dir_exists |
11 | | - |
12 | 16 | ---The options available for in `require('project').setup()`. |
13 | 17 | --- --- |
14 | 18 | ---@class Project.Config.Options |
@@ -58,6 +62,33 @@ local DEFAULTS = { |
58 | 62 | --- --- |
59 | 63 | ---@type boolean |
60 | 64 | 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 | + }, |
61 | 92 | }, |
62 | 93 |
|
63 | 94 | ---Table of options used for `fzf-lua` integration |
@@ -340,7 +371,7 @@ function DEFAULTS:verify_scope_chdir() |
340 | 371 | end |
341 | 372 |
|
342 | 373 | function DEFAULTS:verify_datapath() |
343 | | - if not dir_exists(self.datapath) then |
| 374 | + if not require('project.utils.util').dir_exists(self.datapath) then |
344 | 375 | vim.notify('Invalid `datapath`, reverting to default.', WARN) |
345 | 376 | self.datapath = DEFAULTS.datapath |
346 | 377 | end |
|
358 | 389 | --- --- |
359 | 390 | ---@param self Project.Config.Options |
360 | 391 | function DEFAULTS:verify_methods() |
| 392 | + local is_type = require('project.utils.util').is_type |
| 393 | + |
361 | 394 | if not is_type('table', self.detection_methods) then |
362 | 395 | vim.notify('`detection_methods` option is not a table. Reverting to default option.', WARN) |
363 | 396 | self.detection_methods = DEFAULTS.detection_methods |
@@ -428,24 +461,21 @@ function DEFAULTS:verify() |
428 | 461 | self:verify_histsize() |
429 | 462 | self:verify_methods() |
430 | 463 | self:verify_scope_chdir() |
431 | | - |
432 | 464 | self:verify_logging() |
433 | 465 | end |
434 | 466 |
|
435 | 467 | ---@param opts? Project.Config.Options |
436 | 468 | ---@return Project.Config.Options |
437 | 469 | 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') |
440 | 472 | else |
441 | | - vim.validate({ opts = { opts, { 'table', 'nil' } } }) |
| 473 | + validate({ opts = { opts, { 'table', 'nil' } } }) |
442 | 474 | end |
443 | | - |
444 | 475 | opts = opts or {} |
445 | 476 |
|
446 | 477 | ---@type Project.Config.Options |
447 | 478 | local self = setmetatable(opts, { __index = DEFAULTS }) |
448 | | - |
449 | 479 | self = vim.tbl_deep_extend('keep', self, DEFAULTS) |
450 | 480 |
|
451 | 481 | return self |
|
0 commit comments