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

Absolute rule reference use local scope #173

Open
hediet opened this issue May 2, 2022 · 2 comments
Open

Absolute rule reference use local scope #173

hediet opened this issue May 2, 2022 · 2 comments
Assignees

Comments

@hediet
Copy link
Member

hediet commented May 2, 2022

I think this line:

collectSpecificDependencies(result, baseGrammar, baseGrammar, includedName, patternRepository);

should rather be this:

collectSpecificDependencies(result, baseGrammar, baseGrammar, includedName, baseGrammar.repository);

Also, this line:

collectSpecificDependencies(result, baseGrammar, selfGrammar, includedName, patternRepository);

should be this:

collectSpecificDependencies(result, baseGrammar, selfGrammar, includedName, selfGrammar.repository);

Let's say source.md embeds source.css and a rule in source.css references source.md#link.
Then with the logic in main, a rule in source.css referencing source.md#link would look up link in its local repository (first repositories of this rule or parent rules, then the repository of source.css), but not in the repository of source.md.

@hediet hediet self-assigned this May 2, 2022
@RedCMD
Copy link

RedCMD commented May 15, 2022

I'm cant seem to picture what you're trying to explain
can you provide an example please?

I think we can agree that source.md#link should always include the #link key from inside source.md and never anywhere else
Even if called from source.css or source.md

But if source.css tries to include #link, it should look inside its own repo first; before searching out in source.md?

source.md
source.md#link
source.css
 └ source.css#link

@hediet
Copy link
Member Author

hediet commented May 16, 2022

This is the failing test case (marked as skipped):

test.skip('Shadowed rules are resolved correctly', async function () {
const registry = new Registry({ loadGrammar: async () => undefined, onigLib: getOniguruma() });
try {
const grammar = await registry.addGrammar({
scopeName: 'source.test',
repository: {
$base: undefined!,
$self: undefined!,
foo: { include: '#bar', },
bar: { match: 'bar1', name: 'outer' }
},
patterns: [
{
patterns: [{ include: '#foo' }],
repository: {
$base: undefined!,
$self: undefined!,
bar: { match: 'bar1', name: 'inner' }
}
},
// When you move this up, the test passes
{
begin: 'begin',
patterns: [{ include: '#foo' }],
end: 'end'
},
]
});
const result = grammar.tokenizeLine('bar1', null, undefined);
// TODO this should be inner!
assert.deepStrictEqual(result.tokens, [{ startIndex: 0, endIndex: 4, scopes: ["source.test", "outer"] }]);
} finally {
registry.dispose();
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants