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-1336 Convert partitions.csv or nvs.csv model windows to editors #1070

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

sigmaaa
Copy link
Collaborator

@sigmaaa sigmaaa commented Oct 25, 2024

Description

To avoid overriding and adjusting a lot of code, I'm using MultiPageEditor as a handler to call a TitleAreaDialog.

Fixes # (IEP-1336)

Type of change

Please delete options that are not relevant.

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

How has this been tested?

  • Use the NVS table editor and partition table editor In the old way once to create nvs.csv and partititons.csv
  • Verify it opens and works correctly with double click, similar to sdkconfig

Test Configuration:

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

Dependent components impacted by this PR:

  • NVS table editor
  • Partition table editor

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

    • Introduced two new editors: NVS Table Editor and Partition Table Editor.
    • Added support for new content types for handling .nvs.csv and .partitions.csv files.
  • Improvements

    • Enhanced command and menu structures to integrate new editors and functionalities, improving user accessibility.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request focus on enhancing the Espressif IDF UI plugin by introducing two new editors, NvsEditor and PartitionTableEditor, along with their corresponding content types for handling nvs.csv and partitions.csv files. The plugin.xml file has been updated to include these new elements, and new commands related to the editors have been added. Additionally, two Java classes implementing the editors have been created, featuring basic structures and error handling, although the functionality remains to be fully developed.

Changes

File Path Change Summary
bundles/com.espressif.idf.ui/plugin.xml Added NvsEditor and PartitionTableEditor entries; defined content types for nvs.csv and partitions.csv. Updated command and menu contributions.
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/nvs/dialog/NvsEditor.java Introduced NvsEditor class extending MultiPageEditorPart with basic methods and error handling.
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/partitiontable/dialog/PartitionTableEditor.java Introduced PartitionTableEditor class extending MultiPageEditorPart with similar structure and error handling.

Suggested reviewers

  • AndriiFilippov
  • kolipakakondal
  • alirana01

🐰 In the garden where editors bloom,
New tools emerge to dispel the gloom.
NVS and partitions, a pair so bright,
Crafting with ease, bringing delight.
With every click, our work will soar,
Hopping to features we've longed for! 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (1)
bundles/com.espressif.idf.ui/plugin.xml (1)

716-735: Consider externalizing editor names for internationalization.

The editor names "NVS Table Editor" and "Partition Table Editor" are hardcoded. Consider using externalized strings (e.g., %editor.name.nvs and %editor.name.partition) to support internationalization.

-        name="NVS Table Editor">
+        name="%editor.name.nvs">
-        name="Partition Table Editor">
+        name="%editor.name.partition">
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1a6fb43 and 3b470ba.

📒 Files selected for processing (3)
  • bundles/com.espressif.idf.ui/plugin.xml (2 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/nvs/dialog/NvsEditor.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/partitiontable/dialog/PartitionTableEditor.java (1 hunks)
🔇 Additional comments (4)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/nvs/dialog/NvsEditor.java (1)

1-50: Verify editor registration for nvs.csv files.

Let's ensure the editor is properly registered in plugin.xml for handling nvs.csv files.

bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/partitiontable/dialog/PartitionTableEditor.java (3)

1-11: LGTM: Class structure aligns with requirements

The class correctly extends MultiPageEditorPart and includes necessary imports.


30-46: Implement or document save behavior requirements

The save-related methods are currently TODO stubs. If this editor is meant to be temporary (as suggested by the immediate closure), we should either:

  1. Document why save functionality isn't needed, or
  2. Implement proper save behavior if required

Would you like me to help implement the save functionality or create a GitHub issue to track this requirement?

Let's check if save functionality is implemented in related editors:


25-28: ⚠️ Potential issue

Clarify the purpose of immediate editor closure

The current implementation of createPages() immediately closes the editor, which seems counterintuitive. If this is intentional behavior (e.g., if the editor is meant to be temporary), it should be documented.

Let's check if this pattern is used elsewhere in the codebase:

Consider these improvements:

  1. Add documentation explaining why the editor is closed immediately
  2. Ensure proper cleanup of resources
  3. Consider adding a user-friendly message explaining why the editor was closed
+ /**
+  * Creates the pages of the editor.
+  * Note: This implementation immediately closes the editor because [explain reason].
+  */
  protected void createPages()
  {
+   // Ensure cleanup of any resources
+   dispose();
    getSite().getPage().closeEditor(this, false);
  }

Comment on lines 1 to 50
package com.espressif.idf.ui.nvs.dialog;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.part.MultiPageEditorPart;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.ui.nvs.handlers.NvsEditorHandler;

public class NvsEditor extends MultiPageEditorPart
{

public NvsEditor()
{
try
{
new NvsEditorHandler().execute(null);
}
catch (ExecutionException e)
{
Logger.log(e);
}

}

protected void createPages()
{
// TODO Auto-generated method stub
getSite().getPage().closeEditor(this, false);
}

public void doSave(IProgressMonitor monitor)
{
// TODO Auto-generated method stub

}

public void doSaveAs()
{
// TODO Auto-generated method stub

}

public boolean isSaveAsAllowed()
{
// TODO Auto-generated method stub
return false;
}

}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add essential editor lifecycle methods.

The editor is missing several essential methods for proper lifecycle management.

Consider adding these methods:

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    if (!(input instanceof IFileEditorInput)) {
        throw new PartInitException("Invalid input: Must be IFileEditorInput");
    }
    super.init(site, input);
    setPartName(input.getName());
}

@Override
public boolean isDirty() {
    // Implement dirty state tracking
    return false;
}

@Override
public void setFocus() {
    // Set focus to the active page
    getContainer().setFocus();
}

@Override
public void dispose() {
    // Clean up resources
    super.dispose();
}

Comment on lines 26 to 30
protected void createPages()
{
// TODO Auto-generated method stub
getSite().getPage().closeEditor(this, false);
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement proper page creation instead of closing the editor.

The current implementation defeats the purpose of the editor by immediately closing it. According to the PR objectives, this should create a TitleAreaDialog for NVS table editing.

Consider this implementation:

 protected void createPages()
 {
-    // TODO Auto-generated method stub
-    getSite().getPage().closeEditor(this, false);
+    try {
+        // Create the dialog page
+        NvsTableDialog dialog = new NvsTableDialog(getSite().getShell());
+        int page = addPage(dialog.createDialogArea(getContainer()));
+        setPageText(page, "NVS Table Editor");
+    } catch (Exception e) {
+        Logger.log("Failed to create NVS editor pages", e);
+        MessageDialog.openError(
+            getSite().getShell(),
+            "Page Creation Error",
+            "Failed to create editor pages: " + e.getMessage());
+    }
 }

Committable suggestion was skipped due to low confidence.

Comment on lines +10 to +11
public class NvsEditor extends MultiPageEditorPart
{
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider implementing essential editor interfaces.

The editor should implement IReusableEditor if it's meant to be reused for different inputs, and ISaveablePart for proper integration with Eclipse's save lifecycle.

-public class NvsEditor extends MultiPageEditorPart
+public class NvsEditor extends MultiPageEditorPart implements IReusableEditor

Committable suggestion was skipped due to low confidence.

Comment on lines 32 to 48
public void doSave(IProgressMonitor monitor)
{
// TODO Auto-generated method stub

}

public void doSaveAs()
{
// TODO Auto-generated method stub

}

public boolean isSaveAsAllowed()
{
// TODO Auto-generated method stub
return false;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Implement proper save functionality.

The editor is missing proper save functionality which is essential for editing nvs.csv files.

Consider implementing these methods:

 public void doSave(IProgressMonitor monitor)
 {
-    // TODO Auto-generated method stub
+    try {
+        // Get the editor's input file
+        IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+        // Save the NVS table data
+        saveNvsTableData(file, monitor);
+        // Mark editor as not dirty
+        firePropertyChange(PROP_DIRTY);
+    } catch (Exception e) {
+        Logger.log("Failed to save NVS table", e);
+        MessageDialog.openError(
+            getSite().getShell(),
+            "Save Error",
+            "Failed to save NVS table: " + e.getMessage());
+    }
 }

 public void doSaveAs()
 {
-    // TODO Auto-generated method stub
+    // Implement if needed in future
 }

 public boolean isSaveAsAllowed()
 {
-    // TODO Auto-generated method stub
-    return false;
+    return false; // Save As not supported for NVS tables
 }

Committable suggestion was skipped due to low confidence.

Comment on lines 13 to 24
public NvsEditor()
{
try
{
new NvsEditorHandler().execute(null);
}
catch (ExecutionException 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.

⚠️ Potential issue

Refactor constructor implementation.

The current implementation has several issues:

  1. Executing the handler in the constructor violates separation of concerns and could cause issues during editor initialization
  2. Silent error handling could mask critical issues
  3. Missing call to super()

Consider this refactoring:

 public NvsEditor()
 {
+    super();
+ }
+
+ @Override
+ protected void init() {
     try
     {
         new NvsEditorHandler().execute(null);
     }
     catch (ExecutionException e)
     {
-        Logger.log(e);
+        Logger.log("Failed to initialize NVS editor", e);
+        MessageDialog.openError(
+            getSite().getShell(),
+            "NVS Editor Error",
+            "Failed to initialize the NVS editor: " + e.getMessage());
     }
 }

Committable suggestion was skipped due to low confidence.

Comment on lines 13 to 23
public PartitionTableEditor()
{
try
{
new PartitionTableEditorHandler().execute(null);
}
catch (ExecutionException 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.

⚠️ Potential issue

Refactor constructor to improve error handling and separation of concerns

The current implementation has several issues:

  1. Executing the handler in the constructor violates separation of concerns and could lead to issues during editor initialization
  2. Silent error handling could mask critical issues from users
  3. If execution fails, resources might not be properly cleaned up

Consider this alternative implementation:

- public PartitionTableEditor()
- {
-   try
-   {
-     new PartitionTableEditorHandler().execute(null);
-   }
-   catch (ExecutionException e)
-   {
-     Logger.log(e);
-   }
- }
+ public PartitionTableEditor() {
+   // Initialize editor resources here
+ }
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input) 
+     throws PartInitException {
+   super.init(site, input);
+   try {
+     new PartitionTableEditorHandler().execute(null);
+   } catch (ExecutionException e) {
+     Logger.log(e);
+     throw new PartInitException("Failed to initialize Partition Table Editor", e);
+   }
+ }

Committable suggestion was skipped due to low confidence.

Comment on lines +841 to +852
<content-type
file-patterns="nvs.csv"
id="com.espressif.idf.ui.nvs_editor_content_type"
name="NVS Table"
priority="normal">
</content-type>
<content-type
file-patterns="partitions.csv"
id="com.espressif.idf.ui.partition_editor_content_type"
name="Partition Table"
priority="normal">
</content-type>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance content type declarations.

Consider the following improvements:

  1. Remove redundant priority="normal" as it's the default value
  2. Add base-type="org.eclipse.core.runtime.text" to inherit text file behavior
  <content-type
        file-patterns="nvs.csv"
        id="com.espressif.idf.ui.nvs_editor_content_type"
        name="NVS Table"
-        priority="normal">
+        base-type="org.eclipse.core.runtime.text">
  </content-type>
  <content-type
        file-patterns="partitions.csv"
        id="com.espressif.idf.ui.partition_editor_content_type"
        name="Partition Table"
-        priority="normal">
+        base-type="org.eclipse.core.runtime.text">
  </content-type>
📝 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
<content-type
file-patterns="nvs.csv"
id="com.espressif.idf.ui.nvs_editor_content_type"
name="NVS Table"
priority="normal">
</content-type>
<content-type
file-patterns="partitions.csv"
id="com.espressif.idf.ui.partition_editor_content_type"
name="Partition Table"
priority="normal">
</content-type>
<content-type
file-patterns="nvs.csv"
id="com.espressif.idf.ui.nvs_editor_content_type"
name="NVS Table"
base-type="org.eclipse.core.runtime.text">
</content-type>
<content-type
file-patterns="partitions.csv"
id="com.espressif.idf.ui.partition_editor_content_type"
name="Partition Table"
base-type="org.eclipse.core.runtime.text">
</content-type>

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.

Thanks for the PR. LGTM.

Can you check the errors reported in the error log while opening these files.

java.lang.NullPointerException: Cannot invoke "org.eclipse.e4.core.contexts.IEclipseContext.createChild(String)" because "parentContext" is null
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:630)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:762)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:727)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:711)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.createElement(PartServiceImpl.java:1314)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:797)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1271)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3228)
	at org.eclipse.ui.internal.WorkbenchPage.lambda$11(WorkbenchPage.java:3118)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3116)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3086)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3077)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:546)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:506)
	at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:370)
	at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:172)
	at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:288)
	at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:254)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:274)
	at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:252)
	at org.eclipse.jdt.internal.ui.navigator.OpenAndExpand.run(OpenAndExpand.java:53)
	at org.eclipse.ui.actions.RetargetAction.run(RetargetAction.java:215)
	at org.eclipse.ui.navigator.CommonNavigatorManager$1.open(CommonNavigatorManager.java:184)
	at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
	at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:799)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174)
	at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:796)
	at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1110)
	at org.eclipse.ui.navigator.CommonViewer.handleOpen(CommonViewer.java:451)
	at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:295)
	at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:330)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:91)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4660)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1622)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1645)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1630)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1392)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4427)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:4003)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1151)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1042)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:152)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:639)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:546)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:173)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:668)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:605)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1481)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1454)

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi

Confirm errors
logs.log

@sigmaaa
Copy link
Collaborator Author

sigmaaa commented Nov 4, 2024

Hi @kolipakakondal, @AndriiFilippov

I've added a workaround (adding empty page) to close the editor without exception in the last commit

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

Reviewing files that changed from the base of the PR and between 3b470ba and 835a677.

📒 Files selected for processing (2)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/nvs/dialog/NvsEditor.java (1 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/partitiontable/dialog/PartitionTableEditor.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/partitiontable/dialog/PartitionTableEditor.java
🔇 Additional comments (1)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/nvs/dialog/NvsEditor.java (1)

1-55: Verify editor registration and file association.

To ensure the editor works with double-clicking nvs.csv files as mentioned in PR objectives, we need to verify the plugin.xml configuration.

✅ Verification successful

Editor registration and file association are properly configured

The NVS editor is correctly registered in plugin.xml with:

  • Editor class registration pointing to com.espressif.idf.ui.nvs.dialog.NvsEditor
  • Content type binding for nvs.csv files via com.espressif.idf.ui.nvs_editor_content_type
  • Proper icon and name configuration
  • Content type definition with file pattern nvs.csv
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify editor registration and file association in plugin.xml

# Test 1: Check editor registration
echo "Checking editor registration..."
rg -A 5 '<editor.*class="com\.espressif\.idf\.ui\.nvs\.dialog\.NvsEditor"' plugin.xml

# Test 2: Check content type association
echo "Checking content type association..."
rg -A 5 '<content-type.*file-patterns="nvs\.csv"' plugin.xml

# Test 3: Check file extension association
echo "Checking file extension association..."
rg -A 5 '<fileTypes.*extension="csv"' plugin.xml

Length of output: 597


Script:

#!/bin/bash
# Search for plugin.xml files in the repository
echo "Searching for plugin.xml files..."
fd "plugin.xml"

# After finding the correct path, let's check editor registration
echo -e "\nChecking editor registration in all plugin.xml files..."
fd "plugin.xml" --exec rg -A 5 '<editor.*class="com\.espressif\.idf\.ui\.nvs\.dialog\.NvsEditor"' {}

# Check content type and file associations
echo -e "\nChecking content type and file associations..."
fd "plugin.xml" --exec rg -A 5 'nvs\.csv|\.csv' {}

Length of output: 1649


Script:

#!/bin/bash
# Let's specifically check the UI plugin.xml since that's where our editor is located
echo "Checking com.espressif.idf.ui/plugin.xml for editor and extension configurations..."
cat bundles/com.espressif.idf.ui/plugin.xml

# Also check for any editor associations in plugin.xml
echo -e "\nChecking for editor associations in plugin.xml..."
rg -A 10 '<editor' bundles/com.espressif.idf.ui/plugin.xml

Length of output: 26913

Comment on lines +15 to +28
public NvsEditor()
{
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
try
{
new NvsEditorHandler().execute(null);
}
catch (ExecutionException 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.

⚠️ Potential issue

Critical: Constructor implementation has severe issues.

The current constructor implementation has several critical problems:

  1. Executing async code in constructor violates object lifecycle management
  2. Missing required super() call
  3. Silent error handling masks issues from users
  4. Handler execution belongs in editor initialization, not construction

Apply this refactoring to fix the issues:

 public NvsEditor()
 {
-    PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
-        try
-        {
-            new NvsEditorHandler().execute(null);
-        }
-        catch (ExecutionException e)
-        {
-            Logger.log(e);
-        }
-    });
+    super();
+}
+
+@Override
+protected void init() {
+    try {
+        new NvsEditorHandler().execute(null);
+    }
+    catch (ExecutionException e) {
+        Logger.log("Failed to initialize NVS editor", e);
+        MessageDialog.openError(
+            getSite().getShell(),
+            "Editor Initialization Error",
+            "Failed to initialize the NVS editor: " + e.getMessage());
+    }
 }
📝 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 NvsEditor()
{
PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
try
{
new NvsEditorHandler().execute(null);
}
catch (ExecutionException e)
{
Logger.log(e);
}
});
}
public NvsEditor()
{
super();
}
@Override
protected void init() {
try {
new NvsEditorHandler().execute(null);
}
catch (ExecutionException e) {
Logger.log("Failed to initialize NVS editor", e);
MessageDialog.openError(
getSite().getShell(),
"Editor Initialization Error",
"Failed to initialize the NVS editor: " + e.getMessage());
}
}

Comment on lines +30 to +38
protected void createPages()
{
Composite emptyPage = new Composite(getContainer(), SWT.NONE);

int index = addPage(emptyPage);
setPageText(index, "Empty Page"); //$NON-NLS-1$
getSite().getShell().getDisplay().asyncExec(() -> getSite().getPage().closeEditor(this, false));

}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Page creation implementation contradicts PR objectives.

The current implementation creates an empty page and immediately closes the editor, which:

  1. Contradicts the PR objective of using TitleAreaDialog for NVS table editing
  2. Creates poor UX by showing and immediately closing the editor
  3. Makes the editor effectively non-functional

Implement proper dialog-based editing as per PR objectives:

 protected void createPages()
 {
-    Composite emptyPage = new Composite(getContainer(), SWT.NONE);
-
-    int index = addPage(emptyPage);
-    setPageText(index, "Empty Page"); //$NON-NLS-1$
-    getSite().getShell().getDisplay().asyncExec(() -> getSite().getPage().closeEditor(this, false));
+    try {
+        // Create dialog page using TitleAreaDialog as per PR objectives
+        NvsTableDialog dialog = new NvsTableDialog(getSite().getShell());
+        Composite dialogArea = dialog.createDialogArea(getContainer());
+        
+        int index = addPage(dialogArea);
+        setPageText(index, "NVS Table Editor");
+        
+        // Initialize the dialog with file content
+        IFile file = ((IFileEditorInput) getEditorInput()).getFile();
+        dialog.initializeFromFile(file);
+    } catch (Exception e) {
+        Logger.log("Failed to create NVS editor page", e);
+        MessageDialog.openError(
+            getSite().getShell(),
+            "Editor Error",
+            "Failed to create editor page: " + e.getMessage());
+    }
 }

Committable suggestion skipped: line range outside the PR's diff.

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

@AndriiFilippov
Copy link
Collaborator

@sigmaaa hi !

Tested under:
OS - Windows 11 / Mac arm64
ESP-IDF: v5.3.1

able to open with double click both NVS and Partition.
all functionality is working. able to add / delete / save.
No error logs.
Screenshot 2024-11-06 at 14 59 00

LGTM 👍

@sigmaaa sigmaaa merged commit 56fcb66 into master Nov 6, 2024
2 of 4 checks passed
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