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

fix: include universal patterns in bindings #431

Merged
merged 11 commits into from
Jul 22, 2024
Merged

fix: include universal patterns in bindings #431

merged 11 commits into from
Jul 22, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented Jul 22, 2024

Greptile Summary

This is an auto-generated summary

The pull request introduces AI placeholder functions and improves the handling of universal patterns in various modules.

  • crates/cli/src/analyze.rs: Injected AI placeholder functions into compile method of RichPattern struct.
  • crates/core/src/built_in_functions.rs: Added llm_chat and embedding placeholder functions; introduced get_ai_placeholder_functions.
  • crates/gritmodule/src/patterns_directory.rs: Introduced get_universal method; updated get_language_and_universal_directory and get methods.
  • crates/lsp/src/util.rs: Modified get_ai_built_in_functions_for_feature to return AI placeholder functions when ai_builtins is disabled.
  • crates/core/src/pattern_compiler/compiler.rs: Minor formatting adjustments and added a blank line for readability.

Summary by CodeRabbit

  • New Features

    • Introduced AI placeholder functions for enhanced testing and development without reliance on actual built-in functions.
    • Added a new method for simplified access to the universal language directory.
  • Improvements

    • Enhanced error handling for AI feature accessibility, providing clearer responses when AI features are not available.
    • Added a mechanism to conditionally skip pattern indexes during analysis.
  • Refactor

    • Adjusted visibility and organization of methods within the PatternsDirectory for improved encapsulation and clarity.

@morgante morgante changed the title [skip ci] yolo fix: include universal patterns in bindings Jul 22, 2024
@morgante morgante marked this pull request as ready for review July 22, 2024 03:07
@morgante morgante requested a review from a team as a code owner July 22, 2024 03:07
Copy link
Contributor

coderabbitai bot commented Jul 22, 2024

Walkthrough

Walkthrough

The recent changes enhance the codebase by integrating AI placeholder functions and improving encapsulation through modified visibility. When the "ai_builtins" feature is disabled, the system now provides placeholder functions instead of returning None, thereby increasing robustness. Additionally, the handling of language directories has been refined for better clarity and maintainability. These modifications facilitate testing and streamline access to language-related information.

Changes

Files Change Summary
crates/cli/src/analyze.rs Updated injected_builtins to retrieve AI placeholder functions when the "ai_builtins" feature is not enabled.
crates/core/src/built_in_functions.rs Introduced get_ai_placeholder_functions to provide placeholder functions, with ai_fn_placeholder enforcing an error.
crates/lsp/src/util.rs Modified get_ai_built_in_functions_for_feature to return AI placeholder functions instead of None when disabled.
crates/gritmodule/src/patterns_directory.rs Restricted get_language_directory visibility, added get_universal, and improved structure for language access.
crates/core/src/pattern_compiler/compiler.rs Minor formatting change, adding a blank line after comments; no logic change.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant MarzanoCore
    participant BuiltIns

    User->>CLI: Request to analyze with AI built-ins
    alt AI built-ins enabled
        CLI->>BuiltIns: Retrieve built-in functions
    else AI built-ins not enabled
        CLI->>MarzanoCore: Get AI placeholder functions
        MarzanoCore-->>CLI: Return AI placeholders
    end
    CLI-->>User: Provide analysis results
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4a46c95 and c81b8c5.

Files ignored due to path filters (5)
  • crates/cli_bin/tests/snapshots/apply__output_jsonl.snap is excluded by !**/*.snap
  • crates/cli_bin/tests/snapshots/parse__correct_variable_ranges_in_snippet_with_multiple_contexts.snap is excluded by !**/*.snap
  • crates/cli_bin/tests/snapshots/parse__correct_variable_ranges_multiple_snippets_multiple_contexts.snap is excluded by !**/*.snap
  • crates/cli_bin/tests/snapshots/parse__parses_foreign_function.snap is excluded by !**/*.snap
  • crates/cli_bin/tests/snapshots/parse__parses_grit_file.snap is excluded by !**/*.snap
Files selected for processing (3)
  • crates/core/src/built_in_functions.rs (1 hunks)
  • crates/core/src/problem.rs (1 hunks)
  • crates/grit-pattern-matcher/src/context.rs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • crates/core/src/built_in_functions.rs
Additional context used
Learnings (1)
Common learnings
Learnt from: morgante
URL: https://github.com/getgrit/gritql/pull/231

Timestamp: 2024-04-15T05:47:47.743Z
Learning: User morgante prefers not to be asked for documentation.
Additional comments not posted (6)
crates/grit-pattern-matcher/src/context.rs (3)

78-79: Addition of skippable_indexes field looks good.

The new field skippable_indexes enhances the functionality by allowing certain pattern indexes to be skipped.


92-92: Constructor update to initialize skippable_indexes looks good.

Initializing skippable_indexes as an empty vector ensures sensible default behavior.


97-99: Modification of get_pattern method looks good.

The added conditional check enhances the method's flexibility by allowing certain pattern indexes to be skipped.

crates/core/src/problem.rs (3)

71-75: Initialization of StaticDefinitions object looks good.

Assigning the object to a mutable variable allows for additional logic to be applied before returning it.


76-79: Addition of conditional logic to set skippable_indexes looks good.

This enhances the method's flexibility by allowing certain indexes to be skipped based on the state of pattern_definitions.


80-80: Return statement looks good.

Returning the defs object after applying the conditional logic ensures that skippable_indexes are set correctly.


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

grit-app bot commented Jul 22, 2024

View earlier commits On commit 3e3652d, Grit tried to heal these tests:
Job Original Status Final Status
main / Rust tests (marzano) ❌ Failed ❗ Failed on attempt #2 after trying strategies ai, rerun

On commit 4a46c95, Grit tried to heal these tests:

Job Original Status Final Status
main / Rust tests (marzano) ❌ Failed ❗ Failed on attempt #3 after trying strategies ai, rerun

On commit 1dd6b81, Grit tried to heal these tests:

Job Original Status Final Status
main / Rust tests (marzano) ❌ Failed ❗ Failed on attempt #3 after trying strategies ai, rerun

Tip

You can view and edit CI healing settings on the Grit App.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

5 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings

BuiltInFunction::new(
"llm_chat",
vec!["model", "messages", "pattern"],
Box::new(ai_fn_placholder),
Copy link

Choose a reason for hiding this comment

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

Spelling: Typo in function name ai_fn_placholder. Should be ai_fn_placeholder.

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: 2

Comment on lines 512 to 519
fn ai_fn_placholder<'a>(
_args: &'a [Option<Pattern<MarzanoQueryContext>>],
_context: &'a MarzanoContext<'a>,
_state: &mut State<'a, MarzanoQueryContext>,
_logs: &mut AnalysisLogs,
) -> Result<MarzanoResolvedPattern<'a>> {
bail!("AI features are not supported in your GritQL distribution. Please upgrade to the Enterprise version to use AI features.")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the typo in the function name.

The function name ai_fn_placholder contains a typo. It should be ai_fn_placeholder.

-fn ai_fn_placholder<'a>(
+fn ai_fn_placeholder<'a>(
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fn ai_fn_placholder<'a>(
_args: &'a [Option<Pattern<MarzanoQueryContext>>],
_context: &'a MarzanoContext<'a>,
_state: &mut State<'a, MarzanoQueryContext>,
_logs: &mut AnalysisLogs,
) -> Result<MarzanoResolvedPattern<'a>> {
bail!("AI features are not supported in your GritQL distribution. Please upgrade to the Enterprise version to use AI features.")
}
fn ai_fn_placeholder<'a>(
_args: &'a [Option<Pattern<MarzanoQueryContext>>],
_context: &'a MarzanoContext<'a>,
_state: &mut State<'a, MarzanoQueryContext>,
_logs: &mut AnalysisLogs,
) -> Result<MarzanoResolvedPattern<'a>> {
bail!("AI features are not supported in your GritQL distribution. Please upgrade to the Enterprise version to use AI features.")
}

Comment on lines 498 to 510
pub fn get_ai_placeholder_functions() -> Option<BuiltIns> {
Some(
vec![
BuiltInFunction::new(
"llm_chat",
vec!["model", "messages", "pattern"],
Box::new(ai_fn_placholder),
),
BuiltInFunction::new("embedding", vec!["target"], Box::new(ai_fn_placholder)),
]
.into(),
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the typo in the function name.

The function name ai_fn_placholder contains a typo. It should be ai_fn_placeholder.

-  Box::new(ai_fn_placholder),
+  Box::new(ai_fn_placeholder),
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
pub fn get_ai_placeholder_functions() -> Option<BuiltIns> {
Some(
vec![
BuiltInFunction::new(
"llm_chat",
vec!["model", "messages", "pattern"],
Box::new(ai_fn_placholder),
),
BuiltInFunction::new("embedding", vec!["target"], Box::new(ai_fn_placholder)),
]
.into(),
)
}
pub fn get_ai_placeholder_functions() -> Option<BuiltIns> {
Some(
vec![
BuiltInFunction::new(
"llm_chat",
vec!["model", "messages", "pattern"],
Box::new(ai_fn_placeholder),
),
BuiltInFunction::new("embedding", vec!["target"], Box::new(ai_fn_placeholder)),
]
.into(),
)
}

@morgante morgante merged commit 3eb6cbf into main Jul 22, 2024
10 checks passed
@morgante morgante deleted the good-stuff branch July 22, 2024 05:14
@github-actions github-actions bot mentioned this pull request Jul 22, 2024
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.

1 participant