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

Better ToggleComments support for Comment and Doc #10113

Closed
1 task done
huacnlee opened this issue Apr 3, 2024 · 3 comments · Fixed by #10126
Closed
1 task done

Better ToggleComments support for Comment and Doc #10113

huacnlee opened this issue Apr 3, 2024 · 3 comments · Fixed by #10126
Labels
editor Feedback for code editing, formatting, editor iterations, etc enhancement [core label]

Comments

@huacnlee
Copy link
Contributor

huacnlee commented Apr 3, 2024

Check for existing issues

  • Completed

Describe the feature

We have line_comments in language config.toml.

For example the Rust:

name = "Rust"
grammar = "rust"
path_suffixes = ["rs"]
line_comments = ["// ", "/// ", "//! "]
autoclose_before = ";:.,=}])>"
brackets = [
    { start = "{", end = "}", close = true, newline = true },
    { start = "[", end = "]", close = true, newline = true },
    { start = "(", end = ")", close = true, newline = true },
    { start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },
    { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
    { start = "/*", end = " */", close = true, newline = false, not_in = ["string", "comment"] },
]
collapsed_placeholder = " /* ... */ "

But by my test, the Toggle Comments command just work for the first item in line_comments.

If applicable, add mockups / screenshots to help present your vision of the feature

2024-04-03 18 32 08

As shown in the screen recording, if ToggleComments can correctly handle Rust's /// and //!, it will be more convenient for us to write documents.

For example, many times we need to write a large section of Rust code example. So we many write the code first, and then add /// prefix to them. If the ToggleComments can handle that, we can just select the all new addition code and run ToggleComments to add the prefix.

@huacnlee huacnlee added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Apr 3, 2024
@osiewicz
Copy link
Contributor

osiewicz commented Apr 3, 2024

Yeah, back in #6713 we've ommited Toggle comments support and additional entries in line_comments array are there mostly for comment continuations. I'll tackle Toggle comments support though.

@osiewicz
Copy link
Contributor

osiewicz commented Apr 3, 2024

Oh, now I get why we didn't add support for Toggle Comments there; how do you decide which comment flavour to add? Like:

For example, many times we need to write a large section of Rust code example. So we many write the code first, and then add /// prefix to them. If the ToggleComments can handle that, we can just select the all new addition code and run ToggleComments to add the prefix.

How would you decide that we should insert /// as a comment prefix and not // or //!?

@huacnlee
Copy link
Contributor Author

huacnlee commented Apr 3, 2024

What if we check what type of prefix is the nearest Comment before or after the current line. Then use the same prefix with matching one of the line_comments?

I am not sure if this can be done.

Even that, with the Uncomment case, we can that to remove the right prefix by matching the line_comments.

@Moshyfawn Moshyfawn added editor Feedback for code editing, formatting, editor iterations, etc and removed triage Maintainer needs to classify the issue labels Apr 3, 2024
osiewicz added a commit that referenced this issue Apr 3, 2024
…n language config (#10126)

This does not try to heuristically pick a comment style based on
surroundings anyhow. It does improve our story around uncommenting
though.

Fixes #10113.

Release Notes:

- Fixed "Toggle comment" action not working in presence of non-default
line comments such as doc comments in Rust
([#10113](#10113)).
@JosephTLyons JosephTLyons removed the admin read Pending admin review label Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editor Feedback for code editing, formatting, editor iterations, etc enhancement [core label]
Projects
None yet
4 participants