Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jsx): correctly comment first line of JSX #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lua/ts_context_commentstring/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,21 @@ function M.check_node(node, language_config, commentstring_key)
end

local node_type = node:type()
local match = language_config[node_type]

-- A workaround for an edge case in JSX.
-- The first line of JSX should be commented with `// %s` rather than
-- `{/* %s */}` but the general logic does not allow us to configure that
-- behaviour. This is a bit of an edge case though, and so we have this
-- workaround here rather than allowing for more complex configuration.
-- For more information, see:
-- https://github.com/JoosepAlviste/nvim-ts-context-commentstring/issues/29
-- NOTE: We should NOT add any more of these sort of workarounds
local is_first_line_of_jsx = node_type == 'jsx_element' and node:parent():type() == 'parenthesized_expression'
if is_first_line_of_jsx then
return language_config[commentstring_key] or language_config.__default or language_config
end

local match = language_config[node_type]
if match then
return match[commentstring_key] or match.__default or match
end
Expand Down