feat: lint GLSL in JS/TS tagged template literals - #28
Merged
Conversation
Extract GLSL from `glsl`...`` and `/* glsl */ `...`` tagged templates in
.ts/.tsx/.js/.jsx files and lint it in place, with every diagnostic mapped
to the exact host-file line and column.
- embed.rs: a heuristic scanner (sibling to derive.rs) that finds each
tagged-template shader, tracks strings/comments, and records a per-line
map back to the host file. Line continuations are applied and `${...}`
interpolations are blanked (line/column preserving).
- check.rs: check_source dispatches JS/TS files to check_embedded, which
validates each template and remaps glslang errors and source lints alike.
- Interpolated templates are checked lints-only (an incomplete translation
unit) with an informational note; non-interpolated ones are fully
validated.
- Stage is inferred from stage-specific builtins first, then the binding
name, then a fragment default -- ordered so the default can never
misreport a builtin as undeclared.
- luma modules are resolved for an inline binding via derive_for_binding.
- lsp.rs diagnoses JS/TS documents (symbol features stay GLSL-only); new
Severity::Note. The VS Code extension activates on and selects JS/TS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lint GLSL written inline in JS/TS
glsl`...`tagged template literals — and the/* glsl */ `...`marker form — the way deck.gl/luma.gl projects keep shaders next to theirnew Model(...)call rather than in separate.glslfiles. The most-requested capability in this space.What's covered
src/embed.rs, new): a heuristic scanner — sibling toderive.rs— that finds each tagged-template shader in.ts/.tsx/.js/.jsx/.mts/.cts/.mjs/.cjs, tracking strings/comments so a backtick in a"..."string orglslinside a longer identifier isn't mistaken for a shader. It records a per-line map back to the host file.glslint check 'src/**/*.ts'validates each embedded shader and maps every diagnostic — glslang errors and the source lints — to the exact host.tsline and column (embed's per-line host map composed with the assembler's own line map)..glslfiles.Practical cases
${...}): a template with any interpolation is an incomplete translation unit (the injected value can declare symbols the shader uses, or use ones it declares), so it's checked with the source-level lints only — never a validation error that might be our own substitution's fault — and gets one informationalnote. Non-interpolated templates are fully validated. The${...}is blanked to spaces (newlines preserved) purely so the lints' line/column math stays exact.gl_Position/gl_VertexID→ vertex,gl_FragCoord/discard→ fragment,local_size_x→ compute), then the binding name, then a fragment default — ordered so the default and name hint are only reached when no stage-specific builtin is present, and therefore can't cause a wrong-stage false positive. Nomain→ a chunk wrapped syntax-only under its inferred stage.new Model({ modules })call wires up the shader's binding, via the newderive_for_binding.The glslang backend is untouched. New
Severity::Note(→ LSPINFORMATION). Fixtures + unit/integration tests cover extraction, mapping accuracy, the interpolation path, and the stage-guess false-positive regression.Docs: README gains a "Shaders inside JS/TS" section and an
embed.rsentry in "How it works"; the extension README documents the JS/TS support.