use alternate language if case-insensitive matches a language in the json files

This commit is contained in:
Alan Hamlett 2017-02-20 12:40:24 -08:00
parent c5531312da
commit fad721530a
4 changed files with 85 additions and 89 deletions

View file

@ -127,16 +127,16 @@ class LanguagesTestCase(utils.TestCase):
with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer: with utils.mock.patch('wakatime.stats.smart_guess_lexer') as mock_guess_lexer:
mock_guess_lexer.return_value = None mock_guess_lexer.return_value = None
language = u('Java')
now = u(int(time.time())) now = u(int(time.time()))
config = 'tests/samples/configs/good_config.cfg' config = 'tests/samples/configs/good_config.cfg'
entity = 'tests/samples/codefiles/python.py' entity = 'tests/samples/codefiles/python.py'
args = ['--file', entity, '--config', config, '--time', now, '--alternate-language', 'Java'] args = ['--file', entity, '--config', config, '--time', now, '--alternate-language', language.upper()]
retval = execute(args) retval = execute(args)
self.assertEquals(retval, 102) self.assertEquals(retval, 102)
language = u('Java')
self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].get('language'), language) self.assertEqual(self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0].get('language'), language)
def test_vim_alternate_language_is_used_when_not_guessed(self): def test_vim_alternate_language_is_used_when_not_guessed(self):

View file

@ -1,80 +1,81 @@
{ {
"ActionScript": "ActionScript", "actionscript": "ActionScript",
"ApacheConf": "ApacheConf", "apacheconf": "ApacheConf",
"AppleScript": "AppleScript", "applescript": "AppleScript",
"ASP": "ASP", "asp": "ASP",
"Assembly": "Assembly", "assembly": "Assembly",
"Awk": "Awk", "awk": "Awk",
"Bash": "Bash", "bash": "Bash",
"Basic": "Basic", "basic": "Basic",
"BrightScript": "BrightScript", "brightscript": "BrightScript",
"C": "C", "c": "C",
"C#": "C#", "c#": "C#",
"C++": "C++", "c++": "C++",
"Clojure": "Clojure", "clojure": "Clojure",
"Cocoa": "Cocoa", "cocoa": "Cocoa",
"CoffeeScript": "CoffeeScript", "coffeescript": "CoffeeScript",
"ColdFusion": "ColdFusion", "coldfusion": "ColdFusion",
"Common Lisp": "Common Lisp", "common lisp": "Common Lisp",
"CSHTML": "CSHTML", "cshtml": "CSHTML",
"CSS": "CSS", "css": "CSS",
"Dart": "Dart", "dart": "Dart",
"Delphi": "Delphi", "delphi": "Delphi",
"Elixir": "Elixir", "elixir": "Elixir",
"Elm": "Elm", "elm": "Elm",
"Emacs Lisp": "Emacs Lisp", "emacs lisp": "Emacs Lisp",
"Erlang": "Erlang", "erlang": "Erlang",
"F#": "F#", "f#": "F#",
"Fortran": "Fortran", "fortran": "Fortran",
"Go": "Go", "go": "Go",
"Gous": "Gosu", "gous": "Gosu",
"Groovy": "Groovy", "groovy": "Groovy",
"Haml": "Haml", "haml": "Haml",
"HaXe": "HaXe", "haskell": "Haskell",
"Haskell": "Haskell", "haxe": "HaXe",
"HTML": "HTML", "html": "HTML",
"INI": "INI", "ini": "INI",
"Jade": "Jade", "jade": "Jade",
"Java": "Java", "java": "Java",
"JavaScript": "JavaScript", "javascript": "JavaScript",
"JSON": "JSON", "json": "JSON",
"JSX": "JSX", "jsx": "JSX",
"Kotlin": "Kotlin", "kotlin": "Kotlin",
"LESS": "LESS", "less": "LESS",
"Lua": "Lua", "lua": "Lua",
"Markdown": "Markdown", "markdown": "Markdown",
"Matlab": "Matlab", "matlab": "Matlab",
"Mustache": "Mustache", "mustache": "Mustache",
"OCaml": "OCaml", "objective-c": "Objective-C",
"Objective-C": "Objective-C", "objective-c++": "Objective-C++",
"Objective-C++": "Objective-C++", "objective-j": "Objective-J",
"Objective-J": "Objective-J", "ocaml": "OCaml",
"Perl": "Perl", "perl": "Perl",
"PHP": "PHP", "php": "PHP",
"PowerShell": "PowerShell", "powershell": "PowerShell",
"Prolog": "Prolog", "prolog": "Prolog",
"Puppet": "Puppet", "puppet": "Puppet",
"Python": "Python", "python": "Python",
"R": "R", "r": "R",
"reStructuredText": "reStructuredText", "restructuredtext": "reStructuredText",
"Ruby": "Ruby", "ruby": "Ruby",
"Rust": "Rust", "rust": "Rust",
"Sass": "Sass", "sass": "Sass",
"Scala": "Scala", "scala": "Scala",
"Scheme": "Scheme", "scheme": "Scheme",
"SCSS": "SCSS", "scss": "SCSS",
"Shell": "Shell", "shell": "Shell",
"Slim": "Slim", "slim": "Slim",
"Smalltalk": "Smalltalk", "smalltalk": "Smalltalk",
"SQL": "SQL", "sql": "SQL",
"Swift": "Swift", "swift": "Swift",
"Text": "Text", "text": "Text",
"Turing": "Turing", "turing": "Turing",
"Twig": "Twig", "twig": "Twig",
"TypeScript": "TypeScript", "typescript": "TypeScript",
"VB.net": "VB.net", "typoscript": "TypoScript",
"VimL": "VimL", "vb.net": "VB.net",
"XAML": "XAML", "viml": "VimL",
"XML": "XML", "xaml": "XAML",
"YAML": "YAML" "xml": "XML",
"yaml": "YAML"
} }

View file

@ -3,7 +3,7 @@
wakatime.main wakatime.main
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
wakatime module entry point. Module entry point.
:copyright: (c) 2013 Alan Hamlett. :copyright: (c) 2013 Alan Hamlett.
:license: BSD, see LICENSE for more details. :license: BSD, see LICENSE for more details.

View file

@ -197,11 +197,8 @@ def standardize_language(language, plugin):
# standardize language against default languages # standardize language against default languages
standardized = get_language_from_json(language, 'default') standardized = get_language_from_json(language, 'default')
if standardized is not None:
return standardized return standardized
return None
def get_language_from_json(language, key): def get_language_from_json(language, key):
"""Finds the given language in a json file.""" """Finds the given language in a json file."""
@ -214,10 +211,8 @@ def get_language_from_json(language, key):
try: try:
with open(file_name, 'r', encoding='utf-8') as fh: with open(file_name, 'r', encoding='utf-8') as fh:
languages = json.loads(fh.read()) languages = json.loads(fh.read())
if language in languages.values(): if languages.get(language.lower()):
return language return languages[language.lower()]
if languages.get(language):
return languages[language]
except: except:
pass pass