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

Repository works only when it defined at top level of grammar file #140

Open
graceful-potato opened this issue Oct 6, 2020 · 8 comments
Labels
feature-request Request for new features or functionality

Comments

@graceful-potato
Copy link

In textmate you can define repositroy within a specific rule and it works fine.

I created this grammar file for test

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>fileTypes</key>
	<array>
		<string>qwe</string>
	</array>
	<key>name</key>
	<string>Qwe</string>
	<key>patterns</key>
	<array>
		<dict>
			<key>begin</key>
			<string>begin</string>
			<key>beginCaptures</key>
			<dict>
				<key>0</key>
				<dict>
					<key>name</key>
					<string>keyword.control.begin.qwe</string>
				</dict>
			</dict>
			<key>end</key>
			<string>end</string>
			<key>endCaptures</key>
			<dict>
				<key>0</key>
				<dict>
					<key>name</key>
					<string>keyword.control.end.qwe</string>
				</dict>
			</dict>
			<key>name</key>
			<string>meta.begin-end.qwe</string>
			<key>patterns</key>
			<array>
				<dict>
					<key>include</key>
					<string>#foo</string>
				</dict>
			</array>
			<key>repository</key>
			<dict>
				<key>foo</key>
				<dict>
					<key>match</key>
					<string>foo</string>
					<key>name</key>
					<string>keyword.control.foo.qwe</string>
				</dict>
			</dict>
		</dict>
	</array>
	<key>scopeName</key>
	<string>source.qwe</string>
	<key>uuid</key>
	<string>06AD8311-7342-4086-843E-BFB83EBC2377</string>
</dict>
</plist>

result in textmate:
Screen Shot 2020-10-05 at 10 30 28
result in vscode:
Screenshot from 2020-10-06 22-50-26

In vscode whole rule stopped working without any error

@msftrncs
Copy link
Contributor

I have used sub repository several times. My current experience says that it needs to reside in the root element, or directly in other repositories, in order to work, not within any patterns element. It is possible that TextMate allows repository to appear anywhere, but it is not documented.

@alexdima alexdima added the feature-request Request for new features or functionality label Jan 29, 2021
@jtbandes
Copy link

jtbandes commented Nov 3, 2023

+1! This was a tough one to debug! 😬

I believe I am running into the same issue. As a reduced test case I defined this simple grammar:

patterns:
  - include: "#aaaaaa"

repository:
  aaaaaa:
    name: meta.definition.operator.swift
    begin: abc
    end: $
    beginCaptures:
      0: { name: storage.modifier.swift }
    patterns:
      - include: "#xxx"

    repository:
      xxx:
        match: def
        captures:
          0: { name: entity.name.function.operator.swift }

In TextMate this renders as expected:

image

In VS Code, somehow even the name and beginCaptures are not applied. It's like the whole pattern is being thrown away.

image

If I change it to:

patterns:
  - include: "#aaaaaa"

repository:
  aaaaaa:
    ...
  xxx:
    ...

then it seems to work.

Would you agree this looks like the same issue, or do you think it's a different one?

I would disagree somewhat with the original issue title. Like @msftrncs said, I've had nested repository work in many cases. Yet in some cases, it stops working. I have not determined when it works and when it doesn't. I will probably just abandon nested repositories to avoid a recurrence of this issue.

@graceful-potato
Copy link
Author

@jtbandes looks like the very same issue. Rule stops working when you define repository in this rule and include it

@RedCMD
Copy link

RedCMD commented Nov 4, 2023

@jtbandes also keep in mind another bug
if all includes inside the patterns array cannot be found
then the entire repository item aaaaaa will fail and be skipped

an empty patterns array or having atleast one working include inside it will not cause an error, and allow it to work as expected

@jtbandes
Copy link

jtbandes commented Nov 5, 2023

Thanks for the info. I've also noticed another bug which is causing some grief: a 2nd match of a group (e.g. via \g<1>) will cancel/override an earlier match:

  - match: (AAA)\g<1>
    captures:
      1: { name: keyword.control }

produces: image

This seems related to #164 but I'm not sure it's the same issue.

@jtbandes
Copy link

jtbandes commented Nov 5, 2023

Also, patterns executed inside a capture group seem to cancel/override scopes from parent groups:

  - match: (A(BCD+EF)G)
    captures:
      1:
        name: keyword.control
      2:
        patterns:
          - match: CDE
            name: storage.modifier

produces: image

@RedCMD
Copy link

RedCMD commented Nov 5, 2023

@jtbandes

This seems related to #164 but I'm not sure it's the same issue.

it is also the same as #208

Also, patterns executed inside a capture group seem to cancel/override scopes from parent groups:

I think there was a work around
you can place name at same level as patterns ? or smth
or only at the same level as the first match
or maybe just for begin/end rules

@RedCMD
Copy link

RedCMD commented Nov 21, 2023

I found the problem to be; if theres a match or begin at the same level as the nested repository
then VSCode will just ignore the repository

workaround is to nest everything except the repository inside a patterns array

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>fileTypes</key>
	<array>
		<string>qwe</string>
	</array>
	<key>name</key>
	<string>Qwe</string>
	<key>patterns</key>
	<array>
		<dict>
			<key>patterns</key>
			<array>
				<dict>
					<key>begin</key>
					<string>begin</string>
					<key>beginCaptures</key>
					<dict>
						<key>0</key>
						<dict>
							<key>name</key>
							<string>keyword.control.begin.qwe</string>
						</dict>
					</dict>
					<key>end</key>
					<string>end</string>
					<key>endCaptures</key>
					<dict>
						<key>0</key>
						<dict>
							<key>name</key>
							<string>keyword.control.end.qwe</string>
						</dict>
					</dict>
					<key>name</key>
					<string>meta.begin-end.qwe</string>
					<key>patterns</key>
					<array>
						<dict>
							<key>include</key>
							<string>#foo</string>
						</dict>
					</array>
				</dict>
			</array>
			<key>repository</key>
			<dict>
				<key>foo</key>
				<dict>
					<key>match</key>
					<string>foo</string>
					<key>name</key>
					<string>keyword.control.foo.qwe</string>
				</dict>
			</dict>
		</dict>
	</array>
	<key>scopeName</key>
	<string>source.qwe</string>
	<key>uuid</key>
	<string>06AD8311-7342-4086-843E-BFB83EBC2377</string>
</dict>
</plist>

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants