autolab / Autolab

Course management service that enables auto-graded programming assignments.
http://www.autolabproject.com/
Apache License 2.0
741 stars 209 forks source link

Highlighting multi-line comments #2150

Closed KesterTan closed 4 weeks ago

KesterTan commented 2 months ago

Fixes #1732.

Before, multi-line comments were not highlighted:

Screenshot 2024-04-22 at 4 50 42 PM

With this change:

Screenshot 2024-04-22 at 4 51 06 PM

How Has This Been Tested?

Types of changes

Checklist:

coderabbitai[bot] commented 2 months ago
Walkthrough ## Walkthrough The changes introduce JavaScript logic and CSS styles to highlight comments in code blocks within the `view.html.erb` file. A new function `highlightComments()` processes and styles comments, which are colored green using a new SCSS variable. Event listeners are added to ensure this function runs on page load and navigation events. These updates improve the readability and visual distinction of comments in the code view. ## Changes | File | Change Summary | |-----------------------------------------|---------------------------------------------------------------------------------------------------------------| | `app/views/submissions/view.html.erb` | Added `highlightComments()` function, event listeners for `DOMContentLoaded` and `navigate`, and updated HTML elements for better readability. | | `app/assets/stylesheets/annotations.scss` | Added styling for comments in code blocks, setting the color to green (#008000). | | `app/assets/stylesheets/_variables.scss` | Added a new SCSS variable `$autolab-highlight-comments` with the color `#008000`. | ## Assessment against linked issues | Objective | Addressed | Explanation | |---------------------------------------------------------------------------|-----------|-----------------------------------------------------------------------------| | Ensure multi-line comments are highlighted correctly (#1732) | ✅ | | | Add a new SCSS variable for comment color (#1732) | ✅ | | | Introduce JavaScript function to process and style comments (#1732) | ✅ | | | Update event listeners to call the new function on page load and navigation events (#1732) | ✅ | |

Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 54ea9c9c270aa7ad70c7a2efd53dcb4cf5d928a7 and 1eeae38748a0f42f551411a44c59ed64ea8a8dcb.
Files selected for processing (1) * app/views/submissions/view.html.erb (2 hunks)
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
20wildmanj commented 2 months ago

It seems that on initial load, the highlighting works, but switching to other files breaks the highlighting (the file will revert back to broken highlighting

https://github.com/autolab/Autolab/assets/25730111/a6a4000c-8933-4ec3-bb5e-aa1e32d5cb16

20wildmanj commented 2 months ago

Discussed offline that this PR still has some issues with highlighting, so needs a second attempt / revision.

KesterTan commented 1 month ago

Updated highlighting code highlights code even if we change files.

Highlighting code also takes into account keywords such as "#include', previously these were flagged out as comments.

Screenshot 2024-05-15 at 2 42 21 PM

To check that it works as expected, check that the output is the same as that in: https://highlightjs.org/demo

20wildmanj commented 1 month ago
Screenshot 2024-05-21 at 8 57 23 AM

seems like the issue with #include getting turned into a comment also happens with #define. Functionally though the multi-line comments seem to work a lot more reliably now. Might be worth looking into updating highlight.js since it seems like the local highlight.pack.js was last updated in 2015, so these issues might have been fixed in later releases. Other than nit, LGTM for the most part.