Closes #308. Beautify On Save is opt-in for each language
Deprecate old global beautifyOnSave option
This commit is contained in:
parent
d1b0e6d66d
commit
a94721e1b5
|
@ -213,6 +213,13 @@ module.exports = class Beautifiers
|
||||||
description: "Default Beautifier to be used for #{name}"
|
description: "Default Beautifier to be used for #{name}"
|
||||||
enum: _.uniq(beautifiers)
|
enum: _.uniq(beautifiers)
|
||||||
}
|
}
|
||||||
|
flatOptions["#{optionName}_beautify_on_save"] = {
|
||||||
|
title: "Language Config - #{name} - Beautify On Save"
|
||||||
|
type: 'boolean'
|
||||||
|
default: false
|
||||||
|
description: "Automatically beautify #{name} files on save"
|
||||||
|
}
|
||||||
|
|
||||||
# logger.verbose('flatOptions', flatOptions)
|
# logger.verbose('flatOptions', flatOptions)
|
||||||
return flatOptions
|
return flatOptions
|
||||||
|
|
||||||
|
@ -236,7 +243,7 @@ module.exports = class Beautifiers
|
||||||
###
|
###
|
||||||
|
|
||||||
###
|
###
|
||||||
beautify: (text, allOptions, grammar, filePath) ->
|
beautify: (text, allOptions, grammar, filePath, {onSave}={}) ->
|
||||||
return new Promise((resolve, reject) =>
|
return new Promise((resolve, reject) =>
|
||||||
logger.info('beautify', text, allOptions, grammar, filePath)
|
logger.info('beautify', text, allOptions, grammar, filePath)
|
||||||
|
|
||||||
|
@ -247,13 +254,19 @@ module.exports = class Beautifiers
|
||||||
# Check if unsupported language
|
# Check if unsupported language
|
||||||
if languages.length < 1
|
if languages.length < 1
|
||||||
unsupportedGrammar = true
|
unsupportedGrammar = true
|
||||||
|
|
||||||
|
# Check if on save
|
||||||
|
if onSave
|
||||||
|
# Ignore this, as it was just a general file save, and
|
||||||
|
# not intended to be beautified
|
||||||
|
return resolve(null)
|
||||||
|
|
||||||
else
|
else
|
||||||
# TODO: select appropriate language
|
# TODO: select appropriate language
|
||||||
language = languages[0]
|
language = languages[0]
|
||||||
|
|
||||||
# Get language config
|
# Get language config
|
||||||
langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled")
|
langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled")
|
||||||
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
|
|
||||||
|
|
||||||
# Beautify!
|
# Beautify!
|
||||||
unsupportedGrammar = false
|
unsupportedGrammar = false
|
||||||
|
@ -261,6 +274,16 @@ module.exports = class Beautifiers
|
||||||
if langDisabled
|
if langDisabled
|
||||||
return resolve(null)
|
return resolve(null)
|
||||||
|
|
||||||
|
# Get more language config
|
||||||
|
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
|
||||||
|
beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save")
|
||||||
|
legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave")
|
||||||
|
|
||||||
|
# Verify if beautifying on save
|
||||||
|
if onSave and not (beautifyOnSave or legacyBeautifyOnSave)
|
||||||
|
# Saving, and beautify on save is disabled
|
||||||
|
return resolve(null)
|
||||||
|
|
||||||
# Options for Language
|
# Options for Language
|
||||||
options = @getOptions(language.namespace, allOptions) || {}
|
options = @getOptions(language.namespace, allOptions) || {}
|
||||||
# Support fallback for options
|
# Support fallback for options
|
||||||
|
|
|
@ -43,8 +43,21 @@ setCursors = (editor, posArray) ->
|
||||||
return
|
return
|
||||||
|
|
||||||
beautify = ({onSave}) ->
|
beautify = ({onSave}) ->
|
||||||
# Verify if beautify on save
|
# Deprecation warning for beautify on save
|
||||||
return if onSave and atom.config.get("atom-beautify.beautifyOnSave") is false
|
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")
|
||||||
LoadingView ?= require "./views/loading-view"
|
LoadingView ?= require "./views/loading-view"
|
||||||
|
@ -133,7 +146,7 @@ beautify = ({onSave}) ->
|
||||||
grammarName = editor.getGrammar().name
|
grammarName = editor.getGrammar().name
|
||||||
# Finally, beautify!
|
# Finally, beautify!
|
||||||
try
|
try
|
||||||
beautifier.beautify(text, allOptions, grammarName, editedFilePath)
|
beautifier.beautify(text, allOptions, grammarName, editedFilePath, onSave:onSave)
|
||||||
.then(beautifyCompleted)
|
.then(beautifyCompleted)
|
||||||
.catch(beautifyCompleted)
|
.catch(beautifyCompleted)
|
||||||
catch e
|
catch e
|
||||||
|
@ -350,6 +363,7 @@ plugin.config = _.merge(
|
||||||
description: 'Set the level for the logger'
|
description: 'Set the level for the logger'
|
||||||
enum: ['verbose','debug','info','warn','error']
|
enum: ['verbose','debug','info','warn','error']
|
||||||
beautifyOnSave:
|
beautifyOnSave:
|
||||||
|
title: "DEPRECATED: Beautfy On Save"
|
||||||
type: 'boolean'
|
type: 'boolean'
|
||||||
default: false
|
default: false
|
||||||
description: "Beautify active editor on save"
|
description: "Beautify active editor on save"
|
||||||
|
|
Loading…
Reference in New Issue