Add block_comment
to JS, TSX, and TS (#31400)
This is the first step of ["Solution proposal for folding multiline comments with no indentation"](https://github.com/zed-industries/zed/discussions/31395): > 1. Add block_comment in the config.toml for the languages javascript, typescript, tsx. These are simple languages for this feature, and I am already familiar with them. The next step will be: > 2. Modify the function `crease_for_buffer_row` in `DisplaySnapshot` to handle multiline comments. `editor::fold` and `editor::fold_all` will handle multiline comments after this change. To my knowledge, `editor::unfold`, `editor::unfold_all`, and the **unfold** indicator in the gutter will already work after folding, but there will be no **fold** indicator. Release Notes: - N/A
This commit is contained in:
parent
10af3c7e58
commit
29f0762b6c
4 changed files with 20 additions and 0 deletions
|
@ -2216,6 +2216,7 @@ fn test_language_scope_at_with_javascript(cx: &mut App) {
|
||||||
LanguageConfig {
|
LanguageConfig {
|
||||||
name: "JavaScript".into(),
|
name: "JavaScript".into(),
|
||||||
line_comments: vec!["// ".into()],
|
line_comments: vec!["// ".into()],
|
||||||
|
block_comment: Some(("/*".into(), "*/".into())),
|
||||||
brackets: BracketPairConfig {
|
brackets: BracketPairConfig {
|
||||||
pairs: vec![
|
pairs: vec![
|
||||||
BracketPair {
|
BracketPair {
|
||||||
|
@ -2279,6 +2280,10 @@ fn test_language_scope_at_with_javascript(cx: &mut App) {
|
||||||
|
|
||||||
let config = snapshot.language_scope_at(0).unwrap();
|
let config = snapshot.language_scope_at(0).unwrap();
|
||||||
assert_eq!(config.line_comment_prefixes(), &[Arc::from("// ")]);
|
assert_eq!(config.line_comment_prefixes(), &[Arc::from("// ")]);
|
||||||
|
assert_eq!(
|
||||||
|
config.block_comment_delimiters(),
|
||||||
|
Some((&"/*".into(), &"*/".into()))
|
||||||
|
);
|
||||||
// Both bracket pairs are enabled
|
// Both bracket pairs are enabled
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
config.brackets().map(|e| e.1).collect::<Vec<_>>(),
|
config.brackets().map(|e| e.1).collect::<Vec<_>>(),
|
||||||
|
@ -2297,6 +2302,10 @@ fn test_language_scope_at_with_javascript(cx: &mut App) {
|
||||||
.language_scope_at(text.find("b\"").unwrap())
|
.language_scope_at(text.find("b\"").unwrap())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(string_config.line_comment_prefixes(), &[Arc::from("// ")]);
|
assert_eq!(string_config.line_comment_prefixes(), &[Arc::from("// ")]);
|
||||||
|
assert_eq!(
|
||||||
|
string_config.block_comment_delimiters(),
|
||||||
|
Some((&"/*".into(), &"*/".into()))
|
||||||
|
);
|
||||||
// Second bracket pair is disabled
|
// Second bracket pair is disabled
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
string_config.brackets().map(|e| e.1).collect::<Vec<_>>(),
|
string_config.brackets().map(|e| e.1).collect::<Vec<_>>(),
|
||||||
|
@ -2324,6 +2333,10 @@ fn test_language_scope_at_with_javascript(cx: &mut App) {
|
||||||
.language_scope_at(text.find(" d=").unwrap() + 1)
|
.language_scope_at(text.find(" d=").unwrap() + 1)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(tag_config.line_comment_prefixes(), &[Arc::from("// ")]);
|
assert_eq!(tag_config.line_comment_prefixes(), &[Arc::from("// ")]);
|
||||||
|
assert_eq!(
|
||||||
|
tag_config.block_comment_delimiters(),
|
||||||
|
Some((&"/*".into(), &"*/".into()))
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tag_config.brackets().map(|e| e.1).collect::<Vec<_>>(),
|
tag_config.brackets().map(|e| e.1).collect::<Vec<_>>(),
|
||||||
&[true, true]
|
&[true, true]
|
||||||
|
@ -2337,6 +2350,10 @@ fn test_language_scope_at_with_javascript(cx: &mut App) {
|
||||||
expression_in_element_config.line_comment_prefixes(),
|
expression_in_element_config.line_comment_prefixes(),
|
||||||
&[Arc::from("// ")]
|
&[Arc::from("// ")]
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
expression_in_element_config.block_comment_delimiters(),
|
||||||
|
Some((&"/*".into(), &"*/".into()))
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
expression_in_element_config
|
expression_in_element_config
|
||||||
.brackets()
|
.brackets()
|
||||||
|
|
|
@ -4,6 +4,7 @@ path_suffixes = ["js", "jsx", "mjs", "cjs"]
|
||||||
# [/ ] is so we match "env node" or "/node" but not "ts-node"
|
# [/ ] is so we match "env node" or "/node" but not "ts-node"
|
||||||
first_line_pattern = '^#!.*\b(?:[/ ]node|deno run.*--ext[= ]js)\b'
|
first_line_pattern = '^#!.*\b(?:[/ ]node|deno run.*--ext[= ]js)\b'
|
||||||
line_comments = ["// "]
|
line_comments = ["// "]
|
||||||
|
block_comment = ["/*", "*/"]
|
||||||
autoclose_before = ";:.,=}])>"
|
autoclose_before = ";:.,=}])>"
|
||||||
brackets = [
|
brackets = [
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
|
|
|
@ -2,6 +2,7 @@ name = "TSX"
|
||||||
grammar = "tsx"
|
grammar = "tsx"
|
||||||
path_suffixes = ["tsx"]
|
path_suffixes = ["tsx"]
|
||||||
line_comments = ["// "]
|
line_comments = ["// "]
|
||||||
|
block_comment = ["/*", "*/"]
|
||||||
autoclose_before = ";:.,=}])>"
|
autoclose_before = ";:.,=}])>"
|
||||||
brackets = [
|
brackets = [
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
|
|
|
@ -3,6 +3,7 @@ grammar = "typescript"
|
||||||
path_suffixes = ["ts", "cts", "d.cts", "d.mts", "mts"]
|
path_suffixes = ["ts", "cts", "d.cts", "d.mts", "mts"]
|
||||||
first_line_pattern = '^#!.*\b(?:deno run|ts-node|bun|tsx)\b'
|
first_line_pattern = '^#!.*\b(?:deno run|ts-node|bun|tsx)\b'
|
||||||
line_comments = ["// "]
|
line_comments = ["// "]
|
||||||
|
block_comment = ["/*", "*/"]
|
||||||
autoclose_before = ";:.,=}])>"
|
autoclose_before = ";:.,=}])>"
|
||||||
brackets = [
|
brackets = [
|
||||||
{ start = "{", end = "}", close = true, newline = true },
|
{ start = "{", end = "}", close = true, newline = true },
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue