Skip to content

Commit

Permalink
IEP-1371 Language Server hangs on 28% when a project contains spaces (#…
Browse files Browse the repository at this point in the history
…1086)

* fix: enclousing build folder path in quotation marks

* fix: splitting clangd additional options only by newline
  • Loading branch information
sigmaaa authored Dec 17, 2024
1 parent ef6fb5e commit 7c5fe56
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ public ICMakeToolChainFile getToolChainFile() throws CoreException
IToolChain toolChain = getToolChain();
if (toolChain == null)
{
throw new CoreException(new Status(IStatus.ERROR, IDFCorePlugin.PLUGIN_ID, Messages.IDFToolChainsMissingErrorMsg));
throw new CoreException(
new Status(IStatus.ERROR, IDFCorePlugin.PLUGIN_ID, Messages.IDFToolChainsMissingErrorMsg));
}
this.toolChainFile = manager.getToolChainFileFor(toolChain);
return toolChainFile;
Expand Down Expand Up @@ -395,8 +396,6 @@ private boolean buildPrechecks(IConsole console) throws Exception

return false;
}



return true;
}
Expand Down Expand Up @@ -430,10 +429,10 @@ private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IP
}
}
}

envVars.add(new EnvironmentVariable(IDFCorePreferenceConstants.IDF_TOOLS_PATH,
IDFUtil.getIDFToolsPathFromPreferences()));

String buildCommand = getProperty(BUILD_COMMAND);
if (buildCommand.isBlank())
{
Expand Down Expand Up @@ -536,7 +535,7 @@ private void runCmakeCommand(IConsole console, IProgressMonitor monitor, IProjec
{
command.add("-DIDF_TOOLCHAIN=clang"); //$NON-NLS-1$
}

String userArgs = getProperty(CMAKE_ARGUMENTS);
if (userArgs != null && !userArgs.isBlank())
{
Expand All @@ -554,10 +553,11 @@ private void runCmakeCommand(IConsole console, IProgressMonitor monitor, IProjec
// Set PYTHONUNBUFFERED to 1/TRUE to dump the messages back immediately without
// buffering
IEnvironmentVariable bufferEnvVar = new EnvironmentVariable("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
IEnvironmentVariable idfToolsPathEnvVar = new EnvironmentVariable(IDFCorePreferenceConstants.IDF_TOOLS_PATH, IDFUtil.getIDFToolsPathFromPreferences());
IEnvironmentVariable idfToolsPathEnvVar = new EnvironmentVariable(IDFCorePreferenceConstants.IDF_TOOLS_PATH,
IDFUtil.getIDFToolsPathFromPreferences());

Process p = startBuildProcess(command, new IEnvironmentVariable[] { bufferEnvVar, idfToolsPathEnvVar }, workingDir, errConsole,
monitor);
Process p = startBuildProcess(command, new IEnvironmentVariable[] { bufferEnvVar, idfToolsPathEnvVar },
workingDir, errConsole, monitor);
if (p == null)
{
console.getErrorStream().write(String.format(Messages.CMakeBuildConfiguration_Failure, "")); //$NON-NLS-1$
Expand Down
4 changes: 2 additions & 2 deletions bundles/com.espressif.idf.lsp/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ 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
Service-Component: OSGI-INF/com.espressif.idf.lsp.preferences.IDFClangdEnable.xml,OSGI-INF/com.espressif.idf.lsp.preferences.IDFClangdOptionsDefaults.xml,
OSGI-INF/com.espressif.idf.lsp.preferences.IDFClangdConfigurationAccess.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="com.espressif.idf.lsp.preferences.IDFClangdConfigurationAccess">
<property name="service.ranking" type="Integer" value="100"/>
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdConfiguration"/>
</service>
<reference cardinality="1..1" field="metadata" interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata" name="metadata"/>
<reference cardinality="1..1" field="workspace" interface="org.eclipse.core.resources.IWorkspace" name="workspace"/>
<implementation class="com.espressif.idf.lsp.preferences.IDFClangdConfigurationAccess"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.espressif.idf.lsp.preferences;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.clangd.ClangdQualifier;
import org.eclipse.cdt.lsp.config.ConfigurationAccess;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IPreferenceMetadataStore;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore;
import org.eclipse.osgi.util.NLS;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component(service = ClangdConfiguration.class, property = "service.ranking:Integer=100")
public class IDFClangdConfigurationAccess extends ConfigurationAccess implements ClangdConfiguration
{

@Reference
private ClangdMetadata metadata;

@Reference
private IWorkspace workspace;

public IDFClangdConfigurationAccess()
{
super(new ClangdQualifier().get());
}

@Override
public ClangdMetadata metadata()
{
return metadata;
}

@Override
public ClangdOptions defaults()
{
return new IDFClangdPreferredOptions(qualifier, new IScopeContext[] { DefaultScope.INSTANCE }, metadata);
}

@Override
public ClangdOptions options(Object context)
{
Optional<ProjectScope> project = projectScope(workspace, context);
IScopeContext[] scopes;
if (project.isPresent())
{
scopes = new IScopeContext[] { project.get(), InstanceScope.INSTANCE, DefaultScope.INSTANCE };
}
else
{
scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE };
}
return new IDFClangdPreferredOptions(qualifier, scopes, metadata);

}

@Override
public IPreferenceMetadataStore storage(Object context)
{
return new OsgiPreferenceMetadataStore(//
preferences(//
projectScope(workspace, context)//
.map(IScopeContext.class::cast)//
.orElse(InstanceScope.INSTANCE)));
}

@Override
public String qualifier()
{
return qualifier;
}

@Override
public List<String> commands(Object context)
{
ClangdOptions options = options(context);
List<String> list = new ArrayList<>();
list.add(options.clangdPath());
if (options.useTidy())
{
list.add("--clang-tidy"); //$NON-NLS-1$
}
if (options.useBackgroundIndex())
{
list.add("--background-index"); //$NON-NLS-1$
}
if (!options.completionStyle().isBlank())
{
list.add(NLS.bind("--completion-style={0}", options.completionStyle())); //$NON-NLS-1$
}
if (options.prettyPrint())
{
list.add("--pretty"); //$NON-NLS-1$
}
if (!options.queryDriver().isBlank())
{
list.add(NLS.bind("--query-driver={0}", options.queryDriver())); //$NON-NLS-1$
}

list.addAll(options.additionalOptions());
return list;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package com.espressif.idf.lsp.preferences;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;

public class IDFClangdPreferredOptions implements ClangdOptions
{
private final String qualifier;
private final IScopeContext[] scopes;
private final ClangdMetadata metadata;

IDFClangdPreferredOptions(String qualifier, IScopeContext[] scopes, ClangdMetadata metadata)
{
this.qualifier = Objects.requireNonNull(qualifier);
this.scopes = Objects.requireNonNull(scopes);
this.metadata = Objects.requireNonNull(metadata);
}

@Override
public String clangdPath()
{
return stringValue(metadata.clangdPath());
}

@Override
public boolean useTidy()
{
return booleanValue(metadata.useTidy());
}

@Override
public boolean useBackgroundIndex()
{
return booleanValue(metadata.useBackgroundIndex());
}

@Override
public String completionStyle()
{
return stringValue(metadata.completionStyle());
}

@Override
public boolean prettyPrint()
{
return booleanValue(metadata.prettyPrint());
}

@Override
public String queryDriver()
{
return stringValue(metadata.queryDriver());
}

@Override
public List<String> additionalOptions()
{
var options = stringValue(metadata.additionalOptions());
if (options.isBlank())
{
return new ArrayList<>();
}
return Arrays.asList(options.split(System.lineSeparator()));
}

private String stringValue(PreferenceMetadata<?> meta)
{
String actual = String.valueOf(meta.defaultValue());
for (int i = scopes.length - 1; i >= 0; i--)
{
IScopeContext scope = scopes[i];
String previous = actual;
actual = scope.getNode(qualifier).get(meta.identifer(), previous);
}
return actual;
}

private boolean booleanValue(PreferenceMetadata<Boolean> meta)
{
return Optional.of(meta)//
.map(this::stringValue)//
.map(Boolean::valueOf)//
.orElseGet(meta::defaultValue);
}

}

0 comments on commit 7c5fe56

Please sign in to comment.