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

Inbuilt comment feature not working properly for JSX files #28830

Closed
Antony-AXS opened this issue May 18, 2024 · 7 comments
Closed

Inbuilt comment feature not working properly for JSX files #28830

Antony-AXS opened this issue May 18, 2024 · 7 comments
Labels
enhancement feature request

Comments

@Antony-AXS
Copy link

Problem

when i type 'gcc; this is how it gets commented in a JSX file
image

Steps to reproduce

image

Expected behavior

this is how it should be for JSX when commented.
image

Neovim version (nvim -v)

0.10

Vim (not Nvim) behaves the same?

no

Operating system/version

ubuntu 22.04

Terminal name/version

GNOME Terminal 3.44.0 using VTE 0.68.0 +BIDI +GNUTLS +ICU +SYSTEMD

$TERM environment variable

xterm-256color

Installation

appimage

@Antony-AXS Antony-AXS added the bug issues reporting wrong behavior label May 18, 2024
@zeertzjq

This comment was marked as off-topic.

@towry
Copy link

towry commented May 18, 2024

vi-mode on zed works well with gcc on tsx file.

@zeertzjq
Copy link
Member

Oops, I was wrong. https://github.com/tree-sitter/tree-sitter-javascript does support .jsx files, but it seems that the comment string may change even though the filetype doesn't change. From numToStr/Comment.nvim#133 it seems that this is quite a complicated problem.

@ribru17
Copy link
Contributor

ribru17 commented May 18, 2024

@zeertzjq Would you be opposed to a PR that sets the {/* ... */} comment string when the cursor is in a (jsx_element) node (maybe only checked in (javascript|typescript)react files)? I have had that in my own config for quite some time and it works fine. Or would that be out of scope for the built-in comment module since the parser isn't bundled

@clason
Copy link
Member

clason commented May 18, 2024

Yes, that would be out of scope. React files are such a mess, you need a dedicated plugin to make sense of it. We shouldn't add one-off hacks for individual languages.

ribru17 added a commit to ribru17/neovim that referenced this issue May 19, 2024
Problem: it's difficult for users to customize the inbuilt commenting
behavior (changing or extending)

Solution: expose a hook that can override the selected commentstring, to
allow for finer control

Closes neovim#28830
@folke
Copy link
Member

folke commented May 20, 2024

This is a work-around I use in LazyVim to use nvim-ts-context-commentstring together with native comments:

local get_option = vim.filetype.get_option
vim.filetype.get_option = function(filetype, option)
  return option == "commentstring"
    and require("ts_context_commentstring.internal").calculate_commentstring()
    or get_option(filetype, option)
end

An alternative would be to at least expose vim._comment.get_commentstring so that it can be easily overridden,
OR have an option that always uses vim.bo.commentstring for a given buffer instead of treesitter.

askoufis added a commit to askoufis/dotfiles that referenced this issue May 20, 2024
@folke
Copy link
Member

folke commented May 20, 2024

Just created a tiny plugin to enhance the native comments with support for custom comment strings for certain treesitter node types.

It's an alternative to ts-context-commentstring.

https://github.com/folke/ts-comments.nvim

@wookayin wookayin added enhancement feature request and removed bug issues reporting wrong behavior labels May 20, 2024
@justinmk justinmk closed this as not planned Won't fix, can't repro, duplicate, stale May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants