-
Notifications
You must be signed in to change notification settings - Fork 588
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
[JavaScript] Uppercase constant gets support.class.js
scope
#3469
Comments
I don't know if this is an instance of it, but VSC runs a second, completely different tokenizer after the main one that tweaked the scopes a little bit more. It was (may still be?) asynchronous, and you'd sometimes see the code change colors when you opened certain files. |
I don't know. But when people are amazed by VSCode's syntax highlighting, I will guess they all comes from language server's semantic highlighting. VSCode's highlighting engine is inferior to ST's but semantic highlighting from plugins are usually perfect accurate.
Is this an official standard or de facto standard in JS? |
Very little is official about JavaScript 😅 But I don't remember ever seeing any real-life projects or style guides that use PascalCase for anything but classes, components, enums, interfaces, types. Does anybody have any counter-examples? https://eslint.org/docs/latest/rules/new-cap |
I asked that mainly because for Python, there is So, if it's not even an official standard for JS, I doubt that will work here. But I do agree that it's rare that a PascalCase thing is not a class. |
From my experience, "PascalCase = abstraction/namespace" has comparable level of certainty to "SCREAMING_SNAKE_CASE = constant" in the JavaScript/TypeScript world. |
I agree that it's weird that |
The same discussion was recently on the forum for Python, and I suggested that the PascalCase heuristic could be used to highlight identifiers as class name: https://forum.sublimetext.com/t/incorrect-syntax-with-python-for-none-type-hints/64640/12.
If you use LSP and LSP-typescript, and enable semantic highlighting in the LSP settings, then it should give (almost) similar highlighting as in VSCode, which I think uses the same language server. There are a few limitations compared to VSCode, for example italic font style doesn't work, and you may need to tweak your color scheme (see LSP docs) if you want to achieve certain highlighting colors rather than what's defined as default by LSP - see in the screenshot below that it used different colors based on whether something is a declaration or usage, but in general the token type (function, constant, class) is recognized correctly. |
What happened?
With this code:
I get the following result:
Due to this part:
Packages/JavaScript/JavaScript.sublime-syntax
Lines 2087 to 2089 in e76cf75
I understand that the syntax engine doesn't have any idea what type it is, so it can only guess, but it's weird to see the same identifier have a different color depending on whether there's a dot after it or not. Could the heuristic be adjusted, perhaps? E.g. have CONSTANT_CASE identifiers be always treated as
variable.other.constant.js
, and allCamelCasePascalCase assupport.class.js
?Also, how does VSC handle this?
Can ST do that?
The text was updated successfully, but these errors were encountered: