Skip to content

Commit

Permalink
[#410] Evolve options API without bumping major version every time
Browse files Browse the repository at this point in the history
* extract predefined preference metadata to another "noimplement"
interface
  • Loading branch information
ruspl-afed committed Feb 19, 2025
1 parent 1943391 commit 6c0dfad
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,154 +32,143 @@
public interface ClangdMetadata extends ConfigurationMetadata {

/**
* The predefined metadata for the "Clangd path" option.
*
* @see ClangdOptions#clangdPath()
* Predefined preference metadata
*
* @since 3.0
*/
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);

/**
* The predefined metadata for the "Enable clang-tidy" option.
*
* @see ClangdOptions#useTidy()
*
* @since 3.0
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
PreferenceMetadata<Boolean> useTidy = new PreferenceMetadata<>(Boolean.class, //
"use_tidy", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_enable_tidy, //
LspEditorUiMessages.LspEditorPreferencePage_enable_tidy);
interface Predefined {
/**
* The predefined metadata for the "Clangd path" option.
*
* @see ClangdOptions#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);

/**
* The predefined metadata for the "Background index" option.
*
* @see ClangdOptions#useBackgroundIndex()
*
* @since 3.0
*/
PreferenceMetadata<Boolean> useBackgroundIndex = new PreferenceMetadata<>(Boolean.class, //
"background_index", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_background_index, //
LspEditorUiMessages.LspEditorPreferencePage_background_index);
/**
* The predefined metadata for the "Enable clang-tidy" option.
*
* @see ClangdOptions#useTidy()
*/
PreferenceMetadata<Boolean> useTidy = new PreferenceMetadata<>(Boolean.class, //
"use_tidy", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_enable_tidy, //
LspEditorUiMessages.LspEditorPreferencePage_enable_tidy);

/**
* The predefined metadata for the "Completion style" option.
*
* @see ClangdOptions#completionStyle()
*
* @since 3.0
*/
PreferenceMetadata<String> completionStyle = new PreferenceMetadata<>(String.class, //
"completion_style", //$NON-NLS-1$
"detailed", //$NON-NLS-1$
LspEditorUiMessages.LspEditorPreferencePage_completion, //
LspEditorUiMessages.LspEditorPreferencePage_completion_description);
/**
* The predefined metadata for the "Background index" option.
*
* @see ClangdOptions#useBackgroundIndex()
*/
PreferenceMetadata<Boolean> useBackgroundIndex = new PreferenceMetadata<>(Boolean.class, //
"background_index", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_background_index, //
LspEditorUiMessages.LspEditorPreferencePage_background_index);

/**
* The predefined metadata for the "Pretty print" option.
*
* @see ClangdOptions#prettyPrint()
*
* @since 3.0
*/
PreferenceMetadata<Boolean> prettyPrint = new PreferenceMetadata<>(Boolean.class, //
"pretty_print", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_pretty_print, //
LspEditorUiMessages.LspEditorPreferencePage_pretty_print);
/**
* The predefined metadata for the "Completion style" option.
*
* @see ClangdOptions#completionStyle()
*/
PreferenceMetadata<String> completionStyle = new PreferenceMetadata<>(String.class, //
"completion_style", //$NON-NLS-1$
"detailed", //$NON-NLS-1$
LspEditorUiMessages.LspEditorPreferencePage_completion, //
LspEditorUiMessages.LspEditorPreferencePage_completion_description);

/**
* The predefined metadata for the "Query driver" option.
*
* @see ClangdOptions#queryDriver()
*
* @since 3.0
*/
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);
/**
* The predefined metadata for the "Pretty print" option.
*
* @see ClangdOptions#prettyPrint()
*/
PreferenceMetadata<Boolean> prettyPrint = new PreferenceMetadata<>(Boolean.class, //
"pretty_print", //$NON-NLS-1$
true, //
LspEditorUiMessages.LspEditorPreferencePage_pretty_print, //
LspEditorUiMessages.LspEditorPreferencePage_pretty_print);

/**
* The predefined metadata for the additional options, must not return <code>null</code>.
*
* @see ClangdOptions#additionalOptions
*
* @since 3.0
*/
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);
/**
* The predefined metadata for the "Query driver" option.
*
* @see ClangdOptions#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);

/**
* The predefined metadata for the "Log to Console" option.
*
* @see ClangdOptions#logToConsole()
*
* @since 3.0
*/
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);
/**
* The predefined metadata for the additional options, must not return <code>null</code>.
*
* @see ClangdOptions#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);

/**
* The predefined metadata for the "Validate clangd options" option.
*
* @see ClangdOptions#validateClangdOptions()
*
* @since 3.0
*/
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);
/**
* The predefined metadata for the "Log to Console" option.
*
* @see ClangdOptions#logToConsole()
*/
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 "Fill function arguments and show guessed arguments" option.
*
* @see ClangdOptions#fillFunctionArguments()
*
* @since 3.0
*/
PreferenceMetadata<Boolean> fillFunctionArguments = new PreferenceMetadata<>(Boolean.class, //
"fill_function_arguments", //$NON-NLS-1$
true, //
LspEditorUiMessages.ContentAssistConfigurationPage_fill_function_arguments,
LspEditorUiMessages.ContentAssistConfigurationPage_fill_function_arguments_description);
/**
* The predefined metadata for the "Validate clangd options" option.
*
* @see ClangdOptions#validateClangdOptions()
*/
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);

/**
* Returns the default {@link List} of {@link PreferenceMetadata}
*
* @since 3.0
*/
List<PreferenceMetadata<?>> defaults = List.of(//
clangdPath, //
useTidy, //
useBackgroundIndex, //
completionStyle, //
prettyPrint, //
queryDriver, //
additionalOptions, //
logToConsole, //
validateClangdOptions, //
fillFunctionArguments//
);
/**
* Returns the metadata for the "Fill function arguments and show guessed arguments" option.
*
* @see ClangdOptions#fillFunctionArguments()
*/
PreferenceMetadata<Boolean> fillFunctionArguments = new PreferenceMetadata<>(Boolean.class, //
"fill_function_arguments", //$NON-NLS-1$
true, //
LspEditorUiMessages.ContentAssistConfigurationPage_fill_function_arguments,
LspEditorUiMessages.ContentAssistConfigurationPage_fill_function_arguments_description);

/**
* Returns the default {@link List} of {@link PreferenceMetadata}
*/
List<PreferenceMetadata<?>> defaults = List.of(//
clangdPath, //
useTidy, //
useBackgroundIndex, //
completionStyle, //
prettyPrint, //
queryDriver, //
additionalOptions, //
logToConsole, //
validateClangdOptions, //
fillFunctionArguments//
);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class ClangdMetadataDefaults extends ConfigurationMetadataBase impl

@Override
protected List<PreferenceMetadata<?>> definePreferences() {
return defaults;
return Predefined.defaults;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,37 @@ final class ClangdPreferredOptions extends PreferredOptions implements ClangdOpt

@Override
public String clangdPath() {
return stringValue(ClangdMetadata.clangdPath);
return stringValue(ClangdMetadata.Predefined.clangdPath);
}

@Override
public boolean useTidy() {
return booleanValue(ClangdMetadata.useTidy);
return booleanValue(ClangdMetadata.Predefined.useTidy);
}

@Override
public boolean useBackgroundIndex() {
return booleanValue(ClangdMetadata.useBackgroundIndex);
return booleanValue(ClangdMetadata.Predefined.useBackgroundIndex);
}

@Override
public String completionStyle() {
return stringValue(ClangdMetadata.completionStyle);
return stringValue(ClangdMetadata.Predefined.completionStyle);
}

@Override
public boolean prettyPrint() {
return booleanValue(ClangdMetadata.prettyPrint);
return booleanValue(ClangdMetadata.Predefined.prettyPrint);
}

@Override
public String queryDriver() {
return stringValue(ClangdMetadata.queryDriver);
return stringValue(ClangdMetadata.Predefined.queryDriver);
}

@Override
public List<String> additionalOptions() {
var options = stringValue(ClangdMetadata.additionalOptions);
var options = stringValue(ClangdMetadata.Predefined.additionalOptions);
if (options.isBlank()) {
return new ArrayList<>();
}
Expand All @@ -69,17 +69,17 @@ public List<String> additionalOptions() {

@Override
public boolean logToConsole() {
return booleanValue(ClangdMetadata.logToConsole);
return booleanValue(ClangdMetadata.Predefined.logToConsole);
}

@Override
public boolean validateClangdOptions() {
return booleanValue(ClangdMetadata.validateClangdOptions);
return booleanValue(ClangdMetadata.Predefined.validateClangdOptions);
}

@Override
public boolean fillFunctionArguments() {
return booleanValue(ClangdMetadata.fillFunctionArguments);
return booleanValue(ClangdMetadata.Predefined.fillFunctionArguments);
}

}
Loading

0 comments on commit 6c0dfad

Please sign in to comment.