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

Source filenames from linguist language.yml #931

Open
1 task done
silverwind opened this issue Feb 19, 2024 · 4 comments
Open
1 task done

Source filenames from linguist language.yml #931

silverwind opened this issue Feb 19, 2024 · 4 comments

Comments

@silverwind
Copy link
Contributor

silverwind commented Feb 19, 2024

Is there an existing issue for this?

  • I have searched the existing issues

What problem does this feature solve?

Chroma's language metadata is somewhat lacking.

What feature do you propose?

Linguist's languages.yml is probably the most up to date data on programming languages filenames on the internet.

I think one solution could be to embed either the whole file or just the relevant parts of it into the module via go:embed during a build process and then use it as the single authorative source for chroma's lexer-from-filename detection.

@alecthomas
Copy link
Owner

Sorry, I have no idea what this issue is asking for?

@alecthomas
Copy link
Owner

Are you suggesting using it for file extension detection, or something else?

I think the issue is that the mapping from Linguist file types to Chroma file types won't be 1:1

@silverwind
Copy link
Contributor Author

silverwind commented Feb 19, 2024

Take for example the json lexer, Chroma only knows 2 filename for it:

<filename>*.json</filename>
<filename>*.avsc</filename>

Linguist knows 17 extensions and 15 filenames:

https://github.com/github-linguist/linguist/blob/559a6426942abcae16b6d6b328147476432bf6cb/lib/linguist/languages.yml#L3159-L3193

This rich data from the linguist file could for example be extracted from the linguist file and written into chroma lexer's .xml and .go files so chroma ends up with much better filename-based language detection in lexers.Match. But overall I think it might be better to just reduce and embed the linguist file in a build script that runs before each release.

Yes, it won't be a 1:1 mapping but the data extraction could be made best-effort where we map linguist name to chroma lexer name.

@silverwind
Copy link
Contributor Author

Not sure how you would feel about an additional dependency, but there is also https://github.com/go-enry/go-enry which offers various ways to detect a language based on filename or content (think bash scripts with no file extension). As far as I know, it is based on a somewhat-regularily updated dataset sourced from linguist. All that's left to do for chroma would be to map the detected language to a lexer.

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

No branches or pull requests

2 participants