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

feat: add Theme child combinator ">" (and fix a specificity bug) #768

Merged
merged 3 commits into from
Jul 8, 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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.eclipse.tm4e.core.registry.Registry;

/**
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/tests/tokenization.test.ts">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/tests/tokenization.test.ts">
* github.com/microsoft/vscode-textmate/blob/main/src/tests/tokenization.test.ts</a>
*/
public class RawTestImpl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* VSCode TextMate matcher tests
*
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/tests/matcher.test.ts">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/tests/matcher.test.ts">
* github.com/microsoft/vscode-textmate/blob/main/src/tests/matcher.test.ts</a>
*/
public class MatcherTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/tests/themes.test.ts#L126">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/tests/themes.test.ts#L126">
* github.com/microsoft/vscode-textmate/blob/main/src/tests/themes.test.ts</a>
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/tests/themes.test.ts#L286">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/tests/themes.test.ts#L286">
* github.com/microsoft/vscode-textmate/blob/main/src/tests/themes.test.ts</a>
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.List;

import org.eclipse.tm4e.core.internal.grammar.ScopeStack;
import org.eclipse.tm4e.core.internal.utils.StringUtils;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.MethodOrderer;
Expand All @@ -34,7 +35,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/tests/themes.test.ts#L323">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/tests/themes.test.ts#L323">
* github.com/microsoft/vscode-textmate/blob/main/src/tests/themes.test.ts</a>
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand Down Expand Up @@ -347,6 +348,72 @@ public void testRulesWithParentScopes() {

@Test
@Order(15)
@DisplayName("Theme resolving a rule with child combinator")
public void testRuleWithChildCombinator() throws Exception {
final var theme = createTheme("""
{"settings": [
{ "settings": { "foreground": "#100000" } },
{ "scope": "b a", "settings": { "foreground": "#200000" } },
{ "scope": "b > a", "settings": { "foreground": "#300000" } },
{ "scope": "c > b > a", "settings": { "foreground": "#400000" } },
{ "scope": "a", "settings": { "foreground": "#500000" } },
]}""");

final var colorMap = theme.getColorMap();

interface Matcher {
String match(String... path);
}

final Matcher matcher = (String[] path) -> {
final var result = theme.match(ScopeStack.from(path));
if (result == null || result.foregroundId == 0)
return null;
return colorMap.get(result.foregroundId);
};

assertEquals(matcher.match("b", "a"), "#300000", "b a");
assertEquals(matcher.match("b", "c", "a"), "#200000", "b c a");
assertEquals(matcher.match("c", "b", "a"), "#400000", "c b a");
assertEquals(matcher.match("c", "b", "d", "a"), "#200000", "c b d a");
}

@Test
@Order(16)
@DisplayName("Theme resolving should give deeper scopes higher specificity (#233)")
public void testGiveDeeperScopesHigherSpecificity() throws Exception {
final var theme = createTheme("""
{"settings": [
{ "settings": { "foreground": "#100000" } },
{ "scope": "y.z a.b", "settings": { "foreground": "#200000" } },
{ "scope": "x y a.b", "settings": { "foreground": "#300000" } },
]}""");

final var colorMap = theme.getColorMap();

interface Matcher {
String match(String... path);
}

final Matcher matcher = (String[] path) -> {
final var result = theme.match(ScopeStack.from(path));
if (result == null || result.foregroundId == 0)
return null;
return colorMap.get(result.foregroundId);
};

assertEquals(matcher.match("x", "a.b"), null, "x a.b");
assertEquals(matcher.match("y", "a.b"), null, "y a.b");
assertEquals(matcher.match("y.z", "a"), null, "y.z a");
assertEquals(matcher.match("x", "y", "a.b"), "#300000", "x y a.b");

// Even though the "x y a.b" rule has more scopes in its path, the "y.z a.b" rule has
// a deeper match, so it should take precedence.
assertEquals(matcher.match("x", "y.z", "a.b"), "#200000", "y.z a.b");
}

@Test
@Order(17)
@DisplayName("Theme resolving issue #38: ignores rules with invalid colors")
public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception {
final var actual = parseTheme("""
Expand Down Expand Up @@ -404,7 +471,7 @@ public void testIssue_38_ignores_rules_with_invalid_colors() throws Exception {
}

@Test
@Order(16)
@Order(18)
@DisplayName("Theme resolving issue #35: Trailing comma in a tmTheme scope selector")
public void testIssue_35_Trailing_comma_in_a_tmTheme_scope_selector() throws Exception {
final var actual = parseTheme("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* TextMate grammar API.
*
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/main.ts#L200">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/main.ts#L200">
* github.com/microsoft/vscode-textmate/blob/main/src/main.ts</a>
*/
public interface IGrammar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Represents a "pushed" state on the stack (as a linked list element).
*
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/main.ts#L258">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/main.ts#L258">
* github.com/microsoft/vscode-textmate/blob/main/src/main.ts</a>
*/
public interface IStateStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.List;

/**
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/main.ts#L249">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/main.ts#L249">
* github.com/microsoft/vscode-textmate/blob/main/src/main.ts</a>
*/
public interface IToken {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/**
* Result of the line tokenization API.
*
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/main.ts#L219">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/main.ts#L219">
* github.com/microsoft/vscode-textmate/blob/main/src/main.ts</a>
*/
public interface ITokenizeLineResult<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L418">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L418">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
final class AttributedScopeStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L898">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L898">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
public final class BalancedBracketSelectors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/basicScopesAttributeProvider.ts#L10">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/basicScopesAttributeProvider.ts#L10">
* github.com/microsoft/vscode-textmate/blob/main/src/basicScopesAttributeProvider.ts</a>
*/
final class BasicScopeAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/basicScopesAttributeProvider.ts#L18">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/basicScopesAttributeProvider.ts#L18">
* github.com/microsoft/vscode-textmate/blob/main/src/basicScopesAttributeProvider.ts</a>
*/
final class BasicScopeAttributesProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* TextMate grammar implementation.
*
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L98">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L98">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
public final class Grammar implements IGrammar, IRuleFactoryHelper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L49">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L49">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
final class Injection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/tokenizeString.ts#L31">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/tokenizeString.ts#L31">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/tokenizeString.ts</a>
*/
final class LineTokenizer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L945">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L945">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
final class LineTokens {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/theme.ts#L101">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/theme.ts#L101">
* github.com/microsoft/vscode-textmate/blob/main/src/theme.ts</a>
*/
public final class ScopeStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* Represents a "pushed" state on the stack (as a linked list element).
*
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L592">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L592">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
public final class StateStack implements IStateStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammar.ts#L893">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammar.ts#L893">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammar.ts</a>
*/
final class TokenTypeMatcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* Result of the line tokenization implementation.
*
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/main.ts#L219">
* @see <a href="https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/main.ts#L219">
* github.com/microsoft/vscode-textmate/blob/main/src/main.ts</a>
*/
final class TokenizeLineResult<T> implements ITokenizeLineResult<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammarDependencies.ts#L10">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammarDependencies.ts#L10">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammarDependencies.ts</a>
*/
public abstract class AbsoluteRuleReference {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammarDependencies.ts#L240">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammarDependencies.ts#L240">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammarDependencies.ts</a>
*/
public final class IncludeReference {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/grammar/grammarDependencies.ts#L59">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/grammar/grammarDependencies.ts#L59">
* github.com/microsoft/vscode-textmate/blob/main/src/grammar/grammarDependencies.ts</a>
*/
public final class ScopeDependencyProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/rawGrammar.ts#L62">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/rawGrammar.ts#L62">
* github.com/microsoft/vscode-textmate/blob/main/src/rawGrammar.ts</a>
*/
public interface IRawCaptures {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/rawGrammar.ts#L8">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/rawGrammar.ts#L8">
* github.com/microsoft/vscode-textmate/blob/main/src/rawGrammar.ts</a>
*/
public interface IRawGrammar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/rawGrammar.ts#L37">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/rawGrammar.ts#L37">
* github.com/microsoft/vscode-textmate/blob/main/src/rawGrammar.ts</a>
*/
public interface IRawRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/rawGrammar.ts#L39">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/rawGrammar.ts#L39">
* github.com/microsoft/vscode-textmate/blob/main/src/rawGrammar.ts</a>
*/
public interface IRawRule {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/encodedTokenAttributes.ts#L9">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/encodedTokenAttributes.ts#L9">
* github.com/microsoft/vscode-textmate/blob/main/src/encodedTokenAttributes.ts</a>
*/
public final class EncodedTokenAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
* - b = background color (9 bits)
*
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/encodedTokenAttributes.ts#L143">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/encodedTokenAttributes.ts#L143">
* github.com/microsoft/vscode-textmate/blob/main/src/encodedTokenAttributes.ts</a>
*/
final class EncodedTokenDataConsts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/encodedTokenAttributes.ts#L181">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/encodedTokenAttributes.ts#L181">
* github.com/microsoft/vscode-textmate/blob/main/src/encodedTokenAttributes.ts</a>
*/
public final class OptionalStandardTokenType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Standard TextMate token type.
*
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/encodedTokenAttributes.ts#L159">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/encodedTokenAttributes.ts#L159">
* github.com/microsoft/vscode-textmate/blob/main/src/encodedTokenAttributes.ts</a>
*/
final class StandardTokenType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

/**
* @see <a href=
* "https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/matcher.ts#L10">
* "https://github.com/microsoft/vscode-textmate/blob/167bbbd509356cc4617f250c0d754aef670ab14a/src/matcher.ts#L10">
* github.com/microsoft/vscode-textmate/blob/main/src/matcher.ts</a>
*/
@FunctionalInterface
Expand Down
Loading
Loading