-
Notifications
You must be signed in to change notification settings - Fork 85
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
base: main
Are you sure you want to change the base?
Aliases for --lang. #488
Conversation
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 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. WalkthroughWalkthroughThe changes introduce a new public method, Changes
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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
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, | ||
} | ||
} |
There was a problem hiding this comment.
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.
@@ -245,6 +288,7 @@ impl PatternLanguage { | |||
} | |||
|
|||
pub fn from_extension(extension: &str) -> Option<Self> { | |||
Self::from_string_or_alias(extension, None) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!!!
working on it!!! |
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
PatternLanguage
instances from string names and optional flavors, enhancing language identification flexibility.Improvements