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

lexers.DelegatingLexer always does not highlight tokens correctly #960

Closed
1 task done
Delta456 opened this issue Apr 15, 2024 · 5 comments
Closed
1 task done

lexers.DelegatingLexer always does not highlight tokens correctly #960

Delta456 opened this issue Apr 15, 2024 · 5 comments
Labels

Comments

@Delta456
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am currently working on a feature for charmbracelet/freeze which makes use of the chroma library and I am using the DelegatingLexer where I am passing two languages py and go as the language and root respectively. My PR implementation can be seen here: charmbracelet/freeze#79

Using

  • ./freeze --language py,go file.py gives
    image

  • ./freeze --language go,py file.py gives
    image

As it can be seen chroma doesn't highlight the root of the lexers.DelegatingLexer. Only the language part is highlighted. However, this is not always the case.

  • ./freeze --language jinja,html file.jinja gives

image

  • ./freeze --language jinja file.jinja gives

image

In this case, jinja,html languages correctly highlight the code snippet.

To Reproduce

Chroma Playground doesn't support syntax highlighting of two languages at one time.

To locally reproduce this:

Contents of file.py:

def hello():
    print('hello world')

func Hello() {
    fmt.Println("Hello world")
} 
@Delta456 Delta456 added the bug label Apr 15, 2024
@isabelroses
Copy link

Also noticing the issue, particularly with PHP and html, with any any combination of PHP or html being the root.

@alecthomas
Copy link
Owner

@Delta456 the delegating lexer is working as intended. If you read the documentation it describes how it works, in that the root lexer must return a token type of Other. Neither Go or Python are designed for this, and I'm not sure how that would even work.

@alecthomas
Copy link
Owner

@isabelroses if you find a bug please file an issue. There are tests for the delegating lexer, and the "phtml" lexer uses it directly and nobody has filed any bugs for a few years, but anything's possible.

@alecthomas alecthomas closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
@Delta456
Copy link
Author

@Delta456 the delegating lexer is working as intended. If you read the documentation it describes how it works, in that the root lexer must return a token type of Other. Neither Go or Python are designed for this, and I'm not sure how that would even work.

That's true indeed. Can you add an explicit list of supported explicit languages for DelegatingLexer?

@alecthomas
Copy link
Owner

No, but if you wish to send a PR with an update to the README I'd consider it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants