src-d / enry

A faster file programming language detector
https://blog.sourced.tech/post/enry/
Apache License 2.0
460 stars 51 forks source link

Get color from "parent language" if there is no definition for the language itself #252

Closed alexanderadam closed 4 years ago

alexanderadam commented 4 years ago

I opened this issue because of a corresponding issue in gitea.

Gitea uses enry for the language bar and some colors can't be fetched.

IMHO Linguist uses groups for this and properties are inherited from the parent group. For example Haml inherits from HTML.

So I guess it would help if the color mapping would work similar.

PS: Just some examples to point out what it looks like in gitea:

Screenshot_20200226_140920

Screenshot_20200226_141331

lunny commented 4 years ago

Maybe @mcuadros would like also to move this project to go-git organization?

bzz commented 4 years ago

That would be a simple change to the https://github.com/src-d/enry/blob/697929e1498cbdb7726a4d3bf4c48e706ee8c967/utils.go#L78 if group information would have been stored somewhere in the data generated from .yml

A naive approach to implement that is to add a new internal/code-generator asset that would output a map Language -> Group so the new GetColor impl would do a lookup in there.

Originally, enry did not have a use case for colors, so implementation of the GetColor was done by @lafriks under #233.

lafriks commented 4 years ago

when enry is hard forked to go-enry organization I could probably implement this

bzz commented 4 years ago

JFYI I'm not related to the plans of forking enry to a go-enry org.

Meanwhile I have just pushed a https://pkg.go.dev/github.com/bzz/enry/v2 and will be happy to assist adding this feature, if needed.

bzz commented 4 years ago

This has been implemented by @lafriks and is included in latest https://github.com/go-enry/go-enry/releases/tag/v2.3.0

alexanderadam commented 4 years ago

Awesome, thank you folks!