vscode: migrate settings.json writer to full hujson AST manipulation
还没有人认领这个 Issue。
评估
调研方向
从 cmd/modern/root/open/jsonc.go 和 cmd/modern/root/open/vscode.go 开始,跟踪当前的 hujson 解析、配置文件构建和更新路径。扩展 cmd/modern/root/open/jsonc_test.go,包括 TestApplyJSONCSettingsUpdates_PreservesComments,覆盖与 add 相邻的注释以及每个连接的注释。对于新的和现有的配置文件,直接的 hujson AST 更新能够保留注释、顺序和无关字段,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Background
PR #688 added sqlcmd open vscode, which writes the user's settings.json to register a connection profile. The original implementation stripped JSONC comments and trailing commas, marshaled fresh JSON, and saved the user's original to a .sqlcmd-backup file. dlevy flagged that this clobbers the backup on every subsequent run (e.g. creating a second container loses the first backup) and silently destroys hand-authored comments.
PR #688 follow-up commit replaced the strip-and-marshal round trip with github.com/tailscale/hujson. We now parse the original AST and apply an RFC 6902 patch that touches only the two keys we own (mssql.connections, mssql.connectionGroups). Comments, trailing commas, and unrelated user keys round-trip untouched on replace operations, and the .sqlcmd-backup file is no longer needed.
Remaining limitation
hujson's Patch "add" operation (used when the document doesn't yet have an mssql.connections key) can blank a comment immediately adjacent to the insertion point. Unrelated keys are preserved; only a comment line at the insertion site is affected. This is a one-time event per settings.json (subsequent runs use the "replace" path, which fully preserves comments).
Additionally, createProfile / updateOrAddProfile in cmd/modern/root/open/vscode.go operate on map[string]interface{} for the connection array itself. This means per-connection comments inside mssql.connections[*] are not preserved when sqlcmd updates an existing profile.
Proposed work
Refactor cmd/modern/root/open/jsonc.go and the profile-construction helpers to operate directly on hujson.Value AST nodes instead of decoded maps. Specifically:
- Walk the parsed root
*hujson.Objectto findmssql.connectionsandmssql.connectionGroupsmembers, mutating theirValuein place rather than going through a JSON patch. - For the array of profiles, locate the existing profile member by
idand rewrite its*hujson.Objectfields one at a time, leaving member ordering and surrounding extras intact. - When inserting a new profile or a new top-level key, set
ObjectMember.Name.BeforeExtraexplicitly so the preceding comment isn't absorbed by hujson's leading-comment extraction.
Verification
The round-trip test in cmd/modern/root/open/jsonc_test.go (TestApplyJSONCSettingsUpdates_PreservesComments) should be extended to cover the add-comment-adjacent case, and a new test should verify per-connection comments inside the mssql.connections array survive an update to an existing profile.
References
- PR: #688
- Related review thread: https://github.com/microsoft/go-sqlcmd/pull/688#discussion_r3325235606
- hujson patch semantics: https://github.com/tailscale/hujson/blob/main/patch.go
- 主要语言
- Go
- 星标
- 601
- 派生
- 91
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/go-sqlcmd 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 3/5 1-2 天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 65/100
-
-r discards the "Msg N, Level N, State N" error header — errors on stderr lose message number and line info可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 3/5 1-2 天 新手友好度 76/100
查看 microsoft/go-sqlcmd 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
LanternOps/breeze#8353 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
prime-radiant-inc/evener#4223 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
input.Scanner.Scan loops forever when the input reaches EOF, hanging every ConfirmAction prompt可能已有人在做 @mlliarm 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
elastic/cloud-sdk-go#521 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
open-telemetry/opentelemetry-go-compile-instrumentation#1467 ·
维护者通常 3 天内回复