-
Notifications
You must be signed in to change notification settings - Fork 353
Fix Various Syntax Highlighting Issues #631
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
Fix Various Syntax Highlighting Issues #631
Conversation
@@ -25,6 +25,7 @@ syntax sync fromstart | |||
syntax case match | |||
|
|||
syntax match jsNoise /[:,\;\.]\{1}/ | |||
syntax match jsSemiEndOfLine /\;\{1}\(\(\s*\/[\/\*].*\)\?$\)\@=/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this also handles the use case of ;
followed by comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just at a quick glance, I don't like this one at all because it's not contained AND has a look ahead. This will probably destroy performance in a larger file. Also, I am not quite sure the rationale to match end of line semis? Wouldn't it be better to isolate particular semis in contained groups we already have?
Thanks for opening this! It's gonna take me a it to go over this and test it! |
syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError | ||
syntax keyword jsBuiltins decodeURI decodeURIComponent encodeURI encodeURIComponent eval isFinite isNaN parseFloat parseInt uneval | ||
syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object Symbol Map WeakMap Set RegExp String Proxy Promise Buffer ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray JSON Math console document window Intl Collator DateTimeFormat NumberFormat | ||
syntax match jsConstant "\<[A-Z][A-Za-z]\+\>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've had many some similar discussions in the past regarding things how to handle things constants and keywords, and whether to highlight them or not.
My personal opinion on the matter is something like this should NOT be in our syntax file because it's more of a stylistic convention (using capital letters to denote a constants), not a rule of the language.
You could easily add something like this as an after
plugin, because an initial capital letter does not a constant make.
Also, this regex could be improved if you use it in an after
plugin, since it will break if there are numbers or $
in the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you even get this diff above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.... you're looking at the merged diff and not each individual commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amadeus what do you think about a global variable to add in syntax highlighting for constants? Like you do with this
, return
, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this:
if exists('g:javascript_highlight_upper_camel_as_constants')
syntax match jsConstant "\<[A-Z][A-Za-z]\+\>"
syntax region jsImportContainer add=jsConstant
syntax region jsDestructuringBlock add=jsConstant
syntax cluster jsExpression add=jsConstant
syntax region jsDestructuringBlock add=jsConstant
HiLink jsClassDefinition Constant
HiLink jsConstant Constant
else
HiLink jsClassDefinition Function
endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, not sure yet. Let's move that to another issue or PR for further discussion. My initial thought is that it adds clutter where it doesn't need to be, but other maintainers here may have counter opinions and it would be good to isolate that discussion.
@amadeus all great feedback thanks! Regarding the end of line semicolons, the look ahead was just for the comments. I'm fine with doing it a different way if you have another suggestion. I'm not sure how you would do it for each individual type of statement and be sure to grab it. But I'll give it a shot. :) With regards to the constants, no, JavaScript does not force this but have you ever been in a newer codebase (or any codebase) where this was not the convention? I know with So I think that this is something that would be very useful to most developers. Potentially this could be added as an option like you're doing for concealing certain matches? |
I just realized I missed what you were saying on end of line semicolons. Matching on a particular type of semi wouldn't do what I wanted. :( The issue is thus: var foo = 'hello';
var bar = 'goodbye'; Both semis in those lines should be matched. Because they're end of line semis, the have no use to the reader and are noise. They're there only for the compiler (minification, etc) If I wrote it like this: var foo = 'hello'; var bar = 'goodbye'; Then only the second semi is noise in this case. The first one acts as a break between statements so that it's easier for the human to parse. Obviously this is a contrived example. So if we matched semis on the _type _ of line, it would have matched both in the second example. Which I do not want. |
Thing is though, the last semi in a line, to style it differently is still completely a stylistic thing, and even seemingly kind of arbitrary. Take an example like this: I still think this is a case of you creating an |
On the subject of consts, yes, while I agree it's pretty common, I still personally don't think it belongs since it's a stylistic thing, and starts to get into lexical parsing, which our syntax file isn't really equipped to do. |
@@ -42,12 +42,12 @@ syntax keyword jsModuleKeywords contained import | |||
syntax keyword jsModuleKeywords contained export skipwhite skipempty nextgroup=jsExportBlock,jsModuleDefault | |||
syntax keyword jsModuleOperators contained from | |||
syntax keyword jsModuleOperators contained as | |||
syntax region jsModuleGroup contained matchgroup=jsBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment | |||
syntax region jsModuleGroup contained matchgroup=jsModuleBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with this, however it would be good to link it back to jsBraces
at the bottom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsModuleBraces
is not linked to anything right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that one! Fixing.
Anyways, overall I like some of these changes. Always nice to get finer granularity with various braces and parens. However I definitely disagree with the stylistic opinionated changes, and therefore I think those should be removed before merging. You could always remove them to get the good stuff merged in, and we could bike shed in another issue afterwards. |
Btw, something like
In |
syntax region jsExportContainer start=/\<export\> / end="\%(;\|$\)" contains=jsModuleKeywords,jsModuleOperators,jsStorageClass,jsModuleDefault,@jsExpression | ||
syntax region jsExportBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment | ||
syntax region jsExportBlock contained matchgroup=jsExportBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also don't forget to link this to jsBraces
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the changes in this PR yet? Mebe not pushed yet? Or github being slow.
@amadeus I think I got everything. I'll open another issue with the constant discussion. |
syntax match jsObjectKey contained /\<[0-9a-zA-Z_$]*\>\(\s*:\)\@=/ contains=jsFunctionKey skipwhite skipempty nextgroup=jsObjectValue | ||
syntax match jsObjectColon contained /:/ skipwhite skipempty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick thing - we should link this back to jsNoise
for backwards compat.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Many of these are noise, but I don't consider function parenthesis to be so. Rather than creating a non-function parens group, I just created a group for each type and then linked them all to `jsParens` so that everything will behave as it currently does for users who are using `jsParens`.
Similar to the parens from the previous commit, this will allow users to customize the look of various types of braces rather than having to go all-in on non-function braces. ------------------------------------------------------------------------------ Actions: * Fix #589
`this` can be used outside of any other block and thus needs to be highlighted there. ------------------------------------------------------------------------------ Actions: * Fix #610
There were a few issues here: * Class decorators weren't being highlighted since they exist outside of any other group * Decorators which take a parameter didn't have their parameters property highlighted * Decorators which decorated a function within an object weren't being highlighted -------------------------------------------------------------------------------- Actions: * Fixes #590 * Fixes #572
This makes quite a bit more sense to me since decorators are a type of annotation to the function below.
It's right there in the name: "Keyword" and should be highlighted as such.
Outside of the |
@amadeus you seemed ambivalent on the All of those groups seem very specific to C IMO. Not all of them apply to other languages. Nor in the same way. |
Up to you. I can add it to my local config. |
I definitely thing |
Doh! Of course yesterday I was heads deep in Objective-C and had no time to test, hopefully today will be ok, or if Dev gets merged into Master, then we can just go ahead and test in dev first, but it's up to @bounceme for when he's ready. |
I'm good with this going into the dev -> master merge when you guys are ready. no rush |
This is merged, once again, thanks @jfelchner for the PR! I went ahead and just added the hilinks into develop manually, to get this in. |
I've annotated each commit with what/why of the changes.
This fixes 3 or 4 current outstanding issues.
I've also made some opinionated tweaks to the current highlight linkages. Hopefully you all agree with them. The improvements to the readability of the code I'm currently working on are substantial.