Skip to content

Add ruby support#117

Merged
robmck1995 merged 13 commits intomainfrom
rob
Jan 26, 2025
Merged

Add ruby support#117
robmck1995 merged 13 commits intomainfrom
rob

Conversation

@robmck1995
Copy link
Copy Markdown
Contributor

@robmck1995 robmck1995 commented Jan 26, 2025

CodeAnt-AI Description

  • Added support for Ruby language in the LSP manager, including a new RubyClient for handling Ruby LSP processes.
  • Implemented tests for finding Ruby decorator references.
  • Updated installation scripts and Dockerfiles to include Ruby and Ruby LSP.
  • Added Ruby sample code for graph operations and A* search algorithm.
  • Defined AST grep rules for Ruby classes, modules, methods, and identifiers.

Changes walkthrough

Relevant files
Tests
1 files
find_references.rs
Add test for Ruby decorator references                                                 

lsproxy/src/handlers/find_references.rs

  • Added a new test for finding Ruby decorator references.
  • Included ruby_sample_path in test utilities.
  • +100/-1 
    Enhancement
    15 files
    ruby.rs
    Implement Ruby LSP client                                                                           

    lsproxy/src/lsp/languages/ruby.rs

  • Implemented RubyClient for handling Ruby language server protocol.
  • Added methods for initializing and managing Ruby LSP processes.
  • +88/-0   
    manager.rs
    Add Ruby support to LSP manager                                                               

    lsproxy/src/lsp/manager/manager.rs

  • Added support for Ruby in the LSP manager.
  • Integrated Ruby file patterns and client initialization.
  • +13/-4   
    file_utils.rs
    Update file utilities for Ruby support                                                 

    lsproxy/src/utils/file_utils.rs

  • Added Ruby extensions to language detection.
  • Updated functions to recognize Ruby files.
  • +3/-1     
    workspace_documents.rs
    Define Ruby file patterns and extensions                                             

    lsproxy/src/utils/workspace_documents.rs

  • Defined Ruby root files and file patterns.
  • Added Ruby extensions for workspace document handling.
  • +9/-0     
    mod.rs
    Include Ruby module in language modules                                               

    lsproxy/src/lsp/languages/mod.rs

    • Added Ruby module to the list of available language modules.
    +2/-1     
    test_utils.rs
    Add Ruby sample path utility                                                                     

    lsproxy/src/test_utils.rs

    • Added ruby_sample_path function for Ruby test samples.
    +4/-0     
    api_types.rs
    Add Ruby to supported languages                                                               

    lsproxy/src/api_types.rs

    • Added Ruby to the SupportedLanguages enum.
    +2/-0     
    graph.rb
    Add Ruby sample code for graph operations                                           

    sample_project/ruby/graph.rb

  • Added Ruby sample code for graph operations.
  • Implemented A* graph with cost strategies.
  • +75/-0   
    search.rb
    Add Ruby sample code for A* search                                                         

    sample_project/ruby/search.rb

  • Added Ruby sample code for A* search algorithm.
  • Implemented search with logging of execution time.
  • +66/-0   
    main.rb
    Add main Ruby script for graph search                                                   

    sample_project/ruby/main.rb

  • Added main Ruby script for executing graph search.
  • Included visualization with matplotlib if available.
  • +56/-0   
    decorators.rb
    Add Ruby decorators for logging execution time                                 

    sample_project/ruby/decorators.rb

    • Added Ruby module for logging execution time of methods.
    +20/-0   
    class.yml
    Add Ruby class symbol rules                                                                       

    lsproxy/src/ast_grep/symbol/rules/ruby/class.yml

    • Added AST grep rules for Ruby class symbols.
    +22/-0   
    module.yml
    Add Ruby module symbol rules                                                                     

    lsproxy/src/ast_grep/symbol/rules/ruby/module.yml

    • Added AST grep rules for Ruby module symbols.
    +18/-0   
    method.yml
    Add Ruby method symbol rules                                                                     

    lsproxy/src/ast_grep/symbol/rules/ruby/method.yml

    • Added AST grep rules for Ruby method symbols.
    +12/-0   
    all-identifiers.yml
    Add Ruby identifier rules                                                                           

    lsproxy/src/ast_grep/identifier/rules/ruby/all-identifiers.yml

    • Added AST grep rules for all Ruby identifiers.
    +7/-0     
    Configuration changes
    3 files
    install-lsproxy.sh
    Update install script for Ruby support                                                 

    release/install-lsproxy.sh

  • Updated LSProxy version to 0.3.4.
  • Added installation steps for Ruby and Ruby LSP.
  • +9/-1     
    Dockerfile
    Update Dockerfile for Ruby support                                                         

    release/Dockerfile

    • Added installation of Ruby and Ruby LSP to Dockerfile.
    +7/-0     
    Cargo.toml
    Bump version to 0.3.4                                                                                   

    lsproxy/Cargo.toml

    • Updated package version to 0.3.4.
    +1/-1     

    🔍 Infra Scan Results:
    Failed Dockerfile Checks
    Check NameFile PathLines
    Ensure that APT isn't usedlsproxy/Dockerfile90-92
    Ensure that HEALTHCHECK instructions have been added to container imageslsproxy/Dockerfile1-117
    Ensure that a user for the container has been createdlsproxy/Dockerfile1-117
    Ensure that APT isn't usedrelease/Dockerfile90-92
    Ensure that HEALTHCHECK instructions have been added to container imagesrelease/Dockerfile1-122
    Ensure that a user for the container has been createdrelease/Dockerfile1-122
    💡 Usage Guide

    Checking Your Pull Request

    Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

    Talking to CodeAnt AI

    Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

    @codeant-ai ask: Your question here
    

    This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

    Retrigger review

    Ask CodeAnt AI to review the PR again, by typing:

    @codeant-ai: review
    

    Check Your Repository Health

    To analyze the health of your code repository, visit our dashboard at app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

    @robmck1995 robmck1995 marked this pull request as ready for review January 26, 2025 00:34
    Comment thread lsproxy/Dockerfile
    Comment on lines +90 to +92
    RUN apt update && apt install -y ruby-full \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Ensure that APT isn't used

    • Ensuring that Advanced Packaging Tool (APT) isn't used helps to prevent security vulnerabilities from unverified packages or outdated versions, improving the overall security posture of the docker container.
    • By not using APT, we reduce the risk of an attacker exploiting known bugs present in packages that are included in APT but haven’t been patched yet, thereby enhancing the resilience of the system against potential attacks.

    Comment thread release/Dockerfile
    Comment on lines +90 to +92
    RUN apt update && apt install -y ruby-full \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Ensure that APT isn't used

    • Ensuring that Advanced Packaging Tool (APT) isn't used helps to prevent security vulnerabilities from unverified packages or outdated versions, improving the overall security posture of the docker container.
    • By not using APT, we reduce the risk of an attacker exploiting known bugs present in packages that are included in APT but haven’t been patched yet, thereby enhancing the resilience of the system against potential attacks.

    @codeant-ai codeant-ai Bot added the size:XL This PR changes 500-999 lines, ignoring generated files label Jan 26, 2025
    @codeant-ai
    Copy link
    Copy Markdown
    Contributor

    codeant-ai Bot commented Jan 26, 2025

    Pull Request Feedback 🔍

    🔒 No security issues identified
    ⚡ Recommended areas for review

    Test Coverage
    The new test test_ruby_decorator_references is added to verify Ruby decorator references. Ensure that this test covers all relevant scenarios and edge cases for Ruby decorator references.

    Error Handling
    The RubyClient::new function logs an error when failing to start the ruby-lsp process but does not provide a mechanism to handle this error gracefully. Consider adding error handling to manage this failure scenario.

    Language Detection
    The addition of Ruby language support in the detect_language function should be thoroughly tested to ensure it correctly identifies Ruby files under various conditions.

    include_raw_response: false,
    });

    let response = find_references(state, mock_request).await;
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Consider adding error handling for the find_references function call to manage potential failures gracefully. [best practice]

    Suggested change
    let response = find_references(state, mock_request).await;
    let response = find_references(state, mock_request).await?;

    Ok(InitializeParams {
    capabilities: self.get_capabilities(),
    workspace_folders: Some(workspace_folders.clone()),
    root_uri: workspace_folders.first().map(|f| f.uri.clone()), // <--------- Not default behavior
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Consider handling the case where workspace_folders might be empty to avoid potential runtime errors when accessing the first element. [possible issue]

    Suggested change
    root_uri: workspace_folders.first().map(|f| f.uri.clone()), // <--------- Not default behavior
    root_uri: workspace_folders.first().map(|f| f.uri.clone()).or_else(|| Some(default_uri)),

    Comment on lines +62 to +65
    .map_err(|e| {
    eprintln!("Failed to start ruby-lsp process: {}", e);
    Box::new(e) as Box<dyn std::error::Error + Send + Sync>
    })?;
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Ensure that the Command::new("ruby-lsp") is resilient to the absence of the ruby-lsp executable by providing a more informative error message. [best practice]

    Suggested change
    .map_err(|e| {
    eprintln!("Failed to start ruby-lsp process: {}", e);
    Box::new(e) as Box<dyn std::error::Error + Send + Sync>
    })?;
    .map_err(|e| {
    eprintln!("Failed to start ruby-lsp process. Ensure 'ruby-lsp' is installed and accessible: {}", e);
    Box::new(e) as Box<dyn std::error::Error + Send + Sync>
    })?;

    # Function to install Ruby and Ruby LSP
    install_ruby() {
    echo "Installing Ruby and Ruby LSP..."
    DEBIAN_FRONTEND=noninteractive apt-get install -y ruby-full
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Consider adding a check to verify if Ruby is already installed before attempting to install it, to avoid unnecessary installations. [enhancement]

    Suggested change
    DEBIAN_FRONTEND=noninteractive apt-get install -y ruby-full
    if ! command -v ruby &> /dev/null; then DEBIAN_FRONTEND=noninteractive apt-get install -y ruby-full; fi

    Comment thread lsproxy/Dockerfile
    Comment on lines +90 to +94
    RUN apt update && apt install -y ruby-full \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

    RUN gem install ruby-lsp
    Copy link
    Copy Markdown
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: Combine the Ruby installation commands into a single RUN command to reduce the number of layers in the Docker image. [performance]

    Suggested change
    RUN apt update && apt install -y ruby-full \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*
    RUN gem install ruby-lsp
    RUN apt update && apt install -y ruby-full \
    && gem install ruby-lsp \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

    @robmck1995 robmck1995 merged commit 3f35d5c into main Jan 26, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    size:XL This PR changes 500-999 lines, ignoring generated files

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants