Skip to content

Commit

Permalink
Closes #237. Add debugging information command
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Mar 16, 2015
1 parent 77ec0b2 commit 874d281
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 4 deletions.
100 changes: 100 additions & 0 deletions lib/beautify.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# global atom

"use strict"
pkg = require('../package.json')
# Dependencies
plugin = module.exports
_ = require("lodash")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
18 changes: 14 additions & 4 deletions menus/atom-beautify.cson
Original file line number Diff line number Diff line change
@@ -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':
Expand All @@ -11,8 +12,17 @@
{
'label': 'Packages'
'submenu': [
'label': 'Beautify'
'command': 'beautify:beautify-editor'
]
'label': 'Atom Beautify'
'submenu': [
{
'label': 'Beautify'
'command': 'beautify:beautify-editor'
}
{
'label': 'Debug'
'command': 'beautify:debug'
}
]
]
}
]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"activationCommands": {
"atom-workspace": [
"beautify:beautify-editor",
"beautify:debug",
"core:save",
"core:save-as"
],
Expand Down

0 comments on commit 874d281

Please sign in to comment.