Overview
Freshworks products often empower users with scripting capabilities, enabling custom logic for automation, integrations, or data manipulation. A robust and user-friendly code editor component is crucial for these developers and administrators to write and debug their code snippets effectively. This problem challenges you to build a core part of such an editor, focusing on real-time feedback and a smooth user experience, which directly impacts developer productivity within our platforms.
What you need to do / Task
Your goal is to implement an interactive code editor component that provides real-time syntax highlighting and basic linting for a simplified JavaScript-like language.
- Code Editor Foundation: Set up a basic multi-line code input area that functions as a single component.
- Real-time Syntax Highlighting: Implement syntax highlighting for a predefined set of language constructs (keywords, strings, single-line comments).
- Basic Linter Integration: Develop a simple 'linter' that detects common syntax issues (e.g., unclosed brackets, missing semicolons, unknown keywords/identifiers) in real-time.
- Inline Diagnostics Display: Visually present the detected diagnostics (errors/warnings) directly within the editor's text area (e.g., using wavy underlines, custom tooltips on hover).
- Performance & Responsiveness: Ensure that the editor remains responsive during typing, with highlighting and diagnostics updating efficiently.
UI/UX expectations
- The editor should provide a seamless typing experience, with minimal lag for updates.
- Syntax highlighting should be visually distinct (e.g., different colors for keywords, strings, comments) and applied to the text as the user types.
- Diagnostics should be non-intrusive but clearly visible. A common pattern is to show a wavy underline beneath the problematic code segment, with a tooltip appearing on hover to display the diagnostic message.
- The editor should have a reasonable default size and be visually integrated with a diagnostics panel displaying a list of all current issues.
- Scrolling the editor content should also scroll the highlighted/diagnosed overlay to maintain alignment.
Acceptance criteria
- Basic text input and editing functionality works correctly within the editor.
- Keywords (e.g.,
function, if, return, var, const) are highlighted with a distinct color.
- Strings (enclosed in single or double quotes) are highlighted with a distinct color.
- Single-line comments (
//) are highlighted with a distinct color and style (e.g., italic).
- Unclosed parentheses
() and curly braces {} are detected and marked as 'error' diagnostics.
- Missing semicolons at the end of relevant lines (e.g., statements not ending with
} or //) are detected as 'warning' diagnostics.
- Simple unknown identifiers (words not matching keywords, strings, or comments) are detected as 'warning' diagnostics.
- Diagnostics are displayed visually within the editor (e.g., wavy underlines).
- Hovering over an underlined diagnostic in the editor displays its message in a tooltip.
- All syntax highlighting and diagnostic feedback updates within approximately 300ms of user input.
- The editor is visually presentable and scrolls correctly.