Incorrect programming language reported for a config.h.in file
FileName: ./config.h.in
IsSource: True
IsScript: False
ProgLanguage: JavaScript+Lasso
From https://raw.githubusercontent.com/vysheng/tg/master/config.h.in if I upgrade pygments to 2.2.0 the programming language is "Rexx" We need to supplement this with a file name and extension registry: after all config.h.in is kinda well known autotools pattern
This is also closely related to #426
Reported by tglx
This is now reported as "ASCII text" which is quite acceptable given that this is a generated file.
Hey!! @pombredanne I want to help you with this issue. May I know what I should do about that? Give me a chance that I could understand the system and the issue.
@D-lang14 sorry for the late reply. The key issue is that we are putting too much emphasis on using Pygments and libmagic to detect programming langauges. A config.h should ALWAYS be reported as C/C++ So this would consists in:
- study the way we detect and report types in typecode
- in particular check out our we use a registry of extensions
- evolve the way we report programming languages to work first (and only?) from the registry for some cases
Hello @pombredanne I have studied the typecode library thoroughly and made some changes in pygments_lexers_mapping.py in site-packages and I am getting the desired results but it seems Lib\site-packages are git ignored. So where would I make the changes such that after configuring, the package changes would be reflected? I aspire to join AboutCode in GSoC-21.
@pombredanne A slight change in typecode can give the correct results by changing
'CLexer': ('typecode._vendor.pygments.lexers.c_cpp', 'C', ('c',), ('*.c', '*.h', '*.idc'), ('text/x-chdr', 'text/x-csrc')), to
'CLexer': ('typecode._vendor.pygments.lexers.c_cpp', 'C', ('c',), ('*.c', '*.h', '*.idc','config.h.in'), ('text/x-chdr', 'text/x-csrc')),
Hi @pombredanne, I'd like to work on this.
I reproduced it on the current typecode main: for config.h.in, programming_language is ___, while config.h gives C.
From what I can see, get_pygments_lexer in contenttype.py only guesses from the file content when there is no extension. config.h.in has a .in extension and no lexer matches it, so nothing is detected.
Which fix would you prefer?
- Add *.h.in to the C lexer patterns (Rust already has *.rs.in in pygments_lexers_mapping.py), or
- The filename and extension lookup first approach you suggested in 2021?
I'd open the PR in typecode with a test in tests/data/filetest/code/c/. Does that work?
Hi!
I have submitted a pull request addressing this issue in the TypeCode repository.
PR: https://github.com/aboutcode-org/typecode/pull/55
The implementation adds *.h.in to the CLexer filename patterns and includes a regression fixture with data-driven expectations.
I have verified the fix locally and tested the existing C/C++ test suite.
I would appreciate your feedback on whether this focused solution is preferred over the broader filename/extension registry approach discussed earlier.
Thank you!