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: fixing duplicates configs when creating new project #918

Merged
merged 5 commits into from
Apr 5, 2024

Conversation

sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Mar 21, 2024

Description

Steps to reproduce for me:

  1. create a new default project "test"
  2. delete a project without deleting all related configuration
  3. create a default "test" project again
  4. click edit on the configuration
  5. The name of configuration is not "test" as supposed to be and a lot of duplicates are created

The problem happens because the default launch config is removed during project deletion and then we can't find it in a map always creating duplicates of the original one. Fixed by looking for existing config via launch manager first before creating a new configuration.
Fixes # (IEP-1187)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

  1. create a new default project "test"
  2. delete a project without deleting all related configuration
  3. create a default "test" project again
  4. click edit on the configuration
  5. make sure no duplicates were created.

Test Configuration:

  • ESP-IDF Version:
  • OS (Windows,Linux and macOS):

Dependent components impacted by this PR:

  • Launch configuration
  • Debug configuration

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Added Documentation
  • Added Unit Test
  • Verified on all platforms - Windows,Linux and macOS

Summary by CodeRabbit

  • New Features
    • Enhanced project creation wizard to better handle and search for debug configurations.
  • Refactor
    • Improved the efficiency and readability of the launch configuration process.
  • Documentation
    • Added import statements and updated logic in performFinish method for better clarity in the project creation wizard.
    • Introduced test cases to validate the functionality of the LaunchConfigFinder class.

Copy link

coderabbitai bot commented Mar 21, 2024

Walkthrough

The changes encompass improvements to the ESP-IDF tooling in Eclipse, focusing on enhancing usability and efficiency. These updates aim to streamline the development workflow by refining the launch configuration process for readability and performance, introducing methods to find existing and debug launch configurations, and updating project handling logic to facilitate easier management and debugging of IoT projects.

Changes

File Path Changes
.../idf.core/.../LaunchConfigFinder.java
.../idf.core.test/.../LaunchConfigFinderTest.java
- Introduced LaunchConfigFinder class for finding launch configurations based on descriptors and identifiers.
- Added test cases for LaunchConfigFinder class to validate configuration retrieval methods.
.../idf.launch.serial.core/.../IDFCoreLaunchConfigProvider.java - Refactored getLaunchConfiguration method for efficiency and readability.
- Added findExistingLaunchConfiguration method.
.../idf.ui/.../NewIDFProjectWizard.java - Added import for LaunchConfigFinder.
- Replaced DisposeListener with lambda expression.
- Updated logic in performFinish method for debug configurations.

Poem

Among the code's branches, a rabbit did play,
🐇 Refactoring with joy, making improvements all day.
🌱 Efficiency bloomed, like flowers in the spring,
🚀 Debug configurations, a useful thing.
"Streamline the workflow," the rabbit did sing,
🎉 IoT development made easier with each swing.
🌟 "Our work here is done," it proclaimed with a grin!

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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/coderabbit-overrides.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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4ede117 and ea6270e.
Files selected for processing (2)
  • bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java (3 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java (3 hunks)
Additional comments: 6
bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java (2)
  • 28-36: The refactoring of getLaunchConfiguration improves readability and efficiency by streamlining the process of obtaining and creating launch configurations. Consider adding comments to explain the logic, especially for the use of computeIfAbsent and the decision-making process for when to create a new configuration. Ensure comprehensive testing to cover all edge cases.
  • 102-116: The findExistingLaunchConfiguration method correctly searches for existing launch configurations based on the project and descriptor name. However, consider the performance implications of iterating over all launch configurations, especially in environments with a large number of configurations. If performance becomes a concern, you might want to explore more efficient search strategies or caching mechanisms.
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java (4)
  • 11-21: The addition of imports for ILaunchConfiguration and ILaunchManager is necessary for the new functionality introduced in this file, specifically for handling launch configurations. This change is appropriate and aligns with the modifications made in the file.
  • 118-133: Replacing the DisposeListener with a lambda expression modernizes the code and enhances readability. This change is a good practice that leverages modern Java features to make the code more concise and maintainable.
  • 139-153: The introduction of findAppropriateDebugConfig method is a logical addition for searching debug configurations based on the project and descriptor. Similar to the findExistingLaunchConfiguration method in IDFCoreLaunchConfigProvider.java, consider the performance implications of iterating over all configurations and explore more efficient search strategies if necessary. Ensure comprehensive testing to cover various scenarios.
  • 118-133: The updated logic in the performFinish method to handle debug configurations more effectively is well-integrated with the existing flow. It correctly manages the creation and activation of debug configurations. Consider adding comments to explain the logic, especially for the new parts related to debug configurations. Ensure comprehensive testing to cover all edge cases.

Copy link
Collaborator

@alirana01 alirana01 left a comment

Choose a reason for hiding this comment

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

Looks good please see if we can somehow reuse the code by making one single function for mentioned uses in the review comment

@sigmaaa sigmaaa requested a review from alirana01 March 26, 2024 12:39
Copy link
Collaborator Author

@sigmaaa sigmaaa left a comment

Choose a reason for hiding this comment

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

Self reviewed. Extracted similar method to the core util class and added unit tests

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ea6270e and 3a9a293.
Files selected for processing (4)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchConfigFinder.java (1 hunks)
  • bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java (3 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java (3 hunks)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchConfigFinderTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3a9a293 and 27eea8c.
Files selected for processing (1)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchConfigFinder.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchConfigFinder.java

@kolipakakondal kolipakakondal added this to the v2.13.0 milestone Mar 27, 2024
Copy link
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

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

LGTM

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 27eea8c and 0735672.
Files selected for processing (4)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/LaunchUtil.java (1 hunks)
  • bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java (3 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java (3 hunks)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchConfigFinderTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • bundles/com.espressif.idf.launch.serial.core/src/com/espressif/idf/launch/serial/core/IDFCoreLaunchConfigProvider.java
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/LaunchConfigFinderTest.java
Additional Context Used

Comment on lines +23 to +36
public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descriptor, String configIndentifier)
throws CoreException
{
IProject project = descriptor.getAdapter(IProject.class);
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations())
{
IResource[] mappedResource = config.getMappedResources();
if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project)
&& config.getType().getIdentifier().contentEquals(configIndentifier))
{
return config;
}
}
return null;
Copy link

Choose a reason for hiding this comment

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

The method findAppropriateLaunchConfig is well-implemented and follows good practices in searching for the appropriate launch configuration. However, consider adding a null check for descriptor at the beginning of the method to prevent potential NullPointerExceptions if a null descriptor is passed. This would enhance the robustness of the method.

public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descriptor, String configIndentifier)
        throws CoreException
{
+   if (descriptor == null) {
+       throw new IllegalArgumentException("Descriptor cannot be null");
+   }
    IProject project = descriptor.getAdapter(IProject.class);
    for (ILaunchConfiguration config : launchManager.getLaunchConfigurations())
    {
        IResource[] mappedResource = config.getMappedResources();
        if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project)
                && config.getType().getIdentifier().contentEquals(configIndentifier))
        {
            return config;
        }
    }
    return null;
}

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.

Suggested change
public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descriptor, String configIndentifier)
throws CoreException
{
IProject project = descriptor.getAdapter(IProject.class);
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations())
{
IResource[] mappedResource = config.getMappedResources();
if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project)
&& config.getType().getIdentifier().contentEquals(configIndentifier))
{
return config;
}
}
return null;
public ILaunchConfiguration findAppropriateLaunchConfig(ILaunchDescriptor descriptor, String configIndentifier)
throws CoreException
{
if (descriptor == null) {
throw new IllegalArgumentException("Descriptor cannot be null");
}
IProject project = descriptor.getAdapter(IProject.class);
for (ILaunchConfiguration config : launchManager.getLaunchConfigurations())
{
IResource[] mappedResource = config.getMappedResources();
if (mappedResource != null && mappedResource.length > 0 && mappedResource[0].getProject().equals(project)
&& config.getType().getIdentifier().contentEquals(configIndentifier))
{
return config;
}
}
return null;

@kolipakakondal
Copy link
Collaborator

@AndriiFilippov Could you please check this?

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi !

Tested under:
OS - Windows 10
ESP-IDF: v5.1.2

Followed steps from description -> don't see duplicates are created, config name stay same. able to build - debug.

image

LGTM 👍

Copy link
Collaborator

@alirana01 alirana01 left a comment

Choose a reason for hiding this comment

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

LGTM!

@kolipakakondal kolipakakondal merged commit 3866cb9 into master Apr 5, 2024
1 of 4 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1187 branch April 5, 2024 10:48
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: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0735672 and a9fc856.
Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/wizard/NewIDFProjectWizard.java

AndriiFilippov pushed a commit that referenced this pull request Apr 22, 2024
* fix: fixing duplicates configs when creating new project

* fix: refactoring code and adding unit tests
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.

4 participants