Skip to content
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 @@ -16,6 +16,7 @@ public interface IJsonServerConfig
String VISIBLE = "visible"; //$NON-NLS-1$
String RANGES = "ranges"; //$NON-NLS-1$
String VERSION = "version"; //$NON-NLS-1$
String DEFAULTS = "defaults"; //$NON-NLS-1$

// data types
String HEX_TYPE = "hex"; //$NON-NLS-1$
Expand All @@ -29,6 +30,7 @@ public interface IJsonServerConfig
String SET = "set"; //$NON-NLS-1$
String SAVE = "save"; //$NON-NLS-1$
String LOAD = "load"; //$NON-NLS-1$
String RESET = "reset"; //$NON-NLS-1$

String COMPONENT_CONFIG_TITLE = "Component config"; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class KConfigMenuItem
private String type;
private String id;
private boolean isMenuConfig;
private boolean isDefault;

public KConfigMenuItem(KConfigMenuItem parent)
{
Expand Down Expand Up @@ -173,5 +174,21 @@ private boolean isVisible(JSONObject visibleJsonMap, String configKey)
return visibleJsonMap.get(configKey) != null ? (boolean) visibleJsonMap.get(configKey) : false;
}

public boolean isDefault()
{
return isDefault;
}

public void setDefault(boolean isDefault)
{
this.isDefault = isDefault;
}

}
public void updateDefaultState(JSONObject defaultsJsonMap)
{
if (defaultsJsonMap != null && defaultsJsonMap.containsKey(getId()))
{
this.isDefault = (boolean) defaultsJsonMap.get(getId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public enum CommandType
*/
SET,

RESET,

/**
* To represent server connection is closed
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public interface IJsonConfigOutput
*/
public JSONObject getRangesJsonMap();

public JSONObject getDefaultsJsonMap();

public long getVersion();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public class JsonConfigOutput implements IJsonConfigOutput
private JSONObject valuesJsonMap;
private JSONObject visibleJsonMap;
private JSONObject rangesJsonMap;
private JSONObject defaultsJsonMap;
private long version = 1;

@Override
public long getVersion()
{
return version;
}

@Override
public JSONObject getValuesJsonMap()
Expand Down Expand Up @@ -56,12 +64,18 @@ public void parse(String response, boolean isUpdate) throws ParseException
JSONObject jsonObj = (JSONObject) parser.parse(response);
if (jsonObj != null)
{
if (jsonObj.containsKey(IJsonServerConfig.VERSION))
{
version = (long) jsonObj.get(IJsonServerConfig.VERSION);
}

if (isUpdate)
{
// newly updated values and visible items
JSONObject visibleJson = (JSONObject) jsonObj.get(IJsonServerConfig.VISIBLE);
JSONObject valuesJson = (JSONObject) jsonObj.get(IJsonServerConfig.VALUES);
JSONObject rangesJson = (JSONObject) jsonObj.get(IJsonServerConfig.RANGES);
JSONObject defaultsJson = (JSONObject) jsonObj.get(IJsonServerConfig.DEFAULTS);

// Updated visible items
Set<String> newVisibleKeyset = visibleJson.keySet();
Expand Down Expand Up @@ -89,9 +103,15 @@ public void parse(String response, boolean isUpdate) throws ParseException
valuesJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.VALUES);
visibleJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.VISIBLE);
rangesJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.RANGES);
defaultsJsonMap = (JSONObject) jsonObj.get(IJsonServerConfig.DEFAULTS);
}
}

}

public JSONObject getDefaultsJsonMap()
{
return defaultsJsonMap;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ public JsonConfigServer(IProject project, IFile file)
this.file = file;
}

public void resetElementById(String id)
{
String resetRequest = String.format("{\"version\": 3, \"reset\": [\"%s\"]}", id);
execute(resetRequest, CommandType.RESET);
}

public void resetElementChildren(List<String> children)
{
if (children == null || children.isEmpty())
{
return;
}

String joinedIds = String.join("\", \"", children);
String resetRequest = String.format("{\"version\": 3, \"reset\": [\"%s\"]}", joinedIds);
execute(resetRequest, CommandType.RESET);
}

@Override
public void addListener(IMessageHandlerListener listener)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,20 @@ protected boolean isValidJson(String output)
{
String jsonOutput = new JsonConfigProcessor().getInitialOutput(output);
if (StringUtil.isEmpty(jsonOutput))
{
return false;
}

try
{
JSONObject jsonObj = (JSONObject) new JSONParser().parse(jsonOutput);
if (jsonObj != null)
{
if (jsonObj.get(IJsonServerConfig.VISIBLE) != null && jsonObj.get(IJsonServerConfig.VALUES) != null
&& jsonObj.get(IJsonServerConfig.RANGES) != null)
{
return true;
}
return jsonObj.containsKey(IJsonServerConfig.VERSION) && jsonObj.containsKey(IJsonServerConfig.VALUES);
Comment on lines 205 to +210
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Keep version optional in response validation.

JsonConfigOutput already falls back to protocol version 1 when the field is missing. Making VERSION mandatory here means older config-server payloads never reach notifyHandler(...), so the editor just times out instead of loading.

Possible fix
-				return jsonObj.containsKey(IJsonServerConfig.VERSION) && jsonObj.containsKey(IJsonServerConfig.VALUES);
+				return jsonObj.containsKey(IJsonServerConfig.VALUES);
📝 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
try
{
JSONObject jsonObj = (JSONObject) new JSONParser().parse(jsonOutput);
if (jsonObj != null)
{
if (jsonObj.get(IJsonServerConfig.VISIBLE) != null && jsonObj.get(IJsonServerConfig.VALUES) != null
&& jsonObj.get(IJsonServerConfig.RANGES) != null)
{
return true;
}
return jsonObj.containsKey(IJsonServerConfig.VERSION) && jsonObj.containsKey(IJsonServerConfig.VALUES);
try
{
JSONObject jsonObj = (JSONObject) new JSONParser().parse(jsonOutput);
if (jsonObj != null)
{
return jsonObj.containsKey(IJsonServerConfig.VALUES);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@bundles/com.espressif.idf.sdk.config.core/src/com/espressif/idf/sdk/config/core/server/JsonConfigServerRunnable.java`
around lines 205 - 210, The current validation in JsonConfigServerRunnable that
returns only when both IJsonServerConfig.VERSION and IJsonServerConfig.VALUES
are present should be relaxed so VERSION is optional; update the check in the
JSON parsing logic to require only IJsonServerConfig.VALUES (leave
IJsonServerConfig.VERSION optional because JsonConfigOutput falls back to
protocol version 1) so the parsed payload is passed through to
notifyHandler(...); modify the condition that references
IJsonServerConfig.VERSION and IJsonServerConfig.VALUES to only assert the
presence of IJsonServerConfig.VALUES.

}
}
catch (ParseException e)
{
return false;
}

return false;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.espressif.idf.sdk.config.ui;

import org.json.simple.JSONObject;

import com.espressif.idf.sdk.config.core.KConfigMenuItem;

public interface ConfigActionHandler
{
void onCommandExecuted(JSONObject jsonMap);

void onTextModified(String key, Object value);

void onResetRequested(String key);

void onMenuResetRequested(KConfigMenuItem menu);
}
Loading
Loading