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-1018 Automation of hints viewer #809

Merged
merged 15 commits into from
Sep 13, 2023
Merged

IEP-1018 Automation of hints viewer #809

merged 15 commits into from
Sep 13, 2023

Conversation

sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Aug 9, 2023

Description

Added automated build hints viewer which appears after the build if there are available hints for founded errors. Also, can be turned on manually via Windows -> Show View -> Other... -> Espressif -> Build Hints

Fixes # (IEP-1018)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How has this been tested?

Test 1:

  • Add some errors which will match regular expressions from the hints.yml, for example, #import spiram.h
  • After build should appear and focused Build Hints viewer with a suggested hint
    Test 2:
  • turn off search for hints in the Espressif Preference Page -> close Build Hints viewer and rebuild again -> Build Hints should not be opened automatically

Test Configuration:

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

Dependent components impacted by this PR:

  • Build

Checklist

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

Summary by CodeRabbit

  • New Feature: Added automated build hints functionality to assist users in identifying and resolving ESP-IDF errors. This feature can be enabled or disabled via a new checkbox in the preferences dialog.
  • New Feature: Introduced a new UI view, "BuildView", for displaying build hints. The view consists of a table that displays error messages and corresponding hints.
  • Refactor: Improved handling of regular expressions in the ReHintPair class by using Pattern objects instead of String.
  • Test: Added comprehensive tests for the new EspIdfErrorParser class and updated existing tests to accommodate changes in the ReHintPair class.
  • Chore: Updated various UI elements and tooltips to improve user experience and provide additional information about new features.

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. Need to add documentation and test coverage for EspIdfErrorParser

@sigmaaa sigmaaa changed the title WIP: IEP-1018 Automation of hints viewer IEP-1018 Automation of hints viewer Aug 16, 2023
@sigmaaa sigmaaa self-assigned this Aug 16, 2023
@kolipakakondal kolipakakondal added this to the v2.11.0 milestone Aug 24, 2023
@AndriiFilippov
Copy link
Collaborator

AndriiFilippov commented Aug 26, 2023

@sigmaaa hi !
Tested under:
OS - Windows 10 / MacOS

ESP-IDF: v5.0 - v5.1

release 5.1 / 5.1.1 LGTM 👍 able to enable / disable hint feature. able to see useful hints.

release 5.0 / 5.0.3

when hint option is selected
image

unable to build a project.
the build just stuck.

image

CMakeOutput.log

LOGS:

-- Check size of time_t - done
-- Found Python3: C:/Python311/python.exe (found version "3.11.0") found components: Interpreter 
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS
-- Performing Test C_COMPILER_SUPPORTS_WFORMAT_SIGNEDNESS - Success
-- App "hello_world" version: v5.0-dev-4379-g36f49f361-dirty
-- Adding linker script C:/Users/AndriiFilippov/runtime-launchConfiguration(12)/fcvijnl/build/esp-idf/esp_system/ld/memory.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_system/ld/esp32s2/sections.ld.in
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom/esp32s2/ld/esp32s2.rom.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom/esp32s2/ld/esp32s2.rom.api.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom/esp32s2/ld/esp32s2.rom.libgcc.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-funcs.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-data.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom/esp32s2/ld/esp32s2.rom.spiflash.ld
-- Adding linker script C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/soc/esp32s2/ld/esp32s2.peripherals.ld
-- Components: app_trace app_update bootloader bootloader_support bt cmock console cxx driver efuse esp-tls esp_adc esp_app_format esp_common esp_eth esp_event esp_gdbstub esp_hid esp_http_client esp_http_server esp_https_ota esp_https_server esp_hw_support esp_lcd esp_local_ctrl esp_netif esp_partition esp_phy esp_pm esp_psram esp_ringbuf esp_rom esp_system esp_timer esp_wifi espcoredump esptool_py fatfs freertos hal heap http_parser idf_test ieee802154 json log lwip main mbedtls mqtt newlib nvs_flash openthread partition_table perfmon protobuf-c protocomm pthread sdmmc soc spi_flash spiffs tcp_transport touch_element ulp unity usb vfs wear_levelling wifi_provisioning wpa_supplicant xtensa
-- Component paths: C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/app_trace C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/app_update C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/bootloader C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/bootloader_support C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/bt C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/cmock C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/console C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/cxx C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/driver C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/efuse C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp-tls C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_adc C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_app_format C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_common C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_eth C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_event C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_gdbstub C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_hid C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_http_client C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_http_server C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_https_ota C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_https_server C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_hw_support C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_lcd C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_local_ctrl C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_netif C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_partition C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_phy C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_pm C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_psram C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_ringbuf C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_rom C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_system C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_timer C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esp_wifi C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/espcoredump C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/esptool_py C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/fatfs C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/freertos C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/hal C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/heap C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/http_parser C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/idf_test C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/ieee802154 C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/json C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/log C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/lwip C:/Users/AndriiFilippov/runtime-launchConfiguration(12)/fcvijnl/main C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/mbedtls C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/mqtt C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/newlib C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/nvs_flash C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/openthread C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/partition_table C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/perfmon C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/protobuf-c C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/protocomm C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/pthread C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/sdmmc C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/soc C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/spi_flash C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/spiffs C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/tcp_transport C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/touch_element C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/ulp C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/unity C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/usb C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/vfs C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/wear_levelling C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/wifi_provisioning C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/wpa_supplicant C:/Users/AndriiFilippov/e/new/esp-idf-v5.0/components/xtensa
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/AndriiFilippov/runtime-launchConfiguration(12)/fcvijnl/build
cmake --build . -- -v
[1/855] cmd.exe /C "cd /D C:\Users\AndriiFilippov\runtime-launchConfiguration(12)\fcvijnl\build && C:\Users\AndriiFilippov\.espressif\tools\cmake\3.24.0\bin\cmake.exe -E touch C:/Users/AndriiFilippov/runtime-launchConfiguration(12)/fcvijnl/build/project_elf_src_esp32s2.c"

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

@coderabbitai
Copy link

coderabbitai bot commented Aug 28, 2023

Walkthrough

This pull request introduces automated build hints to the ESP-IDF Eclipse plugin. It adds a new view for displaying build hints, modifies the preferences page to enable/disable this feature, and includes changes to handle regular expressions more safely. The PR also includes relevant tests and UI updates.

Changes

File(s) Summary
.../IDFCorePreferenceConstants.java
.../EspresssifPreferencesPage.java
.../preferences/Messages.java
.../preferences/messages.properties
Introduced a new preference constant and UI elements for enabling/disabling automated build hints.
.../EspIdfErrorParser.java
.../EspIdfErrorParserTest.java
Added a new class for parsing console output for errors and extracting relevant hints, along with its tests.
.../IDFBuildConfiguration.java Modified the build process to include error parsing based on the new preference setting.
.../PopupDialog.java
.../ParitionSizeHandler.java
Introduced a new enum for popup dialogs and updated the partition size handler accordingly.
.../InitializeToolsStartup.java Updated the startup initialization to handle property change events related to build hints.
.../BuildView.java
.../HintsView.java
.../dialogs/Messages.java
.../dialogs/messages.properties
Added a new view for displaying build hints and made necessary UI updates.
.../ReHintPair.java
.../util/test/HintsUtilTest.java
Improved handling of regular expressions by using Pattern objects instead of String, and updated tests accordingly.

🐇💻

Code is hopping, errors are dropping,

With build hints popping, there's no stopping!

Regular expressions, handled with care,

Make bugs run scared, from their rabbit lair! 🎉🥕


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

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

Commits Files that changed from the base of the PR and between 8bf0e70 and f294aa7 commits.
Files selected for processing (15)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFCorePreferenceConstants.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/EspIdfErrorParser.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (3 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/resources/PopupDialog.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ParitionSizeHandler.java (3 hunks)
  • bundles/com.espressif.idf.ui/OSGI-INF/l10n/bundle.properties (1 hunks)
  • bundles/com.espressif.idf.ui/plugin.xml (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java (6 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/BuildView.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/messages.properties (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (5 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties (1 hunks)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/build/test/EspIdfErrorParserTest.java (1 hunks)
Files skipped from review due to trivial changes (8)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFCorePreferenceConstants.java
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/resources/PopupDialog.java
  • bundles/com.espressif.idf.ui/OSGI-INF/l10n/bundle.properties
  • bundles/com.espressif.idf.ui/plugin.xml
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/Messages.java
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/messages.properties
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties
Additional comments (Suppressed): 13
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ParitionSizeHandler.java (3)
  • 57-61: The getPartitionTable() method now returns the output of the process as a string directly. This change seems to be fine, but ensure that all calls to this function throughout the codebase have been updated to handle the new return type.

  • 65-69: The startProcess() method has been refactored to return the started process directly instead of storing it in a local variable first. This is a good improvement as it simplifies the code and reduces unnecessary variable usage.

  • 99-105: The firePropertyChange() method call in the checkRemainingSize() method has been updated to use PopupDialog.LOW_PARTITION_SIZE.name() as the property name instead of null. This is a good change as it makes the code more readable and understandable by clearly indicating what property change event is being fired.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (5)
  • 35-35: The new button automateHintsBtn has been added to the preference page. Ensure that this button is correctly initialized and its state is properly managed.

  • 75-87: A new group for build settings has been added to the main composite of the preference page. This group contains a checkbox for enabling/disabling automated build hints. The checkbox's selection status is retrieved from the preference store. This looks good and follows the existing pattern for adding controls to the preference page.

  • 151-156: The state of the automateHintsBtn is saved in the preference store when the user clicks the OK button. This is consistent with how other preferences are saved.

  • 171-175: The performDefaults() method has been updated to reset the automateHintsBtn to its default state. This is consistent with how other preferences are reset to their default values.

  • 182-186: The initializeDefaults() method has been updated to set the default value for the AUTOMATE_BUILD_HINTS_STATUS preference. This is consistent with how other preferences are initialized.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (2)
  • 105-111: The new import import com.espressif.idf.core.util.HintsUtil; has been added. Ensure that this class is available in the project and it's correctly implemented.

  • 509-515: The shutdown method is now called on all console parsers after the process finishes. This is a good practice as it ensures that any resources held by the parsers are released.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java (1)
  • 72-88: The switch statement inside the lambda function for handling property change events has been refactored to handle two cases: LOW_PARTITION_SIZE and AVAILABLE_HINTS. Ensure that all places where these events are fired have been updated accordingly.
tests/com.espressif.idf.core.test/src/com/espressif/idf/core/build/test/EspIdfErrorParserTest.java (1)
  • 47-59: The test process_line_returns_false_if_no_hint_found_for_error_line is well written and covers the scenario where no hint is found for an error line. It's good to see that you're testing both positive and negative scenarios.
bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/EspIdfErrorParser.java (1)
  • 64-69: Ensure that the shutdown method is called at the end of each parsing session to clear the allMatchesList. If it's not called, the list will keep growing with entries from previous sessions, which could lead to incorrect results and memory issues.

Comment on lines 121 to 160
private void createColumns(Composite container)
{
TableViewerColumn col = createTableViewerColumn(titles[0]);
col.setLabelProvider(new ColumnLabelProvider()
{
@Override
public Image getImage(Object element)
{
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
}

@Override
public String getText(Object element)
{
return ((ReHintPair) element).getRe();
}
});
col = createTableViewerColumn(titles[1]);
col.setLabelProvider(new ColumnLabelProvider()
{
@Override
public Image getImage(Object element)
{
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_INFO_TSK);
}

@Override
public String getText(Object element)
{
return ((ReHintPair) element).getHint();
}
});
col.getViewer().addDoubleClickListener(event ->
{
StructuredSelection selection = (StructuredSelection) event.getViewer().getSelection();
MessageDialog.openInformation(container.getShell(), Messages.HintDetailsTitle,
((ReHintPair) selection.getFirstElement()).getHint());

});
}
Copy link

Choose a reason for hiding this comment

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

The createColumns method is creating two columns with similar properties. This code could be refactored to avoid repetition. Consider creating a method that takes the title, image, and text as parameters and creates a column.

Comment on lines 420 to 433
console.getErrorStream().write(String.format(Messages.CMakeBuildConfiguration_Failure, "")); //$NON-NLS-1$
throw new CmakeBuildException();
}

watchProcess(p, new IConsoleParser[] { epm, new StatusParser() });
boolean buildHintsStatus = Platform.getPreferencesService().getBoolean(IDFCorePlugin.PLUGIN_ID,
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_STATUS,
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_DEFAULT_STATUS, null);
IConsoleParser[] consoleParsers = buildHintsStatus
? new IConsoleParser[] { epm, new StatusParser(),
new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()))) }
: new IConsoleParser[] { epm, new StatusParser() };
watchProcess(p, consoleParsers);

final String isSkip = System.getProperty("skip.idf.components"); //$NON-NLS-1$
if (!Boolean.parseBoolean(isSkip))
Copy link

Choose a reason for hiding this comment

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

The code now checks for a preference setting to decide whether to use the EspIdfErrorParser or not. This is a good approach as it allows users to toggle the feature on/off. However, there seems to be no error handling if HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath())) fails (e.g., file not found, parsing error). Consider adding appropriate error handling here.

- new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath())))
+ List<Hint> hints = Collections.emptyList();
+ try {
+     hints = HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()));
+ } catch (Exception e) {
+     Logger.log(e);
+ }
+ new EspIdfErrorParser(hints)

Comment on lines +54 to +55
private static final String BUILDHINTS_ID = "com.espressif.idf.ui.views.buildhints"; //$NON-NLS-1$

Copy link

Choose a reason for hiding this comment

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

The constant BUILDHINTS_ID is defined but there are no comments explaining its purpose. It would be beneficial to add a comment describing what this constant represents in the context of your application.

Comment on lines +219 to +220
catch (PartInitException e)
{
Copy link

Choose a reason for hiding this comment

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

Exception logging is good, but it might be more helpful to provide some context or additional information about what operation was being attempted when the exception occurred. This can make debugging easier if an error occurs.

Comment on lines +202 to +227
@SuppressWarnings("unchecked")
private void openAvailableHintsDialog(PropertyChangeEvent evt)
{
Display.getDefault().asyncExec(() ->
{
List<ReHintPair> erroHintPairs = (List<ReHintPair>) evt.getNewValue();
// if list is empty we don't want to change focus from the console output
if (erroHintPairs.isEmpty())
{
updateValuesInBuildView(erroHintPairs);
return;
}
try
{
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView(BUILDHINTS_ID);
}
catch (PartInitException e)
{
Logger.log(e);
}
updateValuesInBuildView(erroHintPairs);
}
);

}
Copy link

Choose a reason for hiding this comment

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

This method opens a dialog with available hints. However, it seems like it's doing more than just opening a dialog. It's also updating the values in the BuildView. Consider renaming this method to better reflect its functionality or splitting it into two methods: one for opening the dialog and another for updating the BuildView.

Comment on lines +229 to +237
private void updateValuesInBuildView(List<ReHintPair> erroHintPairs)
{
BuildView view = ((BuildView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.findView(BUILDHINTS_ID));
if (view != null)
{
view.updateReHintsPairs(erroHintPairs);
}
}
Copy link

Choose a reason for hiding this comment

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

This method updates the values in the BuildView. However, it doesn't check whether the erroHintPairs parameter is null before using it. This could lead to a NullPointerException if the method is called with a null argument. Consider adding a null check at the beginning of this method.

+    if (erroHintPairs == null) {
+        throw new IllegalArgumentException("erroHintPairs cannot be null");
+    }

Comment on lines +34 to +45
void process_line_returns_true_if_hint_available_for_error_line()
{
List<ReHintPair> reHintPairs = new ArrayList<>();
reHintPairs.add(
new ReHintPair(ERROR_REGEX, StringUtil.EMPTY));
String errorLine = ERROR_LINE;
EspIdfErrorParser ep = new EspIdfErrorParser(reHintPairs);

boolean actualResult = ep.processLine(errorLine);

assertTrue(actualResult);
}
Copy link

Choose a reason for hiding this comment

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

The test process_line_returns_true_if_hint_available_for_error_line is well written and covers the scenario where a hint is available for an error line. However, it would be beneficial to also verify that the correct hint was returned. This can be done by adding an assertion to check the hint value.

Comment on lines 62 to 84
@Test
void shutdown_should_trigger_property_change_listener_with_error_hints_pairs_as_new_value()
{
List<ReHintPair> actualReHintPair = new ArrayList<>();
OpenDialogListenerSupport.getSupport().addPropertyChangeListener(evt -> {
PopupDialog popupDialog = PopupDialog.valueOf(evt.getPropertyName());
if (popupDialog.equals(PopupDialog.AVAILABLE_HINTS))
actualReHintPair.addAll((List<ReHintPair>) evt.getNewValue());
});
List<ReHintPair> reHintPairs = new ArrayList<>();
String expectedHint = EXPECTED_HINT;
reHintPairs.add(
new ReHintPair(ERROR_REGEX, expectedHint));
String errorLine = ERROR_LINE;

EspIdfErrorParser ep = new EspIdfErrorParser(reHintPairs);
boolean actualResult = ep.processLine(errorLine);
ep.shutdown();

assertTrue(actualResult);
assertEquals(expectedHint, actualReHintPair.get(0).getHint());
assertEquals(errorLine, actualReHintPair.get(0).getRe());
}
Copy link

Choose a reason for hiding this comment

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

The test shutdown_should_trigger_property_change_listener_with_error_hints_pairs_as_new_value is well written and covers the scenario where the shutdown method should trigger a property change listener with error hints pairs as new value. However, it would be beneficial to also verify that the property change listener is not triggered when there are no error hints pairs. This can be done by adding another test case.

Comment on lines +44 to +48
public EspIdfErrorParser(List<ReHintPair> reHintPairs)
{
this.reHintsList = reHintPairs;
this.allMatchesList = new ArrayList<>();
}
Copy link

Choose a reason for hiding this comment

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

The constructor EspIdfErrorParser(List<ReHintPair> reHintPairs) does not check if the passed list reHintPairs is null. This can lead to a NullPointerException in the processLine method when it tries to iterate over reHintsList. It's a good practice to validate constructor parameters to avoid potential runtime exceptions.

-    public EspIdfErrorParser(List<ReHintPair> reHintPairs)
-    {
-        this.reHintsList = reHintPairs;
-        this.allMatchesList = new ArrayList<>();
-    }
+    public EspIdfErrorParser(List<ReHintPair> reHintPairs)
+    {
+        if (reHintPairs == null) {
+            throw new IllegalArgumentException("reHintPairs cannot be null");
+        }
+        this.reHintsList = reHintPairs;
+        this.allMatchesList = new ArrayList<>();
+    }

Comment on lines 51 to 60
for (ReHintPair reHintEntry : reHintsList)
{
boolean isRegexMatchesWithProcessedString = Pattern.compile(reHintEntry.getRe()).matcher(paramString)
.find();
if (isRegexMatchesWithProcessedString)
{
allMatchesList.add(new ReHintPair(paramString, reHintEntry.getHint()));
return true;
}
}
Copy link

Choose a reason for hiding this comment

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

The regular expression pattern is compiled for every line processed, which can be inefficient if the number of lines or patterns is large. Consider compiling the patterns once during initialization and reusing them.

-    public boolean processLine(String paramString)
-    {
-        for (ReHintPair reHintEntry : reHintsList)
-        {
-            boolean isRegexMatchesWithProcessedString = Pattern.compile(reHintEntry.getRe()).matcher(paramString)
-                    .find();
-            if (isRegexMatchesWithProcessedString)
-            {
-                allMatchesList.add(new ReHintPair(paramString, reHintEntry.getHint()));
-                return true;
-            }
-        }
-        return false;
-    }
+    public boolean processLine(String paramString)
+    {
+        for (ReHintPair reHintEntry : reHintsList)
+        {
+            boolean isRegexMatchesWithProcessedString = reHintEntry.getPattern().matcher(paramString).find();
+            if (isRegexMatchesWithProcessedString)
+            {
+                allMatchesList.add(new ReHintPair(paramString, reHintEntry.getHint()));
+                return true;
+            }
+        }
+        return false;
+    }

In the above diff, I'm assuming that you will modify the ReHintPair class to store a Pattern object instead of a String for the regex. You would compile the pattern when creating the ReHintPair instance.

@coderabbitai
Copy link

coderabbitai bot commented Aug 28, 2023

Walkthrough

This change introduces automated build hints to the ESP-IDF Eclipse plugin. It adds a new preference for enabling/disabling this feature, parses console output for errors and matches them with hints, displays these hints in a new view, and provides tests for the error parser.

Changes

File Summary
.../IDFCorePreferenceConstants.java Introduced a new constant for automating build hints.
.../EspIdfErrorParser.java, .../EspIdfErrorParserTest.java Added a new class for parsing ESP-IDF errors and extracting relevant hints, along with its test cases.
.../IDFBuildConfiguration.java Modified to add a new console parser based on the preference setting.
.../PopupDialog.java, .../InitializeToolsStartup.java Added a new enum for handling different types of popup dialogs and updated the startup class accordingly.
.../ParitionSizeHandler.java Updated to handle low partition size warning.
.../bundle.properties, .../plugin.xml Added UI elements for the new build hints feature.
.../BuildView.java, .../Messages.java, .../messages.properties Created a new UI view for displaying build hints and added related messages.
.../EspresssifPreferencesPage.java, .../Messages.java, .../messages.properties Added a new preference for enabling/disabling automated build hints and updated related messages.

"With each line of code, we strive,
To make our software come alive.
With hints now automated, no more despair,
For CodeRabbit is always there! 🐇💻🎉"


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance. The bot stays silent unless called upon.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

@AndriiFilippov
Copy link
Collaborator

Hi @sigmaaa !

Tested under:
OS - Windows 10

Issue still persist.

@kolipakakondal
Copy link
Collaborator

Hi @sigmaaa !

Tested under: OS - Windows 10

Issue still persist.

Hi @sigmaaa Can you please check this issue? Let's target this for 2.11.0

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Sep 5, 2023

Hi @AndriiFilippov, @kolipakakondal,

fixed in the last commit by catching incompatible Python regex. This regex is fixed on a version higher than 5.0.3 on esp-idf side as well, that's why I was not able to reproduce this problem earlier

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

Commits Files that changed from the base of the PR and between 8bf0e70 and e252066 commits.
Files selected for processing (15)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFCorePreferenceConstants.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/EspIdfErrorParser.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (3 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/resources/PopupDialog.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ParitionSizeHandler.java (3 hunks)
  • bundles/com.espressif.idf.ui/OSGI-INF/l10n/bundle.properties (1 hunks)
  • bundles/com.espressif.idf.ui/plugin.xml (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java (6 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/BuildView.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/messages.properties (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (5 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties (1 hunks)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/build/test/EspIdfErrorParserTest.java (1 hunks)
Files skipped from review due to trivial changes (7)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/IDFCorePreferenceConstants.java
  • bundles/com.espressif.idf.ui/OSGI-INF/l10n/bundle.properties
  • bundles/com.espressif.idf.ui/plugin.xml
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/Messages.java
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/messages.properties
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/messages.properties
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/build/test/EspIdfErrorParserTest.java
Additional comments (Suppressed): 20
bundles/com.espressif.idf.core/src/com/espressif/idf/core/resources/PopupDialog.java (1)
  • 1-6: The new PopupDialog enum is introduced to manage the types of popup dialogs in the application. Ensure that all references to these dialog types throughout the codebase have been updated to use this enum.
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/EspresssifPreferencesPage.java (5)
  • 35-35: The new button automateHintsBtn is added to the class. Ensure that it is properly disposed of in the appropriate lifecycle method to prevent memory leaks.

  • 67-87: A new section for build settings is added to the main composite. The code looks good and follows the same pattern as other sections. The checkbox for automated build hints is created, its text and tooltip are set, and its initial state is retrieved from the preference store.

  • 151-156: The state of the automateHintsBtn is saved to the preference store when the user clicks the OK button. This is consistent with how other preferences are saved.

  • 171-175: The state of the automateHintsBtn is restored from the preference store when the defaults are loaded. This is consistent with how other preferences are restored.

  • 182-186: The default state of the automateHintsBtn is set in the initializeDefaults() method. This is consistent with how other default preferences are set.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/ParitionSizeHandler.java (2)
  • 63-69: The startProcess() method has been refactored to remove the creation of the Process object from the ProcessBuilder. This change simplifies the code and makes it easier to understand. However, please ensure that this change does not affect other parts of the code that may rely on the previous behavior.

  • 99-105: The property change event fired in the checkRemainingSize() method now uses a constant (PopupDialog.LOW_PARTITION_SIZE.name()) instead of null for the property name. This is a good practice as it avoids potential null pointer exceptions and makes the code more readable. Ensure that the listener for this event is updated to handle this new property name.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/InitializeToolsStartup.java (8)
  • 16-17: The import of org.eclipse.cdt.cmake.core.internal.Activator seems to be unused in the new hunks. Please verify if this is necessary or can be removed.

  • 35-48: The imports for ReHintPair, BuildView, and PopupDialog are new additions. Ensure that these classes are correctly implemented and used within the code.

  • 54-54: The constant BUILDHINTS_ID is a new addition. Make sure it's being used appropriately in the code.

  • 75-88: The property change listener has been updated to handle different types of popup dialogs. This is a good improvement as it makes the code more flexible and easier to extend with new dialog types in the future.

  • 219-220: Ensure proper error handling is in place for exceptions caught here. It might be beneficial to add some user-facing error messages or logs for debugging purposes.

  • 202-227: This method opens a dialog with available hints. The logic seems fine, but ensure that the BUILDHINTS_ID view exists and can be shown without issues.

  • 229-237: This method updates the values in the BuildView. Ensure that the updateReHintsPairs method in the BuildView class handles the list of ReHintPair objects correctly.

  • 239-246: This method opens a dialog warning about low partition size. The implementation looks correct.

bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/IDFBuildConfiguration.java (2)
  • 105-109: The new import import com.espressif.idf.core.util.HintsUtil; is added to use the HintsUtil class. Ensure that this class exists and is accessible from this package.

  • 512-512: The shutdown method is now called on all console parsers after the build process completes. This is a good practice as it ensures any resources held by the parsers are released promptly.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/preferences/Messages.java (2)
  • 8-8: The new string EspresssifPreferencesPage_BuildGroupTxt is added. Ensure that this string is properly initialized and used in the appropriate context.

  • 12-13: Two new strings EspresssifPreferencesPage_SearchHintsCheckBtn and EspresssifPreferencesPage_SearchHintsTooltip are introduced for the checkbox to enable or disable automated build hints. Make sure these strings are correctly initialized and used where the checkbox is defined.

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

Commits Files that changed from the base of the PR and between e252066 and c96ba4b commits.
Files selected for processing (6)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/EspIdfErrorParser.java (1 hunks)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ReHintPair.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/BuildView.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/HintsView.java (5 hunks)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/build/test/EspIdfErrorParserTest.java (1 hunks)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/HintsUtilTest.java (2 hunks)
Files skipped from review due to trivial changes (1)
  • tests/com.espressif.idf.core.test/src/com/espressif/idf/core/util/test/HintsUtilTest.java
Additional comments (Suppressed): 4
bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ReHintPair.java (1)
  • 35-38: The method getRe() now returns an Optional<Pattern>, which is a good practice for handling null values. However, ensure that all calls to this method throughout the codebase have been updated to handle the returned Optional.
tests/com.espressif.idf.core.test/src/com/espressif/idf/core/build/test/EspIdfErrorParserTest.java (1)
  • 47-59: The test process_line_returns_false_if_no_hint_found_for_error_line correctly checks the case where no hint is found for an error line. Good job on covering this edge case.
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/dialogs/HintsView.java (2)
  • 11-24: The import statements are well organized and necessary for the functionality of the class. The removal of unused imports improves the readability and maintainability of the code.

  • 33-38: The addition of import com.espressif.idf.core.util.StringUtil; is a good practice as it provides utility methods for string manipulation which can be used throughout the class. The rest of the changes in this hunk do not alter the functionality of the code.

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Sep 6, 2023

Hi @kolipakakondal, @alirana01, @AndriiFilippov
I also added the commit with the optimization of pattern compilation by refactoring the ReHintPair class. The idea is to compile all regular expressions only once. Please, take a look

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

Commits Files that changed from the base of the PR and between c96ba4b and 4394945 commits.
Files selected for processing (1)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ReHintPair.java (1 hunks)
Additional comments (Suppressed): 1
bundles/com.espressif.idf.core/src/com/espressif/idf/core/build/ReHintPair.java (1)
  • 36-39: The getRe() method now returns an Optional<Pattern>, which is a good practice for handling potential null values. Ensure that all calls to this method throughout the codebase have been updated to handle the returned Optional.

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi !

Tested under:
OS - Windows 10 / MacOS / Linux Ubuntu 20.04

ESP-IDF: v5.0 - v5.1

release 5.1 / 5.1.1 / release 5.0 / 5.0.3 - able to enable / disable hint feature. able to see useful hints.

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 kolipakakondal merged commit 31b7055 into master Sep 13, 2023
7 checks passed
@kolipakakondal kolipakakondal deleted the IEP-1018 branch September 13, 2023 06:05
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.

3 participants