mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
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:
@@ -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 = []
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user