Fixes the virtual lab code editor to support all 4 available programming languages instead of just Python.#932
Fixes the virtual lab code editor to support all 4 available programming languages instead of just Python.#932Ananya44444 wants to merge 7 commits intoalphaonelabs:mainfrom
Conversation
WalkthroughAdds a language configuration map and UI-driven mode switching to the Ace-based editor, sample "Hello, World!" snippets per language, unsaved-change detection with discard confirmation, wrap/font options, and removes hardcoded initial editor content from the template. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This pull request fixes the code editor to support all 4 available programming languages (Python, JavaScript, C, C++) by implementing dynamic language switching functionality. Previously, only Python was functional despite the dropdown showing all 4 language options.
Changes:
- Added language configuration object mapping each language to its Ace Editor mode and sample Hello World code
- Implemented dynamic editor mode switching when users select a different language from the dropdown
- Removed hardcoded Python sample code from HTML template in favor of JavaScript initialization
- Enhanced editor options with text wrapping and autocomplete features
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| web/virtual_lab/templates/virtual_lab/code_editor/code_editor.html | Removed hardcoded Python sample code from editor div to allow JavaScript initialization |
| web/virtual_lab/static/virtual_lab/js/code_editor.js | Added language configuration, language selector event handler, and dynamic mode switching functionality |
Comments suppressed due to low confidence (1)
web/virtual_lab/static/virtual_lab/js/code_editor.js:38
- The enableBasicAutocompletion and enableLiveAutocompletion options require the Ace Editor language tools extension to be loaded. Currently, only the base ace.js is loaded from the CDN (line 11 in code_editor.html). These options will have no effect without loading the ext-language_tools.js extension. Either remove these options or add the required script tag.
enableBasicAutocompletion: true,
enableLiveAutocompletion: true
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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/static/virtual_lab/js/code_editor.js`:
- Line 51: The inline comment on editor.setValue(config.sample, -1) is wrong:
update the comment to correctly state that -1 moves the cursor to the start and
1 moves it to the end; if the intent was to place the cursor at the end, change
the second argument from -1 to 1 and update the comment accordingly (locate the
call to editor.setValue and the config.sample usage to make the fix).
- Line 32: Remove the redundant explicit mode set by deleting the
editor.session.setMode("ace/mode/python") call; rely on the existing
updateEditorLanguage("python") function to set the Ace mode centrally (ensure
updateEditorLanguage and any callers remain responsible for setting
editor.session.setMode to avoid duplicate calls).
- Around line 56-59: The language selector's change handler calls
updateEditorLanguage blindly, which overwrites user code; modify the
langSel.addEventListener callback to first check the current editor state (e.g.,
editor.getValue() or a tracked "isModified" flag) and only call
updateEditorLanguage immediately if the editor is empty or still matches the
original sample for the current language; otherwise prompt the user with a
confirmation dialog (or automatically persist per-language content in a map
keyed by language and restore instead of replacing) and only replace content
when the user confirms or when no custom content exists; use
updateEditorLanguage and any existing sample-provider function (or add
getSampleForLanguage) and store per-language content in a simple object to
implement the preservation behavior.
- Around line 33-39: The autocompletion options in editor.setOptions
(enableBasicAutocompletion, enableLiveAutocompletion) require the Ace language
tools extension; load the extension script (ext-language_tools.js) in the page
and, in code_editor.js, call ace.require("ace/ext/language_tools") before
calling editor.setOptions so the extension is initialized and the options take
effect.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/static/virtual_lab/js/code_editor.js`:
- Around line 65-94: The language switch applies editor.session.setMode too
early causing langSel.value to drift from the actual editor contents; modify
updateEditorLanguage to check hasUnsavedChanges() before calling
editor.session.setMode, and if the user cancels the confirm, revert
langSel.value back to the previous language (tracked in a new currentLanguage
variable) and return; on successful switch, call
editor.session.setMode(config.mode), then editor.setValue(config.sample, -1) and
set currentLanguage = language so the run handler (which reads langSel.value)
stays in sync with the editor contents; also initialize currentLanguage during
startup so it reflects the initially loaded language.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/static/virtual_lab/js/code_editor.js`:
- Around line 99-100: The editor is being initialized with a hardcoded string
("python") which can desync from the restored <select> value; instead seed the
editor with the select's current value by calling
updateEditorLanguage(langSel.value) (use the existing langSel variable) at
initialization time and ensure this call happens after langSel is defined so the
editor and dropdown stay in sync even when the browser restores form state.
|
Hey @Ananya44444 |
|
@Ananya44444 everything is good, could you please provide the screen recording of running the code in different language to see if it's working or not. |
|
Hii @ghanshyam2005singh |
|
@ghanshyam2005singh Yes, it is working. Screen.Recording.2026-02-25.201557.mp4 |
Related issues
Fixes #931
Checklist
Changes Made
Technical Details
code_editor.jswith language configuration objectScreen.Recording.2026-02-22.185038.mp4
Summary by CodeRabbit
New Features
Usability