-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IEP-1371 Language Server hangs on 28% when a project contains spaces (#…
…1086) * fix: enclousing build folder path in quotation marks * fix: splitting clangd additional options only by newline
- Loading branch information
Showing
5 changed files
with
229 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...essif.idf.lsp/OSGI-INF/com.espressif.idf.lsp.preferences.IDFClangdConfigurationAccess.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
114 changes: 114 additions & 0 deletions
114
...espressif.idf.lsp/src/com/espressif/idf/lsp/preferences/IDFClangdConfigurationAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
...om.espressif.idf.lsp/src/com/espressif/idf/lsp/preferences/IDFClangdPreferredOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |