Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disabling indentation rules not working #725

Merged
merged 4 commits into from
Mar 4, 2024
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ updates:
schedule:
interval: daily
commit-message:
prefix: build
prefix: fix
prefix-development: build
include: scope
labels:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/licensecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -86,6 +88,11 @@ public static String toJson(final Collection<ILanguageConfigurationDefinition> 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() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -193,46 +218,16 @@ public List<AutoClosingPair> 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"
final var definitions = new ArrayList<ILanguageConfigurationDefinition>();
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);
}
});
Expand Down
Loading