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

Highlight and surround a word with angled brackets in languages typescript and tsx #8636

Open
1 task done
jlarmstrongiv opened this issue Feb 29, 2024 · 4 comments
Open
1 task done
Labels
editor Feedback for code editing, formatting, editor iterations, etc enhancement [core label] language An umbrella label for all programming languages syntax behaviors tsx TypeScript JSX support typescript TypeScript programming language support

Comments

@jlarmstrongiv
Copy link

Check for existing issues

  • Completed

Describe the feature

I would like to highlight a word and press < to surround it with angled brackets, similar to how you can highlight a word and surround it with braces by pressing {.

TypeScript makes heavy use of Type<Generic>, so having that autocomplete would be nice

These settings are defined in:

And may be a relatively simple change

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

No response

@jlarmstrongiv jlarmstrongiv added admin read Pending admin review enhancement [core label] triage Maintainer needs to classify the issue labels Feb 29, 2024
@jlarmstrongiv
Copy link
Author

jlarmstrongiv commented Feb 29, 2024

@Moshyfawn
Copy link
Contributor

This comment contains the source links, but it is already a language-dependent feature.

You can open a markdown file right now and press shift-< or shift-{ with some text selected to see it in effect.

@Moshyfawn Moshyfawn added needs info / awaiting response Issue that needs more information from the user editor Feedback for code editing, formatting, editor iterations, etc language An umbrella label for all programming languages syntax behaviors and removed triage Maintainer needs to classify the issue labels Mar 2, 2024
@JosephTLyons JosephTLyons removed the admin read Pending admin review label Mar 4, 2024
@jlarmstrongiv
Copy link
Author

jlarmstrongiv commented Mar 11, 2024

@Moshyfawn that’s a great feature! I noticed it worked in markdown, but not typescript, tsx, or astro. Is there a way to enable that language-dependent feature in other languages?

@notpeter
Copy link
Contributor

notpeter commented Jun 20, 2024

Hi @jlarmstrongiv. I dug into this. This appears to be controlled by the close = true line for < > in the config.toml brackets section for each language. For example compare typescript to markdown:

{ start = "<", end = ">", close = false, newline = true, not_in = ["string", "comment"] },

{ start = "<", end = ">", close = true, newline = true },

Currently this setting controls two behaviors:

  1. Nothing selected: Inserts closing > after you type <
  2. Something selected: Wraps selection in < and > when you type <.

This means if we enable the behavior we're looking for (great!) we also get autoclosing <> (not great), because then any expression with a less than < operator will get an extraneous closing tag.

I'll leave this open as an enhancement request. In the future we may to support enabling the second behavior without the first, but at the moment that's where we're at.

You can see this behavior by building from source with the following diff:

diff --git a/crates/languages/src/typescript/config.toml b/crates/languages/src/typescript/config.toml
index ca115622c..2fdc007ec 100644
--- a/crates/languages/src/typescript/config.toml
+++ b/crates/languages/src/typescript/config.toml
@@ -7,7 +7,7 @@ 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 = true, not_in = ["string", "comment"] },
     { start = "\"", end = "\"", close = true, newline = false, not_in = ["string"] },
     { start = "'", end = "'", close = true, newline = false, not_in = ["string", "comment"] },
     { start = "`", end = "`", close = true, newline = false, not_in = ["string"] },

@notpeter notpeter added typescript TypeScript programming language support tsx TypeScript JSX support and removed needs info / awaiting response Issue that needs more information from the user labels Jun 20, 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] language An umbrella label for all programming languages syntax behaviors tsx TypeScript JSX support typescript TypeScript programming language support
Projects
None yet
Development

No branches or pull requests

4 participants