Skip to content

Commit

Permalink
fix: buffername and filetype when using Telescope
Browse files Browse the repository at this point in the history
buffername and filetype was not detected correctly when using
:GreyjoyTelescope
  • Loading branch information
desdic committed Sep 21, 2024
1 parent b9b6e33 commit bf65df2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lua/greyjoy/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ greyjoy.run = function(arg, method)

local pluginname = arg or ""

local fileobj = utils.new_file_obj(greyjoy.patterns)
local fileobj = utils.new_file_obj(
greyjoy.patterns,
vim.api.nvim_buf_get_name(0),
vim.bo.filetype
)
local rootdir = fileobj.rootdir
local elements = {}

Expand Down
22 changes: 19 additions & 3 deletions lua/greyjoy/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ local collect_output = function(output, on_item_collected)
end
end

greytelescope.run_async = function(arg, on_item_collected, on_complete)
local fileobj = utils.new_file_obj(greyjoy.patterns)
greytelescope.run_async = function(
arg,
bufname,
filetype,
on_item_collected,
on_complete
)
local fileobj = utils.new_file_obj(greyjoy.patterns, bufname, filetype)
local rootdir = fileobj.rootdir

local pluginname = arg or ""
Expand Down Expand Up @@ -120,6 +126,10 @@ greytelescope.run = function(arg)
})
end

-- Get name of buffer before opening telescope, else we get the telescope buffer
local bufname = vim.api.nvim_buf_get_name(0)
local filetype = vim.bo.filetype

local picker = pickers.new({}, {
prompt_title = "Runners",
finder = generate_finder(),
Expand Down Expand Up @@ -195,7 +205,13 @@ greytelescope.run = function(arg)
end

-- Start the asynchronous collection and processing
greytelescope.run_async(arg, on_item_collected, on_complete)
greytelescope.run_async(
arg,
bufname,
filetype,
on_item_collected,
on_complete
)
end

return greytelescope
9 changes: 4 additions & 5 deletions lua/greyjoy/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ M.str_to_array = function(str)
return words
end

M.new_file_obj = function(patterns)
local filetype = vim.bo.filetype
local fullname = vim.api.nvim_buf_get_name(0)
local filename = vim.fs.basename(fullname)
local filepath = vim.fs.dirname(fullname)
M.new_file_obj = function(patterns, bufname, filetype)
local fullname = bufname
local filename = vim.fs.basename(bufname)
local filepath = vim.fs.dirname(bufname)

filepath = M.if_nil(filepath, "")
if filepath == "" then
Expand Down

0 comments on commit bf65df2

Please sign in to comment.