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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import java.io.File;
import java.text.MessageFormat;
import java.util.Optional;
import java.util.stream.Stream;

import org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants;
import org.eclipse.core.resources.IProject;
Expand All @@ -17,6 +19,8 @@
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.launchbar.core.ILaunchBarListener;
import org.eclipse.launchbar.core.ILaunchBarManager;
Expand Down Expand Up @@ -49,6 +53,40 @@
targetChangeIgnored = status;
}

@Override
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor)
{
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);
}

@Override
public void activeLaunchTargetChanged(ILaunchTarget target)
{
Expand Down Expand Up @@ -213,9 +251,27 @@
NLS.bind("Deleting {0} status...{1}", sdkconfigOld.getAbsolutePath(), sdkconfigOld.delete())); //$NON-NLS-1$

// attempting one more time!
sdkconfig.renameTo(sdkconfigOld);

Check warning on line 254 in bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/LaunchBarListener.java

View workflow job for this annotation

GitHub Actions / spotbugs

RV_RETURN_VALUE_IGNORED_BAD_PRACTICE

Exceptional return value of java.io.File.renameTo(File) ignored in com.espressif.idf.ui.LaunchBarListener.cleanSdkConfig(IResource)
Raw output
This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the File.delete() method returns false if the file could not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value.
}
}
}

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);
}
}
Comment on lines +259 to +275
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);
}
}


}
Loading
Loading