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-1212 Headers unresolved after build Custom Build Folder #961

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.lsp;
package com.espressif.idf.core;

/**
* @author Kondal Kolipaka <kondal.kolipaka@espressif.com>
*/
public interface ILSPConstants
{
String CLANGD_EXECUTABLE = "clangd"; //$NON-NLS-1$
String CLANGD_CONFIG_FILE = ".clangd"; // $NON-NLS-1$
String CLANGD_CONFIG_FILE = ".clangd"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.stream.Stream;

import org.eclipse.cdt.build.gcc.core.ClangToolChain;
import org.eclipse.cdt.build.gcc.core.GCCToolChain;
import org.eclipse.cdt.cmake.core.ICMakeToolChainFile;
import org.eclipse.cdt.cmake.core.ICMakeToolChainManager;
import org.eclipse.cdt.cmake.core.internal.CMakeUtils;
Expand Down Expand Up @@ -84,6 +85,7 @@
import com.espressif.idf.core.internal.CMakeConsoleWrapper;
import com.espressif.idf.core.internal.CMakeErrorParser;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.ClangdConfigFileHandler;
import com.espressif.idf.core.util.DfuCommandsUtil;
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.IDFUtil;
Expand Down Expand Up @@ -322,7 +324,7 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
runCmakeCommand(console, monitor, project, generator, infoStream, buildDir);
}
runCmakeBuildCommand(console, monitor, project, start, generator, infoStream, buildDir);

new ClangdConfigFileHandler().update(project);
return new IProject[] { project };
}
catch (Exception e)
Expand Down Expand Up @@ -414,27 +416,35 @@ private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IP
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
ParitionSizeHandler paritionSizeHandler = new ParitionSizeHandler(project, infoStream, console);
paritionSizeHandler.startCheckingSize();

writeConsoleNotes(infoStream);

if (getToolChain() instanceof GCCToolChain toolchain)
writeConsoleNotes(infoStream, workingDir.toOSString(), toolchain.getPath().toString());

}

infoStream.write(MessageFormat.format("Total time taken to build the project: {0} ms", timeElapsed)); //$NON-NLS-1$
}
}

private void writeConsoleNotes(ConsoleOutputStream infoStream) throws IOException

private void writeConsoleNotes(ConsoleOutputStream infoStream, String workingDir, String toolchainPath)
throws IOException
{
infoStream.write("clangd Troubleshooting:"); //$NON-NLS-1$
infoStream.write("\n");//$NON-NLS-1$
infoStream.write(
"1. If there are any unresolved header issues, please check the query driver configured in Preferences > C/C++ > Build > Editor(LSP) > clangd and" //$NON-NLS-1$
+ "\n set the correct Drivers path. This should always point to the current target toolchain you're using." //$NON-NLS-1$
+ "\n For example, if you are building for esp32, it should point to /user/path/.espressif/tools/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc."); //$NON-NLS-1$
infoStream.write(String.format(
"""
1. If there are any unresolved header issues, please check the query driver configured in Preferences > C/C++ > Build > Editor(LSP) > clangd and
set the correct Drivers path. This should always point to the current target toolchain you're using.
. For example, if you are building for the current target, it should point to %s""", //$NON-NLS-1$
toolchainPath));
infoStream.write("\n");//$NON-NLS-1$
infoStream.write("\n");//$NON-NLS-1$
infoStream.write(
"2. To enable source code navigation (i.e., navigation to .c files), you need to set compile-commands-cmd argument to clangd with the build folder." //$NON-NLS-1$
+ "\n To do this, navigate to Preferences > C/C++ > Build > Editor(LSP) > clangd and set --compile-commands-cmd=/user/path/workspace/project/build in the additional arguments text area."); //$NON-NLS-1$
+ String.format(
"%nTo do this, navigate to Preferences > C/C++ > Build > Editor(LSP) > clangd and set --compile-commands-cmd=%s in the additional arguments text area.", //$NON-NLS-1$
workingDir));
infoStream.write("\n");//$NON-NLS-1$
}

private void runCmakeCommand(IConsole console, IProgressMonitor monitor, IProject project, String generator,
Expand Down Expand Up @@ -605,7 +615,6 @@ public IToolChain getToolChain() throws CoreException
return matchedToolChains.stream().findAny().orElse(toolChainManager.getToolChain(typeId, id));
}


@Override
public void clean(IConsole console, IProgressMonitor monitor) throws CoreException
{
Expand Down Expand Up @@ -672,7 +681,6 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
}
}


/**
* Recursively removes any files and directories found below the specified Path.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.lsp;
package com.espressif.idf.core.util;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -19,8 +19,13 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.QualifiedName;
import org.yaml.snakeyaml.Yaml;

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

/**
* @author Kondal Kolipaka <kondal.kolipaka@espressif.com>
*/
Expand All @@ -40,13 +45,14 @@ public void update(IProject project) throws CoreException, IOException
Map<String, Object> data = createOrGetExistingYamlStructure(obj);

// Add or update CompileFlags section
Map<String, Object> compileFlags = (Map<String, Object>) data.get("CompileFlags");
Map<String, Object> compileFlags = (Map<String, Object>) data.get("CompileFlags"); //$NON-NLS-1$
if (compileFlags == null)
{
compileFlags = new LinkedHashMap<>();
data.put("CompileFlags", compileFlags); //$NON-NLS-1$
}
updateCompileFlagsSection(compileFlags);
updateCompileFlagsSection(compileFlags, project
.getPersistentProperty(new QualifiedName(IDFCorePlugin.PLUGIN_ID, IDFConstants.BUILD_DIR_PROPERTY)));

// Write updated clangd back to file
try (Writer writer = new FileWriter(file))
Expand All @@ -69,10 +75,10 @@ private Map<String, Object> createOrGetExistingYamlStructure(Object obj)
return new LinkedHashMap<>();
}

private void updateCompileFlagsSection(Map<String, Object> compileFlags)
private void updateCompileFlagsSection(Map<String, Object> compileFlags, String buildFolderName)
{
compileFlags.put("CompilationDatabase", "build"); //$NON-NLS-1$ //$NON-NLS-2$
compileFlags.put("Remove", Arrays.asList("-m*", "-f*")); //$NON-NLS-1$ //$NON-NLS-2$
compileFlags.put("CompilationDatabase", buildFolderName.isEmpty() ? "build" : buildFolderName); //$NON-NLS-1$ //$NON-NLS-2$
compileFlags.put("Remove", Arrays.asList("-m*", "-f*")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

private File getClangdConfigFile(IProject project) throws IOException, CoreException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults;
import org.osgi.service.component.annotations.Component;

import com.espressif.idf.core.ILSPConstants;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.lsp.ILSPConstants;

/**
* @author Kondal Kolipaka <kondal.kolipaka@espressif.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.eclipse.ui.IPageLayout;

import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.lsp.ClangdConfigFileHandler;
import com.espressif.idf.core.util.ClangdConfigFileHandler;

/**
* @author Kondal Kolipaka <kondal.kolipaka@espressif.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
import com.espressif.idf.core.IDFConstants;
import com.espressif.idf.core.build.IDFLaunchConstants;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.ClangdConfigFileHandler;
import com.espressif.idf.core.util.LaunchUtil;
import com.espressif.idf.lsp.ClangdConfigFileHandler;
import com.espressif.idf.ui.UIPlugin;
import com.espressif.idf.ui.handlers.EclipseHandler;
import com.espressif.idf.ui.handlers.NewProjectHandlerUtil;
Expand Down
Loading