Skip to content

Commit

Permalink
[405] fix broken ClangdOptionsDefault (#406)
Browse files Browse the repository at this point in the history
fixes #405 

Co-authored-by: Jonah Graham <[email protected]>
  • Loading branch information
ghentschke and jonahgraham authored Jan 30, 2025
1 parent ddd803d commit 0d89d8a
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 122 deletions.
19 changes: 19 additions & 0 deletions bundles/org.eclipse.cdt.lsp.clangd/.settings/.api_filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<component id="org.eclipse.cdt.lsp.clangd" version="2">
<resource path="src/org/eclipse/cdt/lsp/clangd/ClangdMetadata.java" type="org.eclipse.cdt.lsp.clangd.ClangdMetadata">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.lsp.clangd.ClangdMetadata"/>
<message_argument value="logToConsole()"/>
</message_arguments>
</filter>
</resource>
<resource path="src/org/eclipse/cdt/lsp/clangd/ClangdOptions.java" type="org.eclipse.cdt.lsp.clangd.ClangdOptions">
<filter id="404000815">
<message_arguments>
<message_argument value="org.eclipse.cdt.lsp.clangd.ClangdOptions"/>
<message_argument value="logToConsole()"/>
</message_arguments>
</filter>
</resource>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.lsp.clangd.internal.config.BuiltinClangdOptionsDefaults">
<property name="service.ranking" type="Integer" value="0"/>
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults"/>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults"/>
</service>
<implementation class="org.eclipse.cdt.lsp.clangd.internal.config.BuiltinClangdOptionsDefaults"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdConfiguration"/>
</service>
<reference cardinality="1..1" field="metadata" interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata2" name="metadata"/>
<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="org.eclipse.cdt.lsp.clangd.internal.config.ClangdConfigurationAccess"/>
</scr:component>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="org.eclipse.cdt.lsp.clangd.internal.config.ClangdMetadataDefaults">
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata2"/>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata"/>
</service>
<reference cardinality="1..1" field="defaults" interface="org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults" name="defaults"/>
<reference cardinality="1..1" field="defaults" interface="org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults" name="defaults"/>
<implementation class="org.eclipse.cdt.lsp.clangd.internal.config.ClangdMetadataDefaults"/>
</scr:component>
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,21 @@ public interface ClangdMetadata {
*/
PreferenceMetadata<String> additionalOptions();

/**
* Returns the metadata for the "Log to Console" option, must not return <code>null</code>.
*
* @return the metadata for the "Log to Console" option
*
* @see ClangdOptions#logToConsole()
*
* @since 2.2
*/
default PreferenceMetadata<Boolean> logToConsole() {
return new PreferenceMetadata<>(Boolean.class, //
"log_to_console", //$NON-NLS-1$
false, //
"Log to Console", // //$NON-NLS-1$
"Log to Console"); //$NON-NLS-1$
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ public interface ClangdOptions {
*/
List<String> additionalOptions();

/**
* Enable logging to Clangd console
*
* @return true if clangd logging is enabled
*
* @since 2.2
*/
default boolean logToConsole() {
return false;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;
import java.util.Optional;

import org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults;
import org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.runtime.IPath;
import org.osgi.service.component.annotations.Component;
Expand All @@ -25,7 +25,7 @@
* Provides the default clangd options for cdt-lsp.
*/
@Component(property = { "service.ranking:Integer=0" })
public class BuiltinClangdOptionsDefaults implements ClangdOptions2Defaults {
public class BuiltinClangdOptionsDefaults implements ClangdOptionsDefaults {

@Override
public String clangdPath() {
Expand Down Expand Up @@ -66,9 +66,4 @@ public String queryDriver() {
public List<String> additionalOptions() {
return Collections.emptyList();
}

@Override
public boolean logToConsole() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import java.util.Optional;

import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2;
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;
Expand All @@ -37,7 +37,7 @@
public final class ClangdConfigurationAccess extends ConfigurationAccess implements ClangdConfiguration {

@Reference
private ClangdMetadata2 metadata;
private ClangdMetadata metadata;

@Reference
private IWorkspace workspace;
Expand All @@ -47,17 +47,17 @@ public ClangdConfigurationAccess() {
}

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

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

@Override
public ClangdOptions2 options(Object context) {
public ClangdOptions options(Object context) {
Optional<ProjectScope> project = projectScope(workspace, context);
IScopeContext[] scopes;
if (project.isPresent()) {
Expand All @@ -84,7 +84,7 @@ public String qualifier() {

@Override
public List<String> commands(Object context) {
ClangdOptions2 options = options(context);
ClangdOptions options = options(context);
List<String> list = new ArrayList<>();
list.add(options.clangdPath());
if (options.useTidy()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdFallbackFlags;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.config.Configuration;
import org.eclipse.cdt.lsp.editor.LanguageServerEnable;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider3;
Expand Down Expand Up @@ -74,7 +74,8 @@ public boolean isEnabledFor(IProject project) {
@Override
public boolean logToConsole() {
boolean[] enabled = new boolean[1];
configuration.call(c -> enabled[0] = ((ClangdOptions2) c.options(null)).logToConsole());
configuration
.call(c -> enabled[0] = c.options(null) instanceof ClangdOptions copt ? copt.logToConsole() : false);
return enabled[0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

import java.util.stream.Collectors;

import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults;
import org.eclipse.cdt.lsp.clangd.internal.ui.LspEditorUiMessages;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component
public class ClangdMetadataDefaults implements ClangdMetadata2 {
public final class ClangdMetadataDefaults implements ClangdMetadata {

@Reference
private ClangdOptions2Defaults defaults;
private ClangdOptionsDefaults defaults;

@Override
public PreferenceMetadata<String> clangdPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package org.eclipse.cdt.lsp.clangd.internal.config;

import org.eclipse.cdt.lsp.clangd.ClangdConfiguration;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.core.runtime.ServiceCaller;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.core.runtime.preferences.DefaultScope;
Expand All @@ -28,7 +28,7 @@ public void initializeDefaultPreferences() {
}

private void initializeDefaults(ClangdConfiguration configuration) {
ClangdMetadata2 metadata = (ClangdMetadata2) configuration.metadata();
ClangdMetadata metadata = (ClangdMetadata) configuration.metadata();
String qualifier = configuration.qualifier();
initializeString(metadata.clangdPath(), qualifier);
initializeBoolean(metadata.useTidy(), qualifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
import java.util.Objects;
import java.util.Optional;

import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2;
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;

final class ClangdPreferredOptions implements ClangdOptions2 {
final class ClangdPreferredOptions implements ClangdOptions {

private final String qualifier;
private final IScopeContext[] scopes;
private final ClangdMetadata2 metadata;
private final ClangdMetadata metadata;

ClangdPreferredOptions(String qualifier, IScopeContext[] scopes, ClangdMetadata2 metadata) {
ClangdPreferredOptions(String qualifier, IScopeContext[] scopes, ClangdMetadata metadata) {
this.qualifier = Objects.requireNonNull(qualifier);
this.scopes = Objects.requireNonNull(scopes);
this.metadata = Objects.requireNonNull(metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2;
import org.eclipse.cdt.lsp.ui.ConfigurationArea;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.OsgiPreferenceMetadataStore;
Expand Down Expand Up @@ -65,7 +64,7 @@ public final class ClangdConfigurationArea extends ConfigurationArea {
LspEditorUiMessages.LspEditorPreferencePage_completion_default };
private final Map<String, String> completions;

public ClangdConfigurationArea(Composite parent, ClangdMetadata2 metadata, boolean isProjectScope) {
public ClangdConfigurationArea(Composite parent, ClangdMetadata metadata, boolean isProjectScope) {
super(3);
this.texts = new HashMap<>();
this.combos = new HashMap<>();
Expand Down Expand Up @@ -188,9 +187,9 @@ public void load(Object options, boolean enable) {
additional.setText(
clangdOptions.additionalOptions().stream().collect(Collectors.joining(System.lineSeparator())));
enablePreferenceContent(enable);
}
if (logToConsole != null && options instanceof ClangdOptions2 clangdOptions2) {
logToConsole.setSelection(clangdOptions2.logToConsole());
if (logToConsole != null) {
logToConsole.setSelection(clangdOptions.logToConsole());
}
}
}

Expand All @@ -209,7 +208,7 @@ public void dispose() {
combos.clear();
}

public boolean optionsChanged(ClangdOptions2 options) {
public boolean optionsChanged(ClangdOptions options) {
return !options.clangdPath().equals(path.getText()) || options.useTidy() != tidy.getSelection()
|| options.useBackgroundIndex() != index.getSelection()
|| !options.completionStyle().equals(completions.get(completion.getText()))
Expand Down
Loading

0 comments on commit 0d89d8a

Please sign in to comment.