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

Support JSON Schema in Config - #3613

Merged
benogle merged 77 commits into
masterfrom
bo-config-types
Sep 30, 2014
Merged

benogle merged 77 commits into
masterfrom
bo-config-types

Conversation

@benogle

@benogle benogle commented Sep 24, 2014

Copy link
Copy Markdown
Contributor

JSON Schema (schema core, and the supported keys)

It will look like this:

@config:
  fontSize:
    type: 'integer'
    default: 16
  lineHeight:
    type: 'number'
    default: 1.3
  someArray:
    type: 'array'
    default: ['ok', 'yeah']
    items:
      type: 'string'
  invisibles:
    type: 'object'
    properties:
      eol:
        type: 'string'
        default: '\u00ac'
      space:
        type: 'string'
        default: '\u00b7'

Notes

  • If a value is passed to ::set cannot be coerced, it will not be set (eg. passing 'omg' to an integer type)

TODO

  • support some of the fancy bits of the schema (minimum, maximum, enum)
  • deprecate the getInt style methods
  • use in our internal classes
  • read schema from loaded packages
  • figure out a reasonable notification when there are issues loading user's config
  • deprecate configDefaults
  • write a doc about it I can point to
  • write good docs into Config class
  • Move config schemas out of workspace and editor
  • convert a package to use schema in a PR Specify config schema git-diff#40
  • make sure settings view works

@kevinsawicki

Copy link
Copy Markdown
Contributor

If a value is passed to ::set cannot be coerced, it will not be set (eg. passing 'omg' to an integer type)

Will this throw an error or silently fail?

@benogle

benogle commented Sep 24, 2014

Copy link
Copy Markdown
Contributor Author

Will this throw an error or silently fail?

::set returns false and does not set the value.

@kevinsawicki

Copy link
Copy Markdown
Contributor

::set returns false and does not set the value.

So set will no longer return the value?

@benogle

benogle commented Sep 24, 2014

Copy link
Copy Markdown
Contributor Author

It makes more sense IMO, to return a bool indicating set / not set. Do you rely on the returned value? Cant you call get afterward? Would you rather it throws an error? How do we handle those when they happen?

@kevinsawicki

Copy link
Copy Markdown
Contributor

I'm fine with it returning false, I've never relied on the returned value, I just wanted to double check that we weren't going to return the value on the success state if it returned false in the error state.

I'm kind of curious how this will handle values it reads off disk that are invalid though, like if you have a bad value already written to your ~/.atom/config.cson file, what happens when that file gets read back in, how are errors surfaced, etc.

@benogle

benogle commented Sep 24, 2014

Copy link
Copy Markdown
Contributor Author

Yeah, no more value returned, just the bool.

I'm not sure yet on feedback when reading bad data from disk. Right now, it would just not set the bad data. Would be interesting to have it show somewhere in the UI (status icon!), or we could log a warning in the console (though no one will find it).

Comment thread src/config.coffee Outdated

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.

Might want to check isFinite as well, or is Infinity, -Infinity allowed?

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.

I think they are reasonable, no? If they want bounds checking, they can use the bounds keys. As long as parsing some random string doesnt result in Infinity, I'm ok with allowing these

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.

parseInt called with a string can return Infinity.

Also you can't write out Infinity to a .json file, so it would seem weird to be able to set Infinity without being able to save it like that to disk.

Comment thread spec/editor-component-spec.coffee Outdated

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.

-50 will get coerced to 10 as 10 is the minimum/

@benogle

benogle commented Sep 25, 2014

Copy link
Copy Markdown
Contributor Author

Ok, I'm happy with this. @nathansobo @kevinsawicki wanna give this a quick pass?

Comment thread src/config.coffee Outdated

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.

Since no one is directly subscribing, think it's safe to pull out the emits and the mixed in emitter?

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.

Obviously only one tiny, little voice, but I'm currently relying on the broad updated event being emitted to listen for any and all updates to configuration values. Is there any alternative means of doing that? Otherwise it'd be awesome if the emits could stay 🙏

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.

@thomasjo Makes sense. I can make onDidChange accept no keypath or something. Or Maybe an onDidChangeAnyKeyPath or something. @nathansobo wdyt?

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.

So this makes me want to rename the event methods. I want

observeKeyPath
onDidChangeKeyPath
onDidChange for all changes

Such pain for authors.

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.

onDidChange now accepts just a callback, and no keypath for watching all changes.

benogle added a commit that referenced this pull request Sep 30, 2014
Support JSON Schema in Config
@benogle
benogle merged commit 05b3f16 into master Sep 30, 2014
@benogle
benogle deleted the bo-config-types branch September 30, 2014 00:24
@kevinsawicki

Copy link
Copy Markdown
Contributor

@nathansobo

Copy link
Copy Markdown
Contributor

💖

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants