Can't get atom.config.get to work with scope


#1

I have a .coffee file open and I run

atom.config.get('editor.preferredLineLength', {scope: atom.workspace.getActiveTextEditor().getRootScopeDescriptor()})

in the JS console and it gives me the main editor.preferredLineLength (120) value instead of the value for coffeescript files (100). Here’s my config.json:

"*":
  editor:
    preferredLineLength: 120
"source.coffee":
  editor:
    preferredLineLength: 100

Running just atom.workspace.getActiveTextEditor().getRootScopeDescriptor() gives

ScopeDescriptor {scopes: Array[1], getScopesArray: function, getScopeChain: function, toString: function}scopes: Array[1]0: "source.coffee"length: 1 [...]

It seems like atom.config.get with scope just… doesn’t work. Any ideas?


#2

I think I ran into the same problem. If I remember correctly, the key in your config.cson for the coffeescript scope should read: ".source.coffee" (note the dot at the start). This is really not obvious and it’s inconsistent with the scopes in the ScopeDescriptor above, and should be changed in my opinion.


#3

There is a document that describes the difference between scope descriptors (what atom.config.get accepts) and scope selectors (what is used as the key in the config.cson) here:

https://atom.io/docs/latest/behind-atom-scoped-settings-scopes-and-scope-descriptors


#4

Executing the code in the page you linked, @leedohm, causes some very odd things to happen:

> atom.config.get(['source.coffee'], 'editor.preferredLineLength')
Object {editor: Object, exception-reporting: Object, welcome: Object, core: Object, autocomplete-plus: Object…}

> editor = atom.workspace.getActiveTextEditor()
TextEditor {softTabs: true, displayBuffer: DisplayBuffer, mini: undefined, placeholderText: undefined, handleMarkerCreated: function…}
> atom.config.get(editor.getRootScopeDescriptor(), 'editor.preferredLineLength')
Object {editor: Object, exception-reporting: Object, welcome: Object, core: Object, autocomplete-plus: Object…}

Here is my entire config.cson file, and I’m running Atom in safe mode.

"*":
  editor:
    preferredLineLength: 120
  "exception-reporting":
    userId: "4118c62f-141a-f5b2-4403-4ee2c3d2a5ef"
  welcome:
    showOnStartup: false
"source.gfm":
  editor:
    preferredLineLength: 80
"source.coffee":
  editor:
    preferredLineLength: 100

I’m running Atom version 0.204.0


#5

@olmokramer I tried the following config.cson as well:

"*":
  editor:
    preferredLineLength: 120
  "exception-reporting":
    userId: "4118c62f-141a-f5b2-4403-4ee2c3d2a5ef"
  welcome:
    showOnStartup: false
".source.gfm":
  editor:
    preferredLineLength: 80
".source.coffee":
  editor:
    preferredLineLength: 100

But had the same issues as in my last post using the calls from my last post, but was finally able to get it to work using:

atom.config.get('editor.preferredLineLength', {scope: ['source.coffee']})

#6

It is weird that the latest docs suggest scope is the first parameter of get, but really it’s an optional options parameter. And the config.cson settings are prefixed with a ‘.’, but in code the scope selector omits the dot. So confusing >_<


#7

Sadly, there isn’t any such thing as “latest docs”. They’re all an admixture of new and old content :blush:


#8

Thanks for posting this, @lexicalunit. I ran into the same issue with atom.config.observe and atom.config.onDidChange. Spent more time than I’d care to admit trying to understand why I could observe global config changes but if I tried to observe scoped configs, nothing happened!

Thanks,
Paul