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

[json] add commas automatically #69545

Open
fulldecent opened this issue Feb 27, 2019 · 10 comments · May be fixed by microsoft/vscode-json-languageservice#185
Open

[json] add commas automatically #69545

fulldecent opened this issue Feb 27, 2019 · 10 comments · May be fixed by microsoft/vscode-json-languageservice#185
Assignees
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities json JSON support issues
Milestone

Comments

@fulldecent
Copy link

fulldecent commented Feb 27, 2019

Test case

untitledb2

Expected behavior

  • After typing age TAB, the comma should be added to the end of the previous line.
  • After typing " for the next object property, the comma should be added to the end of the previous line.

Actual behavior

The autocomplete does not produce valid text.

Discussion

In general, the autocomplete should strive to produce output that is maximally valid in whatever language grammar it is using.

@vscodebot vscodebot bot added the editor-autoindent Editor auto indentation issues label Feb 27, 2019
@rebornix rebornix removed the editor-autoindent Editor auto indentation issues label Feb 27, 2019
@aeschli aeschli added the json JSON support issues label Mar 2, 2019
@aeschli aeschli added this to the Backlog milestone Mar 2, 2019
@aeschli aeschli added the feature-request Request for new features or functionality label Mar 2, 2019
@apaolino
Copy link

It would be useful if could add an automatic comma when you hit the enter key after a line (as Android Studio does)

@aeschli aeschli changed the title JSON editor: add commas automatically [json] add commas automatically Oct 9, 2019
@hfantauzzi
Copy link

Really should be implemented.

@AcerFeng
Copy link

You can try Auto Insert Comma .

@AcerFeng
Copy link

Really should be implemented.

You can try Auto Insert Comma .

@AcerFeng
Copy link

It would be useful if could add an automatic comma when you hit the enter key after a line (as Android Studio does)

You can try Auto Insert Comma .

@ahmafi
Copy link

ahmafi commented Dec 9, 2021

The extension is nice, but wish we had this built-in in VSCode

@peteruithoven
Copy link

It's most annoying when you add a { and VS Code auto adds the } at the end.
Screen record from 2022-01-28 15 17 53

I get in this situation all the time:

const value = {
  a: "a",
  b: {
    
  }
  c: "c"
}

It's very common in Vue's option syntax for example.

@fulldecent
Copy link
Author

@peteruithoven , yes that is in-scope for this issue.

I do not support the behavior of Auto Insert Comma as a default for VS Code.

That extension is adding commas greedily. It is possible for that extension to add a comma that you may not want and which you would have to delete. This proposal is for a default behavior where generally it is nice to err on the side of being correct rather than helpful. And that means adding a comma when it is 100% sure that is desired, including the top post and #69545 (comment).

@aeschli aeschli added the help wanted Issues identified as good community contribution opportunities label Jan 31, 2022
@zardoy
Copy link
Contributor

zardoy commented Nov 30, 2022

I do not support the behavior of Auto Insert Comma as a default for VS Code.

I do not recommend it. It doesn't work with ctrl+Enter & ctrl+shift+Enter correctly, use Fix All JSON instead of Auto Insert Comma for JSON.

However, @fulldecent I'm really interested in your feedback:

That extension is adding commas greedily. ... This proposal is for a default behavior where generally it is nice to err on the side of being correct rather than helpful.

Do you mean that comma shouldn't be inserted after Enter? But when then? After what specific action it should happen?

Also as I read from issue body, autocomplete should have additionalTextEdits to insert , after previous node if needed, but what if next line doesn't have autocomplete items? I didn't really get the idea of feature request.

@fulldecent
Copy link
Author

Got it @zardoy, I have updated the expected behavior above and added another behavior that doesn't require auto complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities json JSON support issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants