Skip to content

Commit

Permalink
[eclipse-cdt#410] Evolve options API without bumping major version ev…
Browse files Browse the repository at this point in the history
…ery time

* make provider interfaces less domain specific but more stable
* improve API and implementation
  • Loading branch information
ruspl-afed committed Feb 5, 2025
1 parent 98a6aac commit 66416c1
Show file tree
Hide file tree
Showing 53 changed files with 942 additions and 882 deletions.
5 changes: 2 additions & 3 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.2.0.qualifier
Bundle-Version: 3.0.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 @@ -30,8 +30,7 @@ Require-Bundle: org.eclipse.cdt.lsp;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.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,
Service-Component: OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.ClangFormatFileHandler.xml,
OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.ClangdCommandLineValidator.xml,
OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.ClangdConfigurationAccess.xml,
OSGI-INF/org.eclipse.cdt.lsp.clangd.internal.config.ClangdConfigurationFileManager.xml,
Expand Down

This file was deleted.

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">
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.cdt.lsp.clangd.internal.config.ClangdMetadataDefaults">
<property name="service.ranking" type="Integer" value="0"/>
<service>
<provide interface="org.eclipse.cdt.lsp.clangd.ClangdMetadata"/>
</service>
<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 @@ -15,7 +15,7 @@
import org.eclipse.core.resources.IProject;

/**
* @since 2.2
* @since 3.0
*/
public interface ClangFormatFile {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 ArSysOp.
* Copyright (c) 2023, 2025 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -31,6 +31,18 @@
*/
public interface ClangdConfiguration extends Configuration {

/**
* @since 3.0
*/
@Override
ClangdOptions defaults();

/**
* @since 3.0
*/
@Override
ClangdOptions options(Object context);

/**
* Provides list of commands suitable for {@link ProcessStreamConnectionProvider} for the given context like {@link IResource} or {@link URI}, must not return <code>null</code>
* @param context to be adapter to the proper scope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 ArSysOp.
* Copyright (c) 2023, 2025 ArSysOp.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,6 +13,14 @@
*******************************************************************************/
package org.eclipse.cdt.lsp.clangd;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.cdt.lsp.clangd.internal.ui.LspEditorUiMessages;
import org.eclipse.cdt.lsp.config.ConfigurationMetadata;
import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.preferences.PreferenceMetadata;

/**
Expand All @@ -21,103 +29,126 @@
* @see ClangdOptions
* @since 2.0
*/
public interface ClangdMetadata {
public interface ClangdMetadata extends ConfigurationMetadata {

/**
* Returns the metadata for the "Clangd path" option, must not return <code>null</code>.
*
* @return the metadata for the "Clangd path" option
* The predefined metadata for the "Clangd path" option.
*
* @see ClangdOptions#clangdPath()
*
* @since 3.0
*/
PreferenceMetadata<String> clangdPath();
PreferenceMetadata<String> clangdPath = new PreferenceMetadata<>(String.class, //
"clangd_path", //$NON-NLS-1$
Optional.ofNullable(PathUtil.findProgramLocation("clangd", null)) //$NON-NLS-1$
.map(IPath::toOSString).orElse("clangd"), //$NON-NLS-1$
LspEditorUiMessages.LspEditorPreferencePage_path, //
LspEditorUiMessages.LspEditorPreferencePage_path_description);

/**
* Returns the metadata for the "Enable clang-tidy" option, must not return <code>null</code>.
*
* @return the metadata for the "Enable clang-tidy" option
* The predefined metadata for the "Enable clang-tidy" option.
*
* @see ClangdOptions#useTidy()
*
* @since 3.0
*/
PreferenceMetadata<Boolean> useTidy();
PreferenceMetadata<Boolean> useTidy = new PreferenceMetadata<>(Boolean.class, //
"use_tidy", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_enable_tidy, //
LspEditorUiMessages.LspEditorPreferencePage_enable_tidy);

/**
* Returns the metadata for the "Background index" option, must not return <code>null</code>.
*
* @return the metadata for the "Background index" option
* The predefined metadata for the "Background index" option.
*
* @see ClangdOptions#useBackgroundIndex()
*
* @since 3.0
*/
PreferenceMetadata<Boolean> useBackgroundIndex();
PreferenceMetadata<Boolean> useBackgroundIndex = new PreferenceMetadata<>(Boolean.class, //
"background_index", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_background_index, //
LspEditorUiMessages.LspEditorPreferencePage_background_index);

/**
* Returns the metadata for the "Completion style" option, must not return <code>null</code>.
*
* @return the metadata for the "Completion style" option
* The predefined metadata for the "Completion style" option.
*
* @see ClangdOptions#completionStyle()
*
* @since 3.0
*/
PreferenceMetadata<String> completionStyle();
PreferenceMetadata<String> completionStyle = new PreferenceMetadata<>(String.class, //
"completion_style", //$NON-NLS-1$
"detailed", //$NON-NLS-1$
LspEditorUiMessages.LspEditorPreferencePage_completion, //
LspEditorUiMessages.LspEditorPreferencePage_completion_description);

/**
* Returns the metadata for the "Pretty print" option, must not return <code>null</code>.
*
* @return the metadata for the "Pretty print" option
* The predefined metadata for the "Pretty print" option.
*
* @see ClangdOptions#prettyPrint()
*
* @since 3.0
*/
PreferenceMetadata<Boolean> prettyPrint();
PreferenceMetadata<Boolean> prettyPrint = new PreferenceMetadata<>(Boolean.class, //
"pretty_print", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_pretty_print, //
LspEditorUiMessages.LspEditorPreferencePage_pretty_print);

/**
* Returns the metadata for the "Query driver" option, must not return <code>null</code>.
*
* @return the metadata for the "Query driver" option
* The predefined metadata for the "Query driver" option.
*
* @see ClangdOptions#queryDriver()
*
* @since 3.0
*/
PreferenceMetadata<String> queryDriver();
PreferenceMetadata<String> queryDriver = new PreferenceMetadata<>(String.class, //
"query_driver", //$NON-NLS-1$
Optional.ofNullable(PathUtil.findProgramLocation("gcc", null)) //$NON-NLS-1$
.map(p -> p.removeLastSegments(1).append(IPath.SEPARATOR + "*"))// //$NON-NLS-1$
.map(IPath::toString).orElse(""), //$NON-NLS-1$
LspEditorUiMessages.LspEditorPreferencePage_drivers, //
LspEditorUiMessages.LspEditorPreferencePage_drivers_description);

/**
* Returns the metadata for the additional options, must not return <code>null</code>.
*
* @return the metadata for the additional options
* The predefined metadata for the additional options, must not return <code>null</code>.
*
* @see ClangdOptions#additionalOptions
*
* @since 3.0
*/
PreferenceMetadata<String> additionalOptions();
PreferenceMetadata<String> additionalOptions = new PreferenceMetadata<>(String.class, //
"additional_options", //$NON-NLS-1$
List.of("").stream().collect(Collectors.joining(System.lineSeparator())), //$NON-NLS-1$
LspEditorUiMessages.LspEditorPreferencePage_additional, //
LspEditorUiMessages.LspEditorPreferencePage_additional_description);

/**
* Returns the metadata for the "Log to Console" option, must not return <code>null</code>.
*
* @return the metadata for the "Log to Console" option
* The predefined metadata for the "Log to Console" option.
*
* @see ClangdOptions#logToConsole()
*
* @since 2.2
* @since 3.0
*/
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$
}
PreferenceMetadata<Boolean> logToConsole = new PreferenceMetadata<>(Boolean.class, //
"log_to_console", //$NON-NLS-1$
false, //
LspEditorUiMessages.LspEditorPreferencePage_Log_to_Console, //
LspEditorUiMessages.LspEditorPreferencePage_Log_to_Console_description);

/**
* Returns the metadata for the "Validate clangd options" option, must not return <code>null</code>.
*
* @return the metadata for the "Validate clangd options" option
* The predefined metadata for the "Validate clangd options" option.
*
* @see ClangdOptions#validateClangdOptions()
*
* @since 2.2
* @since 3.0
*/
default PreferenceMetadata<Boolean> validateClangdOptions() {
return new PreferenceMetadata<>(Boolean.class, //
"validate_clangd_options", //$NON-NLS-1$
true, //
"Validate clangd options", // //$NON-NLS-1$
"Validate clangd options"); //$NON-NLS-1$
}
PreferenceMetadata<Boolean> validateClangdOptions = new PreferenceMetadata<>(Boolean.class, //
"validate_clangd_options", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_Validate_clangd_options, //
LspEditorUiMessages.LspEditorPreferencePage_Validate_clangd_options_description);

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public interface ClangdOptions {
*
* @return true if clangd logging is enabled
*
* @since 2.2
* @since 3.0
*/
default boolean logToConsole() {
return false;
Expand All @@ -87,7 +87,7 @@ default boolean logToConsole() {
*
* @return true if clangd command line options should be validated prior clangd launch.
*
* @since 2.2
* @since 3.0
*/
default boolean validateClangdOptions() {
return true;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Validator interface for clangd command line options.
*
* @since 2.2
* @since 3.0
*/
public interface IClangdCommandLineValidator {

Expand Down

This file was deleted.

Loading

0 comments on commit 66416c1

Please sign in to comment.