Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code formatter #385

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 279 additions & 0 deletions oioioi/contests/fixtures/test_submission_python.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
[
{
"pk": 1,
"model": "contests.submission",
"fields": {
"status": "OK",
"problem_instance": 1,
"kind": "NORMAL",
"comment": "",
"score": "int:0000000000000000034",
"user": 1001,
"date": "2012-06-03T22:07:07.516Z"
}
},
{
"pk": 1,
"model": "contests.submissionreport",
"fields": {
"status": "ACTIVE",
"kind": "INITIAL",
"submission": 1,
"creation_date": "2012-08-03T22:07:29.547Z"
}
},
{
"pk": 2,
"model": "contests.submissionreport",
"fields": {
"status": "ACTIVE",
"kind": "NORMAL",
"submission": 1,
"creation_date": "2012-08-03T22:07:39.662Z"
}
},
{
"pk": 1,
"model": "contests.scorereport",
"fields": {
"status": "OK",
"comment": null,
"score": null,
"submission_report": 1,
"max_score": "int:0000000000000000100"
}
},
{
"pk": 2,
"model": "contests.scorereport",
"fields": {
"status": "RE",
"comment": null,
"score": "int:0000000000000000034",
"submission_report": 2,
"max_score": "int:0000000000000000100"
}
},
{
"pk": 1,
"model": "contests.userresultforproblem",
"fields": {
"status": "OK",
"problem_instance": 1,
"score": "int:0000000000000000034",
"user": 1001,
"submission_report": 2
}
},
{
"pk": 1,
"model": "contests.userresultforround",
"fields": {
"score": "int:0000000000000000034",
"user": 1001,
"round": 1
}
},
{
"pk": 1,
"model": "contests.userresultforcontest",
"fields": {
"score": "int:0000000000000000034",
"user": 1001,
"contest": "c"
}
},
{
"pk": 1,
"model": "programs.programsubmission",
"fields": {
"source_file": "data:submissions/c/1.py:data:submissions/c/2.py:YSwgYiA9IGlucHV0KCkuc3BsaXQoKQoKcHJpbnQoaW50KGEpICsgaW50KGIpKQ==",
"source_length": 46
}
},
{
"pk": 1,
"model": "programs.compilationreport",
"fields": {
"status": "OK",
"compiler_output": "",
"submission_report": 1
}
},
{
"pk": 2,
"model": "programs.compilationreport",
"fields": {
"status": "OK",
"compiler_output": "",
"submission_report": 2
}
},
{
"pk": 1,
"model": "programs.testreport",
"fields": {
"status": "OK",
"comment": "",
"test_time_limit": 10000,
"submission_report": 1,
"time_used": 1,
"test_group": "0",
"score": "int:0000000000000000000",
"test_name": "0",
"test": 1
}
},
{
"pk": 2,
"model": "programs.testreport",
"fields": {
"status": "OK",
"comment": "",
"test_time_limit": 10000,
"submission_report": 1,
"time_used": 1,
"test_group": "1ocen",
"score": "int:0000000000000000000",
"test_name": "1ocen",
"test": 4
}
},
{
"pk": 3,
"model": "programs.testreport",
"fields": {
"status": "OK",
"comment": "",
"test_time_limit": 10000,
"submission_report": 2,
"time_used": 1,
"test_group": "1",
"score": "int:0000000000000000005",
"test_name": "1a",
"test": 2
}
},
{
"pk": 4,
"model": "programs.testreport",
"fields": {
"status": "OK",
"comment": "",
"test_time_limit": 10000,
"submission_report": 2,
"time_used": 1,
"test_group": "3",
"score": "int:0000000000000000034",
"test_name": "3",
"test": 6
}
},
{
"pk": 5,
"model": "programs.testreport",
"fields": {
"status": "WA",
"comment": "",
"test_time_limit": 10000,
"submission_report": 2,
"time_used": 0,
"test_group": "2",
"score": "int:0000000000000000000",
"test_name": "2",
"test": 5
}
},
{
"pk": 6,
"model": "programs.testreport",
"fields": {
"status": "RE",
"comment": "program exited with code 1",
"test_time_limit": 100,
"submission_report": 2,
"time_used": 0,
"test_group": "1",
"score": "int:0000000000000000000",
"test_name": "1b",
"test": 3
}
},
{
"pk": 1,
"model": "programs.groupreport",
"fields": {
"status": "OK",
"group": "0",
"score": "int:0000000000000000000",
"max_score": "int:0000000000000000000",
"submission_report": 1
}
},
{
"pk": 2,
"model": "programs.groupreport",
"fields": {
"status": "OK",
"group": "1ocen",
"score": "int:0000000000000000000",
"max_score": "int:0000000000000000000",
"submission_report": 1
}
},
{
"pk": 3,
"model": "programs.groupreport",
"fields": {
"status": "RE",
"group": "1",
"score": "int:0000000000000000000",
"max_score": "int:0000000000000000033",
"submission_report": 2
}
},
{
"pk": 4,
"model": "programs.groupreport",
"fields": {
"status": "OK",
"group": "0",
"score": "int:0000000000000000000",
"max_score": "int:0000000000000000000",
"submission_report": 2
}
},
{
"pk": 5,
"model": "programs.groupreport",
"fields": {
"status": "OK",
"group": "3",
"score": "int:0000000000000000034",
"max_score": "int:0000000000000000034",
"submission_report": 2
}
},
{
"pk": 6,
"model": "programs.groupreport",
"fields": {
"status": "OK",
"group": "1ocen",
"score": "int:0000000000000000000",
"max_score": "int:0000000000000000000",
"submission_report": 2
}
},
{
"pk": 7,
"model": "programs.groupreport",
"fields": {
"status": "WA",
"group": "2",
"score": "int:0000000000000000000",
"max_score": "int:0000000000000000033",
"submission_report": 2
}
}
]
1 change: 1 addition & 0 deletions oioioi/programs/static/code_formatter/clang-format.js

Large diffs are not rendered by default.

Binary file not shown.
31 changes: 31 additions & 0 deletions oioioi/programs/static/code_formatter/formatter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import init, { format, version } from "./clang-format.js";

// clang-format
async function cpp_code_formatter(source) {
await init();
const formatted = format(
source,
"main.cc",
JSON.stringify({
BasedOnStyle: "Chromium",
IndentWidth: 4,
ColumnLimit: 80,
})
);
return formatted;
}

async function format_cpp_code() {
twalen marked this conversation as resolved.
Show resolved Hide resolved
const source = document.getElementById("raw_source").textContent;
const formatted_source = await cpp_code_formatter(source);
const visible_source = document.getElementById("visible_source");
const coloured_source = Prism.highlight(formatted_source, Prism.languages.cpp, "cpp");
visible_source.innerHTML = coloured_source;

const button = document.getElementById("format_btn");
button.classList.remove("btn-outline-secondary");
button.classList.add("btn-success");
button.textContent = gettext("Formatted!");
}

globalThis.format_cpp_code = format_cpp_code;
2 changes: 2 additions & 0 deletions oioioi/programs/static/code_formatter/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Clang-format WASM build (with source) can be found here: https://github.com/wasm-fmt/clang-format/releases/download/v0.2.8/clang-format.wasm
In order to update just replace the .wasm file.
4 changes: 4 additions & 0 deletions oioioi/programs/static/common/prism.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading