From f48652186098941d4e08c316805d0d52bac8a3be Mon Sep 17 00:00:00 2001 From: sebthom Date: Sat, 28 Oct 2023 05:51:33 +0200 Subject: [PATCH] feat: Lookup grammars with "langpck." scope name prefix if not found The tm4e language pack plugin registers all languages with a "langpck." scope name prefix. If a grammar references, for example, "scope.python", the grammar registered by the language pack will not be found, resulting in "WARNING: CANNOT find grammar for scopeName [source.python]". With this commit the language will automatically be looked up via "langpck.source.python" as a fallback. --- org.eclipse.tm4e.core/META-INF/MANIFEST.MF | 2 +- org.eclipse.tm4e.core/pom.xml | 2 +- .../tm4e/core/internal/registry/SyncRegistry.java | 11 +++++++++-- org.eclipse.tm4e.registry/META-INF/MANIFEST.MF | 2 +- org.eclipse.tm4e.registry/pom.xml | 2 +- .../eclipse/tm4e/registry/internal/GrammarCache.java | 11 ++++++++++- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF index 43a14766d..76e9995ae 100644 --- a/org.eclipse.tm4e.core/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.core/META-INF/MANIFEST.MF @@ -4,7 +4,7 @@ Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-SymbolicName: org.eclipse.tm4e.core -Bundle-Version: 0.6.1.qualifier +Bundle-Version: 0.6.2.qualifier Require-Bundle: com.google.gson;bundle-version="[2.10.1,3.0.0)", com.google.guava;bundle-version="[32.1.0,33.0.0)", org.apache.batik.css;bundle-version="[1.16.0,2.0.0)";resolution:=optional, diff --git a/org.eclipse.tm4e.core/pom.xml b/org.eclipse.tm4e.core/pom.xml index 9485af6c5..5e5ebf1e0 100644 --- a/org.eclipse.tm4e.core/pom.xml +++ b/org.eclipse.tm4e.core/pom.xml @@ -10,7 +10,7 @@ org.eclipse.tm4e.core eclipse-plugin - 0.6.1-SNAPSHOT + 0.6.2-SNAPSHOT diff --git a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java index fc2e82404..ab43c3c2b 100644 --- a/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java +++ b/org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/internal/registry/SyncRegistry.java @@ -38,7 +38,7 @@ public final class SyncRegistry implements IGrammarRepository, IThemeProvider { private final Map _grammars = new HashMap<>(); - private final Map _rawGrammars = new HashMap<>(); + private final Map _rawGrammars = new HashMap<>(); private final Map> _injectionGrammars = new HashMap<>(); private Theme _theme; @@ -68,7 +68,14 @@ public void addGrammar(final IRawGrammar grammar, @Nullable final Collection "lngpck.source.python" + if (grammar == null && !scopeName.startsWith("lngpck.")) { + grammar = this._rawGrammars.get("lngpck." + scopeName); + } + + return grammar; } @Override diff --git a/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF b/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF index ad4636add..9cf74f202 100644 --- a/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF +++ b/org.eclipse.tm4e.registry/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-SymbolicName: org.eclipse.tm4e.registry;singleton:=true -Bundle-Version: 0.6.5.qualifier +Bundle-Version: 0.6.6.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.core.runtime, org.eclipse.equinox.preferences, diff --git a/org.eclipse.tm4e.registry/pom.xml b/org.eclipse.tm4e.registry/pom.xml index c3e1f06c0..1cd3102c8 100644 --- a/org.eclipse.tm4e.registry/pom.xml +++ b/org.eclipse.tm4e.registry/pom.xml @@ -10,5 +10,5 @@ org.eclipse.tm4e.registry eclipse-plugin - 0.6.5-SNAPSHOT + 0.6.6-SNAPSHOT diff --git a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java index 55a7d0407..5b6bbac72 100644 --- a/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java +++ b/org.eclipse.tm4e.registry/src/main/java/org/eclipse/tm4e/registry/internal/GrammarCache.java @@ -11,6 +11,8 @@ */ package org.eclipse.tm4e.registry.internal; +import static org.eclipse.tm4e.core.internal.utils.NullSafetyHelper.castNullable; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -61,7 +63,14 @@ Collection getDefinitions() { */ @Nullable IGrammarDefinition getDefinition(final String scopeName) { - return definitions.get(scopeName); + var grammar = castNullable(definitions.get(scopeName)); + + // check if tm4e language pack is installed, e.g. "source.python" -> "lngpck.source.python" + if (grammar == null && !scopeName.startsWith("lngpck.")) { + grammar = definitions.get("lngpck." + scopeName); + } + + return grammar; } /**