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

Support multi line strings #26

Closed
KoyamaSohei opened this issue Oct 23, 2019 · 3 comments
Closed

Support multi line strings #26

KoyamaSohei opened this issue Oct 23, 2019 · 3 comments
Assignees

Comments

@KoyamaSohei
Copy link
Contributor

KoyamaSohei commented Oct 23, 2019

related issue:
microsoft/vscode#15140

My proposal

Support multi line strings with python-like syntax

{
  "prefix": "foo",
  "body": """ 
int main() {
  return 0;
}"""
}
// Equals to
/*
{
  "prefix": "foo",
  "body": "\nint main() {\n  return 0;\n}"
}
*/

End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line.

{
  "prefix": "foo",
  "body": """\
int main() {
  return 0;
}"""
}
// Equals to
/*
{
  "prefix": "foo",
  "body": "int main() {\n  return 0;\n}"
}
*/

Motivation

When we create a snippet with multi line, we have 2 choices.

  1. wrap the string of "body" every line. (it's bothersome)
{
  "prefix": "foo",
  "body": [
    "int main() {",
    "  return 0;",
    "}"
  ]
}
  1. join with \n (the longer the code, the harder it is to read)
{
  "prefix": "foo",
  "body": "int main() {\n  return 0;\n}"
}

There is no problem if the number of lines is small or if there are few opportunities to create snippets,
but there is room for improvement in terms of labor and readability for snippets heavy use.

I hope this proposal is taken into account. Thanks!

@KoyamaSohei
Copy link
Contributor Author

KoyamaSohei commented Oct 27, 2019

@aeschli

I read this issue json5/json5#190

json5 is not the best solution to solve my issue. ( because json5 line break does not include the meaning of '\n'. I want to copy code & paste it directly into config file).

// we need '\n\' end of every line ...
{
  prefix: "foo",
  body: "\
int main() {\n\
  return 0;\n\
}"
}

However, jsonc seems better to integrate with json5.

Do you have any plans to integrate jsonc into json5 in the future? If there is, my proposal was not in line with the integration process and may be inappropriate.

@aeschli
Copy link
Contributor

aeschli commented Oct 28, 2019

Hi @KoyamaSohei, thanks for the suggestion, but I would like to keep JSONC just as JSON with comments. That's what's in use for many existing the VSCode configuration files but e.g. also in Sublime, for eslint.json, tsconfig.json which to this with other parser libraries.

Adding multi-line strings would introduce another flavor of JSON and make things more complex.

If the snippet declarations syntax is too limiting, I'd suggest filing an issue against snippets in VSCode to also support JSON5 or YAML or any of ther already existing formats.

@aeschli aeschli closed this as completed Oct 28, 2019
@aeschli
Copy link
Contributor

aeschli commented Oct 28, 2019

We have no plans to integrate jsonc into json5 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants