Skip to content

fix(editor): resolve grammar queries through Bundle instead of a path built on resourceURL - #2887

Merged
datlechin merged 1 commit into
mainfrom
fix/grammars-resource-bundle-lookup
Sep 15, 2026
Merged

datlechin merged 1 commit into
mainfrom
fix/grammars-resource-bundle-lookup

Conversation

@datlechin

@datlechin datlechin commented Sep 15, 2026

Copy link
Copy Markdown
Member

main has been red since #2878. Every branch fails the same CI step:

Run TableProGrammars package tests   failure
  ✘ "Every language's highlight query compiles against its own grammar" (5 issues)
  ✘ "Every query file a language names is on disk" (8 issues)
     missing .../TableProGrammars_TableProGrammars.bundle/Resources/Resources/tree-sitter-bash/highlights.scm

Note the doubled Resources in the path.

Cause

CodeLanguage.queryURL(for:) built its path by hand:

Bundle.module.resourceURL?.appendingPathComponent("Resources/tree-sitter-\(grammarName)/\(query).scm")

That assumes resourceURL is the bundle root. It is not, because the copied directory was itself
named Resources: in the flat bundle layout SwiftPM writes on the CI toolchain, Bundle sees a
top-level Resources directory and adopts that as the bundle's resources root, so resourceURL
already ends in /Resources and the appended path names Resources/Resources/....

Measured with a two-bundle probe, one directory named Resources and one named Queries,
identical in every other respect:

flat bundle resourceURL ends in resourceURL + path url(forResource:withExtension:subdirectory:)
Resources/tree-sitter-sql/ Resources false true
Queries/tree-sitter-sql/ <name>.bundle true true

Xcode's own SwiftPM writes the structured layout (Contents/Resources/Resources/...), where the
hand-built path happens to land correctly. That is why it passes on a developer Mac and on the app
build, and fails only in swift test on the runner. The shipping app was never affected.

Fix

Two changes, each sufficient on its own, and the pair leaves nothing layout-dependent:

  • The resource directory is Queries, not Resources, so it cannot be mistaken for a resources root.
  • The lookup goes through Bundle.module.url(forResource:withExtension:subdirectory:), which is the
    only thing that knows where a given bundle keeps its resources.

Test

A new case asserts the invariant directly: the bundle's resource directory contains Queries and
no directory named Resources. The two suites that caught this keep their coverage; with the
lookup returning nil for a file that is not there, #require fails before the fileExists check.

swift test --package-path Packages/TableProGrammars --force-resolved-versions: 10 tests, 0 failures.
swiftlint lint --strict: 0 violations.

No CHANGELOG entry: nothing here reaches a user.

What this uncovers

The job runs its package-test steps in order under set -e, so the grammars failure was hiding
whatever came after it. With this fixed, Run CodeEditSourceEditor package tests fails next, on
a stale lockfile. That is #2889, and both have to land before Package Tests is green on main.

@datlechin
datlechin merged commit a72a546 into main Sep 15, 2026
7 of 8 checks passed
@datlechin
datlechin deleted the fix/grammars-resource-bundle-lookup branch September 15, 2026 08:06
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.

1 participant