Skip to content

bnf: fix slow keyword completion in grammars with 20+ rules - #467

Merged
Max Medvedev (maxmedvedev) merged 1 commit into
JetBrains:masterfrom
goto1134:fix/dummy-block-sibling-walk
Sep 19, 2026
Merged

Max Medvedev (maxmedvedev) merged 1 commit into
JetBrains:masterfrom
goto1134:fix/dummy-block-sibling-walk

Conversation

@goto1134

Copy link
Copy Markdown
Contributor

Keyword completion in .bnf files with 20 or more top-level rules re-parsed the
file from the start on every completion request, instead of resuming after the
last preceding rule. Suggestions were still correct, just slower — and
increasingly so as the file grew. Fixed.

@goto1134

Copy link
Copy Markdown
Contributor Author

Merge after #458

@goto1134 Andrei Efanov (goto1134) changed the title bnf: fix slow keyword completion in grammars with 20+ rules Draft: bnf: fix slow keyword completion in grammars with 20+ rules Aug 28, 2026
@goto1134 Andrei Efanov (goto1134) changed the title Draft: bnf: fix slow keyword completion in grammars with 20+ rules bnf: fix slow keyword completion in grammars with 20+ rules Aug 28, 2026
@goto1134
Andrei Efanov (goto1134) marked this pull request as draft August 28, 2026 11:23
@goto1134
Andrei Efanov (goto1134) force-pushed the fix/dummy-block-sibling-walk branch 2 times, most recently from 65e9c71 to cfab6d6 Compare August 29, 2026 10:26
getDummyAwarePrevSibling has two return paths: one descends into a chunk
found as a direct sibling, the other climbs to a non-empty-leading
ancestor and returns that ancestor's previous sibling as-is. The second
path never unwraps a DUMMY_BLOCK, so once a grammar has two or more
chunks in a row, walking backward across the boundary returns a raw
chunk node instead of the rule inside it, and stops there.
BnfCompletionContributor.suggestKeywords, the one caller, does not
recognize DUMMY_BLOCK either, so it gives up and completes from the
start of the file instead of resuming after the last rule.

Fix: compute prevSibling from whichever branch applies, then run it
through the same unwrap loop, so both paths unwrap consistently,
including through chunks nested more than one level deep.

GrammarUtilTest.testPrevSiblingCrossesChunkBoundaries walks a
nested-chunk grammar backward and asserts no rule is skipped; on the old
code it stops at the first chunk boundary. There is no completion-level
test: the fallback reparses the whole file, but a free top-level
position still offers the same keywords, so the regression is not
observable through suggestKeywords -- only its cost is.
@goto1134
Andrei Efanov (goto1134) marked this pull request as ready for review August 29, 2026 10:55
@maxmedvedev
Max Medvedev (maxmedvedev) merged commit bc81c7a into JetBrains:master Sep 19, 2026
5 checks passed
@goto1134
Andrei Efanov (goto1134) deleted the fix/dummy-block-sibling-walk branch September 19, 2026 12:43
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

Successfully merging this pull request may close these issues.

2 participants