`Analyse()` should return the score as well
Is there an existing issue for this?
- [X] I have searched the existing issues
What problem does this feature solve?
Chroma can classify text by its contents:
lexer := lexers.Analyse("package main\n\nfunc main()\n{\n}\n")
With this API though, it's not possible for me to know if even the best match is bad.
I would like to find that out, so that I can just not highlight if the text contents is uncertain.
What feature do you propose?
One possible suggestion would be to change the API to this...
lexer, certainty := lexers.Analyse("package main\n\nfunc main()\n{\n}\n")
... where certainty is a number on a well defined and documented scale.
Then, if I feel this number is too low, I could choose not to highlight anything.
Seems reasonable, how could we do this in a backwards compatible manner?
Maybe this?
lexer, certainty := lexers.AnalyseScore("package main\n\nfunc main()\n{\n}\n")
Possibly in combination with deprecating the existing function since it's sort of unpredictable.
In what way is it unpredictable?
Not sure if "unpredictable" is the right word, but let's say:
- I get a file
lexers.Analyse()says it's a C program, with 1% confidence
This means that even though C is the "best" guess, it's still a bad guess, and it might be better to not highlight at all.
That's why I'd like to have the confidence number as well to be able to make this judgement.