Skip to content

Commit

Permalink
feat: Lookup grammars with "langpck." scope name prefix if not found
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebthom committed Oct 28, 2023
1 parent 8bfea3d commit f486521
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<artifactId>org.eclipse.tm4e.core</artifactId>
<packaging>eclipse-plugin</packaging>
<version>0.6.1-SNAPSHOT</version>
<version>0.6.2-SNAPSHOT</version>

<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public final class SyncRegistry implements IGrammarRepository, IThemeProvider {

private final Map<String, Grammar> _grammars = new HashMap<>();
private final Map<String, IRawGrammar> _rawGrammars = new HashMap<>();
private final Map<String, @Nullable IRawGrammar> _rawGrammars = new HashMap<>();
private final Map<String, Collection<String>> _injectionGrammars = new HashMap<>();
private Theme _theme;

Expand Down Expand Up @@ -68,7 +68,14 @@ public void addGrammar(final IRawGrammar grammar, @Nullable final Collection<Str
@Override
@Nullable
public IRawGrammar lookup(final String scopeName) {
return this._rawGrammars.get(scopeName);
var grammar = this._rawGrammars.get(scopeName);

// check if tm4e language pack is installed, e.g. "source.python" -> "lngpck.source.python"
if (grammar == null && !scopeName.startsWith("lngpck.")) {
grammar = this._rawGrammars.get("lngpck." + scopeName);
}

return grammar;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.registry/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.tm4e.registry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

<artifactId>org.eclipse.tm4e.registry</artifactId>
<packaging>eclipse-plugin</packaging>
<version>0.6.5-SNAPSHOT</version>
<version>0.6.6-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +63,14 @@ Collection<IGrammarDefinition> 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;
}

/**
Expand Down

0 comments on commit f486521

Please sign in to comment.