From ff6a10698ea5026f92285673c9761311a2d4c449 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 10 Nov 2014 11:43:30 +0100 Subject: [PATCH] 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. --- lib/linguist/heuristics.rb | 3 ++- lib/linguist/language.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linguist/heuristics.rb b/lib/linguist/heuristics.rb index 13f0173f..53bb10a9 100644 --- a/lib/linguist/heuristics.rb +++ b/lib/linguist/heuristics.rb @@ -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 = [] diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index f4c7a62e..444c925c 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -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)