highlight.js
highlight.js copied to clipboard
(Typescript) highlight obvious user defined type names (`interface`, etc)
See this example:
as you can see in boudingRect params the
Rect
type has not been highlighted. also interface name.
I think these one should be highlighted
This is because we are not a full TypeScript parser (nor do we desire to be), we're more of a "fancy pattern matcher". As such it's impossible to know that Rect[]
there is a type... For some languages we can examine the immediate context but in this case that is also insufficient. :
is used in many places in JS and )
isn't helpful.
Note: The []
in this case is strange, but even if that were a strong signal that would only allow us to detect Blah[]
types, not all types in general, and therefore it'd be even more confusing - vs now where we highlight the "standard" types always, and simply do not highlight user types.
I'd love to see someone attempt a plugin/grammar pairing that hooked up an entirely different parser - with our HTML generation. https://github.com/codemirror/lang-javascript would be a good choice I think. If you're interested in a project like that, let us know.
Rules could be added for the simpler cases such as interface [type]
... this would be a perfect use for our new multi-class matcher support... but that doesn't help with params or types in other contexts.
Rules could be added for the simpler cases such as interface [type]...
Tagging as "good first issue" as these simple cases shouldn't be too hard and there are examples from other modern grammars, like Wren.
Also worth exploring if this could somehow just be handled by a general CamelCaseIsAClass rule...
@joshgoebel I can pick this up, but will need some guidance as to which existing examples/files I can refer to and how I should approach this
I dunno about samples. I think start might be just a CamelCaseIsAClass
as mentioned above which we already have examples of in Ruby and JS I think?
I have a possible solution that I can link -- I noticed the CamelCaseAsAClass
behavior and attempted to fix it based on looking for any titles following "interface." Right now, I only have an implementation for interfaces, but if everything looks good I can implement this for other instances of user-defined types or variables
Hi @joshgoebel, I want to fix this issue and I have a suggested solution to this issue this is the result I have reached now. I want to know what I should do else edit the typescript file and update the markup tests to make a valid solution.
Thanks in advance,
I have a suggested solution
What is your suggested solution? Just make a PR with your changes and we'll have a look.
update the markup tests to make a valid solution.
You can edit the existing tests or add new ones... if you look at the markup test js file itself you can uncomment a line to have it write the expectations for you, but you should still read the result to make sure it's correct... the developer tool in debug mode is also super helpful for this kind of thing.