Repository navigation
analysis: diagnostics carry the answer (DiagnosticContext) - #298
Merged
Merged
Conversation
nearest ranks members by closeness to a name that wasn't found: case-only differences and a few edits (a transposition counts as one, fewer allowed for short names) first, then prefixes, and only when neither matches, names sharing a camelCase word. It backs the closest-name suggestions of diagnostic context. Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
48ee8a6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8e6e8e95.dang-3kk.pages.dev |
| Branch Preview URL: | https://diagnostic-context.dang-3kk.pages.dev |
With Options.DiagnosticContext, a type error on a selection or a name carries Diagnostic.Context, found after inference from the node the *dang.InferError is on: the member the name does name (e.g. the signature a call missing its block needs), or, when Lookup finds nothing, the receiver's members, the closest names by spelling, and the members whose names or docs match the name's camelCase words. An unknown free name is looked up in the scope at its position, leaving out what the Source declares there but the reference can't see yet (a block's later locals, a declaration's own name in its value). It's off by default: it serves readers that can't ask a follow-up question, like a model reading a tool's output, and finding it can walk every type the source reaches, which editors shouldn't pay for. Off, no context work is done at all. The type checker and its messages are untouched: whether a name is missing is decided by Lookup, never by reading the message. Signed-off-by: Alex Suraci <[email protected]>
Render and Diagnostic.Format print `path:line:col: severity: message` with the diagnostic's context, when it has one, on indented lines: the signature it names, the closest names, doc-search hits, and the receiver's member names, capped and wrapped. It's the one shape for a CLI, an engine tool, or a model to read. Signed-off-by: Alex Suraci <[email protected]>
vito
force-pushed
the
diagnostic-context
branch
from
November 11, 2026 21:18
6061532 to
48ee8a6
Compare
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 12, 2026
vito/dang main past v2.4.1: analysis's opt-in diagnostic context and Render (vito/dang#298), and rule-2 snapshot reads, so `let before = ws` stays readable after `ws = …` (vito/dang#301). No language version changes: Dang's current version is still 2.4. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Nov 12, 2026
The 2.5 page covered only the string change. It now covers everything merged since v2.4.1: declaration snapshots (#301), the editor and syntax-error changes from #300, and a Go embedders section with DiagnosticContext (#298) and the AST's new string spelling. Sources and verification name the full range. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Nov 13, 2026
The 2.5 page covered only the string change. It now covers everything merged since v2.4.1: declaration snapshots (#301), the editor and syntax-error changes from #300, and a Go embedders section with DiagnosticContext (#298) and the AST's new string spelling. Sources and verification name the full range. Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
to dagger/dagger
that referenced
this pull request
Nov 14, 2026
vito/dang main past v2.4.1: analysis's opt-in diagnostic context and Render (vito/dang#298), and rule-2 snapshot reads, so `let before = ws` stays readable after `ws = …` (vito/dang#301). No language version changes: Dang's current version is still 2.4. 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.
Type errors about a name can now carry the answer. With the new opt-in
analysis.Options{DiagnosticContext: true},analysis.Diagnosticgains aContextfield, which is filled in after inference from the AST node the*dang.InferErrorsits on. The option is off by default, and when it's off no context work is done at all, so editors pay nothing. The type checker and its error strings are unchanged. Whether a name is really missing is decided byLookup, never by parsing the message.This is the hook that the engine's planned
DangCheck/DangEvaltools and enriched module-load errors build on (design: gist0588bb5f, "The one hook, in vito/dang"). The LSP and any CLI can use it too.Before / after
Render(diags, RenderOptions{})output, analyzed withDiagnosticContext: true:Before this change, each of these was the first line alone. With the option off, it still is.
API
Options.DiagnosticContext bool: the opt-in, default off.Diagnostic.Context *DiagnosticContext(jsoncontext,omitempty), set only with the opt-in. Its fields:Name,NameRange: the name as written and its range.Member: what the name refers to, when it exists.Receiver,Has: the type being selected from, and its members.Near: the closest names by spelling.Query,Search: doc-search hits on the name's camelCase words (words of 3 or more letters).analysis.Render(diags, RenderOptions{MaxNames, Width}) stringandDiagnostic.Format(opts).nearest(unexported) ranks names by spelling. Case-only differences and small edit distances (a transposition counts as one edit) come first, then prefixes. Names that only share a camelCase word are a fallback, used when nothing else matches.Notes for review
Nearlist. This PR splits it intoNear(spelling) andSearch(doc hits), because they render differently, and because a spelling quick fix should only offer names that are close in spelling.ScopeAt. That scope also contains names declared later in the block, and a declaration's own name inside its value. Those are left out using the symbol index, solet a = total + 1; let total = 2doesn't suggesttotal.Searchover an unknown free name walks every reachable named type, which matters when a large schema (Dagger) is imported. The LSP doesn't opt in. A later LSP "Changelenghttolength" quick fix could opt in and useNearandNameRange.dang checkcommand, so no CLI is wired toRenderyet.