atom / toggle-quotes

An Atom package to toggle between single and double quotes
MIT License
77 stars 36 forks source link

JSON grammar defeats toggle quotes #7

Closed brandom closed 10 years ago

brandom commented 10 years ago

Toggle quotes does not seem to work with JSON grammar.

izuzak commented 10 years ago

@brandom Hm, never knew that JSON supported comments. Just had a look at http://www.json.org/ and didn't find comments mentioned -- could you provide some links that suggest otherwise?

kevinsawicki commented 10 years ago

@brandom do you mean it doesn't convert single quotes to double quotes?

izuzak commented 10 years ago

Uhhh, totally misread that, sorry @brandom and thanks @kevinsawicki. :sweat_smile:

izuzak commented 10 years ago

So, again checking http://www.json.org/, JSON strings can only be defined with " and not with '. This is also how the language-json package recognizes JSON strings.

Currently, the toggle-quotes package can toggle quotes only on strings, as detected by a language grammar. As a result, toggling quotes on 'foo' in JSON will not work since that's not recognized as a string. However, toggling on "foo" still works since that's recognized as a string.

kevinsawicki commented 10 years ago

@izuzak I was thinking perhaps of allowing toggle-quotes to work on error class tokens. So if your cursor is on an error region that begins/ends with quotes it would still work.

izuzak commented 10 years ago

I was thinking perhaps of allowing toggle-quotes to work on error class tokens.

Sounds like a good idea :+1:

brandom commented 10 years ago

@kevinsawicki My thoughts exactly. This was the use case I was referring to, to fix up plain JS objects / arrays when pasted into a JSON doc.

FWIW I tweaked the JSON prettify package to make a best effort using regex to convert to valid JSON before JSON.parse.

kevinsawicki commented 10 years ago

Just published a fix for this in 0.7.0, let me know if you see any issues after upgrading.