microsoft / microsoft/vscode-textmate

scoping lookaheads prevents scoping same region when consumed

Open
#108 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
TypeScript
Stars
678
Forks
135
Avg merge
1d 14h
Merged PRs (30d)
2

Description

In the following rule, I am trying to apply two scopes to the same character in the text. Other ways I have attempted to use do not seem to be supported by all editors that support TextMate grammars. I get inconsistent results between editors with this approach as well.

The text is:

$( some text )

The goal is to apply two scopes to the $.

This is the rule I tried, using a look-ahead that is captured to apply a scope, and then a consuming capture to scope it a second time.

		{
			"begin": "(?=(\\$)\\()",
			"beginCaptures": {
				"1": {
					"name": "punctuation.definition.subexpression.powershell"
				}
			},
			"comment": "TODO: move to repo; make recursive.",
			"end": "\\)",
			"endCaptures": {
				"0": {
					"name": "punctuation.section.group.end.powershell"
				}
			},
			"patterns": [
				{
					"begin": "\\G(\\$)(\\()",
					"beginCaptures": {
						"1": {
							"name": "keyword.other.substatement.powershell"
						},
						"2": {
							"name": "punctuation.section.group.begin.powershell"
						}
					},
					"comment": "TODO: move to repo; make recursive.",
					"end": "(?=\\))",
					"name": "meta.group.complex.subexpression.powershell",
					"patterns": [
						{
							"include": "$self"
						}
					]
				}
			]
		},

In VSCode-TextMate, the first scope (applied by the look-ahead) is the result, and the scope applied by the inner rule which consumes the text is ignored.

image

In Atom, its the other way around. The last applied scope seems to stick.

Atom also does not support assigning multiple scopes, separated by spaces, to a single capture. I cannot confirm is this is supported by TextMate, but it definitely is supposed by VSCode-TextMate.

I would like to have thought that I can add as many scopes to a given region, through what ever capturing means possible. I do not know if TextMate supports this either, though.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JSON grammar rule in the issue and reproduce its overlapping look-ahead and consuming captures in VSCode-TextMate. Compare the observed scope assignment with the Atom behavior described; done means the supported behavior for multiple scopes on the same region is defined and the inconsistent result is resolved or documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
vscode
Domain
tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.