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

Aliases for --lang. #488

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Aliases for --lang. #488

wants to merge 7 commits into from

Conversation

xonx4l
Copy link

@xonx4l xonx4l commented Sep 6, 2024

Issue-: #445

Aliases for --lang.

Added the from_string_or_alias function to handle both full language names and their aliases.

Summary by CodeRabbit

  • New Features

    • Introduced a new method for creating PatternLanguage instances from string names and optional flavors, enhancing language identification flexibility.
  • Improvements

    • Updated existing methods to utilize the new method, streamlining the logic for language identification and improving maintainability.
    • Enhanced language pattern determination in the CLI by allowing for more flexible handling of language aliases and string representations.
    • Added support for additional programming languages with new pattern aliases, improving the robustness of language recognition.

@xonx4l xonx4l requested a review from a team as a code owner September 6, 2024 12:46
Copy link
Contributor

coderabbitai bot commented Sep 6, 2024

Warning

Rate limit exceeded

@xonx4l has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 36 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 2d62b4c and 718c4b7.

Walkthrough

Walkthrough

The changes introduce a new public method, from_string_or_alias, to the PatternLanguage implementation, enabling the creation of a PatternLanguage instance from a string name and an optional flavor. The existing methods, from_string and from_extension, have been updated to call this new method, enhancing code reuse and simplifying language identification logic. Additionally, the run_apply_pattern function in the CLI has been modified to utilize this new method. New test cases have also been added for additional programming languages.

Changes

Files Change Summary
crates/language/src/target_language.rs Added a new public method from_string_or_alias. Modified from_string and from_extension to utilize this new method.
crates/cli/src/commands/apply_pattern.rs Updated run_apply_pattern to use PatternLanguage::from_string_or_alias(ext, None) instead of from_extension(ext) for language determination.
crates/core/src/pattern_compiler/compiler.rs Added new test cases for additional programming languages, defining new pattern aliases and validating language recognition.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PatternLanguage

    User->>PatternLanguage: from_string(name, flavor)
    PatternLanguage->>PatternLanguage: Call from_string_or_alias(name, flavor)
    PatternLanguage-->>User: Return PatternLanguage instance

    User->>PatternLanguage: from_extension(extension)
    PatternLanguage->>PatternLanguage: Call from_string_or_alias(extension, None)
    PatternLanguage-->>User: Return PatternLanguage instance
Loading

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>.
    • 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 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 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.

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
Contributor

@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: 3

Comment on lines 132 to 172
impl PatternLanguage {
pub fn from_string_or_alias(name: &str, flavor: Option<&str>) -> Option<Self> {
match name {
"py" | "python" => Some(Self::Python),
"js" | "javascript" => match flavor {
Some("jsx") => Some(Self::Tsx),
Some("flow") => Some(Self::Tsx),
Some("FlowComments") => Some(Self::Tsx),
Some("typescript") => Some(Self::TypeScript),
Some("js_do_not_use") => Some(Self::JavaScript),
_ => Some(Self::Tsx),
},
"ts" | "typescript" => Some(Self::Typescript),
"html" => Some(Self::Html),
"css" => Some(Self::Css),
"json" => Some(Self::Json),
"java" => Some(Self::Java),
"cs" | "csharp" => Some(Self::CSharp),
"md" | "markdown" => match flavor {
Some("block") => Some(Self::MarkdownBlock),
Some("inline") => Some(Self::MarkdownInline),
_ => Some(Self::MarkdownInline),
},
"go" => Some(Self::Go),
"rs" | "rust" => Some(Self::Rust),
"rb" | "ruby" => Some(Self::Ruby),
"sol" | "solidity" => Some(Self::Solidity),
"hcl" | "tf" | "terraform" => Some(Self::Hcl),
"yml" | "yaml" => Some(Self::Yaml),
"sql" => Some(Self::Sql),
"vue" => Some(Self::Vue),
"toml" => Some(Self::Toml),
"php" => match flavor {
Some("html") => Some(Self::Php),
Some("only") => Some(self::PhpOnly),
_ => Some(Self::Php),
},
"universal" => Some(Self::Universal),
_ => None,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Approve the implementation of from_string_or_alias.

The new function from_string_or_alias is well-implemented and covers a comprehensive range of languages and aliases. It effectively centralizes the logic for language identification, which enhances maintainability and code reuse.

Suggestion: Add documentation.
It would be beneficial to add documentation comments to this function to explain its purpose, parameters, and the handling of different cases, especially the use of the flavor parameter.

crates/language/src/target_language.rs Outdated Show resolved Hide resolved
crates/language/src/target_language.rs Outdated Show resolved Hide resolved
@@ -245,6 +288,7 @@ impl PatternLanguage {
}

pub fn from_extension(extension: &str) -> Option<Self> {
Self::from_string_or_alias(extension, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

This call isn't doing anything, I think you probably meant to delegate this entirely?

Copy link
Author

Choose a reason for hiding this comment

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

I have changed the from_extension function which now uses the updated from_string function, which handles both full language names and aliases.

Copy link
Contributor

@morgante morgante left a comment

Choose a reason for hiding this comment

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

Thanks! I'm not sure this actually fixes the issue because clap attempts to use the enum directly. Can you add CLI test in crates/cli_bin/tests/apply.rs too?

@@ -129,6 +129,48 @@ impl PatternLanguage {
Self::from_string(lang, flavor.as_deref())
}

impl PatternLanguage {
pub fn from_string_or_alias(name: &str, flavor: Option<&str>) -> Option<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

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

@xonx4l This should be removed, you don't need both.

Copy link
Author

Choose a reason for hiding this comment

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

Done!!!

@xonx4l
Copy link
Author

xonx4l commented Sep 7, 2024

Thanks! I'm not sure this actually fixes the issue because clap attempts to use the enum directly. Can you add CLI test in crates/cli_bin/tests/apply.rs too?

working on it!!!

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.

2 participants