Skip to content

Fix modify calls over user/org settings.

Administrator requested to merge code-insights/jsonc-operation-fix into main

Created by: vovakulikov

Closes https://github.com/sourcegraph/sourcegraph/issues/21623

You can see this problem If you try to edit insight and you have an empty extension object below this insight config in a user or org settings.

Example

{
  "experimentalFeatures": {
    "codeInsights": true
  },
   // [2] attempt edit insight but we will produce bad jsonc
   // because we shift all document on the first step 
  "searchInsights.insight.migrationToNewGraphQlTsTypes2Dfd23": {
    "title": "Migration to new GraphQL TS types #2dfd23",
    "repositories": [
      "github.com/sourcegraph/sourcegraph"
    ],
    "series": [
      {
        "name": "Imports of old GQL.* types",
        "stroke": "var(--oc-grape-7)",
        "query": "patternType:regex case:yes \\*\\sas\\sGQL"
      }
    ],
    "step": {
      "months": 2
    }
  },
   // [1] First modification of extensions object shifts all documents by at least one line
  "extensions": {},
}

If you edit the extension object first you change the document length and indexes of all symbols below the extension field (shift by one line since we're adding a new extension to the extension object). Then we try to edit insight by ID but the indexes/place of this insight in a user document has already been changed by extension edit operation so we just will produce an illegal JSON object by this operation.

As a result, we have this problem.

Merge request reports

Loading