From 0ef3b975bf4bff50fe9c3b1a5657de3fc757d050 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 4 Mar 2024 19:25:16 +0100 Subject: [PATCH 1/4] refact: improve loading of LangCfg configs from prefs --- .../preferences/PreferenceHelper.java | 9 ++- .../LanguageConfigurationDefinition.java | 3 +- .../LanguageConfigurationRegistryManager.java | 66 ++++++++----------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java index 9270e720a..4c0466ec0 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/preferences/PreferenceHelper.java @@ -15,7 +15,9 @@ import java.util.Collection; import java.util.Objects; +import org.eclipse.core.runtime.Platform; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.eclipse.tm4e.languageconfiguration.LanguageConfigurationPlugin; import org.eclipse.tm4e.languageconfiguration.internal.registry.ILanguageConfigurationDefinition; import org.eclipse.tm4e.languageconfiguration.internal.registry.LanguageConfigurationDefinition; @@ -29,7 +31,7 @@ import com.google.gson.JsonSerializer; /** - * Helper class load, save language configuration preferences with Json format. + * Helper class load, save language configuration preferences in JSON format. */ public final class PreferenceHelper { @@ -86,6 +88,11 @@ public static String toJson(final Collection d return DEFAULT_GSON.toJson(definitions); } + public static @Nullable String getPreferenceString(final String key, final @Nullable String defaultValue) { + return Platform.getPreferencesService().getString(LanguageConfigurationPlugin.PLUGIN_ID, key, defaultValue, + null /* = search in all available scopes */); + } + private PreferenceHelper() { } } diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java index a36d1164b..b4a9598ad 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationDefinition.java @@ -66,7 +66,8 @@ public LanguageConfigurationDefinition(final IContentType contentType, final Str * Constructor for user preferences loaded via {@link PreferenceHelper}. */ public LanguageConfigurationDefinition(final IContentType contentType, - final String path, final @Nullable String pluginId, + final String path, + final @Nullable String pluginId, final boolean onEnterEnabled, final boolean indentRulesEnabled, final boolean bracketAutoClosingEnabled, diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java index 416c9a554..ce94e6217 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java @@ -43,14 +43,10 @@ public final class LanguageConfigurationRegistryManager extends AbstractLanguageConfigurationRegistryManager { private static final String EXTENSION_LANGUAGE_CONFIGURATIONS = "languageConfigurations"; - private static final String LANGUAGE_CONFIGURATION_ELT = "languageConfiguration"; /** see https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java */ private static final class InstanceHolder { static final LanguageConfigurationRegistryManager INSTANCE = new LanguageConfigurationRegistryManager(); - static { - INSTANCE.load(); - } } public static LanguageConfigurationRegistryManager getInstance() { @@ -71,6 +67,35 @@ public static LanguageConfigurationRegistryManager getInstance() { return bestFit; } + private LanguageConfigurationRegistryManager() { + /* + * load from extension point + */ + final var xmlConfig = Platform.getExtensionRegistry().getConfigurationElementsFor(LanguageConfigurationPlugin.PLUGIN_ID, + EXTENSION_LANGUAGE_CONFIGURATIONS); + for (final var xmlElem : xmlConfig) { + if ("languageConfiguration".equals(xmlElem.getName())) { + try { + registerLanguageConfigurationDefinition(new LanguageConfigurationDefinition(xmlElem)); + } catch (final CoreException ex) { + LanguageConfigurationPlugin.log(ex.getStatus()); + } + } + } + + /* + * Load grammar definitions from the + * "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs" + */ + final String jsonConfig = PreferenceHelper.getPreferenceString(PreferenceConstants.LANGUAGE_CONFIGURATIONS, null); + if (jsonConfig != null && !jsonConfig.isBlank()) { + final var definitions = PreferenceHelper.loadLanguageConfigurationDefinitions(jsonConfig); + for (final var definition : definitions) { + registerLanguageConfigurationDefinition(definition); + } + } + } + public @Nullable AutoClosingPairConditional getAutoClosingPair(final String text, final int offset, final String newCharacter, final IContentType contentType) { final var definition = getDefinition(contentType); @@ -193,39 +218,6 @@ public List getSurroundingPairs(final IContentType contentType) return definition == null ? null : definition.getCharacterPair(); } - private void load() { - loadFromExtensionPoints(); - loadFromPreferences(); - } - - private void loadFromExtensionPoints() { - final var config = Platform.getExtensionRegistry().getConfigurationElementsFor( - LanguageConfigurationPlugin.PLUGIN_ID, EXTENSION_LANGUAGE_CONFIGURATIONS); - for (final var configElem : config) { - final String name = configElem.getName(); - if (LANGUAGE_CONFIGURATION_ELT.equals(name)) { - try { - registerLanguageConfigurationDefinition(new LanguageConfigurationDefinition(configElem)); - } catch (final CoreException ex) { - LanguageConfigurationPlugin.log(ex.getStatus()); - } - } - } - } - - private void loadFromPreferences() { - // Load grammar definitions from the - // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs" - final var prefs = InstanceScope.INSTANCE.getNode(LanguageConfigurationPlugin.PLUGIN_ID); - final String json = prefs.get(PreferenceConstants.LANGUAGE_CONFIGURATIONS, null); - if (json != null) { - final var definitions = PreferenceHelper.loadLanguageConfigurationDefinitions(json); - for (final var definition : definitions) { - registerLanguageConfigurationDefinition(definition); - } - } - } - void save() throws BackingStoreException { // Save grammar definitions in the // "${workspace_loc}/metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.tm4e.languageconfiguration.prefs" From d46343e3be681432f6eedd62041fb8f2c2d3bab1 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 4 Mar 2024 19:26:17 +0100 Subject: [PATCH 2/4] refact: minor tweak of GHA workflows --- .github/dependabot.yml | 2 +- .github/workflows/build.yml | 7 +++---- .github/workflows/licensecheck.yml | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 1d7af1a9c..dcb5326d5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -15,7 +15,7 @@ updates: schedule: interval: daily commit-message: - prefix: build + prefix: fix prefix-development: build include: scope labels: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 10cf96fd6..c4f1f6640 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,7 +75,7 @@ jobs: if: runner.os == 'Linux' uses: vegardit/fast-apt-mirror.sh@v1 - - name: "Install: Linux packages" + - name: "Install: Linux packages 📦" if: runner.os == 'Linux' run: | set -eux @@ -95,7 +95,7 @@ jobs: # no swt-pi4 in java.library.path: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib sudo apt-get install --no-install-recommends -y libswt-gtk-*-java - - name: "Install: JDK ${{ env.JAVA_VERSION }}" + - name: "Install: JDK ${{ env.JAVA_VERSION }} ☕" uses: actions/setup-java@v4 # https://github.com/actions/setup-java with: distribution: temurin @@ -127,8 +127,7 @@ jobs: with: maven-version: 3.9.6 - - name: Build with Maven - id: maven-build + - name: "Build with Maven 🔨" continue-on-error: ${{ matrix.target-platform == 'unstable' }} run: | set -eu diff --git a/.github/workflows/licensecheck.yml b/.github/workflows/licensecheck.yml index f02ae6cbc..4aad1264d 100644 --- a/.github/workflows/licensecheck.yml +++ b/.github/workflows/licensecheck.yml @@ -35,7 +35,7 @@ jobs: - name: Git Checkout uses: actions/checkout@v4 #https://github.com/actions/checkout - - name: "Install: JDK ${{ env.JAVA_VERSION }}" + - name: "Install: JDK ${{ env.JAVA_VERSION }} ☕" uses: actions/setup-java@v4 # https://github.com/actions/setup-java with: distribution: temurin From 27d56ce6b37a633f8215f16658bba80c13f577b8 Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 4 Mar 2024 19:36:38 +0100 Subject: [PATCH 3/4] fix: disabling indentation rules not working --- .../registry/LanguageConfigurationRegistryManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java index ce94e6217..197e17a6a 100644 --- a/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java +++ b/org.eclipse.tm4e.languageconfiguration/src/main/java/org/eclipse/tm4e/languageconfiguration/internal/registry/LanguageConfigurationRegistryManager.java @@ -224,7 +224,10 @@ void save() throws BackingStoreException { final var definitions = new ArrayList(); userDefinitions.values().forEach(definitions::add); pluginDefinitions.values().forEach(def -> { - if (!(def.isBracketAutoClosingEnabled() && def.isMatchingPairsEnabled() && def.isOnEnterEnabled())) { + if (!(def.isBracketAutoClosingEnabled() + && def.isMatchingPairsEnabled() + && def.isOnEnterEnabled() + && def.isIndentRulesEnabled())) { definitions.add(def); } }); From 753e92aee075d0facbd1db87433dd936e70c2a6d Mon Sep 17 00:00:00 2001 From: sebthom Date: Mon, 4 Mar 2024 19:36:38 +0100 Subject: [PATCH 4/4] fix: disabling indentation rules not working