Skip to content

Feat: Add language specific boilerplate templates to Virtual Lab Code Editor#875

Open
Shubhashish-Chakraborty wants to merge 9 commits intoalphaonelabs:mainfrom
Shubhashish-Chakraborty:feat/codeeditor-boilerplate
Open

Feat: Add language specific boilerplate templates to Virtual Lab Code Editor#875
Shubhashish-Chakraborty wants to merge 9 commits intoalphaonelabs:mainfrom
Shubhashish-Chakraborty:feat/codeeditor-boilerplate

Conversation

@Shubhashish-Chakraborty
Copy link
Contributor

@Shubhashish-Chakraborty Shubhashish-Chakraborty commented Feb 13, 2026

Related issues

Fixes #874

Checklist

  • Did you run the pre-commit? (If not, your PR will most likely not pass — please ensure it passes pre-commit)
  • Did you test the change? (Ensure you didn’t just prompt the AI and blindly commit — test the code and confirm it works)
  • Added screenshots to the PR description (if applicable)

Overview

This PR improves the usability of the Virtual Lab Code Editor by introducing language-specific default boilerplate templates. Currently, the editor loads a Python Hello World snippet initially. When switching to another language, the editor content remains unchanged, which may confuse users.

Changes Made

  • Added default starter templates for Python, JavaScript, C, and C++
  • Editor now updates content when the language selection changes

Benefit

This improves beginner experience and prevents syntax mismatch between selected language and displayed code.
Overall it enhances UX.

Do watch the ScreenRecording and see the implementation in action:

codeeditorFix.mp4

I would appreciate any feedback or suggested improvements..
Thanks!

Summary by CodeRabbit

  • New Features

    • Added boilerplate templates for Python, JavaScript, C, and C++
    • Editor automatically switches language mode when a language is selected
    • Prompts to replace current code when changing languages
    • Initializes the editor with Python boilerplate on load
  • Style

    • Refined language selector layout and styling
    • Rounded editor corners and improved editor container appearance

@github-actions github-actions bot added the files-changed: 2 PR changes 2 files label Feb 13, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds language-specific boilerplates (Python, JavaScript, C, C++), updates Ace editor mode on language selection, injects selected boilerplate into the editor (with replace confirmation), persists last-selected language, and updates editor/select styling in the template.

Changes

Cohort / File(s) Summary
Editor logic
web/virtual_lab/static/virtual_lab/js/code_editor.js
Added BOILERPLATES for Python/JS/C/C++; implemented updateEditorMode(language) to set Ace mode; setBoilerplate(language) to populate editor; language selector change handler prompts to replace current code, switches mode, applies boilerplate, and stores last language; initializes Python by default on load.
Template & UI
web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html
Updated editor container styling and classes (border, rounded, dark mode); replaced inline initial editor content with empty editor div; reworked language selector layout and select styling; minor UI/layout adjustments for input area.

Sequence Diagram(s)

sequenceDiagram
  participant User as User/UI
  participant Editor as Ace Editor
  participant Storage as LocalStorage

  User->>User: change language in selector
  User->>Editor: show "replace current code?" prompt
  alt User confirms
    User->>Editor: call updateEditorMode(language)
    Editor->>Editor: editor.session.setMode(...) (ace mode)
    User->>Editor: call setBoilerplate(language)
    Editor->>Editor: replace content with BOILERPLATES[language], focus, clear selection
    Editor->>Storage: store last-selected language
  else User cancels
    Editor->>Storage: store last-selected language
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Python Editor #649 — Modifies the same code_editor module and template; prior work adding Ace editor initialization and run/evaluate flow.

Suggested reviewers

  • A1L13N
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding language-specific boilerplate templates to the Virtual Lab Code Editor, which directly addresses the PR's primary objective.
Linked Issues check ✅ Passed The code changes fully implement the requirements from issue #874: boilerplate templates for Python, JavaScript, C, and C++ are added, language switching triggers editor content updates, and editor mode changes per language selection.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing language-specific boilerplate functionality. CSS updates to the editor and language selector styling support the new feature and are within scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html (3)

12-29: ⚠️ Potential issue | 🟡 Minor

Custom CSS classes and inline styles violate coding guidelines.

Several issues here:

  1. .language-info (Lines 20-24) is a custom CSS class that is never used in the template — dead code.
  2. select { background-color: white; } (Lines 26-28) is a custom CSS rule; use Tailwind's bg-white on the <select> element instead.
  3. #editor styles (Lines 13-18) use raw CSS properties (border, border-radius) — prefer Tailwind classes like border border-gray-300 rounded on the element.

The height: 400px for #editor is acceptable since Ace needs a fixed height, but the rest should be Tailwind classes.

As per coding guidelines, **/*.{html,htm,css}: "Never use custom CSS classes".

Proposed fix
  <style>
      `#editor` {
          height: 400px;
          width: 100%;
-         border: 1px solid `#ccc`;
-         border-radius: 4px;
      }
-
-     .language-info {
-         color: `#666`;
-         font-size: 0.9em;
-         margin-top: 4px;
-     }
-
-     select {
-         background-color: white;
-     }
  </style>

Then on the editor div:

-    <div id="editor"></div>
+    <div id="editor" class="border border-gray-300 dark:border-gray-600 rounded w-full"></div>

And on the select element, add bg-white:

-        <select id="language-select" class="border px-2 py-1 rounded">
+        <select id="language-select" class="border px-2 py-1 rounded bg-white dark:bg-gray-700 dark:text-gray-300">

49-55: ⚠️ Potential issue | 🟡 Minor

Custom Input label and textarea missing dark mode support.

The label (Line 50) and textarea (Lines 51-54) have no dark mode classes. The label should follow the guideline pattern, and the textarea needs dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600.

As per coding guidelines, "Always include dark mode alternatives using dark: prefix for elements".

Proposed fix
-      <label for="stdin-input" class="block mb-1">Custom Input:</label>
+      <label for="stdin-input" class="block mb-1 text-sm font-medium text-gray-700 dark:text-gray-300">Custom Input:</label>
       <textarea id="stdin-input"
                 rows="4"
-                class="w-full border rounded p-2 font-mono"
+                class="w-full border border-gray-300 dark:border-gray-600 rounded p-2 font-mono bg-white dark:bg-gray-700 dark:text-gray-300"
                 placeholder="Enter input here…"></textarea>

70-73: ⚠️ Potential issue | 🟡 Minor

Remove console.log before merging.

Line 72 has a debug log statement (console.log('▶️ Piston endpoint:', ...)) that should not ship to production.

Proposed fix
  <script>
      window.EVALUATE_CODE_URL = "{% url 'virtual_lab:evaluate_code' %}";
-     console.log('▶️ Piston endpoint:', window.EVALUATE_CODE_URL);
  </script>
🤖 Fix all issues with AI agents
In `@web/virtual_lab/static/virtual_lab/js/code_editor.js`:
- Around line 61-65: The setBoilerplate function currently falls back to
BOILERPLATES.python for unknown languages, causing a mode/code mismatch; update
setBoilerplate to use an empty string fallback instead of BOILERPLATES.python by
changing the value passed to editor.setValue to BOILERPLATES[language] || ''
(referencing setBoilerplate, editor.setValue and BOILERPLATES) so unknown
languages leave the editor empty rather than loading Python boilerplate.
- Around line 67-76: The language-change handler (langSel change listener)
currently calls updateEditorMode(language) and unconditionally
setBoilerplate(language), discarding user code and writing dataset.lastValue
which is never read; change the handler in code_editor.js to first detect
whether the editor content differs from the current boilerplate (or a dirty
flag), and if it does, show a confirmation prompt to the user before calling
setBoilerplate(language); only overwrite when the user confirms or when the
content already matches the existing boilerplate; remove the dead assignment to
e.target.dataset.lastValue (or alternatively use it to track previous selection
consistently) and ensure updateEditorMode(language) still runs regardless of the
user’s confirm decision.

In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html`:
- Around line 58-59: The Run Code button (id="run-btn") uses the wrong Tailwind
classes (bg-blue-600 hover:bg-blue-700); update its class list to match the
project's primary button style by replacing those classes with "bg-teal-300
hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition duration-200" so
the element with id run-btn follows the established design system and includes
the transition and spacing changes.
- Around line 64-65: The <pre id="output"> element uses only bg-gray-100 and
needs dark-mode counterparts: update the class list on the pre with dark:
variants (for example add dark:bg-gray-800 and dark:text-gray-100) and ensure
other utilities (e.g., dark:whitespace-pre-wrap if needed) follow the project's
dark-mode conventions so the output block displays correctly in dark theme;
locate the <pre id="output"> element and modify its class attribute accordingly.
- Around line 37-47: The label and select for the language dropdown lack the
required styling and dark-mode classes; update the <label for="language-select">
element to include the class "block text-sm font-medium text-gray-700
dark:text-gray-300" and update the <select id="language-select"> element to
include the prescribed form input classes (include standard border, px-2 py-1
rounded plus dark-mode variants such as dark:bg-gray-700 dark:border-gray-600
dark:text-gray-200) so the select matches the project's form-input styling and
supports dark mode.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html (2)

49-55: ⚠️ Potential issue | 🟡 Minor

Stdin label and textarea missing dark mode and guideline-mandated classes.

The <label> on Line 50 should use text-sm font-medium text-gray-700 dark:text-gray-300. The <textarea> on Lines 51-54 is missing dark mode variants.

Proposed fix
-      <label for="stdin-input" class="block mb-1">Custom Input:</label>
+      <label for="stdin-input" class="block mb-1 text-sm font-medium text-gray-700 dark:text-gray-300">Custom Input:</label>
       <textarea id="stdin-input"
                 rows="4"
-                class="w-full border rounded p-2 font-mono"
+                class="w-full border border-gray-300 dark:border-gray-600 rounded p-2 font-mono bg-white dark:bg-gray-700 dark:text-gray-300"
                 placeholder="Enter input here…"></textarea>

As per coding guidelines: form labels should use "block text-sm font-medium text-gray-700 dark:text-gray-300" and all elements must include dark mode alternatives.


70-73: ⚠️ Potential issue | 🟡 Minor

Remove debug console.log before merging.

Line 72 logs the Piston endpoint on every page load. This is a debug artifact that should be removed.

Proposed fix
   <script>
       window.EVALUATE_CODE_URL = "{% url 'virtual_lab:evaluate_code' %}";
-      console.log('▶️ Piston endpoint:', window.EVALUATE_CODE_URL);
   </script>
🤖 Fix all issues with AI agents
In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html`:
- Around line 20-28: Remove the unused .language-info CSS and the global select
rule; keep the `#editor` block (Ace needs fixed height) but move any visual border
styles out of the stylesheet and onto the DOM via Tailwind classes on the
element that has id="editor" (add classes like border, rounded, border-gray-200
or similar) so no custom CSS classes or global element overrides remain.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html (2)

38-44: ⚠️ Potential issue | 🟡 Minor

Label and textarea missing guideline-mandated classes and dark mode variants.

The <label> on Line 39 should use block text-sm font-medium text-gray-700 dark:text-gray-300 per guidelines. The <textarea> on Line 42 is missing dark mode variants (dark:bg-gray-700 dark:border-gray-600 dark:text-gray-300) and the full form-input border class (border-gray-300).

Proposed fix
-      <label for="stdin-input" class="block mb-1">Custom Input:</label>
+      <label for="stdin-input" class="block mb-1 text-sm font-medium text-gray-700 dark:text-gray-300">Custom Input:</label>
       <textarea id="stdin-input"
                 rows="4"
-                class="w-full border rounded p-2 font-mono"
+                class="w-full border border-gray-300 dark:border-gray-600 rounded p-2 font-mono bg-white dark:bg-gray-700 dark:text-gray-300"
                 placeholder="Enter input here…"></textarea>

As per coding guidelines, form labels should use "block text-sm font-medium text-gray-700 dark:text-gray-300" and all elements must "Always include dark mode alternatives using dark: prefix".


61-61: ⚠️ Potential issue | 🟡 Minor

Remove debug console.log before merging.

This console.log('▶️ Piston endpoint:', ...) looks like a development-only diagnostic and shouldn't ship to production.

Proposed fix
   <script>
       window.EVALUATE_CODE_URL = "{% url 'virtual_lab:evaluate_code' %}";
-      console.log('▶️ Piston endpoint:', window.EVALUATE_CODE_URL);
   </script>

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 13, 2026
@Shubhashish-Chakraborty
Copy link
Contributor Author

finalCOdeEditor.mp4

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html (2)

65-68: ⚠️ Potential issue | 🟡 Minor

Run button still uses bg-blue-600 instead of the project's primary teal color.

This was flagged in a previous review but remains unaddressed.

🛠️ Proposed fix
-      <button id="run-btn"
-              class="px-4 py-2 bg-blue-600 dark:bg-blue-700 text-white rounded hover:bg-blue-700 dark:hover:bg-blue-800">
+      <button id="run-btn"
+              class="px-6 py-2 bg-teal-300 hover:bg-teal-400 text-white rounded-lg transition duration-200">

As per coding guidelines: "Use Tailwind primary button classes: bg-teal-300 hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition duration-200".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html` around
lines 65 - 68, The Run Code button with id "run-btn" is using the old blue
classes; update its class attribute on the <button id="run-btn"> element to use
the project's primary teal button classes: replace "px-4 py-2 bg-blue-600
dark:bg-blue-700 text-white rounded hover:bg-blue-700 dark:hover:bg-blue-800"
with "bg-teal-300 hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition
duration-200" so it matches the coding guidelines for primary buttons.

44-54: ⚠️ Potential issue | 🟡 Minor

Label missing block from the prescribed Tailwind label class.

The current label class is text-sm font-medium text-gray-700 dark:text-gray-300 but the guideline requires the block modifier as the first token.

🛠️ Proposed fix
-        <label for="language-select" class="text-sm font-medium text-gray-700 dark:text-gray-300">Language:</label>
+        <label for="language-select" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Language:</label>

As per coding guidelines: "Use Tailwind form label classes: block text-sm font-medium text-gray-700 dark:text-gray-300 for form labels".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html` around
lines 44 - 54, The label element for the language selector (label with
for="language-select") is missing the required Tailwind "block" token; update
its class string to start with "block" so it becomes "block text-sm font-medium
text-gray-700 dark:text-gray-300" to conform to the form label guideline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html`:
- Around line 13-19: The `#editor` CSS block is adding raw styles that conflict
with Tailwind on the <div id="editor">; remove border-radius, border, and
background-color from the `#editor` CSS and instead apply the equivalent Tailwind
classes on the element (add rounded, appropriate border classes that handle dark
mode like border-gray-300 dark:border-gray-700, and bg-gray-100) to the <div
id="editor"> (the element referenced on Line 42) so all visual styling is done
via Tailwind and the duplicate/unused CSS rules are deleted.

---

Duplicate comments:
In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html`:
- Around line 65-68: The Run Code button with id "run-btn" is using the old blue
classes; update its class attribute on the <button id="run-btn"> element to use
the project's primary teal button classes: replace "px-4 py-2 bg-blue-600
dark:bg-blue-700 text-white rounded hover:bg-blue-700 dark:hover:bg-blue-800"
with "bg-teal-300 hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition
duration-200" so it matches the coding guidelines for primary buttons.
- Around line 44-54: The label element for the language selector (label with
for="language-select") is missing the required Tailwind "block" token; update
its class string to start with "block" so it becomes "block text-sm font-medium
text-gray-700 dark:text-gray-300" to conform to the form label guideline.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 32bb637 and cbd95fd.

📒 Files selected for processing (1)
  • web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html (1)

65-68: ⚠️ Potential issue | 🟡 Minor

Run button still uses bg-blue-600 — not addressed from the previous review cycle.

This deviates from the project's primary button color (bg-teal-300 hover:bg-teal-400) and was flagged in an earlier review that was not resolved.

As per coding guidelines, primary buttons should use: bg-teal-300 hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition duration-200.

🛠️ Proposed fix
-      <button id="run-btn"
-              class="px-4 py-2 bg-blue-600 dark:bg-blue-700 text-white rounded hover:bg-blue-700 dark:hover:bg-blue-800">
+      <button id="run-btn"
+              class="px-6 py-2 bg-teal-300 hover:bg-teal-400 text-white rounded-lg transition duration-200">
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html` around
lines 65 - 68, The Run button (id "run-btn") still uses the old blue classes;
update its class attribute to match the project's primary button style by
replacing "bg-blue-600 dark:bg-blue-700 text-white rounded hover:bg-blue-700
dark:hover:bg-blue-800" with the specified primary classes "bg-teal-300
hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition duration-200" so
the element with id="run-btn" follows the design guideline.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html`:
- Around line 46-47: The <select id="language-select"> element lacks the
required keyboard focus ring classes; update its class attribute (on the element
with id "language-select") to include the prescribed focus styles (e.g., add
focus:ring-2 and focus:ring-blue-500) alongside the existing
border/spacing/theme classes so the control shows a visible focus indicator for
keyboard users.

---

Duplicate comments:
In `@web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html`:
- Around line 65-68: The Run button (id "run-btn") still uses the old blue
classes; update its class attribute to match the project's primary button style
by replacing "bg-blue-600 dark:bg-blue-700 text-white rounded hover:bg-blue-700
dark:hover:bg-blue-800" with the specified primary classes "bg-teal-300
hover:bg-teal-400 text-white px-6 py-2 rounded-lg transition duration-200" so
the element with id="run-btn" follows the design guideline.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbd95fd and 6ffc567.

📒 Files selected for processing (1)
  • web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 2 PR changes 2 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language specific default boilerplate not updating when switching languages in /virtual_lab/code-editor/

1 participant