Autocomplete and evaluate solutions on the solve page
Test and publish the site / test (push) Successful in 1m25s
Test and publish the site / publish (push) Successful in 1m51s

The editor's completion popup was on but empty for C++, since
@codemirror/lang-cpp has no completion source. web/src/completions.js
adds one: keywords, the STL, every name in the file (the template's
macros show their expansion, typedefs what they alias), members after
. and ->, and snippets for the loops and lambdas typed over and over.
Python gains the contest standard library and members after ., on top
of lang-python's builtins and local names. Nothing knows types, so
members are the common ones plus those already used in the file.

Evaluate (POST/GET /problems/<name>/evaluate) has Claude judge the
editor's code as a strong competitive programmer would before
submitting. It runs the saved tests on the runner first, as Submit
does, and gives Claude the verdicts and up to three failing cases. The
reply is a verdict, correctness, complexity against the constraints,
line-anchored issues and a traced counterexample (internal/evaluate).
The page shows it in an Evaluation tab of the results panel, marks the
issues in the editor beside the lint's for as long as their lines are
unchanged, and can load the counterexample as the custom input.

It is a background job the page polls, like explanations, but it
commits nothing: the code is a draft. explain.Jobs.StartWith keeps a
finished job's answer in memory until the next one or a restart.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-20 12:46:54 +01:00
co-authored by Claude Opus 5.5
parent 34552f2d81
commit d4849859df
18 changed files with 1566 additions and 36 deletions
+25 -4
View File
@@ -14,6 +14,9 @@
* is remote and debounced by the page), and are pushed with setDiagnostics
* rather than through a linter() source the editor would schedule itself.
* CodeMirror maps them through later edits until the next set arrives.
*
* Completions come from basicSetup's autocompletion with sources of our own
* (completions.js), since lang-cpp has none.
*/
import { onBeforeUnmount, onMounted, ref, watch } from "vue";
import { basicSetup } from "codemirror";
@@ -25,6 +28,7 @@ import { lintGutter, setDiagnostics } from "@codemirror/lint";
import { cpp } from "@codemirror/lang-cpp";
import { python } from "@codemirror/lang-python";
import { tags as t } from "@lezer/highlight";
import { cppCompletions, pythonCompletions } from "@/completions";
const props = defineProps({
modelValue: { type: String, required: true },
@@ -37,9 +41,9 @@ const emit = defineEmits(["update:modelValue", "run", "submit", "save"]);
// The workspace's styles: clang-format's two spaces for C++, PEP 8's four.
const LANGS = {
cpp: () => [cpp(), indentUnit.of(" ")],
c: () => [cpp(), indentUnit.of(" ")],
python: () => [python(), indentUnit.of(" ")],
cpp: () => [cpp(), cppCompletions(), indentUnit.of(" ")],
c: () => [cpp(), cppCompletions(), indentUnit.of(" ")],
python: () => [python(), pythonCompletions(), indentUnit.of(" ")],
};
const highlight = HighlightStyle.define([
@@ -95,6 +99,14 @@ const theme = EditorView.theme(
".cm-diagnostic-info": { borderLeftColor: "var(--color-ink-faint)" },
".cm-diagnosticSource": { color: "var(--color-ink-muted)" },
".cm-panels": { backgroundColor: "var(--color-paper-tint)", color: "var(--color-ink)" },
".cm-tooltip.cm-tooltip-autocomplete > ul": { fontFamily: "var(--font-mono)", fontSize: "0.8rem", maxHeight: "16em" },
".cm-tooltip.cm-tooltip-autocomplete > ul > li": { padding: "1px 8px 1px 4px" },
".cm-tooltip-autocomplete ul li[aria-selected]": { backgroundColor: "#d7e6fb", color: "var(--color-ink)" },
".cm-completionMatchedText": { textDecoration: "none", fontWeight: "600" },
".cm-completionDetail": { color: "var(--color-ink-muted)", fontStyle: "normal", marginLeft: "1em" },
".cm-completionIcon": { opacity: "0.55" },
".cm-tooltip.cm-completionInfo": { fontFamily: "var(--font-mono)", fontSize: "0.8rem", padding: "4px 8px" },
".cm-snippetField": { backgroundColor: "rgba(0, 0, 0, 0.05)" },
},
{ dark: false },
);
@@ -186,7 +198,16 @@ watch(
);
watch(() => props.diagnostics, () => view && pushDiagnostics());
defineExpose({ focus: () => view?.focus() });
// Puts the cursor at the start of a line's code and shows it.
function goto(line) {
if (!view) return;
const l = view.state.doc.line(Math.min(Math.max(line, 1), view.state.doc.lines));
const at = l.from + (/^\s*/.exec(l.text)?.[0].length || 0);
view.dispatch({ selection: { anchor: at }, effects: EditorView.scrollIntoView(at, { y: "center" }) });
view.focus();
}
defineExpose({ focus: () => view?.focus(), goto });
</script>
<template>