Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

vscode: migrate settings.json writer to full hujson AST manipulation

Đang mở
#767 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
58/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
go
Lĩnh vực
cli, testing

Hướng nghiên cứu

Bắt đầu với cmd/modern/root/open/jsonc.go và cmd/modern/root/open/vscode.go để theo dõi việc phân tích cú pháp hujson hiện tại, quá trình xây dựng profile và các đường dẫn cập nhật. Mở rộng cmd/modern/root/open/jsonc_test.go, bao gồm TestApplyJSONCSettingsUpdates_PreservesComments, cho các chú thích liền kề với add và theo từng kết nối. Hoàn thành khi các cập nhật AST hujson trực tiếp giữ nguyên chú thích, thứ tự và các trường không liên quan đối với profile mới và hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

  1. Walk the parsed root *hujson.Object to find mssql.connections and mssql.connectionGroups members, mutating their Value in place rather than going through a JSON patch.
  2. For the array of profiles, locate the existing profile member by id and rewrite its *hujson.Object fields one at a time, leaving member ordering and surrounding extras intact.
  3. When inserting a new profile or a new top-level key, set ObjectMember.Name.BeforeExtra explicitly 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

Ngôn ngữ chính
Go
Star
601
Fork
91
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/go-sqlcmd

Tất cả issue của microsoft/go-sqlcmd

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.