Skip to content
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
5 changes: 3 additions & 2 deletions bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.cdt.lsp.clangd
Bundle-ActivationPolicy: lazy
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.cdt.lsp.clangd;singleton:=true
Bundle-Version: 2.1.0.qualifier
Bundle-Version: 2.2.0.qualifier
Export-Package: org.eclipse.cdt.lsp.clangd
Import-Package: org.yaml.snakeyaml;version="1.27.0",
org.yaml.snakeyaml.error;version="1.27.0",
Expand All @@ -28,7 +28,8 @@ Require-Bundle: org.eclipse.cdt.lsp;bundle-version="0.0.0",
org.eclipse.ui.workbench.texteditor;bundle-version="0.0.0",
org.eclipse.core.variables;bundle-version="0.0.0",
org.yaml.snakeyaml;bundle-version="0.0.0",
org.eclipse.tm4e.language_pack;bundle-version="0.0.0"
org.eclipse.tm4e.language_pack;bundle-version="0.0.0",
org.eclipse.ui.console;bundle-version="0.0.0"
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.BuiltinClangdOptionsDefaults.xml,
OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.ClangFormatFileHandler.xml,
OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.ClangdConfigurationAccess.xml,
Expand Down
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.ClangdOptionsDefaults"/>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults"/>
</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.ClangdMetadata" name="metadata"/>
<reference cardinality="1..1" field="metadata" interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata2" 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.ClangdMetadata"/>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata2"/>
</service>
<reference cardinality="1..1" field="defaults" interface="org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults" name="defaults"/>
<reference cardinality="1..1" field="defaults" interface="org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults" name="defaults"/>
<implementation class="org.eclipse.cdt.lsp.clangd.internal.config.ClangdMetadataDefaults"/>
</scr:component>
6 changes: 6 additions & 0 deletions bundles/org.eclipse.cdt.lsp.clangd/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@
content-type="org.eclipse.tm4e.language_pack.yaml"
file-names=".clangd,.clang-format">
</file-association>
</extension>
<extension
point="org.eclipse.cdt.lsp.logProvider">
<logger
class="org.eclipse.cdt.lsp.clangd.console.ClangdConsole">
</logger>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.eclipse.core.resources.IProject;

/**
* @since 2.1
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this increment was necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, otherwise it hadn't build

Copy link
Member

Choose a reason for hiding this comment

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

Very strange. Does this mean that we had this interface for 2.1 already and now we need to redeclare the same interface for 2.2 as well? Or do we have a baseline configuration issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or do we have a baseline configuration issue?

Yes it didn't build because of that:
image
I was wondering as well and hadn't had the time for further investigations.

* @since 2.2
*/
public interface ClangFormatFile {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2025 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
*******************************************************************************/

package org.eclipse.cdt.lsp.clangd;

import org.eclipse.core.runtime.preferences.PreferenceMetadata;

/**
* @since 2.2
*/
public interface ClangdMetadata2 extends ClangdMetadata {

/**
* 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 ClangdOptions2#logToConsole()
*/
PreferenceMetadata<Boolean> logToConsole();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2025 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
*******************************************************************************/

package org.eclipse.cdt.lsp.clangd;

/**
* @since 2.2
*/
public interface ClangdOptions2 extends ClangdOptions {

/**
* Enable logging to Clangd console
*
* @return true if clangd logging is enabled
*/
boolean logToConsole();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*******************************************************************************
* Copyright (c) 2025 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
*******************************************************************************/

package org.eclipse.cdt.lsp.clangd;

/**
* @since 2.2
*/
public interface ClangdOptions2Defaults extends ClangdOptions2 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2025 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
*******************************************************************************/

package org.eclipse.cdt.lsp.clangd.console;

import java.io.IOException;
import java.io.OutputStream;

import org.eclipse.cdt.lsp.server.ILogProvider;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;

public final class ClangdConsole implements ILogProvider {
private static final String CLANGD_CONSOLE = "Clangd"; //$NON-NLS-1$
private OutputStream outputStream;

@Override
public OutputStream getOutputStream() {
if (outputStream == null) {
outputStream = findConsole().newOutputStream();
}
return outputStream;
}

@Override
public void close() {
if (outputStream != null) {
try {
outputStream.close();
outputStream = null;
} catch (IOException e) {
Platform.getLog(ClangdConsole.class).error(e.getMessage(), e);
}
}

}

private MessageConsole findConsole() {
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
for (IConsole existing : conMan.getConsoles()) {
if (CLANGD_CONSOLE.equals(existing.getName()))
return (MessageConsole) existing;
}
// no console found, so create a new one
final var myConsole = new MessageConsole(CLANGD_CONSOLE, null);
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}
}
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.ClangdOptionsDefaults;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults;
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 ClangdOptionsDefaults {
public class BuiltinClangdOptionsDefaults implements ClangdOptions2Defaults {

@Override
public String clangdPath() {
Expand Down Expand Up @@ -66,4 +66,9 @@ 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.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptions;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2;
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 ClangdMetadata metadata;
private ClangdMetadata2 metadata;

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

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

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

@Override
public ClangdOptions options(Object context) {
public ClangdOptions2 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) {
ClangdOptions options = options(context);
ClangdOptions2 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,15 +23,16 @@

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.config.Configuration;
import org.eclipse.cdt.lsp.editor.LanguageServerEnable;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider;
import org.eclipse.cdt.lsp.server.ICLanguageServerProvider3;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ServiceCaller;
import org.eclipse.core.variables.VariablesPlugin;

public final class ClangdLanguageServerProvider implements ICLanguageServerProvider {
public final class ClangdLanguageServerProvider implements ICLanguageServerProvider3 {

private final ServiceCaller<ClangdConfiguration> configuration = new ServiceCaller<>(getClass(),
ClangdConfiguration.class);
Expand Down Expand Up @@ -70,4 +71,11 @@ public boolean isEnabledFor(IProject project) {
return enabled[0];
}

@Override
public boolean logToConsole() {
boolean[] enabled = new boolean[1];
configuration.call(c -> enabled[0] = ((ClangdOptions2) c.options(null)).logToConsole());
return enabled[0];
}

}
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.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdOptionsDefaults;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
import org.eclipse.cdt.lsp.clangd.ClangdOptions2Defaults;
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 final class ClangdMetadataDefaults implements ClangdMetadata {
public class ClangdMetadataDefaults implements ClangdMetadata2 {

@Reference
private ClangdOptionsDefaults defaults;
private ClangdOptions2Defaults defaults;

@Override
public PreferenceMetadata<String> clangdPath() {
Expand Down Expand Up @@ -89,4 +89,13 @@ public PreferenceMetadata<String> additionalOptions() {
LspEditorUiMessages.LspEditorPreferencePage_additional_description);
}

@Override
public PreferenceMetadata<Boolean> logToConsole() {
return new PreferenceMetadata<>(Boolean.class, //
"log_to_console", //$NON-NLS-1$
defaults.logToConsole(), //
LspEditorUiMessages.LspEditorPreferencePage_Log_to_Console, //
LspEditorUiMessages.LspEditorPreferencePage_Log_to_Console_description);
}

}
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.ClangdMetadata;
import org.eclipse.cdt.lsp.clangd.ClangdMetadata2;
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) {
ClangdMetadata metadata = (ClangdMetadata) configuration.metadata();
ClangdMetadata2 metadata = (ClangdMetadata2) configuration.metadata();
String qualifier = configuration.qualifier();
initializeString(metadata.clangdPath(), qualifier);
initializeBoolean(metadata.useTidy(), qualifier);
Expand All @@ -37,6 +37,7 @@ private void initializeDefaults(ClangdConfiguration configuration) {
initializeBoolean(metadata.prettyPrint(), qualifier);
initializeString(metadata.queryDriver(), qualifier);
initializeString(metadata.additionalOptions(), qualifier);
initializeBoolean(metadata.logToConsole(), qualifier);
}

private void initializeBoolean(PreferenceMetadata<Boolean> preference, String qualifier) {
Expand Down
Loading
Loading