Skip to content

Commit c80b372

Browse files
committed
fix(telescope)!: don't invoke telescope setup (fixes #29)
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
1 parent 190304d commit c80b372

5 files changed

Lines changed: 30 additions & 81 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ require('project').setup()
349349
bt = { 'help', 'nofile', 'nowrite', 'terminal' }, -- `buftype`
350350
},
351351
telescope = { ---@type Project.Config.Telescope
352-
enabled = false,
353352
sort = 'newest', ---@type 'oldest'|'newest'
354353
prefer_file_browser = false,
355354
disable_file_picker = false,

doc/project-nvim.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,6 @@ Table of Contents *project-nvim.toc*
370370
2.2 `Project.Config.Telescope` *Project.Config.Telescope*
371371
*project-nvim.telescope-config*
372372

373-
* {enabled} (boolean)
374-
Determines whether the `telescope` picker
375-
should be called from `setup()`.
376-
If `telescope` is not installed, then
377-
this won't make a difference.
378-
Note that even if set to `false`,
379-
you can still load the extension manually
380-
381-
Default: `false` ~
382-
383373

384374
* {sort} (`'newest'|'oldest'`)
385375
Determines whether the newest projects come

lua/project/config.lua

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
local MODSTR = 'project.config'
22
local ERROR = vim.log.levels.ERROR
33
local in_list = vim.list_contains
4-
local floor = math.floor
54

65
---@class Project.Config
76
---@field conf_loc? { win: integer, bufnr: integer }
@@ -48,10 +47,6 @@ function Config.setup(options)
4847
if Config.options.log.enabled then
4948
Log.init()
5049
end
51-
if Config.options.telescope.enabled and Util.mod_exists('telescope') then
52-
require('telescope').load_extension('projects')
53-
Log.info(('(%s.setup): Telescope Picker initialized.'):format(MODSTR))
54-
end
5550

5651
if vim.g.project_setup ~= 1 then
5752
vim.g.project_setup = 1
@@ -93,10 +88,10 @@ function Config.open_win()
9388
end
9489

9590
local bufnr = vim.api.nvim_create_buf(false, true)
96-
local height = floor(vim.o.lines * 0.85)
97-
local width = floor(vim.o.columns * 0.85)
91+
local height = math.floor(vim.o.lines * 0.85)
92+
local width = math.floor(vim.o.columns * 0.85)
9893
local title = 'project.nvim'
99-
local current_config = (' '):rep(floor((width - title:len()) / 2))
94+
local current_config = (' '):rep(math.floor((width - title:len()) / 2))
10095
.. title
10196
.. '\n'
10297
.. ('='):rep(width)
@@ -107,20 +102,20 @@ function Config.open_win()
107102
0,
108103
-1,
109104
true,
110-
vim.split(current_config, '\n', { plain = true, trimempty = true })
105+
vim.split(current_config, '\n', { plain = true })
111106
)
112107
local win = vim.api.nvim_open_win(bufnr, true, {
113108
focusable = true,
109+
border = 'single',
110+
col = math.floor((vim.o.columns - width) / 2) - 1,
111+
row = math.floor((vim.o.lines - height) / 2) - 1,
114112
noautocmd = true,
115113
relative = 'editor',
116-
row = floor((vim.o.lines - height) / 2) - 1,
117-
col = floor((vim.o.columns - width) / 2) - 1,
118114
style = 'minimal',
119115
title = 'Project Config',
120116
title_pos = 'center',
121117
width = width,
122118
height = height,
123-
border = 'single',
124119
zindex = 30,
125120
})
126121

lua/project/config/defaults.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,6 @@ DEFAULTS.log = {
235235
--- ---
236236
---@class Project.Config.Telescope
237237
DEFAULTS.telescope = {
238-
---Determines whether the `telescope` picker should be called
239-
---from the `setup()` function.
240-
---
241-
---If telescope is not installed, this doesn't make a difference.
242-
---
243-
---Note that even if set to `false`, you can still load the extension manually.
244-
--- ---
245-
---Default: `false`
246-
--- ---
247-
enabled = false, ---@type boolean
248238
---Determines whether the newest projects come first in the
249239
---telescope picker (`'newest'`), or the oldest (`'oldest'`).
250240
--- ---

lua/project/popup.lua

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
local MODSTR = 'project.popup'
99
local ERROR = vim.log.levels.ERROR
1010
local WARN = vim.log.levels.WARN
11+
local uv = vim.uv or vim.loop
1112
local in_list = vim.list_contains
1213
local empty = vim.tbl_isempty
1314

@@ -39,7 +40,7 @@ local function hidden_avail(path, hidden)
3940

4041
local fd = Util.executable('fd') and 'fd' or (Util.executable('fdfind') and 'fdfind' or '')
4142
if fd == '' then
42-
error(('(%s.hidden_avail): `fd`/`fdfind` could be found PATH!'):format(MODSTR), ERROR)
43+
error(('(%s.hidden_avail): `fd`/`fdfind` not found in found PATH!'):format(MODSTR), ERROR)
4344
end
4445

4546
local cmd = { fd, '-Iad1' }
@@ -102,8 +103,7 @@ local function open_node(proj, only_cd, ran_cd)
102103
})
103104
end
104105
if not ran_cd then
105-
local success = require('project.api').set_pwd(proj, 'prompt')
106-
if not success then
106+
if not require('project.api').set_pwd(proj, 'prompt') then
107107
vim.notfy('(open_node): Unsucessful `set_pwd`!', ERROR)
108108
return
109109
end
@@ -114,7 +114,7 @@ local function open_node(proj, only_cd, ran_cd)
114114
vim.g.project_nvim_cwd = proj
115115
end
116116

117-
local dir = vim.uv.fs_scandir(proj)
117+
local dir = uv.fs_scandir(proj)
118118
if not dir then
119119
vim.notify(('(%s.open_node): NO DIR `%s`!'):format(MODSTR, proj), ERROR)
120120
return
@@ -123,13 +123,12 @@ local function open_node(proj, only_cd, ran_cd)
123123
local hidden = require('project.config').options.show_hidden
124124
local ls = {}
125125
while true do
126-
local node = vim.uv.fs_scandir_next(dir)
126+
local node = uv.fs_scandir_next(dir)
127127
if not node then
128128
break
129129
end
130130
node = proj .. '/' .. node
131-
local stat = vim.uv.fs_stat(node)
132-
if stat then
131+
if uv.fs_stat(node) then
133132
local hid = is_hidden(node)
134133
if (hidden and hid) or hidden_avail(node, hidden) then
135134
table.insert(ls, node)
@@ -154,7 +153,7 @@ local function open_node(proj, only_cd, ran_cd)
154153
end
155154

156155
item = Util.rstrip('/', vim.fn.fnamemodify(item, ':p'))
157-
local stat = vim.uv.fs_stat(item)
156+
local stat = uv.fs_stat(item)
158157
if not stat then
159158
return
160159
end
@@ -192,6 +191,7 @@ function Popup.select.new(opts)
192191
if empty(opts) then
193192
error(('(%s.select.new): Empty args for constructor!'):format(MODSTR), ERROR)
194193
end
194+
195195
if Util.vim_has('nvim-0.11') then
196196
vim.validate('choices', opts.choices, 'function', false, 'fun(): table<string, function>')
197197
vim.validate('choices_list', opts.choices_list, 'function', false, 'fun(): string[]')
@@ -204,8 +204,7 @@ function Popup.select.new(opts)
204204
})
205205
end
206206

207-
---@type Project.Popup.SelectChoices|ProjectCmdFun
208-
local T = setmetatable({
207+
local T = setmetatable({ ---@type Project.Popup.SelectChoices|ProjectCmdFun
209208
choices = opts.choices,
210209
choices_list = opts.choices_list,
211210
}, {
@@ -267,8 +266,7 @@ Popup.delete_menu = Popup.select.new({
267266
vim.ui.select(choices_list, {
268267
prompt = 'Select a project to delete:',
269268
format_item = function(item) ---@param item string
270-
local session = require('project.utils.history').session_projects
271-
if in_list(session, item) then
269+
if in_list(require('project.utils.history').session_projects, item) then
272270
return '* ' .. item
273271
end
274272
return item
@@ -298,8 +296,7 @@ Popup.delete_menu = Popup.select.new({
298296
return recents
299297
end,
300298
choices = function()
301-
---@type table<string, fun()>
302-
local T = {}
299+
local T = {} ---@type table<string, function>
303300
for _, proj in ipairs(require('project.utils.history').get_recent_projects()) do
304301
T[proj] = function()
305302
require('project.utils.history').delete_project(proj)
@@ -357,9 +354,7 @@ Popup.recents_menu = Popup.select.new({
357354
Popup.open_menu = Popup.select.new({
358355
callback = function()
359356
local choices_list = Popup.open_menu.choices_list()
360-
vim.ui.select(choices_list, {
361-
prompt = 'Select an operation:',
362-
}, function(item)
357+
vim.ui.select(choices_list, { prompt = 'Select an operation:' }, function(item)
363358
if not item then
364359
return
365360
end
@@ -379,28 +374,16 @@ Popup.open_menu = Popup.select.new({
379374
choices = function()
380375
local Config = require('project.config')
381376
local res = { ---@type table<string, ProjectCmdFun>
382-
['Project Session'] = function()
383-
Popup.session_menu()
384-
end,
385-
['New Project'] = function()
386-
require('project.commands').cmds.ProjectAdd()
387-
end,
388-
['Open Recent Project'] = function()
389-
Popup.recents_menu()
390-
end,
391-
['Delete A Project'] = function()
392-
Popup.delete_menu()
393-
end,
394-
['Show Config'] = function()
395-
require('project.commands').cmds.ProjectConfig()
396-
end,
397-
['Open History'] = function()
398-
vim.cmd.ProjectHistory()
399-
end,
377+
['Project Session'] = Popup.session_menu,
378+
['New Project'] = require('project.commands').cmds.ProjectAdd,
379+
['Open Recent Project'] = Popup.recents_menu,
380+
['Delete A Project'] = Popup.delete_menu,
381+
['Show Config'] = require('project.commands').cmds.ProjectConfig,
382+
['Open History'] = vim.cmd.ProjectHistory,
400383
['Open Help Docs'] = function()
401384
vim.cmd.help('project-nvim')
402385
end,
403-
['Run Checkhealth'] = function()
386+
['Run Checkhealth'] = vim.cmd.ProjectHealth or function()
404387
vim.cmd.checkhealth('project')
405388
end,
406389
['Go To Source Code'] = function()
@@ -409,22 +392,14 @@ Popup.open_menu = Popup.select.new({
409392
Exit = function() end,
410393
}
411394
if vim.g.project_telescope_loaded == 1 then
412-
res['Open Telescope Picker'] = function()
413-
require('telescope._extensions.projects').projects()
414-
end
395+
res['Open Telescope Picker'] = require('telescope._extensions.projects').projects
415396
end
416397
if Config.options.fzf_lua.enabled then
417-
res['Open Fzf-Lua Picker'] = function()
418-
require('project.extensions.fzf-lua').run_fzf_lua()
419-
end
398+
res['Open Fzf-Lua Picker'] = require('project.extensions.fzf-lua').run_fzf_lua
420399
end
421400
if Config.options.log.enabled then
422-
res['Open Log'] = function()
423-
require('project.utils.log').open_win()
424-
end
425-
res['Clear Log'] = function()
426-
require('project.utils.log').clear_log()
427-
end
401+
res['Open Log'] = require('project.utils.log').open_win
402+
res['Clear Log'] = require('project.utils.log').clear_log
428403
end
429404
return res
430405
end,

0 commit comments

Comments
 (0)