From 874d281dd606c5ef623ca4aa7c03e00b40de53a3 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Mon, 16 Mar 2015 01:36:53 -0300 Subject: [PATCH] Closes #237. Add debugging information command --- lib/beautify.coffee | 100 +++++++++++++++++++++++++++++++++++++++ menus/atom-beautify.cson | 18 +++++-- package.json | 1 + 3 files changed, 115 insertions(+), 4 deletions(-) diff --git a/lib/beautify.coffee b/lib/beautify.coffee index f44a4a4..ca2981d 100644 --- a/lib/beautify.coffee +++ b/lib/beautify.coffee @@ -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 diff --git a/menus/atom-beautify.cson b/menus/atom-beautify.cson index aad3faa..912eacb 100644 --- a/menus/atom-beautify.cson +++ b/menus/atom-beautify.cson @@ -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': 'Beautify' - 'command': 'beautify:beautify-editor' - ] + 'label': 'Atom Beautify' + 'submenu': [ + { + 'label': 'Beautify' + 'command': 'beautify:beautify-editor' + } + { + 'label': 'Debug' + 'command': 'beautify:debug' + } + ] + ] } ] diff --git a/package.json b/package.json index 48f1437..e4f90bc 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "activationCommands": { "atom-workspace": [ "beautify:beautify-editor", + "beautify:debug", "core:save", "core:save-as" ],