Skip to content

Commit

Permalink
feat: relay on languagetree commentstring as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mortezadadgar committed Nov 20, 2023
1 parent ead792c commit 2e383f4
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/ts_context_commentstring/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ function M.calculate_commentstring(args)

local language = language_tree:lang()
local language_config = config.get_languages_config()[language]
local filetypes = vim.treesitter.language.get_filetypes(language)

return M.check_node(node, language_config, key)
return M.check_node(node, language_config, key, filetypes)
end

---Update the `commentstring` setting based on the current location of the
Expand Down Expand Up @@ -104,9 +105,19 @@ end
---@param commentstring_key string
---
---@return string | nil
function M.check_node(node, language_config, commentstring_key)
function M.check_node(node, language_config, commentstring_key, filetypes)
commentstring_key = commentstring_key or '__default'

-- relay on languagetree for commentstring as much as possible
if filetypes then
for _, ft in ipairs(filetypes) do
local cs = vim.filetype.get_option(ft, 'commentstring')
if type(cs) == 'string' and cs ~= '' then
return cs
end
end
end

-- There is no commentstring configuration for this language, use the
-- `ts_original_commentstring`
if not language_config then
Expand Down

0 comments on commit 2e383f4

Please sign in to comment.