build_pygments_data: Reprioritize and categorize pygment language codes.

We now organize the pygment language codes into meaningful categories
- default, custom and aliases.

Further the `lang.json` list now contains a dataset extracted from the
"language" section of https://insights.stackoverflow.com/survey/2020
and is prioritized based on current language trends.
This commit is contained in:
Sumanth V Rao 2021-05-14 17:08:14 +05:30 committed by Tim Abbott
parent 98253f261e
commit 83a2479a5a
4 changed files with 56 additions and 67 deletions

View File

@ -253,12 +253,12 @@ test("sort_streams", (override) => {
test("sort_languages", () => {
Object.assign(pygments_data, {
langs: {
python: {priority: 40},
javscript: {priority: 50},
php: {priority: 38},
pascal: {priority: 29},
perl: {priority: 22},
css: {priority: 0},
python: {priority: 26},
javscript: {priority: 27},
php: {priority: 16},
pascal: {priority: 15},
perl: {priority: 3},
css: {priority: 21},
},
});
@ -269,7 +269,7 @@ test("sort_languages", () => {
assert.deepEqual(test_langs, ["python", "php", "pascal", "perl", "javascript"]);
// Test if popularity between two languages are the same
pygments_data.langs.php = {priority: 40};
pygments_data.langs.php = {priority: 26};
test_langs = ["pascal", "perl", "php", "python", "javascript"];
test_langs = th.sort_languages(test_langs, "p");
@ -291,7 +291,7 @@ test("sort_languages", () => {
test_langs = th.sort_languages(test_langs, "java");
assert.deepEqual(test_langs, ["java", "javascript", "js", "j"]);
test_langs = th.sort_languages(test_langs, "j");
assert.deepEqual(test_langs, ["j", "javascript", "java", "js"]);
assert.deepEqual(test_langs, ["j", "javascript", "js", "java"]);
});
function get_typeahead_result(query, current_stream, current_topic) {

View File

@ -5,11 +5,15 @@ import os
from pygments.lexers import get_all_lexers
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
# The current priorities data set is based on StackOverflow's 2020 survey.
DATA_PATH = os.path.join(ZULIP_PATH, "tools", "setup", "lang.json")
OUT_PATH = os.path.join(ZULIP_PATH, "static", "generated", "pygments_data.json")
with open(DATA_PATH) as f:
priorities = json.load(f)
pygments_data = json.load(f)
priorities = dict(
**pygments_data["default"], **pygments_data["custom"], **pygments_data["aliases"]
)
lexers = get_all_lexers()
langs = {

View File

@ -1,59 +1,44 @@
{
"abap": 27,
"ada": 25,
"awk": 1,
"bash": 7,
"c": 49,
"c#": 47,
"c++": 48,
"cobol": 26,
"cpp": 48,
"csharp": 47,
"css": 48,
"d": 29,
"dart": 28,
"delphi": 42,
"erlang": 10,
"fsharp": 19,
"go": 34,
"groovy": 13,
"haskell": 15,
"html": 30,
"java": 50,
"javascript": 51,
"js": 43,
"julia": 4,
"latex": 40,
"lisp": 18,
"lua": 22,
"mask": 2,
"math": 50,
"matlab": 33,
"mql": 9,
"mql4": 9,
"objective-c": 35,
"objectivec": 35,
"objectpascal": 42,
"pascal": 42,
"perl": 40,
"php": 44,
"pl": 40,
"prolog": 16,
"python": 46,
"quote": 50,
"r": 37,
"rb": 39,
"ruby": 39,
"rust": 8,
"sas": 30,
"scala": 21,
"scheme": 14,
"sql": 32,
"spoiler": 50,
"swift": 41,
"tex": 40,
"text": 1,
"vb.net": 45,
"vbnet": 45,
"xml": 1
"default": {
"javascript": 27,
"python": 26,
"java": 25,
"go": 24,
"rust": 23,
"html": 22,
"css": 21,
"sql": 20,
"bash": 19,
"powershell": 18,
"c#": 17,
"php": 16,
"typescript": 15,
"c++": 14,
"c": 13,
"kotlin": 12,
"ruby": 11,
"asm": 10,
"vb.net": 9,
"swift": 8,
"r": 7,
"objective-c": 6,
"dart": 5,
"scala": 4,
"perl": 3,
"haskell": 2,
"julia": 1
},
"custom": {
"latex": 10,
"math": 5,
"quote": 5,
"spoiler": 5
},
"aliases": {
"js": 27,
"csharp": 17,
"cpp": 14,
"tex": 10,
"vbnet": 9
}
}

View File

@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 71
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = "147.1"
PROVISION_VERSION = "148.0"