See #713. Properly extract configuration from package settings

This commit is contained in:
Glavin Wiechert 2016-03-30 01:27:54 -03:00
parent 43a3647e31
commit caabb95ed7
2 changed files with 6 additions and 48 deletions

View File

@ -122,7 +122,7 @@ module.exports = class Beautifiers extends EventEmitter
beautifiers = @getBeautifiers(language.name) beautifiers = @getBeautifiers(language.name)
logger.verbose('beautifiers', _.map(beautifiers, 'name')) logger.verbose('beautifiers', _.map(beautifiers, 'name'))
# Select beautifier from language config preferences # Select beautifier from language config preferences
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier") preferredBeautifierName = atom.config.get("atom-beautify.#{language.namespace}.default_beautifier")
beautifier = _.find(beautifiers, (beautifier) -> beautifier = _.find(beautifiers, (beautifier) ->
beautifier.name is preferredBeautifierName beautifier.name is preferredBeautifierName
) or beautifiers[0] ) or beautifiers[0]
@ -229,7 +229,7 @@ module.exports = class Beautifiers extends EventEmitter
logger.verbose("Language #{language.name} supported") logger.verbose("Language #{language.name} supported")
# Get language config # Get language config
langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled") langDisabled = atom.config.get("atom-beautify.#{language.namespace}.disabled")
# Beautify! # Beautify!
@ -242,11 +242,10 @@ module.exports = class Beautifiers extends EventEmitter
return resolve( null ) return resolve( null )
# Get more language config # Get more language config
beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save") beautifyOnSave = atom.config.get("atom-beautify.#{language.namespace}.beautify_on_save")
legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave")
# Verify if beautifying on save # Verify if beautifying on save
if onSave and not (beautifyOnSave or legacyBeautifyOnSave) if onSave and not beautifyOnSave
logger.verbose("Beautify on save is disabled for language #{language.name}") logger.verbose("Beautify on save is disabled for language #{language.name}")
# Saving, and beautify on save is disabled # Saving, and beautify on save is disabled
return resolve( null ) return resolve( null )
@ -410,32 +409,7 @@ module.exports = class Beautifiers extends EventEmitter
null null
getConfigOptionsFromSettings : (langs) -> getConfigOptionsFromSettings : (langs) ->
config = atom.config.get('atom-beautify') config = atom.config.get('atom-beautify')
options = {} options = _.pick(config, langs)
# logger.verbose(langs, config);
# Iterate over keys of the settings
_.every _.keys(config), (k) ->
# Check if keys start with a language
p = k.split("_")[0]
idx = _.indexOf(langs, p)
# logger.verbose(k, p, idx);
if idx >= 0
# Remove the language prefix and nest in options
lang = langs[idx]
opt = k.replace( new RegExp("^" + lang + "_"), "")
options[lang] = options[lang] or {}
options[lang][opt] = config[k]
# logger.verbose(lang, opt)
true
# logger.verbose(options)
options
# Look for .jsbeautifierrc in file and home path, check env variables # Look for .jsbeautifierrc in file and home path, check env variables
getConfig : (startPath, upwards = true) -> getConfig : (startPath, upwards = true) ->

View File

@ -66,21 +66,6 @@ showError = (error) ->
stack, detail, dismissable : true}) stack, detail, dismissable : true})
beautify = ({onSave}) -> beautify = ({onSave}) ->
# Deprecation warning for beautify on save
if atom.config.get("atom-beautify.beautifyOnSave") is true
detail = """See issue https://github.com/Glavin001/atom-beautify/issues/308
To stop seeing this message:
- Uncheck (disable) the deprecated \"Beautify On Save\" option
To enable Beautify on Save for a particular language:
- Go to Atom Beautify's package settings
- Find option for \"Language Config - <Your Language> - Beautify On Save\"
- Check (enable) Beautify On Save option for that particular language
"""
atom?.notifications.addWarning("The option \"atom-beautify.beautifyOnSave\" has been deprecated", {detail, dismissable : true})
# Continue beautifying # Continue beautifying
path ?= require("path") path ?= require("path")
@ -490,7 +475,7 @@ handleSaveEvent = ->
# TODO: select appropriate language # TODO: select appropriate language
language = languages[0] language = languages[0]
# Get language config # Get language config
key = "atom-beautify.language_#{language.namespace}_beautify_on_save" key = "atom-beautify.#{language.namespace}.beautify_on_save"
beautifyOnSave = atom.config.get(key) beautifyOnSave = atom.config.get(key)
logger.verbose('save editor positions', key, beautifyOnSave) logger.verbose('save editor positions', key, beautifyOnSave)
if beautifyOnSave if beautifyOnSave
@ -516,7 +501,6 @@ plugin.config = _.merge(require('./config.coffee'), defaultLanguageOptions)
plugin.activate = -> plugin.activate = ->
@subscriptions = new CompositeDisposable @subscriptions = new CompositeDisposable
@subscriptions.add handleSaveEvent() @subscriptions.add handleSaveEvent()
@subscriptions.add atom.config.observe("atom-beautify.beautifyOnSave", handleSaveEvent)
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:beautify-editor", beautify @subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:beautify-editor", beautify
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:help-debug-editor", debug @subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:help-debug-editor", debug
@subscriptions.add atom.commands.add ".tree-view .file .name", "atom-beautify:beautify-file", beautifyFile @subscriptions.add atom.commands.add ".tree-view .file .name", "atom-beautify:beautify-file", beautifyFile