Closes #237. Add debugging information command

This commit is contained in:
Glavin Wiechert 2015-03-16 01:36:53 -03:00
parent 77ec0b2e6f
commit 874d281dd6
3 changed files with 115 additions and 4 deletions

View File

@ -1,6 +1,7 @@
# global atom
"use strict"
pkg = require('../package.json')
# Dependencies
plugin = module.exports
_ = require("lodash")
@ -210,6 +211,104 @@ beautifyDirectory = ({target}) ->
)
return
debug = () ->
return unless confirm('Are you ready to debug Atom Beautify?\n\n'+
'Warning: This will change your current clipboard contents.')
debugInfo = ""
addInfo = (key, val) ->
debugInfo += "**#{key}**: #{val}\n\n"
addHeader = (level, title) ->
debugInfo += "#{Array(level+1).join('#')} #{title}\n\n"
addHeader(1, "Atom Beautify - Debugging information")
debugInfo += "The following debugging information was " +
"generated by `Atom Beautify` on `#{new Date()}`."+
"\n\n---\n\n"
# Platform
addInfo('Platform', process.platform)
addHeader(2, "Versions")
# Atom Version
addInfo('Atom Version', atom.appVersion)
# Atom Beautify Version
addInfo('Atom Beautify Version', pkg.version)
addHeader(2, "Original file to be beautified")
# Original file
# Get current editor
editor = atom.workspace.getActiveTextEditor()
# Check if there is an active editor
if not editor?
return showError(new Error("Active Editor not found.\n"
"Please select a Text Editor first to beautify."))
# Get editor path and configurations for paths
filePath = editor.getPath()
# Path
addInfo('Original File Path', "`#{filePath}`")
# Get Grammar
grammarName = editor.getGrammar().name
# Grammar
addInfo('Original File Grammar', grammarName)
# Contents
# Get current editor's text
text = editor.getText()
addInfo('Original File Contents', "\n```#{grammarName}\n#{text}\n```")
addHeader(2, "Beautification options")
# Beautification Options
# Get all options
allOptions = options.getOptionsForPath(filePath, editor)
[
editorOptions
configOptions
homeOptions
editorConfigOptions
] = allOptions
projectOptions = allOptions[4..]
addInfo('Editor Options', "\n"+
"Options from Atom Editor settings\n"+
"```json\n#{JSON.stringify(editorOptions, undefined, 4)}\n```")
addInfo('Config Options', "\n"+
"Options from Atom Beautify package settings\n"+
"```json\n#{JSON.stringify(configOptions, undefined, 4)}\n```")
addInfo('Home Options', "\n"+
"Options from `#{path.resolve(options.getUserHome(), '.jsbeautifyrc')}`\n"+
"```json\n#{JSON.stringify(homeOptions, undefined, 4)}\n```")
addInfo('EditorConfig Options', "\n"+
"Options from [EditorConfig](http://editorconfig.org/) file\n"+
"```json\n#{JSON.stringify(editorConfigOptions, undefined, 4)}\n```")
addInfo('Project Options', "\n"+
"Options from `.jsbeautifyrc` files starting from directory `#{path.dirname(filePath)}` and going up to root\n" +
"```json\n#{JSON.stringify(projectOptions, undefined, 4)}\n```")
addHeader(2, "Logs")
# Error logs
addInfo('Error logs', '*Not yet supported*')
# Save to clipboard
atom.clipboard.write(debugInfo)
confirm('Atom Beautify debugging information is now in your clipboard.\n'+
'You can now paste this into an Issue you are reporting here\n'+
'https://github.com/Glavin001/atom-beautify/issues/ \n\n'+
'Warning: Be sure to look over the debug info before you send it,
to ensure you are not sharing undesirable private information.')
handleSaveEvent = =>
atom.workspace.observeTextEditors (editor) =>
buffer = editor.getBuffer()
@ -258,5 +357,6 @@ plugin.activate = ->
handleSaveEvent()
plugin.subscribe atom.config.observe("atom-beautify.beautifyOnSave", handleSaveEvent)
atom.commands.add "atom-workspace", "beautify:beautify-editor", beautify
atom.commands.add "atom-workspace", "beautify:debug", debug
atom.commands.add ".tree-view .file .name", "beautify:beautify-file", beautifyFile
atom.commands.add ".tree-view .directory .name", "beautify:beautify-directory", beautifyDirectory

View File

@ -1,7 +1,8 @@
# See https://atom.io/docs/latest/creating-a-package#menus for more details
'context-menu':
'atom-workspace atom-text-editor:not(.mini)':
'Enable atom-beautify': 'beautify:beautify-editor'
'Beautify editor contents': 'beautify:beautify-editor'
'Debug Atom Beautify': 'beautify:debug'
'.tree-view .file > .name':
'Beautify File': 'beautify:beautify-file'
# '.tree-view .directory > .header > .name':
@ -11,8 +12,17 @@
{
'label': 'Packages'
'submenu': [
'label': 'Atom Beautify'
'submenu': [
{
'label': 'Beautify'
'command': 'beautify:beautify-editor'
}
{
'label': 'Debug'
'command': 'beautify:debug'
}
]
]
}
]

View File

@ -71,6 +71,7 @@
"activationCommands": {
"atom-workspace": [
"beautify:beautify-editor",
"beautify:debug",
"core:save",
"core:save-as"
],