Skip to content

Commit

Permalink
fix: ensure grammars are registered with scopeName defined in plugin.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Dec 22, 2023
1 parent 0dd4241 commit 52fd736
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class RawGrammar extends PropertySettable.HashMap<@Nullable Object>
private static final String INJECTION_SELECTOR = "injectionSelector";
private static final String NAME = "name";
private static final String PATTERNS = "patterns";
private static final String SCOPE_NAME = "scopeName";
public static final String SCOPE_NAME = "scopeName";

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PropertySettable<?> createChild(final TMParser.PropertyPath path, final C
}
};

public static IRawGrammar readGrammar(final IGrammarSource source) throws Exception {
public static RawGrammar readGrammar(final IGrammarSource source) throws Exception {
try (var reader = source.getReader()) {
return switch (source.getContentType()) {
case JSON -> TMParserJSON.INSTANCE.parse(reader, OBJECT_FACTORY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.tm4e.core.grammar.IGrammar;
import org.eclipse.tm4e.core.internal.grammar.BalancedBracketSelectors;
import org.eclipse.tm4e.core.internal.grammar.dependencies.ScopeDependencyProcessor;
import org.eclipse.tm4e.core.internal.grammar.raw.RawGrammar;
import org.eclipse.tm4e.core.internal.grammar.raw.RawGrammarReader;
import org.eclipse.tm4e.core.internal.registry.SyncRegistry;
import org.eclipse.tm4e.core.internal.theme.Theme;
Expand Down Expand Up @@ -158,6 +159,12 @@ private boolean _doLoadSingleGrammar(final String scopeName) {
}
try {
final var grammar = RawGrammarReader.readGrammar(grammarSource);

// this code is specific to the tm4e project and not from upstream:
// adjust the scopeName in case the name as defined inside the TextMate grammar file
// diverges from the scopeName with which it is registered in the plugin.xml.
grammar.put(RawGrammar.SCOPE_NAME, scopeName);

this._syncRegistry.addGrammar(grammar, this._options.getInjections(scopeName));
} catch (final Exception ex) {
throw new TMException("Loading grammar for scope [" + scopeName + "] from [" +
Expand Down

0 comments on commit 52fd736

Please sign in to comment.