Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#767 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
58/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
go
Área
cli, testing

Línea de trabajo

Comienza con cmd/modern/root/open/jsonc.go y cmd/modern/root/open/vscode.go para rastrear el análisis actual de hujson, la construcción de perfiles y las rutas de actualización. Amplía cmd/modern/root/open/jsonc_test.go, incluido TestApplyJSONCSettingsUpdates_PreservesComments, para los comentarios adyacentes a add y por conexión. Se considera terminado cuando las actualizaciones directas del AST de hujson conservan los comentarios, el orden y los campos no relacionados para los perfiles nuevos y existentes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Go
Estrellas
595
Forks
91
Merge medio
9 h 35 min
PR fusionados (30 d)
1

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/go-sqlcmd

Todos los issues de microsoft/go-sqlcmd

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.