Repository navigation
stdlib: restore removed conversion fns as @deprecated - #137
Merged
Merged
Conversation
Builtins can now be marked deprecated via a .Deprecated(reason) builder on the function, method, and static-method DSLs, which records the reason on BuiltinDef and the resulting BuiltinFunction value. When a FunCall resolves to a deprecated builtin, eval prints a warning to the context's stderr that names the reason and points at the call site, reusing the source-highlighting renderer (factored out as formatSourceAnnotation) for a "--> file:line:col" annotation with an underline. Warnings are deduped per call site within a run via a set on EvalContext, so a deprecated call inside a loop warns once; eval is single-threaded, so no lock is needed. This is the Go-side equivalent of a @deprecated directive; a follow-up uses it to restore the removed top-level conversion functions. Signed-off-by: Alex Suraci <[email protected]>
These top-level conversion functions were dropped when JSON/YAML/TOML encode and decode moved into format namespaces (issue #105). Bring them back as thin aliases marked @deprecated so existing scripts keep working while nudging callers toward JSON.encode, JSON.decode, and YAML.decode. Each delegates to the same implementation as its namespaced successor, so they honor codec field directives identically. There was never a top-level toYAML/toTOML/fromTOML, so none is restored. Signed-off-by: Alex Suraci <[email protected]>
The Deprecated reason is prose ("use JSON.encode instead"), which tools can't
rewrite against reliably. Add a Replacement field plus a .Replacement(name)
builder naming the superseding callee, and set it on toJSON/fromJSON/fromYAML.
This lets the LSP offer a mechanical quick fix without parsing the message.
Signed-off-by: Alex Suraci <[email protected]>
Walk the inferred AST for calls whose callee names a deprecated builtin and publish a warning diagnostic over the callee token, tagged Deprecated so editors strike it through. Advertise the codeAction capability and add a handler that returns a quickfix replacing the callee with its structured Replacement (e.g. toJSON -> JSON.encode), leaving the argument list untouched. Matching is by name, which the eval-time warning backstops; a local binding shadowing one of these builtins is vanishingly rare. Adds DiagnosticTag/severity wire types the local protocol structs were missing. Signed-off-by: Alex Suraci <[email protected]>
tiborvass
approved these changes
Jun 17, 2026
A deprecated builtin's card now carries a right-aligned "@deprecated" badge in its header, linking to the superseding entry's card (e.g. toJSON -> JSON.encode) via its anchor tag, which resolves across the page's module sections. The badge and link are driven by the builtin's Deprecated and Replacement metadata, so the reference stays generated rather than hand-maintained. Signed-off-by: Alex Suraci <[email protected]>
Use a plain "=>" instead of the unicode arrow, drop the badge's vertical and right padding so it hugs the header bar, and give the linked replacement code a little left padding so it isn't flush against the arrow. 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.
What
Brings back the top-level
toJSON,fromJSON, andfromYAMLfunctions that were removed when JSON/YAML/TOML encode/decode moved into format namespaces (#105), this time as@deprecatedaliases. Calling one still works but prints a warning pointing at the call site and naming the namespaced replacement — and the LSP now flags and fixes these usages in-editor.How
@deprecatedhandling for builtinsA
.Deprecated(reason)builder on the function/method/static-method DSLs records the reason onBuiltinDefand the resultingBuiltinFunction. When aFunCallresolves to a deprecated builtin, eval prints a warning to the context's stderr using the existing source-highlighting renderer (factored out asformatSourceAnnotation):Warnings are deduped per call site within a run (a set on
EvalContext), so a deprecated call inside a loop warns once. Eval is single-threaded, so no lock is needed.Restored functions
toJSON/fromJSON/fromYAMLare thin aliases that delegate to the same implementation asJSON.encode/JSON.decode/YAML.decode, so they honor codec field directives identically. There was never a top-leveltoYAML/toTOML/fromTOML, so none is restored.LSP integration
.Replacement(name)builder adds a structured successor (e.g.JSON.encode) alongside the prose reason, so tools can rewrite mechanically instead of parsing the message.Deprecatedso editors render it struck-through.textDocument/codeActionhandler (capability now advertised) offers a quick fix that replaces just the callee —toJSON(x)→JSON.encode(x)— leaving the argument list untouched.Matching is by callee name (the eval-time warning is the source of truth); a local binding shadowing one of these builtins is vanishingly rare.
Testing
builtins_test.goasserts the three are present and deprecated.tests/test_to_json_deprecated.danground-trips all three against their successors.dagger checkgreen (lint, go tests, docs-go tests).