Repository navigation
Hint at common mistakes with a docs link (pitfalls) - #302
Merged
Merged
Conversation
Deploying dang with
|
| Latest commit: |
385a331
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b284a796.dang-3kk.pages.dev |
| Branch Preview URL: | https://pitfall-diagnostics.dang-3kk.pages.dev |
Give the sections pitfall diagnostics link to explicit tags, so their anchors survive a heading's rewording. Each tag but if-else and record-literals is the slug the live site already serves. Also say outright that `//` is not a comment and that there is no `&&` or `||`. Signed-off-by: Alex Suraci <[email protected]>
Add a small registry of pitfalls (pkg/dang/pitfalls.go): mistakes Dang
can recognize precisely, each with an ID, a one-line hint and a link to
the docs. An error that is one carries it, and the CLI, the analysis
package (and so analysis.Render), the LSP, the REPL and the playground
show the hint and link beside the error.
- line-comment, logical-operators, loop-keywords, single-brace-record:
detected at a parse failure from the PEG parser's failure offset and
the source text, so they work without tree-sitter (the engine builds
without cgo, where a parse error is otherwise a raw parser dump). They
replace the parser's message. A small lexer (codeMask) keeps them off
comments and string text, every quote kind of Dang 2.5 included; an
interpolation counts as code.
- loop-keywords also matches `for`/`while` that parsed as a call to an
undefined name, logical-operators a `&&` starting a line (which parses
as a reference to a reference), and truthiness a non-Boolean
condition or logical operand: detected in NewInferError from typed
errors, keeping the message.
Each leaves look-alike code alone: Python's floor division (`n // 2`),
a declaration with a misspelled type in a block (`{ count: int = 1 }`),
a nullable Boolean, Decoded data or a function as a condition, and
`for` loops before Dang 2.1.
A pitfall only adds guidance: no semantics change. TestPitfalls
(pkg/dang/analysis) is the table of positive and negative cases, run in
both builds; TestPitfallsAreDocumented checks each docs link names a
tagged heading in docs/lit, which the Go checks now include.
Signed-off-by: Alex Suraci <[email protected]>
Describe where pitfalls live, how each kind is detected, and how to add one with its test rows. Signed-off-by: Alex Suraci <[email protected]>
Without cgo there is no tree-sitter recovery, so a parse error that is no pitfall was the parser's raw message, listing every token it would have taken. That is what the engine shows, since it embeds Dang without cgo. Report it as `syntax error: unexpected 'x'` at the token the parser failed at instead (the whole word or `//`, when it failed inside one), in the same shape as a tree-sitter diagnosis. With cgo, it stands in when tree-sitter finds nothing to diagnose. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
pitfall-diagnostics
branch
from
November 12, 2026 18:13
5e41219 to
385a331
Compare
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302) and tree-sitter compiled to WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs cgo anywhere, and its highlighter (dang.Highlight) is usable from any binary. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs cgo anywhere, and its highlighter (dang.Highlight) is usable from any binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list hints suggest `value.{{id}}`, and a failed declaration no longer cascades "not found" errors through its uses. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs cgo anywhere, and its highlighter (dang.Highlight) is usable from any binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list hints suggest `value.{{id}}`, and a failed declaration no longer cascades "not found" errors through its uses. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 13, 2026
Pulls in pitfall diagnostics (vito/dang#302), tree-sitter compiled to WebAssembly and run by wazero (vito/dang#303, #307): Dang no longer needs cgo anywhere, and its highlighter (dang.Highlight) is usable from any binary. Also checker diagnostics fixes (vito/dang#309): GraphQL object list hints suggest `value.{{id}}`, and a failed declaration no longer cascades "not found" errors through its uses. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Nov 13, 2026
Hints for common mistakes get a section, with two errors as printed. Faster Dagger modules, failed declarations reported once and the GraphQL object list hint join the smaller changes. Go embedders learn that Dang no longer needs cgo, and about LoadTreeSitter. The lede and sources cover them, verified at 2918064. Signed-off-by: Alex Suraci <[email protected]>
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.
Dang now recognizes a few common mistakes, which it calls pitfalls:
//comments,&&/||,for/whileloops, single-brace records and truthiness. The diagnostic for one carries a one-line hint and a link to the docs section that covers it. This is a language feature, so it shows up everywhere a diagnostic does: CLI errors,analysisdiagnostics (and soanalysis.Render, which the engine's DangCheck/DangEval use), the LSP, the REPL and the playground.How it works
pkg/dang/pitfalls.goholds a small registry,Pitfalls. Each entry has an ID, a hint, a docs URL, and a detector:codeMask) keeps detectors off comments and string text for every quote kind of Dang 2.5 ("…","""…""",'…','''…''', backticks). The contents of a${…}interpolation count as code.NewInferErrormatches typed errors (notBooleanErr,nameNotFoundError,notAFunctionError). The original message stays and the hint is added to it.A pitfall never changes semantics and never hides an error: it either adds a hint, or it replaces a parse error's message with a more specific one at the same failure.
Docs links point at explicit
{#tag}headings, so rewording a heading doesn't break them. Three of the five tags (comments,logical,loop) are the slugs the live site already serves.record-literalsandif-elseare new, so those two links land at the top of their page until the docs redeploy.TestPitfallsAreDocumentedchecks that every link names a tagged heading indocs/lit. To support that,dagger.tomlnow includesdocs/lit/**in the Go checks.The pitfalls
line-comment//let x = 1 // onelogical-operators&&/||; also&&xat the start of a line (it parses as&(&x))a && falseloop-keywordsfor/whileheader (not in Dang < 2.1); also"for" not foundfor x in xs {single-brace-record{ name: valuewhere an expression startslet p = { name: "a" }truthiness!operandif (xs) { … }There's no pitfall for interpolation. Since #300,
"…"interpolates, and an undefined${NAME}in one already gets its own hint ("to write ${NAME} as text, single-quote the string or escape it as ${NAME}"). That hint could become a pitfall later to gain a docs link, but that would reword #300's message, so it isn't in this PR.Tests
TestPitfalls(pkg/dang/analysis/pitfalls_test.go) is a table: source goes in, rendered diagnostics come out. It has 50 rows: 21 positive and 29 negative. Negative rows are code that looks like a pitfall but isn't one: floor divisionn // 2,//and&&inside double-quoted, single-quoted and backtick strings (including ones that interpolate),{ count: int = 1 },forin Dang 2.0,${while}in a string (which has #300's own hint),Decodedconditions, and so on. Positive rows include a&&inside an interpolation and a//after an interpolating string. A valid negative row must produce no diagnostics at all. An invalid one may error, but not as a pitfall.Golden fixtures show the CLI rendering:
tests/errors/pitfall_line_comment.dangis new.for_removedandcondition_*goldens now include the hint.TestPitfallsandTestUnexpectedSyntaxErrorpass with bothCGO_ENABLED=0andCGO_ENABLED=1. I ran those locally; the repo's Go checks only run with cgo (see below).Last commit: replace the parser dump (droppable)
"errors: name the token a parse failed at" is separate on purpose so it can be dropped on its own. Without cgo, a parse error that isn't a pitfall used to be pigeon's raw
no match found, expected: "!", "#", …dump. It is nowsyntax error: unexpected 'x'at the token where the parser failed, in the same shape as the cgo output. With cgo, it also stands in when tree-sitter finds nothing to report; tree-sitter's diagnosis still comes first, using #300's choice of the error nearest where the PEG failed. Nothing else depends on this commit.Remaining differences between the builds:
missing closing ')'orinvalid expression after '=', sometimes at a wider span. Without cgo, the message names the token the parser stopped at, e.g.unexpected 'print'.CI
The Go checks (
go/packages/tests/test) only build with cgo, since the toolchain setsCC=clang. So the path the engine uses isn't covered by CI. Adding a nocgo run would take a check that runsCGO_ENABLED=0 go test ./pkg/dang/... ./pkg/lsp(for example, a@checkonTestin.dagger/main.dang)../testsshould stay cgo-only, because its syntax-error goldens record the tree-sitter messages.Docs
testingskill now has a "Pitfalls" section: where pitfalls live, how each kind is detected, and how to add one along with its table rows.docs/litsays outright that//is not a comment and that there is no&&/||.