-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Handle file extension conflicts in --list-languages #1135
Conversation
src/syntax_mapping.rs
Outdated
@@ -24,6 +24,12 @@ impl<'a> SyntaxMapping<'a> { | |||
let mut mapping = Self::empty(); | |||
mapping.insert("*.h", MappingTarget::MapTo("C++")).unwrap(); | |||
mapping.insert("*.fs", MappingTarget::MapTo("F#")).unwrap(); | |||
mapping | |||
.insert("*.js", MappingTarget::MapTo("JavaScript (Babel)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, we should be able to implement this feature without adding theses new syntax mappings. Instead of just querying the syntax_mapping, we would need to run the full syntax detection on the test.xx
filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, I was just following the similar commits before and thought it would do 😅, should I revert it?
Also I doesn't quite understand what is the "full syntax detection" means, could you please do a little explanation for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please revert this.
By "full syntax detection", I mean: determine the syntax in the same way that bat
usually does this for a normal file. This involves not just checking the syntax mapping, but also the full database of syntaxes. See src/assets.rs
=> HighlightingAssets::get_syntax
.
src/bin/bat/main.rs
Outdated
let test_file = Path::new("test").with_extension(extension); | ||
match config.syntax_mapping.get_syntax_for(test_file) { | ||
Some(MappingTarget::MapTo(primary_lang)) => lang_name == primary_lang, | ||
Some(MappingTarget::MapToUnknown) => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, it should be false
.
Thank you very much for your contribution! Could you please add an entry to the "unreleased" section in
where |
I think we can leave this for now. The fact that the list contains |
src/syntax_mapping.rs
Outdated
@@ -24,6 +24,12 @@ impl<'a> SyntaxMapping<'a> { | |||
let mut mapping = Self::empty(); | |||
mapping.insert("*.h", MappingTarget::MapTo("C++")).unwrap(); | |||
mapping.insert("*.fs", MappingTarget::MapTo("F#")).unwrap(); | |||
mapping | |||
.insert("*.js", MappingTarget::MapTo("JavaScript (Babel)")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please revert this.
By "full syntax detection", I mean: determine the syntax in the same way that bat
usually does this for a normal file. This involves not just checking the syntax mapping, but also the full database of syntaxes. See src/assets.rs
=> HighlightingAssets::get_syntax
.
Thank you very much for the updates. How does the diff for |
This is the new diff for the new 13c13
< C:c,h
---
> C:c
49c49
< GLSL:vs,fs,gs,vsh,fsh,gsh,vshader,fshader,gshader,vert,frag,geom,tesc,tese,comp,glsl
---
> GLSL:vs,gs,vsh,fsh,gsh,vshader,fshader,gshader,vert,frag,geom,tesc,tese,comp,glsl
70c70
< JavaScript:js,htc
---
> JavaScript:htc
92,93c92,93
< Objective-C:m,h
< Objective-C++:mm,M,h
---
> Objective-C:m
> Objective-C++:mm,M
119c119
< Ruby Haml:haml,sass
---
> Ruby Haml:haml |
Thank you very much! |
Fix #1076.
Now the each outputted extension should be unique to only one language. Below is the diff output of the old
bat --list-languages
and newbat --list-languages
.But since #1035, some of the output is appearing in the form
Lang ext, *.ext
.For instance in the C++ entry of
bat --list-languages
, containing bothh
and*.h
:and likewise
Should this be the desired behavior? @sharkdp