Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
5 changes: 4 additions & 1 deletion bundles/com.espressif.idf.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ Export-Package: com.espressif.idf.core,
com.espressif.idf.core.util,
com.espressif.idf.core.variable,
org.json.simple,
org.json.simple.parser
org.json.simple.parser,
org.yaml.snakeyaml,
org.yaml.snakeyaml.parser,
org.yaml.snakeyaml.util
Bundle-ClassPath: .,
lib/json-simple-1.1.1.jar,
lib/commons-collections4-4.4.jar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ public File findDebugger(String target)
.map(espToolChainElement -> findToolChain(getAllPaths(), espToolChainElement.debuggerPattern))
.findFirst().orElse(null);
}

public File findCompiler(String target)
{
return toolchainElements.values().stream()
.filter(espToolChainElement -> espToolChainElement.name.equals(target))
.map(espToolChainElement -> findToolChain(getAllPaths(), espToolChainElement.compilerPattern))
.findFirst().orElse(null);
}

public File findToolChain(List<String> paths, String filePattern)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,21 @@ public static String getXtensaToolchainExecutablePath(IProject project)
}
return getXtensaToolchainExecutablePathByTarget(projectEspTarget);
}

public static String getXtensaToolchainExePathForActiveTarget()
{
String target = IDFUtil.getCurrentTarget();
if (target != null)
{
File file = new ESPToolChainManager().findCompiler(target);
if (file != null)
{
return file.getAbsolutePath();
}

}
return null;
}

public static String getXtensaToolchainExecutablePathByTarget(String projectEspTarget)
{
Expand Down
7 changes: 7 additions & 0 deletions bundles/com.espressif.idf.lsp/.classpath
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we need to change a lot of our classpath files to have Java 17 you can see the warnings when building.
We can have a separate ticket for this

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions bundles/com.espressif.idf.lsp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target/
/bin/
33 changes: 33 additions & 0 deletions bundles/com.espressif.idf.lsp/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.espressif.idf.lsp</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17
23 changes: 23 additions & 0 deletions bundles/com.espressif.idf.lsp/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.espressif.idf.lsp;singleton:=true
Bundle-Vendor: ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD
Bundle-Version: 1.0.1.qualifier
Export-Package: com.espressif.idf.lsp
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.cdt.lsp.clangd,
org.eclipse.core.resources,
org.eclipse.cdt.lsp,
com.espressif.idf.core,
org.eclipse.cdt.core,
org.apache.batik.i18n;bundle-version="1.16.0",
org.apache.batik.css;bundle-version="1.16.0",
org.apache.batik.util;bundle-version="1.16.0",
org.apache.batik.constants;bundle-version="1.16.0"
Bundle-RequiredExecutionEnvironment: JavaSE-17
Automatic-Module-Name: com.espressif.idf.lsp
Bundle-ActivationPolicy: lazy
Bundle-Name: ESP-IDF LSP Plugin
Service-Component: OSGI-INF/com.espressif.idf.lsp.preferences.IDFClangdEnable.xml,
OSGI-INF/com.espressif.idf.lsp.preferences.IDFClangdOptionsDefaults.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.espressif.idf.lsp.preferences.IDFClangdEnable">
<property name="service.ranking" type="Integer" value="100"/>
<service>
<provide interface="org.eclipse.cdt.lsp.editor.LanguageServerEnable"/>
</service>
<implementation class="com.espressif.idf.lsp.preferences.IDFClangdEnable"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.espressif.idf.lsp.preferences.IDFClangdOptionsDefaults">
<property name="service.ranking" type="Integer" value="100"/>
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults"/>
</service>
<implementation class="com.espressif.idf.lsp.preferences.IDFClangdOptionsDefaults"/>
</scr:component>
18 changes: 18 additions & 0 deletions bundles/com.espressif.idf.lsp/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
###############################################################################
# Copyright (c) 2023 Contributors to the Eclipse Foundation.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0/.
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# See git history
###############################################################################

bin.includes = META-INF/,\
.,\
OSGI-INF/
source.. = src/
output.. = bin/
15 changes: 15 additions & 0 deletions bundles/com.espressif.idf.lsp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.espressif.idf.lsp</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>com.espressif.idf</groupId>
<artifactId>com.espressif.idf.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.lsp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.yaml.snakeyaml.Yaml;

import com.espressif.idf.core.logging.Logger;

/**
* @author Kondal Kolipaka <kondal.kolipaka@espressif.com>
*/
public class ClangdConfigFileHandler
{
@SuppressWarnings("unchecked")
public void update(IProject project) throws FileNotFoundException
{
File file = getClangdConfigFile(project);

// Load existing clangd file
FileInputStream inputStream = new FileInputStream(file);
Yaml yaml = new Yaml();
Object obj = yaml.load(inputStream);
if (obj instanceof Map)
{
Map<String, Object> data = (Map<String, Object>) obj;

// Add new attribute to CompileFlags
Map<String, Object> compileFlags = (Map<String, Object>) data.get("CompileFlags"); //$NON-NLS-1$
compileFlags.put("Remove", new String[] { "-m*", "-f*" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

// Write updated clangd back to file
try (Writer writer = new FileWriter(file))
{
yaml.dump(data, writer);
}
catch (IOException e)
{
Logger.log("Error writing .clangd file: " + e.getMessage()); //$NON-NLS-1$
}
}
else
{
Logger.log("Invalid .clangd file format."); //$NON-NLS-1$
}
}

private File getClangdConfigFile(IProject project)
{
// Path to the existing clangd file
IFile file = project.getFile(ILSPConstants.CLANGD_CONFIG_FILE);
return file.getLocation().toFile();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*******************************************************************************
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.lsp;

/**
* @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$
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.lsp.preferences;

import org.eclipse.cdt.lsp.editor.LanguageServerEnable;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.osgi.service.component.annotations.Component;

import com.espressif.idf.core.IDFProjectNature;
import com.espressif.idf.core.logging.Logger;

/**
* @author Kondal Kolipaka <kondal.kolipaka@espressif.com>
*/
@Component(property = { "service.ranking:Integer=100" })
public class IDFClangdEnable implements LanguageServerEnable
{

@Override
public boolean isEnabledFor(IProject project)
{
if (project != null)
{
try
{
return project.hasNature(IDFProjectNature.ID); // IDF nature
}
catch (CoreException e)
{
Logger.log(e);
}
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright 2024 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.lsp.preferences;

import java.util.Optional;

import org.eclipse.cdt.lsp.clangd.BuiltinClangdOptionsDefaults;
import org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults;
import org.osgi.service.component.annotations.Component;

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>
*
*/
@SuppressWarnings("restriction")
@Component(service = ClangdOptionsDefaults.class, property = { "service.ranking:Integer=100" })
public class IDFClangdOptionsDefaults extends BuiltinClangdOptionsDefaults
{

@Override
public String clangdPath()
{
String clandPath = IDFUtil.findCommandFromBuildEnvPath(ILSPConstants.CLANGD_EXECUTABLE);
Logger.log("clangd: " + clandPath); //$NON-NLS-1$
return Optional.ofNullable(clandPath).orElse(ILSPConstants.CLANGD_EXECUTABLE);
}

@Override
public String queryDriver()
{

String driverpath = IDFUtil.getXtensaToolchainExePathForActiveTarget();
Logger.log("queryDriver: " + driverpath); //$NON-NLS-1$
return Optional.ofNullable(driverpath).orElse(""); //$NON-NLS-1$

}

}
5 changes: 4 additions & 1 deletion bundles/com.espressif.idf.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tools.templates.core,
org.eclipse.tools.templates.ui,
org.freemarker.freemarker,
org.eclipse.tools.templates.freemarker
org.eclipse.tools.templates.freemarker,
org.eclipse.cdt.lsp;bundle-version="1.0.0",
org.eclipse.cdt.lsp.clangd;bundle-version="1.0.0",
com.espressif.idf.lsp
Automatic-Module-Name: com.espressif.idf.ui
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
Expand Down
Loading