Skip to content

Add positive field query syntax #4456

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

RedCMD
Copy link

@RedCMD RedCMD commented May 18, 2025

@ribru17
Copy link
Contributor

ribru17 commented May 18, 2025

How is this a fix/workaround for query serialization or the slow query parsing issues?

@RedCMD
Copy link
Author

RedCMD commented May 18, 2025

the slow query

(parent (childA) (childB) (childC))
(parent (childA) (childC) (childB))
(parent (childB) (childA) (childC))
(parent (childB) (childC) (childA))
(parent (childC) (childA) (childB))
(parent (childC) (childB) (childA))

can be replaced with the much faster

(parent &childA &childB &childC)

query serialization isn't needed as badly if all queries are fast


wow github...
the checks failed cause it took 20min 8sec
which is longer than the allowed 20min

@ribru17
Copy link
Contributor

ribru17 commented May 18, 2025

I guess, but I personally wouldn't consider this a workaround because this specific case isn't the cause for the truly horrendously slow query parses (which are covered by #4042)

@ribru17
Copy link
Contributor

ribru17 commented May 18, 2025

Also is this for fields or children? I thought the ! syntax applied to field names but it looks like in your example it is meant to test for the existence of nodes, rather than fields

@RedCMD
Copy link
Author

RedCMD commented May 18, 2025

(parent &fieldA &fieldB &fieldC)
@ribru17
Copy link
Contributor

ribru17 commented May 18, 2025

? ok you can change the names of the hypothetical fields but I'm just saying that this:

(parent &childA &childB &childC)

is not equivalent to this:

(parent (childA) (childB) (childC))
(parent (childA) (childC) (childB))
(parent (childB) (childA) (childC))
(parent (childB) (childC) (childA))
(parent (childC) (childA) (childB))
(parent (childC) (childB) (childA))

if & tests for the presence of fields. Recall that:

this_is_a_field: (this_is_a_node)

That said, I'm not sure this PR works as intended. Would you mind adding some tests for the behavior (not just for syntax errors)?

@RedCMD
Copy link
Author

RedCMD commented May 19, 2025

I am now able to build and test the PR
everything seems to be working as expected

is not equivalent to this:

ik
it works in the way I would like
being both orderless and performant
having to use fields instead of node names is kinda a bummer
but that doesn't really affect me much


I replaced this old query: (https://github.com/RedCMD/TmLanguage-Syntax-Highlighter/blob/015b41533fbfda48e881f0af0101e0b51036bde4/src/DiagnosticCollection.ts#L547-L581)

(repo
	[(include) (patterns)] (repository
		(repo
			(key) @nestRepo))
	!match !begin)
(repo
	(repository
		(repo
			(key) @nestRepo)) [(include) (patterns)]
	!match !begin)
(pattern
	(patterns) (repository
		(repo
			(key) @nestRepo))
	!match !begin !include)
(pattern
	(repository
		(repo
			(key) @nestRepo)) (patterns)
	!match !begin !include)
(capture
	(patterns) (repository
		(repo
			(key) @nestRepo))
	!match !begin)
(capture
	(repository
		(repo
			(key) @nestRepo)) (patterns)
	!match !begin)

with this new one:

(repo
	&include (repository
		(repo
			(key) @nestRepo))
	!match !begin)
(repo
	&patterns (repository
		(repo
			(key) @nestRepo))
	!match !begin !include)
(pattern
	&patterns (repository
		(repo
			(key) @nestRepo))
	!match !begin !include)
(capture
	&patterns (repository
		(repo
			(key) @nestRepo))
	!match !begin)

the old one took 4200ms to compile
returned duplicate captures if multiple of the same node existed (patterns)
and is just bigger

while the new one compiles in just 22ms, 190x times faster
doesn't return duplicate captures
and is smaller

and I was able to improve this query as well (https://github.com/RedCMD/TmLanguage-Syntax-Highlighter/blob/015b41533fbfda48e881f0af0101e0b51036bde4/src/DiagnosticCollection.ts#L754-L794)
from 17600ms to 530ms. only a 33x speed up


I will look into creating tests soon

@RedCMD
Copy link
Author

RedCMD commented May 24, 2025

I've added a working positive field query test

@RedCMD
Copy link
Author

RedCMD commented Jun 7, 2025

Fixed merge conflict

even tho there was no conflict..... github??

@ribru17
Copy link
Contributor

ribru17 commented Jun 7, 2025

there was a conflict (#4496)

@clason
Copy link
Contributor

clason commented Jun 7, 2025

git can resolve conflicts that Github can't.

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