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 @@ -27,6 +27,8 @@ public class IDFCorePreferenceConstants
public static final String CMAKE_CCACHE_STATUS = "cmakeCCacheStatus"; //$NON-NLS-1$
public static final String AUTOMATE_BUILD_HINTS_STATUS = "automateHintsStatus"; //$NON-NLS-1$
public static final String HIDE_ERRORS_IDF_COMPONENTS = "hideErrorsOnIdfDerivedFiles"; //$NON-NLS-1$
public static final String AUTOMATE_CLANGD_FORMAT_FILE = "automateClangFormatFileCreation"; //$NON-NLS-1$
public static final boolean AUTOMATE_CLANGD_FORMAT_FILE_DEFAULT = true;
public static final boolean CMAKE_CCACHE_DEFAULT_STATUS = true;
public static final boolean AUTOMATE_BUILD_HINTS_DEFAULT_STATUS = true;
public static final boolean HIDE_ERRORS_IDF_COMPONENTS_DEFAULT_STATUS = true;
Expand All @@ -40,6 +42,7 @@ public class IDFCorePreferenceConstants
public static final String IDF_TOOLS_PATH_DEFAULT = Platform.getOS().equals(Platform.OS_WIN32)
? IDFUtil.resolveEnvVariable("%USERPROFILE%\\.espressif") //$NON-NLS-1$
: IDFUtil.resolveEnvVariable("$HOME/.espressif"); //$NON-NLS-1$

/**
* Returns the node in the preference in the given context.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Platform;

import com.espressif.idf.core.IDFCorePlugin;
import com.espressif.idf.core.IDFCorePreferenceConstants;
import com.espressif.idf.core.ILSPConstants;

public class ClangFormatFileHandler
Expand All @@ -30,7 +33,8 @@ public ClangFormatFileHandler(IProject project) throws CoreException
*/
public void update() throws IOException, CoreException
{
if (clangFormatFile.exists())

if (!shouldCreateClangFormat())
{
return;
}
Expand All @@ -39,4 +43,11 @@ public void update() throws IOException, CoreException
clangFormatFile.create(source, true, new NullProgressMonitor());
}
}

private boolean shouldCreateClangFormat()
{
return !clangFormatFile.exists() && Platform.getPreferencesService().getBoolean(IDFCorePlugin.PLUGIN_ID,
IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE,
IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE_DEFAULT, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class EspresssifPreferencesPage extends PreferencePage implements IWorkbe
private Combo gitAssetsCombo;
private Combo pythonWheelCombo;
private Text idfToolsPathText;
private Button automateClangdFormatCreationBtn;

public EspresssifPreferencesPage()
{
Expand Down Expand Up @@ -81,9 +82,24 @@ protected Control createContents(Composite parent)

addToolsInstallationSettings(mainComposite);

addClangdSettings(mainComposite);
return mainComposite;
}

private void addClangdSettings(Composite mainComposite)
{
Group clangdOptionsGroup = new Group(mainComposite, SWT.SHADOW_ETCHED_IN);
clangdOptionsGroup.setText(Messages.EspresssifPreferencesPage_ClangdSettingsGroupName);
clangdOptionsGroup.setLayout(new GridLayout(1, false));

automateClangdFormatCreationBtn = new Button(clangdOptionsGroup, SWT.CHECK);
automateClangdFormatCreationBtn.setText(Messages.EspresssifPreferencesPage_AutoCreateClangFormatBtnName);
automateClangdFormatCreationBtn
.setToolTipText(Messages.EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg);
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
}

private void addToolsInstallationSettings(Composite mainComposite)
{
Group toolsInstallationGroup = new Group(mainComposite, SWT.SHADOW_ETCHED_IN);
Expand All @@ -93,15 +109,17 @@ private void addToolsInstallationSettings(Composite mainComposite)
Label githubAssetsLabel = new Label(toolsInstallationGroup, SWT.NONE);
githubAssetsLabel.setText(Messages.EspressifPreferencesPage_ToolsInstallationGitAssetUrlLabel);
gitAssetsCombo = new Combo(toolsInstallationGroup, SWT.DROP_DOWN | SWT.BORDER);
gitAssetsCombo.setItems(IDFCorePreferenceConstants.IDF_GITHUB_ASSETS_DEFAULT_GLOBAL, IDFCorePreferenceConstants.IDF_GITHUB_ASSETS_DEFAULT_CHINA);
gitAssetsCombo.setItems(IDFCorePreferenceConstants.IDF_GITHUB_ASSETS_DEFAULT_GLOBAL,
IDFCorePreferenceConstants.IDF_GITHUB_ASSETS_DEFAULT_CHINA);
gitAssetsCombo.select(0);

Label pythonWheelsLabel = new Label(toolsInstallationGroup, SWT.NONE);
pythonWheelsLabel.setText(Messages.EspressifPreferencesPage_ToolsInstallationPythonPyWheelUrlLabel);
pythonWheelCombo = new Combo(toolsInstallationGroup, SWT.DROP_DOWN | SWT.BORDER);
pythonWheelCombo.setItems(IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL_DEFAULT_GLOBAL, IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL_DEFAULT_CHINA);
pythonWheelCombo.select(0);

pythonWheelCombo.setItems(IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL_DEFAULT_GLOBAL,
IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL_DEFAULT_CHINA);
pythonWheelCombo.select(0);

GridData gitTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
gitTextGridData.widthHint = 200;
GridData pythonTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
Expand All @@ -115,37 +133,36 @@ private void addToolsInstallationSettings(Composite mainComposite)
GridData idfToolsPathTextGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
idfToolsPathTextGridData.widthHint = 200;
idfToolsPathText.setLayoutData(idfToolsPathTextGridData);
// Add browse button
Button browseButtonIdfToolsPath = new Button(toolsInstallationGroup, SWT.PUSH);
browseButtonIdfToolsPath.setText(Messages.EspressifPreferencesPage_DirectorySelectionIDFToolsPathBrowseButton);
browseButtonIdfToolsPath.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(mainComposite.getShell());
dialog.setText(Messages.EspressifPreferencesPage_DirectorySelectionIDFToolsPathTitle);
dialog.setMessage(Messages.EspressifPreferencesPage_DirectorySelectionIDFToolsPathMessage);
String dir = dialog.open();
if (dir != null) {
idfToolsPathText.setText(dir);
}
}
});

// Add browse button
Button browseButtonIdfToolsPath = new Button(toolsInstallationGroup, SWT.PUSH);
browseButtonIdfToolsPath.setText(Messages.EspressifPreferencesPage_DirectorySelectionIDFToolsPathBrowseButton);
browseButtonIdfToolsPath.addSelectionListener(new SelectionAdapter()
{
@Override
public void widgetSelected(SelectionEvent e)
{
DirectoryDialog dialog = new DirectoryDialog(mainComposite.getShell());
dialog.setText(Messages.EspressifPreferencesPage_DirectorySelectionIDFToolsPathTitle);
dialog.setMessage(Messages.EspressifPreferencesPage_DirectorySelectionIDFToolsPathMessage);
String dir = dialog.open();
if (dir != null)
{
idfToolsPathText.setText(dir);
}
}
});

String idfToolsPath = getPreferenceStore().getString(IDFCorePreferenceConstants.IDF_TOOLS_PATH);
idfToolsPath = StringUtil.isEmpty(idfToolsPath)
? getPreferenceStore().getDefaultString(IDFCorePreferenceConstants.IDF_TOOLS_PATH)
: idfToolsPath;
idfToolsPathText.setText(idfToolsPath);

String gitUrl = getPreferenceStore().getString(IDFCorePreferenceConstants.IDF_GITHUB_ASSETS);
String pyWheelUrl = getPreferenceStore().getString(IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL);
gitUrl = StringUtil.isEmpty(gitUrl)
? gitAssetsCombo.getItem(0)
: gitUrl;
pyWheelUrl = StringUtil.isEmpty(pyWheelUrl)
? pythonWheelCombo.getItem(0)
: pyWheelUrl;

gitUrl = StringUtil.isEmpty(gitUrl) ? gitAssetsCombo.getItem(0) : gitUrl;
pyWheelUrl = StringUtil.isEmpty(pyWheelUrl) ? pythonWheelCombo.getItem(0) : pyWheelUrl;

gitAssetsCombo.setText(gitUrl);
pythonWheelCombo.setText(pyWheelUrl);
}
Expand Down Expand Up @@ -240,20 +257,24 @@ public boolean performOk()
getPreferenceStore().setValue(IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_STATUS,
automateHintsBtn.getSelection());

boolean prevMarkerValue = getPreferenceStore().getBoolean(IDFCorePreferenceConstants.HIDE_ERRORS_IDF_COMPONENTS);
boolean prevMarkerValue = getPreferenceStore()
.getBoolean(IDFCorePreferenceConstants.HIDE_ERRORS_IDF_COMPONENTS);
getPreferenceStore().setValue(IDFCorePreferenceConstants.HIDE_ERRORS_IDF_COMPONENTS,
hideErrorsOnIdfComponentsBtn.getSelection());
// need to initiate a cleanup for initial clean of markers after they are enabled
if (!prevMarkerValue && hideErrorsOnIdfComponentsBtn.getSelection())
{
IDFCorePlugin.ERROR_MARKER_LISTENER.initialMarkerCleanup();
}

getPreferenceStore().setValue(IDFCorePreferenceConstants.IDF_GITHUB_ASSETS, gitAssetsCombo.getText());

getPreferenceStore().setValue(IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL, pythonWheelCombo.getText());

getPreferenceStore().setValue(IDFCorePreferenceConstants.IDF_TOOLS_PATH, idfToolsPathText.getText());

getPreferenceStore().setValue(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE,
automateClangdFormatCreationBtn.getSelection());
}
catch (Exception e)
{
Expand All @@ -275,6 +296,8 @@ protected void performDefaults()
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_STATUS));
hideErrorsOnIdfComponentsBtn
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.HIDE_ERRORS_IDF_COMPONENTS));
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
Comment on lines +299 to +300
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use getDefaultBoolean for resetting to default value.

When resetting to defaults, use getDefaultBoolean instead of getBoolean to ensure the correct default value is used.

Apply this diff to fix the issue:

-				.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
+				.setSelection(getPreferenceStore().getDefaultBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
📝 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
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));
automateClangdFormatCreationBtn
.setSelection(getPreferenceStore().getDefaultBoolean(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE));

gitAssetsCombo.setText(gitAssetsCombo.getItem(0));
pythonWheelCombo.setText(pythonWheelCombo.getItem(0));
idfToolsPathText.setText(getPreferenceStore().getDefaultString(IDFCorePreferenceConstants.IDF_TOOLS_PATH));
Expand All @@ -291,9 +314,14 @@ private void initializeDefaults()
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_DEFAULT_STATUS);
getPreferenceStore().setDefault(IDFCorePreferenceConstants.HIDE_ERRORS_IDF_COMPONENTS,
IDFCorePreferenceConstants.HIDE_ERRORS_IDF_COMPONENTS_DEFAULT_STATUS);

getPreferenceStore().setDefault(IDFCorePreferenceConstants.IDF_GITHUB_ASSETS, IDFCorePreferenceConstants.IDF_GITHUB_ASSETS_DEFAULT_GLOBAL);
getPreferenceStore().setDefault(IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL, IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL_DEFAULT_GLOBAL);
getPreferenceStore().setDefault(IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFCorePreferenceConstants.IDF_TOOLS_PATH_DEFAULT);

getPreferenceStore().setDefault(IDFCorePreferenceConstants.IDF_GITHUB_ASSETS,
IDFCorePreferenceConstants.IDF_GITHUB_ASSETS_DEFAULT_GLOBAL);
getPreferenceStore().setDefault(IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL,
IDFCorePreferenceConstants.PIP_EXTRA_INDEX_URL_DEFAULT_GLOBAL);
getPreferenceStore().setDefault(IDFCorePreferenceConstants.IDF_TOOLS_PATH,
IDFCorePreferenceConstants.IDF_TOOLS_PATH_DEFAULT);
getPreferenceStore().setDefault(IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE,
IDFCorePreferenceConstants.AUTOMATE_CLANGD_FORMAT_FILE_DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
public class Messages extends NLS
{
private static final String BUNDLE_NAME = "com.espressif.idf.ui.preferences.messages"; //$NON-NLS-1$
public static String EspresssifPreferencesPage_AutoCreateClangFormatBtnName;
public static String EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg;
public static String EspresssifPreferencesPage_BuildGroupTxt;
public static String EspresssifPreferencesPage_CCacheToolTip;
public static String EspresssifPreferencesPage_ClangdSettingsGroupName;
public static String EspresssifPreferencesPage_EnableCCache;
public static String EspresssifPreferencesPage_IDFSpecificPrefs;
public static String EspresssifPreferencesPage_SearchHintsCheckBtn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
EspresssifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg=Ensures .clang-format exists, generating it if missing after project creation and on each build.
Comment on lines +1 to +2
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix spelling and improve message organization.

  1. The key prefix has a spelling error: "Espresssif" should be "Espressif" (3 's' vs 2 's').
  2. Consider moving these entries near other build-related settings for better organization.
  3. The tooltip message could be more concise.

Apply this diff to fix the issues:

-EspresssifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
-EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg=Ensures .clang-format exists, generating it if missing after project creation and on each build.
+EspressifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
+EspressifPreferencesPage_AutoCreateClangFormatTooltipMsg=Automatically generate .clang-format file if missing during project creation and builds.

Move these entries after line 3 (EspresssifPreferencesPage_BuildGroupTxt) to group them with other build-related settings.

📝 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
EspresssifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
EspresssifPreferencesPage_AutoCreateClangFormatTooltipMsg=Ensures .clang-format exists, generating it if missing after project creation and on each build.
# ... (other entries before line 3 remain unchanged)
EspresssifPreferencesPage_BuildGroupTxt=Build Settings
EspressifPreferencesPage_AutoCreateClangFormatBtnName=Auto-create .clang-format
EspressifPreferencesPage_AutoCreateClangFormatTooltipMsg=Automatically generate .clang-format file if missing during project creation and builds.
# ... (any entries after remain unchanged)

EspresssifPreferencesPage_BuildGroupTxt=Build Settings
EspresssifPreferencesPage_CCacheToolTip=This sets CCACHE_ENABLE=1 to the IDF CMake build, if the CCache tool is installed
EspresssifPreferencesPage_ClangdSettingsGroupName=Clangd Settings
EspresssifPreferencesPage_EnableCCache=Enable Ccache
EspresssifPreferencesPage_IDFSpecificPrefs=ESP-IDF Specific Preferences.
EspresssifPreferencesPage_SearchHintsCheckBtn=Search hints for build errors (may affect build performance)
Expand Down
13 changes: 13 additions & 0 deletions docs_readme/clangd_cdt_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,16 @@ If, for some reason, it is not disabled, please follow the steps below to disabl


![](images/clangd/cdt_indexer_disable.png)
```


## Automatic .clang-format Creation

To ensure consistent code formatting across all projects, including those imported from the old plugin 2.x version, Espressif-IDE automatically creates a .clang-format file for each project.

If you want to disable this option or enable this functionality manually, follow these steps:

1. Go to Window > Preferences > Espressif
2. Locate the `Auto-create .clang-format` option
3. Enable or disable the option as needed.
4. Click on `Apply and Close`.
Loading