See #56. Add Atom-Message-Panel to display Unsupported Language messages
This commit is contained in:
parent
6b2b306b9d
commit
ffa2249c3e
|
@ -13,6 +13,8 @@ path = null
|
||||||
strip = null
|
strip = null
|
||||||
yaml = null
|
yaml = null
|
||||||
LoadingView = null
|
LoadingView = null
|
||||||
|
MessagePanelView = null
|
||||||
|
PlainMessageView = null
|
||||||
#MessageView = require "./message-view"
|
#MessageView = require "./message-view"
|
||||||
findFileResults = {}
|
findFileResults = {}
|
||||||
|
|
||||||
|
@ -45,7 +47,7 @@ setCursors = (editor, posArray) ->
|
||||||
return
|
return
|
||||||
|
|
||||||
verifyExists = (fullPath) ->
|
verifyExists = (fullPath) ->
|
||||||
fs ? = require("fs")
|
fs ?= require("fs")
|
||||||
(if fs.existsSync(fullPath) then fullPath else null)
|
(if fs.existsSync(fullPath) then fullPath else null)
|
||||||
|
|
||||||
# Storage for memoized results from find file
|
# Storage for memoized results from find file
|
||||||
|
@ -64,7 +66,7 @@ current working directory)
|
||||||
@returns {string} normalized filename
|
@returns {string} normalized filename
|
||||||
###
|
###
|
||||||
findFile = (name, dir) ->
|
findFile = (name, dir) ->
|
||||||
path ? = require("path")
|
path ?= require("path")
|
||||||
dir = dir or process.cwd()
|
dir = dir or process.cwd()
|
||||||
filename = path.normalize(path.join(dir, name))
|
filename = path.normalize(path.join(dir, name))
|
||||||
return findFileResults[filename] if findFileResults[filename] isnt `undefined`
|
return findFileResults[filename] if findFileResults[filename] isnt `undefined`
|
||||||
|
@ -87,7 +89,7 @@ or in the home directory. Configuration files are named
|
||||||
@returns {string} a path to the config file
|
@returns {string} a path to the config file
|
||||||
###
|
###
|
||||||
findConfig = (config, file) ->
|
findConfig = (config, file) ->
|
||||||
path ? = require("path")
|
path ?= require("path")
|
||||||
dir = path.dirname(path.resolve(file))
|
dir = path.dirname(path.resolve(file))
|
||||||
envs = getUserHome()
|
envs = getUserHome()
|
||||||
home = path.normalize(path.join(envs, config))
|
home = path.normalize(path.join(envs, config))
|
||||||
|
@ -117,8 +119,12 @@ getConfigOptionsFromSettings = (langs) ->
|
||||||
options
|
options
|
||||||
|
|
||||||
beautify = ->
|
beautify = ->
|
||||||
LoadingView ? = require "./loading-view"
|
MessagePanelView ?= require('atom-message-panel').MessagePanelView
|
||||||
@loadingView ? = new LoadingView()
|
PlainMessageView ?= require('atom-message-panel').PlainMessageView
|
||||||
|
LoadingView ?= require "./loading-view"
|
||||||
|
@messagePanel ?= new MessagePanelView title: 'Atom Beautify'
|
||||||
|
@messagePanel.attach();
|
||||||
|
@loadingView ?= new LoadingView()
|
||||||
@loadingView.show()
|
@loadingView.show()
|
||||||
forceEntireFile = atom.config.get("atom-beautify.beautifyEntireFileOnSave")
|
forceEntireFile = atom.config.get("atom-beautify.beautifyEntireFileOnSave")
|
||||||
# Look for .jsbeautifierrc in file and home path, check env variables
|
# Look for .jsbeautifierrc in file and home path, check env variables
|
||||||
|
@ -130,7 +136,7 @@ beautify = ->
|
||||||
configPath = findConfig(".jsbeautifyrc", startPath)
|
configPath = findConfig(".jsbeautifyrc", startPath)
|
||||||
externalOptions = undefined
|
externalOptions = undefined
|
||||||
if configPath
|
if configPath
|
||||||
fs ? = require("fs")
|
fs ?= require("fs")
|
||||||
contents = fs.readFileSync(configPath,
|
contents = fs.readFileSync(configPath,
|
||||||
encoding: "utf8"
|
encoding: "utf8"
|
||||||
)
|
)
|
||||||
|
@ -138,14 +144,13 @@ beautify = ->
|
||||||
externalOptions = {}
|
externalOptions = {}
|
||||||
else
|
else
|
||||||
try
|
try
|
||||||
strip ? = require("strip-json-comments")
|
strip ?= require("strip-json-comments")
|
||||||
externalOptions = JSON.parse(strip(contents))
|
externalOptions = JSON.parse(strip(contents))
|
||||||
catch e
|
catch e
|
||||||
console.log "Failed parsing config as JSON: " + configPath
|
console.log "Failed parsing config as JSON: " + configPath
|
||||||
|
|
||||||
# Attempt as YAML
|
# Attempt as YAML
|
||||||
try
|
try
|
||||||
yaml ? = require("js-yaml")
|
yaml ?= require("js-yaml")
|
||||||
externalOptions = yaml.safeLoad(contents)
|
externalOptions = yaml.safeLoad(contents)
|
||||||
catch e
|
catch e
|
||||||
console.log "Failed parsing config as YAML: " + configPath
|
console.log "Failed parsing config as YAML: " + configPath
|
||||||
|
@ -219,7 +224,15 @@ beautify = ->
|
||||||
]
|
]
|
||||||
grammarName = editor.getGrammar().name
|
grammarName = editor.getGrammar().name
|
||||||
# Finally, beautify!
|
# Finally, beautify!
|
||||||
beautifier.beautify text, grammarName, allOptions, beautifyCompleted
|
try
|
||||||
|
beautifier.beautify text, grammarName, allOptions, beautifyCompleted
|
||||||
|
catch e
|
||||||
|
console.log(e)
|
||||||
|
@loadingView.hide()
|
||||||
|
@messagePanel.add(new PlainMessageView({
|
||||||
|
message: e.message,
|
||||||
|
className: 'text-error'
|
||||||
|
}));
|
||||||
return
|
return
|
||||||
|
|
||||||
handleSaveEvent = ->
|
handleSaveEvent = ->
|
||||||
|
|
|
@ -213,13 +213,11 @@ module.exports =
|
||||||
|
|
||||||
# Check if Analytics is enabled
|
# Check if Analytics is enabled
|
||||||
if atom.config.get("atom-beautify.analytics")
|
if atom.config.get("atom-beautify.analytics")
|
||||||
|
|
||||||
# Setup Analytics
|
# Setup Analytics
|
||||||
analytics = new Analytics(analyticsWriteKey)
|
analytics = new Analytics(analyticsWriteKey)
|
||||||
unless atom.config.get("atom-beautify._analyticsUserId")
|
unless atom.config.get("atom-beautify._analyticsUserId")
|
||||||
uuid = require("node-uuid")
|
uuid = require("node-uuid")
|
||||||
atom.config.set "atom-beautify._analyticsUserId", uuid.v4()
|
atom.config.set "atom-beautify._analyticsUserId", uuid.v4()
|
||||||
|
|
||||||
# Setup Analytics User Id
|
# Setup Analytics User Id
|
||||||
userId = atom.config.get("atom-beautify._analyticsUserId")
|
userId = atom.config.get("atom-beautify._analyticsUserId")
|
||||||
analytics.identify userId: userId
|
analytics.identify userId: userId
|
||||||
|
@ -233,7 +231,9 @@ module.exports =
|
||||||
options: allOptions
|
options: allOptions
|
||||||
label: grammar
|
label: grammar
|
||||||
category: version
|
category: version
|
||||||
|
#
|
||||||
|
if unsupportedGrammar
|
||||||
|
throw new Error("Unsupported language for grammar '#{grammar}'.")
|
||||||
return
|
return
|
||||||
|
|
||||||
getOptions: (selection, allOptions) ->
|
getOptions: (selection, allOptions) ->
|
||||||
|
|
|
@ -88,6 +88,7 @@
|
||||||
"prettydiff": "^1.0.23",
|
"prettydiff": "^1.0.23",
|
||||||
"node-uuid": "^1.4.1",
|
"node-uuid": "^1.4.1",
|
||||||
"analytics-node": "^1.0.2",
|
"analytics-node": "^1.0.2",
|
||||||
"coffee-formatter": "git+https://github.com/Glavin001/Coffee-Formatter.git"
|
"coffee-formatter": "git+https://github.com/Glavin001/Coffee-Formatter.git",
|
||||||
|
"atom-message-panel": "^1.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue