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 3, 2025
1 parent 98a6aac commit 4e5e43b
Show file tree
Hide file tree
Showing 39 changed files with 884 additions and 844 deletions.
3 changes: 1 addition & 2 deletions bundles/org.eclipse.cdt.lsp.clangd/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
@@ -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,12 @@
*/
public interface ClangdConfiguration extends Configuration {

@Override
ClangdOptions defaults();

@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,112 @@
* @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()
*/
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()
*/
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()
*/
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()
*/
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()
*/
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()
*/
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
*/
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
*/
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
*/
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);

}

This file was deleted.

This file was deleted.

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 @@ -53,7 +53,7 @@ public ClangdMetadata metadata() {

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

@Override
Expand All @@ -65,7 +65,7 @@ public ClangdOptions options(Object context) {
} else {
scopes = new IScopeContext[] { InstanceScope.INSTANCE, DefaultScope.INSTANCE };
}
return new ClangdPreferredOptions(qualifier, scopes, metadata);
return new ClangdPreferredOptions(metadata, qualifier, scopes);
}

@Override
Expand Down
Loading

0 comments on commit 4e5e43b

Please sign in to comment.