Skip to content

Add Autocomplete and Syntax Highlighting#109

Draft
AaravMalani wants to merge 20 commits intomainfrom
add-autocomplete
Draft

Add Autocomplete and Syntax Highlighting#109
AaravMalani wants to merge 20 commits intomainfrom
add-autocomplete

Conversation

@AaravMalani
Copy link
Copy Markdown
Member

@AaravMalani AaravMalani commented Mar 24, 2026

  • Added a script to generate autocomplete info from docs/lib/*.js
  • Created a new Conductor plugin for autocomplete and syntax highlighting (information is present as a comment in src/conductor/plugins/autocomplete/index.ts
  • Implemented autocomplete using @lezer/python
  • Implemented syntax highlighting declaratively, with the Ace editor mode creation being offloaded to the frontend

Paired PR: source-academy/frontend#3828

Things left to do:

  • Add for and while loops
  • Fix bug where def x would show x as an autocomplete prompt
  • Add tests for getNames and extractEnvironment
  • Possibly, add support for user-defined functions to have an HTML description via docstrings
  • Possibly, edit the existing tree instead of creating a new tree on every key press.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the code editing experience by integrating autocomplete and syntax highlighting features for Python. It introduces a new Conductor plugin that dynamically generates and utilizes autocomplete data from existing documentation, while also providing robust syntax highlighting based on Python's grammar. These additions aim to make coding more efficient and less error-prone by offering real-time suggestions and improved code readability.

Highlights

  • New Autocomplete and Syntax Highlighting Plugin: Introduced a new Conductor plugin to provide autocomplete suggestions and syntax highlighting for Python code, leveraging @lezer/python for parsing and Ace editor for highlighting.
  • Dynamic Autocomplete Data Generation: Added a new script (scripts/autocomplete.sh) that generates autocomplete information from JSDoc comments in docs/lib/*.js files, which is then processed by src/generate-autocomplete.mts into a simplified JSON format for the plugin.
  • Enhanced Code Editor Experience: Implemented a resolver to identify in-scope variables, functions, and keywords, providing context-aware autocomplete suggestions. Syntax highlighting rules were also defined to improve code readability.
  • Dependency Updates and Configuration: Updated package.json to include the @lezer/python dependency and upgraded @sourceacademy/conductor. ESLint and Prettier configurations were also adjusted to support new .mts file extensions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant new feature: autocomplete and syntax highlighting for Python code. The implementation is comprehensive, involving a new Conductor plugin, code parsing with @lezer/python, and dynamic generation of syntax highlighting rules for the Ace editor. The approach is well-structured. I've identified a few issues, including a potential script failure, a hardcoded language variant, a leftover debug statement, a potential security vulnerability related to HTML injection, and a minor maintainability improvement. Overall, this is a great addition, and addressing these points will make it even more robust.

Comment thread src/conductor/PyEvaluator.ts Outdated
Comment thread src/conductor/plugins/autocomplete/resolver.ts
Comment thread scripts/autocomplete.sh

# Process every JavaScript file in the docs/lib directory with JSDoc,
# outputting the AST as JSON to the src/conductor/plugins/autocomplete/builtins directory.
for file in "$LIB"/*.js; do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This loop will fail with set -e if no .js files are found in the $LIB directory because the glob "$LIB"/*.js will not expand and the script will try to process a file with that literal name. It's good practice to handle cases where no files match the glob pattern.

Comment thread src/conductor/plugins/autocomplete/resolver.ts Outdated
Comment thread src/generate-autocomplete.mts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants