atom / highlights

Syntax highlighter
https://atom.github.io/highlights
MIT License
530 stars 54 forks source link

Grammar no longer detected based on file name #64

Closed jasonrudolph closed 5 years ago

jasonrudolph commented 5 years ago

Description

highlights used to be able to detect the grammar based on a file suffix, but that ability appears to no longer be available.

Behavior changed in v1.2.1

As far as I can tell, this change in behavior was introduced in v1.2.1.

Using v1.2.0 and earlier, it works as follows:

$ node_modules/.bin/highlights --version
1.2.0

$ echo "puts 42" | node_modules/.bin/highlights --file-path /tmp/foo.rb
<pre class="editor editor-colors"><div class="line"><span class="source ruby"><span class="support function kernel ruby"><span>puts</span></span><span>&nbsp;</span><span class="constant numeric ruby"><span>42</span></span></span></div></pre>

Notice that first span tag has a class of source ruby, determined based on the file suffix (.rb) in the specified file path (/tmp/foo.rb)

Using v1.2.1 or later, it no longer works:

$ node_modules/.bin/highlights --version
1.2.1

$ echo "puts 42" | node_modules/.bin/highlights --file-path /tmp/foo.rb
<pre class="editor editor-colors"><div class="line"><span class="text plain null-grammar"><span>puts&nbsp;42</span></span></div></pre>

Notice that first span tag has a class of text plain null-grammar.

The diff between these v1.2.0 and v1.2.1 is fairly small (https://github.com/atom/highlights/compare/v1.2.0...v1.2.1). Based on my brief investigation so far, I don't think this change was intentional. My hunch is that it's a bug. I'll dig into the commit log to see if I can figure out where exactly the behavior changed and whether it was intentional.

jasonrudolph commented 5 years ago

The diff between these v1.2.0 and v1.2.1 is fairly small (v1.2.0...v1.2.1). Based on my brief investigation so far, I don't think this change was intentional. My hunch is that it's a bug. I'll dig into the commit log to see if I can figure out where exactly the behavior changed and whether it was intentional.

I think I've tracked down the root cause. I believe the issue was introduced in https://github.com/atom/highlights/pull/29, where the logic for selecting a grammar moved out of first-mate and into a new module (first-mate-select-grammar).

So far, I'm thinking that we'll need to make a fix to first-mate-select-grammar. I'm gonna dig into that code and see if I can figure out where to go from here.