Pass name of file being analyzed to find_by_heuristics

Some languages are sensitive to file names in the sense that
different kinds of files contain somewhat different data.
Example: GAP .tst files contain test cases, which add some
extra data compared to regular code, and as a consequence are
not directly interchangeable with regular source code.

Heuristics may need to take this into account, thus may need
to know the name of the file being analyzed.
This commit is contained in:
Max Horn
2014-11-10 11:43:30 +01:00
parent 6072a63f99
commit ff6a10698e
2 changed files with 3 additions and 2 deletions

View File

@@ -7,11 +7,12 @@ module Linguist
# apply heuristics against the given data and return an array
# of matching languages, or nil.
#
# name - Name of the file the data is coming from.
# data - Array of tokens or String data to analyze.
# languages - Array of language name Strings to restrict to.
#
# Returns an array of Languages or []
def self.find_by_heuristics(data, languages)
def self.find_by_heuristics(name, data, languages)
if active?
result = []

View File

@@ -120,7 +120,7 @@ module Linguist
if possible_languages.length > 1
data = blob.data
possible_language_names = possible_languages.map(&:name)
heuristic_languages = Heuristics.find_by_heuristics(data, possible_language_names)
heuristic_languages = Heuristics.find_by_heuristics(name, data, possible_language_names)
if heuristic_languages.size > 1
possible_language_names = heuristic_languages.map(&:name)