Skip to content

fix(setup-wizard): stop replacing IDE settings that are JSONC - #1677

Merged
Shashankss1205 merged 1 commit into
CodeGraphContext:mainfrom
AloysJehwin:fix/preserve-jsonc-ide-settings
Sep 2, 2026
Merged

Shashankss1205 merged 1 commit into
CodeGraphContext:mainfrom
AloysJehwin:fix/preserve-jsonc-ide-settings

Conversation

@AloysJehwin

Copy link
Copy Markdown
Contributor

The wizard read the target settings file like this:

try:
    settings = json.load(f)
except json.JSONDecodeError:
    settings = {}

and then wrote settings back over the same file. VS Code and its forks write settings.json as JSONC, so a file with // comments or a trailing comma raises JSONDecodeError — the wizard read that as "no settings yet" and replaced the whole configuration with a lone mcpServers key. Two people on the issue lost their settings this way; one only recovered because Settings Sync was on.

Three changes:

  • Parse JSONC before giving up. _strip_jsonc removes // and /* */ comments and trailing commas, tracking string state so a // inside a URL or an escaped quote is left alone.
  • If it still will not parse, print why and return without writing. That fallback to {} was the actual data loss; an unreadable file should be left alone, not replaced.
  • Back up the file to .cgc-backup before writing, and say so when comments were present, since json.dump cannot preserve them. The backup keeps them.

Comment preservation on the rewritten file would need a JSONC-aware writer and a new dependency, so I kept it to the data loss and made the tradeoff visible instead of silent. Happy to go further if you would rather.

Tests: tests/unit/cli/test_setup_wizard_jsonc.py, 10 passing. They cover line and block comments, trailing commas, comment markers inside strings and URLs, a realistic commented settings.json keeping every key across a round trip, and that unparseable input raises rather than resolving to {}.

$ python -m pytest tests/unit/cli/test_setup_wizard_jsonc.py -q
..........                                                               [100%]
10 passed in 0.82s

Fixes #660

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes CodeGraphContext#660

Signed-off-by: Aloys Jehwin <[email protected]>
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@AloysJehwin is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Shashankss1205 Shashankss1205 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on a local trial-merge: the string-aware JSONC stripper handles comments inside strings and escapes correctly, the destructive except → settings = {} fallback is gone (an unreadable file is now left untouched with manual instructions), a backup is taken before every rewrite, and the dropped-comments note is honest about JSON's limits. All 10 new tests pass; full suite green. This closes a genuine data-loss hazard — VS Code settings.json is JSONC more often than not. Thanks @AloysJehwin!

@Shashankss1205
Shashankss1205 merged commit 5f3f208 into CodeGraphContext:main Sep 2, 2026
15 of 21 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog tasks to Done in CGC Progress Board Sep 2, 2026
Shashankss1205 added a commit that referenced this pull request Sep 2, 2026
* fix(viz): display source filenames for synthetic module nodes

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* normalize module-node label to the plain filename in all render sites

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>
Shashankss1205 added a commit that referenced this pull request Sep 2, 2026
* fix: find functions by argument type

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* fix(viz): display source filenames for synthetic module nodes (#1682)

* fix(viz): display source filenames for synthetic module nodes

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* normalize module-node label to the plain filename in all render sites

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>

* fix the argument query so it filters f; behavioral pin on real kuzu

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Upanshi Mittal <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>
Shashankss1205 added a commit that referenced this pull request Sep 2, 2026
…1676)

* feat: add SSL connection parameters to cassandra_ingester.py

* feat: add SSL connection parameters to mysql_ingester.py

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* fix(viz): display source filenames for synthetic module nodes (#1682)

* fix(viz): display source filenames for synthetic module nodes

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* normalize module-node label to the plain filename in all render sites

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>

* fix: find functions by argument type (#1686)

* fix: find functions by argument type

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* fix(viz): display source filenames for synthetic module nodes (#1682)

* fix(viz): display source filenames for synthetic module nodes

* fix(jobs): serialize last update time in job responses (#1679)

* fix(cli): explain embedded database lock conflicts (#1684)

* fix(setup-wizard): stop replacing IDE settings that are JSONC (#1677)

VS Code and its forks write settings.json as JSONC. json.load rejects comments
and trailing commas, and the wizard treated that rejection as "no settings yet"
before writing the file back, so a user's whole configuration was replaced by a
lone mcpServers key.

Parse JSONC before giving up, and if the file still cannot be parsed, leave it
alone instead of overwriting it. Back up the file before writing either way, and
say so when comments are present, since json.dump cannot preserve them.

Fixes #660

Signed-off-by: Aloys Jehwin <[email protected]>

* feat(cgcignore): treat .gitignore as an ignore source (#1680)

Anything git ignores is now ignored by the indexer, so a repository no longer
needs a .cgcignore that restates its .gitignore.

Patterns are layered defaults -> .gitignore -> .cgcignore. Matching is
last-match-wins, so a negated pattern in .cgcignore can still bring a
git-ignored path back into the graph.

Fixes #729

Signed-off-by: Aloys Jehwin <[email protected]>

* normalize module-node label to the plain filename in all render sites

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>

* fix the argument query so it filters f; behavioral pin on real kuzu

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Upanshi Mittal <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>

* fix(viz): render FalkorDB relationships in the live graph (#1689)

parse_element classified relationships by class name, matching only
Relationship/KuzuRelationship. FalkorDB's edge class is named Edge, so it
matched no branch and every FalkorDB relationship was silently dropped —
on the backend that is CGC's default on Unix under Python 3.12+. parse_rel
directly below already reads FalkorDB edges correctly; it was never reached.

The offline renderer in cli_helpers already classified by duck typing and
handled this (#1453). Both renderers now share those predicates in
utils/graph_shapes, so classification cannot drift apart again.

* expose --ssl-verify/--ssl-ca-certs on the datasource CLI; test the driver kwargs

---------

Signed-off-by: Aloys Jehwin <[email protected]>
Co-authored-by: Donovan Yohan <[email protected]>
Co-authored-by: Aloys Jehwin <[email protected]>
Co-authored-by: Upanshi Mittal <[email protected]>
Co-authored-by: Shashank Shekhar Singh <[email protected]>
Co-authored-by: Mansurshakh Japarov <[email protected]>
Co-authored-by: Abhinav Singh <[email protected]>
@Shashankss1205 Shashankss1205 added gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:exceptional GSSoC quality: x1.5 contributor / +10 mentor type:bug GSSoC type bonus: bug labels Sep 2, 2026
Shashankss1205 added a commit that referenced this pull request Sep 2, 2026
…1567) (#1694)

Every entry is sourced from an actual issue (#1673 census loop, #1683 lock
conflicts, #1317 context desync, #1597 silent vector resolve, #1625 stale
grammar venv, #1677 JSONC settings, #1680 ignore layering, #1685 arg types,
#1689 missing viz edges), with the version each fix shipped in and the
still-applicable workarounds. Linked from the README.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC validation: counts toward scoring level:advanced GSSoC difficulty: 55 pts contributor / 30 mentor mentor:Shashankss1205 GSSoC mentor attribution: credits reviewing mentor quality:exceptional GSSoC quality: x1.5 contributor / +10 mentor type:bug GSSoC type bonus: bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Installation of CodeGraphContext overwrites VS Code settings

2 participants