question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Highlight identifier after 'impl' keyword in Rust language definition

See original GitHub issue

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch highlight.js@9.18.3 for the project I’m working on.

It looks as if the identifier after the impl keyword is not being highlighted. I’ve added an extra element to the class definition to include impl.

Here is the diff that solved my problem:

diff --git a/node_modules/highlight.js/lib/languages/rust.js b/node_modules/highlight.js/lib/languages/rust.js
index 5e2af44..590dc15 100644
--- a/node_modules/highlight.js/lib/languages/rust.js
+++ b/node_modules/highlight.js/lib/languages/rust.js
@@ -89,7 +89,7 @@ module.exports = function(hljs) {
       },
       {
         className: 'class',
-        beginKeywords: 'trait enum struct union', end: '{',
+        beginKeywords: 'trait enum struct union impl', end: '{',
         contains: [
           hljs.inherit(hljs.UNDERSCORE_TITLE_MODE, {endsParent: true})
         ],

This issue body was partially generated by patch-package.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RunDevelopmentcommented, Apr 6, 2021

Isn’t for just a keyword in all cases?

Yes, it is. Sorry for being clear here. I meant that it would strange that in impl Trait for Foo {} only Trait would be highlighted as a class name even though Foo obviously is one as well.

0reactions
joshgoebelcommented, Apr 7, 2021

I’ve made a lot of other changes a cleanups in the simpler struct PR: https://github.com/highlightjs/highlight.js/pull/3078/commits/9d6befcd93ac334b62502c86efb5214f8eaa1eac

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic Data Types - The Rust Programming Language
We use generics to create definitions for items like function signatures or structs, which we can then use with many different concrete data...
Read more >
Syntax Highlighting Improvements · Issue #284 - GitHub
I've done a survey of syntax issues of some things I think can be highlighted better. Syntax highlighting can be subjective so it's...
Read more >
Rust Language Cheat Sheet
Define a method, e.g., within an impl S {} . struct S ​ (T);, More arcanely, also ...
Read more >
2457-non-ascii-idents - The Rust RFC Book
in Rust identifiers. Motivation. Writing code using domain-specific terminology simplifies implementation and discussion as opposed to translating words from ...
Read more >
Rust - Nova Extensions - Panic Inc.
Rust language support for Nova featuring Rust Analyzer, ... Right click an identifier and select Jump to Definition from the menu to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found