Skip to content

Commit

Permalink
feat: check ts language installed
Browse files Browse the repository at this point in the history
  • Loading branch information
crispgm committed Apr 14, 2022
1 parent f685f2d commit b988429
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lua/telescope/_extensions/heading.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ local function filetype()
end

local function support_treesitter(ft)
if ft == 'markdown' or ft == 'rst' then
return true
local ts_ft_maps = {
['markdown'] = true,
['rst'] = true,
['help'] = true,
}

if ts_ft_maps[ft] ~= nil then
return ts_ft_maps[ft]
end
return false
end
Expand All @@ -46,21 +52,31 @@ local function get_headings()
vim.notify(
'The file type is not supported by telescope-heading',
vim.log.levels.WARN,
{ title = 'Telescope heading' }
{ title = 'Telescope Heading' }
)
return nil
end

local index, total = 1, vim.fn.line('$')
local bufnr = vim.api.nvim_get_current_buf()
local filepath = vim.api.nvim_buf_get_name(bufnr)
local headings = {} -- luacheck: ignore
if heading_config.treesitter and support_treesitter(ft) then
headings = mod.ts_get_headings(filepath, bufnr)
else
headings = mod.get_headings(filepath, index, total)
if vim._ts_has_language(ft) then
print('ts')
return mod.ts_get_headings(filepath, bufnr)
else
vim.notify(
string.format(
'No treesitter language parser installed for [%s]. Fallback to normal parser.',
ft
),
vim.log.levels.WARN,
{ title = 'Telescope Heading' }
)
end
end
return headings

return mod.get_headings(filepath, index, total)
end

local function pick_headings(opts)
Expand Down

0 comments on commit b988429

Please sign in to comment.