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

IEP-1262 Changing the configuration should also change the mode #993

Merged
merged 5 commits into from
Jul 10, 2024

Conversation

sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Jun 17, 2024

Description

Now, when we change the configuration it automatically sets the mode to Run/Debug accordingly

Fixes # (IEP-1262)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this been tested?

  • Create a project -> change configuration to the debug configuration -> the mode should be Debug -> Select launch configuration -> the mode should be Run

Test Configuration:

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

Dependent components impacted by this PR:

  • Launch Bar

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 handling of launch configurations and modes.
    • Improved resource deletion wizard with more robust method implementations.
  • Refactor

    • Streamlined import statements and refactored methods for better readability and efficiency.
  • Bug Fixes

    • Corrected logic in dialog handling to ensure accurate user input processing.
  • Style

    • Added braces for code blocks and improved spacing for better code quality and readability.

Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

The recent changes enhance launch handling, refactor code for improved readability, and update methods for better consistency and efficiency. Key modifications include adding imports, introducing and updating methods, and improving implementations in multiple files.

Changes

Files Change Summaries
.../idf/ui/LaunchBarListener.java Added imports for Optional, Stream, ILaunchManager, and ILaunchMode. Introduced setMode method. Updated activeLaunchDescriptorChanged method.
...idf/ui/handlers/RunActionHandler.java Refactored execute method. Added imports, removed SelectLaunchConfigDialog import. Introduced runActionBasedOnDescCount and setLaunchBarWithFirstAppropriateDescriptor methods. Streamlined findSuitableDescNames and showMessage.
...ui/dialogs/DeleteResourceWizard.java Modified several method signatures. Added braces for code blocks. Adjusted spacing. Enhanced method implementations in addUserInputPages, DeleteResourcesRefactoringConfigurationPage inner class, createControl, updateListOfProjects, computeNestedProjects, performFinish, and deleteRelatedConfigurations methods.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant IDE
    participant LaunchBarListener
    participant ILaunchManager

    User->>IDE: Change active launch configuration
    IDE->>LaunchBarListener: Notify activeLaunchDescriptorChanged
    LaunchBarListener->>ILaunchManager: Retrieve specific launch mode
    ILaunchManager-->>LaunchBarListener: Return the retrieved mode
    LaunchBarListener-->>IDE: Update the launch mode
Loading
sequenceDiagram
    participant User
    participant IDE
    participant RunActionHandler

    User->>IDE: Execute a run action
    IDE->>RunActionHandler: Trigger execute method
    RunActionHandler->>RunActionHandler: Determine descriptor count
    alt Single descriptor
        RunActionHandler->>RunActionHandler: setLaunchBarWithFirstAppropriateDescriptor
    else Multiple descriptors
        RunActionHandler->>RunActionHandler: runActionBasedOnDescCount
    end
    RunActionHandler-->>IDE: Complete execution
Loading

Poem

In the codebase deep and bright,
Changes come to make it light,
Launch modes now set with skill,
Run actions tailored, such a thrill!
Pacing through the wizard's maze,
Braces, spacing, all amaze!
With these tweaks, our code shall rise,
To greater heights beneath the skies! 🌟🐰


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

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

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cf7455e and 616eb44.

Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java (4 hunks)
Additional comments not posted (2)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java (2)

9-10: The new imports Optional, Stream, ILaunchManager, and ILaunchMode are appropriate for the functionalities being implemented. Ensure that these classes are being used optimally to justify their inclusion.

Also applies to: 22-23


56-85: The updated activeLaunchDescriptorChanged method now effectively handles different launch configurations. However, the method could be refactored to improve readability and maintainability by extracting the conditional logic into a separate method.
[REFACTOR_SUGGESTion]

- if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
- {
-     setMode(launchBarManager, ILaunchManager.RUN_MODE);
- }
- else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
- {
-     setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
- }
+ setModeBasedOnConfigType(launchBarManager, configTypeIdentifier);

And then define a new method:

private void setModeBasedOnConfigType(ILaunchBarManager launchBarManager, String configTypeIdentifier) {
    if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier)) {
        setMode(launchBarManager, ILaunchManager.RUN_MODE);
    } else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier)) {
        setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
    }
}

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!

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 616eb44 and 4168bf8.

Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java (4 hunks)
Additional comments not posted (1)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java (1)

9-10: Imports Approved.

The newly added imports are necessary for the new functionality and are correctly included.

Also applies to: 22-23

Comment on lines +260 to +276
private void setMode(ILaunchBarManager launchBarManager, String mode)
{
try
{
Optional<ILaunchMode> runMode = Stream.of(launchBarManager.getLaunchModes())
.filter(m -> m.getIdentifier().equals(mode)).findFirst();
if (runMode.isPresent())
{
launchBarManager.setActiveLaunchMode(runMode.get());
}

}
catch (CoreException e)
{
Logger.log(e);
}
}
Copy link

Choose a reason for hiding this comment

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

Enhance Error Logging in setMode.

The error logging in the catch block can be improved to provide more context about the error.

- Logger.log(e);
+ Logger.log("Error setting launch mode", e);
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
private void setMode(ILaunchBarManager launchBarManager, String mode)
{
try
{
Optional<ILaunchMode> runMode = Stream.of(launchBarManager.getLaunchModes())
.filter(m -> m.getIdentifier().equals(mode)).findFirst();
if (runMode.isPresent())
{
launchBarManager.setActiveLaunchMode(runMode.get());
}
}
catch (CoreException e)
{
Logger.log(e);
}
}
private void setMode(ILaunchBarManager launchBarManager, String mode)
{
try
{
Optional<ILaunchMode> runMode = Stream.of(launchBarManager.getLaunchModes())
.filter(m -> m.getIdentifier().equals(mode)).findFirst();
if (runMode.isPresent())
{
launchBarManager.setActiveLaunchMode(runMode.get());
}
}
catch (CoreException e)
{
Logger.log("Error setting launch mode", e);
}
}

Comment on lines 57 to 89
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor)
{
descriptor.getAdapter(ILaunchConfiguration.class);
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);

try
{
ILaunchConfiguration activeLaunchConfiguration = launchBarManager.getActiveLaunchConfiguration();

if (activeLaunchConfiguration != null && activeLaunchConfiguration.getType() != null)
{
String configTypeIdentifier = activeLaunchConfiguration.getType().getIdentifier();
if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set debug mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
setMode(launchBarManager, ILaunchManager.RUN_MODE);
}
else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set run mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.RUN_MODE);
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
}
}
}
catch (CoreException e)
{
Logger.log(e);
}

ILaunchBarListener.super.activeLaunchDescriptorChanged(descriptor);
}
Copy link

Choose a reason for hiding this comment

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

Enhance Error Logging in activeLaunchDescriptorChanged.

The error logging in the catch block can be improved to provide more context about the error.

- Logger.log(e);
+ Logger.log("Error in activeLaunchDescriptorChanged", e);
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
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor)
{
descriptor.getAdapter(ILaunchConfiguration.class);
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
try
{
ILaunchConfiguration activeLaunchConfiguration = launchBarManager.getActiveLaunchConfiguration();
if (activeLaunchConfiguration != null && activeLaunchConfiguration.getType() != null)
{
String configTypeIdentifier = activeLaunchConfiguration.getType().getIdentifier();
if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set debug mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
setMode(launchBarManager, ILaunchManager.RUN_MODE);
}
else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set run mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.RUN_MODE);
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
}
}
}
catch (CoreException e)
{
Logger.log(e);
}
ILaunchBarListener.super.activeLaunchDescriptorChanged(descriptor);
}
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor)
{
descriptor.getAdapter(ILaunchConfiguration.class);
ILaunchBarManager launchBarManager = IDFCorePlugin.getService(ILaunchBarManager.class);
try
{
ILaunchConfiguration activeLaunchConfiguration = launchBarManager.getActiveLaunchConfiguration();
if (activeLaunchConfiguration != null && activeLaunchConfiguration.getType() != null)
{
String configTypeIdentifier = activeLaunchConfiguration.getType().getIdentifier();
if (IDFLaunchConstants.RUN_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set debug mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
setMode(launchBarManager, ILaunchManager.RUN_MODE);
}
else if (IDFLaunchConstants.DEBUG_LAUNCH_CONFIG_TYPE.equals(configTypeIdentifier))
{
// Set run mode first to ensure a mode change, triggering listeners.
setMode(launchBarManager, ILaunchManager.RUN_MODE);
setMode(launchBarManager, ILaunchManager.DEBUG_MODE);
}
}
}
catch (CoreException e)
{
Logger.log("Error in activeLaunchDescriptorChanged", e);
}
ILaunchBarListener.super.activeLaunchDescriptorChanged(descriptor);
}

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi !
Tested under:
OS - Windows 10

change the configuration it automatically sets the mode to Run/Debug accordingly ✔️
LGTM 👍

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

@kolipakakondal
Copy link
Collaborator

Follow-up behavior - Would you also like to handle the case where changing the mode (Run to Debug and vice versa) updates the launch configuration in the dropdown menu? I understand we currently handle this during launch with a pop-up, but if there's only one configuration, we could simply switch it and eliminate the pop-up choice for the user.

Jul-04-2024 12-18-57

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4168bf8 and c0012e5.

Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Jul 5, 2024

Follow-up behavior - Would you also like to handle the case where changing the mode (Run to Debug and vice versa) updates the launch configuration in the dropdown menu? I understand we currently handle this during launch with a pop-up, but if there's only one configuration, we could simply switch it and eliminate the pop-up choice for the user.

Jul-04-2024 12-18-57 Jul-04-2024 12-18-57

Hi @kolipakakondal,

thanks for the review. Implemented in the latest PR

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c0012e5 and 3f20f9e.

Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RunActionHandler.java (6 hunks)
Additional comments not posted (6)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/handlers/RunActionHandler.java (6)

10-10: Import for Stream is appropriate.

The import for Stream is necessary for stream processing in the new methods.


16-16: Import for IStatus is appropriate.

The import for IStatus is necessary for status reporting in the new methods.


70-73: Improvement in the execute method.

Using Boolean.TRUE.equals(isYes) improves readability and reduces the risk of NullPointerException.


111-117: New method runActionBasedOnDescCount improves modularity.

The method encapsulates logic for handling actions based on the count of suitable descriptors, enhancing code readability and modularity.


119-134: New method setLaunchBarWithFirstAppropriateDescriptor improves modularity.

The method encapsulates logic for setting the launch bar with the first appropriate descriptor, enhancing code readability and modularity.


161-161: Simplification in findSuitableDescNames method.

Using toList() instead of collect(Collectors.toList()) simplifies the code and leverages the new method introduced in Java 16.

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3f20f9e and cfc861d.

Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/DeleteResourceWizard.java (4 hunks)
Additional comments not posted (10)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/DeleteResourceWizard.java (10)

69-72: LGTM! Improved readability and maintainability.

The added braces and adjusted spacing enhance the readability and maintainability of the constructor.


75-79: LGTM! Improved readability and maintainability.

The added braces and adjusted spacing enhance the readability and maintainability of the method.


Line range hint 101-297: LGTM! Improved readability, maintainability, and functionality.

The added braces, adjusted spacing, and enhanced implementation improve the readability, maintainability, and functionality of the method.


Line range hint 298-319: LGTM! Improved readability, maintainability, and functionality.

The added braces, adjusted spacing, and improved implementation enhance the readability, maintainability, and functionality of the method.


320-336: LGTM! Improved readability and maintainability.

The added braces and adjusted spacing enhance the readability and maintainability of the method.


337-348: LGTM! Improved readability and maintainability.

The added braces and adjusted spacing enhance the readability and maintainability of the method.


350-364: LGTM! Improved readability and maintainability.

The added braces and adjusted spacing enhance the readability and maintainability of the method.


376-422: LGTM! Improved readability, maintainability, and functionality.

The added braces, adjusted spacing, and enhanced implementation improve the readability, maintainability, and functionality of the method.


425-434: LGTM! Improved functionality.

The added call to deleteRelatedConfigurations ensures that related configurations are deleted when necessary, improving the functionality of the method.


435-452: LGTM! Well-implemented method.

The deleteRelatedConfigurations method is well-implemented and improves functionality by ensuring related configurations are deleted when necessary.

@kolipakakondal
Copy link
Collaborator

thanks for the review. Implemented in the latest PR

Hi @sigmaaa I could still see the same issue where changing the mode is not changing the configuration. Can you please check.
Jul-10-2024 08-28-59

@AndriiFilippov fyi.

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Jul 10, 2024

thanks for the review. Implemented in the latest PR

Hi @sigmaaa I could still see the same issue where changing the mode is not changing the configuration. Can you please check. Jul-10-2024 08-28-59 Jul-10-2024 08-28-59

@AndriiFilippov fyi.

Hi @kolipakakondal, this is the expected behavior for this PR since the goal of this PR was to change the mode based on the configuration, not vice versa. To change the configuration, click run or debug with the wrong configuration.
Changing the configuration based on the mode automatically causes bugs and not consistent behavior, because changing the configuration causes changing the mode, so if we change the configuration based on the mode it could cause an infinite loop. Removing listeners didn't help to remove bugs completely. Check this PR where I tried to implement similar behaviour #806. We can revisit this PR and try to implement it again, however, we considered the logic in this PR as a good alternative.
From the user's perspective, the current behavior looks like this:
The user has a launch configuration selected and he wants to debug the project, so he selects mode to the debug and sees the button "Debug" -> At this point he can click it and the configuration will be changed to the debug, so the debug action will be performed

@kolipakakondal
Copy link
Collaborator

Hi @sigmaaa I'm happy if you would like to revist the existing PR on this problem and fix this issue.

@kolipakakondal kolipakakondal merged commit bbc1b6c into master Jul 10, 2024
7 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1262 branch July 10, 2024 12:25
@kolipakakondal kolipakakondal added this to the v3.1.0 milestone Sep 4, 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.

4 participants