Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reset button #650

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: reset button #650

wants to merge 1 commit into from

Conversation

zhangmo8
Copy link
Contributor

@zhangmo8 zhangmo8 commented Jan 24, 2025

reset config for PatternConfig

20250124_170927.mp4

close #267

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a configuration reset functionality to the Playground
    • Introduced a new reset icon for user interactions
  • Improvements

    • Enhanced AST grep tool with new matching and transformation rules
    • Improved Monaco editor synchronization and reactivity
  • Code Quality

    • Replaced hardcoded configuration values with dynamic imports
    • Refined component structure and styling

Copy link

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request introduces a new reset functionality for the AST grep playground. A new ResetConfig component is added to allow users to reset the configuration and code to default settings. The changes involve creating a new Vue component, updating the Playground interface, modifying the state management, and adding a reset icon. The implementation includes dynamic imports for source code and configuration templates, and provides a mechanism to restore default values.

Changes

File Change Summary
website/.vitepress/config.ts Added newline at end of file
website/src/components/Playground.vue Added ResetConfig import, commented out parser initialization, integrated reset component in template
website/src/components/ResetConfig.vue New component for resetting configuration with onReset method
website/src/components/astGrep/state.ts Replaced hardcoded source and config with dynamic imports
website/src/components/astGrep/template/config.yaml Added new rule for transforming console logging
website/src/components/astGrep/template/source.ts Added example functions demonstrating logging patterns
website/src/components/editors/Monaco.vue Added watcher for modelValue, minor formatting changes
website/src/icons/Reset.vue New SVG icon component for reset functionality

Assessment against linked issues

Objective Addressed Explanation
Add reset button to clear code [#267]

Poem

🐰 A rabbit's reset tale unfolds,
Code springs clean, configuration holds
With a click, defaults restore
Playground magic, we explore!
Hop along, reset and soar! 🔄

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

🧹 Nitpick comments (7)
website/src/components/astGrep/template/source.ts (2)

4-6: Add return type annotation for the function.
Consider explicitly annotating the return type for tryAstGrep() to improve clarity in TypeScript.

-function tryAstGrep() {
+function tryAstGrep(): void {
   console.log('matched in metavar!')
}

8-11: Use consistent indentation and formatting for multi-line expressions.
The multi-line chaining is valid, but consider a consistent indentation style to improve readability.

website/src/components/ResetConfig.vue (1)

7-11: Consider preserving user modifications before resetting.
You might retrieve the current config or notify the user before overwriting. Otherwise, there's a risk of unintended data loss.

website/src/components/editors/Monaco.vue (3)

28-29: Consider using a more specific type instead of any.

The second event parameter for changeCursor is typed as any. You could use a more specific type (e.g., monaco.IModelContentChangedEvent or another relevant Monaco type) for clearer type safety and improved maintainability.


86-86: Provide a more explicit cursor event type.

Currently, 'changeCursor' emits the raw e object without explicit type information. Consider specifying the appropriate Monaco interface for stronger type checking and better IDE support.


187-187: Use of self-closing <div /> in Vue templates may be incompatible with some tooling.

While many Vue build pipelines handle self-closing tags, standard HTML5 doesn't officially allow self-closing <div>. For maximum compatibility, consider writing <div class="editor" ref="containerRef"></div>.

-  <div class="editor" ref="containerRef" />
+  <div class="editor" ref="containerRef"></div>
website/src/components/astGrep/template/config.yaml (1)

3-8: Consider extending the rule set to cover more console methods.

Currently, only console.log and console.debug are matched. If you aim to replace all console calls with a custom logger, you might also include methods like console.warn or console.error for completeness.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cef0d2c and be1e59f.

📒 Files selected for processing (8)
  • website/.vitepress/config.ts (1 hunks)
  • website/src/components/Playground.vue (4 hunks)
  • website/src/components/ResetConfig.vue (1 hunks)
  • website/src/components/astGrep/state.ts (3 hunks)
  • website/src/components/astGrep/template/config.yaml (1 hunks)
  • website/src/components/astGrep/template/source.ts (1 hunks)
  • website/src/components/editors/Monaco.vue (6 hunks)
  • website/src/icons/Reset.vue (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • website/.vitepress/config.ts
  • website/src/icons/Reset.vue
🧰 Additional context used
🪛 Biome (1.9.4)
website/src/components/astGrep/template/source.ts

[error] 12-12: Unexpected constant condition.

(lint/correctness/noConstantCondition)

🔇 Additional comments (15)
website/src/components/astGrep/template/source.ts (1)

1-3: No issues with the initial comments.
They appear to be demonstrative statements for console logging.

website/src/components/ResetConfig.vue (4)

1-3: Imports look correct.
These references are straightforward and do not raise any issues.


5-5: Confirm the availability of the defineModel() utility.
Ensure that defineModel() is properly registered or imported, as it may be part of a custom or experimental API.


14-18: Button usage is straightforward.
The reset button and icon usage is clear and self-explanatory.


20-31: No styling conflicts identified.
The scoped styles are minimal and align with the component’s functionality.

website/src/components/astGrep/state.ts (2)

5-7: Good switch to external resources.
Importing source and config from separate files improves maintainability and keeps this file neat.


45-45: Default query is clear and concise.
Defining 'console.log($MATCH)' as the default fosters a straightforward starting point.

website/src/components/Playground.vue (4)

7-7: New import for ResetConfig is consistent.
The newly added component reference is valid and properly placed.


17-17: Double-check the parser initialization.
Commenting out await initializeParser() may break certain functionalities if parser setup is needed elsewhere.


99-102: Effective placement of the reset functionality.
Integrating ResetConfig with the language selector is intuitive and improves usability.


143-143: No significant style modifications beyond this line.
Nothing additional to note.

website/src/components/editors/Monaco.vue (4)

83-83: The change event logic is correct.

Emitting 'update:modelValue' here ensures that the parent's modelValue is properly synchronized with the editor content. No issues found.


102-108: The highlight transformation logic looks good.

By offsetting indices to align with Monaco's 1-based line/column convention, the highlights and ranges will be rendered accurately. This is correct and consistent with Monaco’s API.


147-154: Excellent use of a watcher to maintain synchronization.

The check prevents redundant updates and avoids potential infinite loops. This ensures the editor content remains in sync with external changes to modelValue.


202-206: Styling for .monaco-match-span is well-defined.

The background color is clearly differentiated from the highlight span. This helps users visually distinguish different match categories.

Comment on lines +12 to +16
if (true) {
const notThis = 'console.log("not me")'
} else {
console.debug('matched by YAML')
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid using a constant condition.
if (true) causes the else block to be unreachable. If your intention is to test both blocks, replace true with a real condition or remove the else.

-if (true) {
+if (someDynamicCondition) {
   const notThis = 'console.log("not me")'
} else {
   console.debug('matched by YAML')
}

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Biome (1.9.4)

[error] 12-12: Unexpected constant condition.

(lint/correctness/noConstantCondition)

@@ -13,7 +14,7 @@ import { initializeParser, useAstGrep, Mode as ModeImport } from './astGrep'
import '../style.css'

// important initialization
await initializeParser()
// await initializeParser()

Choose a reason for hiding this comment

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

this should not be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, it's needed here. I commented it out during debugging and forgot to withdraw it.

@@ -36,40 +39,10 @@ export function deserialize(str: string): State {
return JSON.parse(atou(str))
}

const source =

Choose a reason for hiding this comment

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

I don't think moving it to standalone files make too much difference. I am okay with hardcoding these default templates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe will use it somewhere else in the future, so I used a separate file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[playground] Add reset button to clear code
2 participants