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

Scoping Issues For Relative Rule References #174

Open
hediet opened this issue May 2, 2022 · 1 comment
Open

Scoping Issues For Relative Rule References #174

hediet opened this issue May 2, 2022 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@hediet
Copy link
Member

hediet commented May 2, 2022

This line collects the dependencies of a relative reference:

collectSpecificDependencies(result, baseGrammar, selfGrammar, include.substring(1), patternRepository);

However, it passes in the patternRepository of the current rule.

collectSpecificDependencies then continues to use this patternRepository as new local context for resolving relative references.

However, collectSpecificDependencies should continue with the repository of its own parents.

Related: #174

@hediet hediet added the bug Issue identified by VS Code Team member as probable bug label May 2, 2022
@hediet hediet self-assigned this May 2, 2022
@hediet
Copy link
Member Author

hediet commented May 5, 2022

This test case fails:

test('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' }
					}
				},
                {
					begin: 'begin',
					patterns: [{ include: '#foo' }],
					end: 'end'
				},
			]
		});
		const result = grammar.tokenizeLine('bar1', null, undefined);
		assert.deepStrictEqual(result.tokens, [{ startIndex: 0, endIndex: 4, scopes: ["source.test", "outer"] }]);
	} finally {
		registry.dispose();
	}
});

Interestingly, this succeeds, because the earlier reference to foo causes it to bind to the correct bar:

test('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: [
				{
					begin: 'begin',
					patterns: [{ include: '#foo' }],
					end: 'end'
				},
				{
					patterns: [{ include: '#foo' }],
					repository: {
						$base: undefined!,
						$self: undefined!,
						bar: { match: 'bar1', name: 'inner' }
					}
				},
			]
		});
		const result = grammar.tokenizeLine('bar1', null, undefined);
		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
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

1 participant