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

[Feature request]: Json5 highlighting #11676

Closed
LostTime76 opened this issue May 15, 2022 · 6 comments
Closed

[Feature request]: Json5 highlighting #11676

LostTime76 opened this issue May 15, 2022 · 6 comments
Assignees
Labels
accepted scintilla dependent Can't be considered for N++ implementation unless/until Scintilla changes

Comments

@LostTime76
Copy link

I realize this might be a long shot.. but I am a long time user of N++. I don't think this is currently implemented and apologies if there is another issue open... but would it be possible to add Json5 highlighting via the json5 file extension? It seems like there may be a way to hack the highlighting a little by using JavaScript highlighting instead as that seems to be close; however, if I choose JavaScript highlighting, it's not very good..

I really really x1000 do not want to move to another editor for this support. I tried atom and it seemed like it had support, but I want to continue to use N++.

This is what I currently get using JavaScript highlighting.
image

This standard json highlighting is much more palatable.
image

I may be a long time user of N++ as a software engineer, but I have never gone past the basic UI or twiddled any settings. If there is another way to achieve better highlighting, I am all for it.

@rdipardo
Copy link
Contributor

@donho, just make a new L_JSON5 enum value and use the builtin JSON lexer's option to allow comments 1.

N++ currently uses none of the JSON lexer's available options; ScintillaEditView::setJsonLexer has not been updated since the days when the C++ lexer did the styling for every C-style curly brace language:

execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.compact"), reinterpret_cast<LPARAM>("0"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.comment"), reinterpret_cast<LPARAM>("1"));
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("fold.preprocessor"), reinterpret_cast<LPARAM>("1"));

Footnotes

  1. https://github.com/notepad-plus-plus/notepad-plus-plus/blob/74395977bbf5dbd9bb9bfc3645b78584ce7b03f1/lexilla/lexers/LexJSON.cxx#L125-L127

@LostTime76
Copy link
Author

Json5 has several more changes than just adding comments. As shown above, the first screenshot is valid Json5. For example, property values can be single quoted, double quoted, or not quoted. Additionally, there are changes to allow different number formats for number values.

I don't know enough about javascript to know if Json5 is close to it or not. However, the unquoted property values are highly desirable to use and having them properly highlighted with a different color would be useful. I think the unquoted property value is valid javascript, but the javascript highlighter doesn't seem to highlight it regardless.

Json5 spec: https://spec.json5.org/#prod-JSON5Identifier

@rdipardo
Copy link
Contributor

The lexer module is maintained by another project: https://github.com/ScintillaOrg/lexilla
New language features have to be implemented by them before N+ can benefit.

@donho
Copy link
Member

donho commented May 16, 2022

Adding L_JSON5 enum and applying all *.json5 to L_JSON5 for enabling comment in JSON could be a solution.

@tilleul
Copy link

tilleul commented May 23, 2022

Adding L_JSON5 enum and applying all *.json5 to L_JSON5 for enabling comment in JSON could be a solution.

Maybe this could cause compatibility problems when Scintilla finally supports JSON5 ? Don't know ...

I've made a (related) request to support Scintilla's built-in "comments" for JSON highlighting. #11713 In this request I suggest that the option is a checkbox in the Settings/Preferences/Languages screen but maybe it's not the best way to go ?

If an easier solution is to create a new enum value in the lexer, may I suggest that it's named L_JSONC instead of L_JSON5 ?

"JSONC" is not an official subset of JSON but is used by VS Code and it does just what the "allowComments" option in the lexer does: support line and block comments in JS/C style ...

https://code.visualstudio.com/docs/languages/json#_json-with-comments

@ArkadiuszMichalski
Copy link
Contributor

@chcg chcg added the scintilla dependent Can't be considered for N++ implementation unless/until Scintilla changes label Oct 13, 2022
@donho donho added the accepted label Jan 3, 2023
donho added a commit to donho/notepad-plus-plus that referenced this issue Jan 5, 2023
Currently, it's only JSONC (with js comment supported).
It will be enhanced in the future.

Fix notepad-plus-plus#11676, fix notepad-plus-plus#11713
@donho donho closed this as completed in bdb06d5 Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted scintilla dependent Can't be considered for N++ implementation unless/until Scintilla changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants