Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Add options for ConfigFactory to handle customConfig properly#2588

Merged
mkondratek merged 2 commits intomainfrom
mkondratek/fix/customConfigComments
Nov 7, 2024
Merged

Add options for ConfigFactory to handle customConfig properly#2588
mkondratek merged 2 commits intomainfrom
mkondratek/fix/customConfigComments

Conversation

@mkondratek
Copy link
Copy Markdown
Contributor

@mkondratek mkondratek commented Nov 6, 2024

Fixes https://linear.app/sourcegraph/issue/CODY-4264/a-comment-in-cody-settingsjson-breaks-cody-initialization-stuck-at.

Test plan

  1. Have the cody_settings.json like this:
{
  // other providers...
  "openctx.providers": {
    "https://gist.githubusercontent.com/thenamankumar/3708f084fb2abd57adafe7f14620bdf7/raw/e7c7059cb5b04f6feead002e7b3a90c5b1a4bb96/provider.js": true
  }
}
  1. Cody should initialize

@mkondratek mkondratek self-assigned this Nov 6, 2024
Comment on lines +144 to +142
val config = ConfigFactory.parseString(text).resolve()
val config = JsonParser.parseString(text).asJsonObject
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ConfigFactory does not render json. The rendered config contained the comment with # instead of //. Using JsonParser fixes the problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Other option would be adding .setComments(false) in the current code.
I thought Lightened Config was a bit more forgiving when parsing e.g. additional commas.
Maybe we can write simple test for that and check how those corner cases looks in case of both approaches?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@mkondratek mkondratek requested a review from pkukielka November 6, 2024 17:24
@mkondratek mkondratek force-pushed the mkondratek/fix/customConfigComments branch from 95ac480 to 6264807 Compare November 7, 2024 09:37
@mkondratek mkondratek changed the title Use JsonParser instead of ConfigFactory for customConfig Add options for ConfigFactory to handle customConfig properly Nov 7, 2024
val config = ConfigFactory.parseString(text).resolve()
var config = ConfigFactory.parseString(text).resolve()
additionalProperties.forEach { (key, value) ->
config.withValue(key, ConfigValueFactory.fromAnyRef(value))
Copy link
Copy Markdown
Contributor Author

@mkondratek mkondratek Nov 7, 2024

Choose a reason for hiding this comment

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

There was a bug 😄 configs are immutable

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Basically, we ignored "foldingRanges": "indentation-based" - how important for us is this option?

Comment on lines +27 to +33
parsed
.get("cody")
.asJsonObject
.get("experimental")
.asJsonObject
.get("foldingRanges")
.asString)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

withValue adds the field as

"cody": {
  "experimental": {
    "foldingRanges": "indentation-based"
  }
}

instead of

"cody.experimental.foldingRanges": "indentation-based"

Is it a problem? 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO It is not, those are equivalent in VSC config.

Copy link
Copy Markdown
Contributor

@pkukielka pkukielka left a comment

Choose a reason for hiding this comment

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

LGTM

@mkondratek mkondratek merged commit 6ab342f into main Nov 7, 2024
@mkondratek mkondratek deleted the mkondratek/fix/customConfigComments branch November 7, 2024 12:22
This was referenced Nov 8, 2024
kalanchan added a commit that referenced this pull request Nov 8, 2024
cherry pick #2588 - allowing more flexibility as we didn't inform the
team when branch cut was

Fixes

https://linear.app/sourcegraph/issue/CODY-4264/a-comment-in-cody-settingsjson-breaks-cody-initialization-stuck-at.


## Test plan
1. Have the cody_settings.json like this:
```
{
  // other providers...
  "openctx.providers": {
    "https://gist.githubusercontent.com/thenamankumar/3708f084fb2abd57adafe7f14620bdf7/raw/e7c7059cb5b04f6feead002e7b3a90c5b1a4bb96/provider.js": true
  }
}
```
2. Cody should initialize

## Test plan

<!-- All pull requests REQUIRE a test plan:
https://sourcegraph.com/docs/dev/background-information/testing_principles

Why does it matter?

These test plans are there to demonstrate that are following industry
standards which are important or critical for our customers.
They might be read by customers or an auditor. There are meant be simple
and easy to read. Simply explain what you did to ensure
your changes are correct!

Here are a non exhaustive list of test plan examples to help you:

- Making changes on a given feature or component:
- "Covered by existing tests" or "CI" for the shortest possible plan if
there is zero ambiguity
  - "Added new tests"
- "Manually tested" (if non trivial, share some output, logs, or
screenshot)
- Updating docs:
  - "previewed locally"
  - share a screenshot if you want to be thorough
- Updating deps, that would typically fail immediately in CI if
incorrect
  - "CI"
  - "locally tested"
-->

Co-authored-by: Mikołaj Kondratek <mik.kondratek@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants