Skip to content

Commit 99d35a3

Browse files
committed
Fix issue #1 + add query on unknown type.
1 parent f040b1f commit 99d35a3

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22

33
[![Build Status](https://api.travis-ci.org/HookyQR/VSCodeBeautify.svg?branch=master)](https://travis-ci.org/HookyQR/VSCodeBeautify)
44

5-
VS Code has its own code formater. But it lacks the ability to modify the style you wish to use. This extension enables running [js-beautify](http://jsbeautifier.org/) in VS Code, and searches for `.jsbeautifyrc` file in the files path tree to load *your* code styling. Run with **⌘⇧P** `Beautify`.
5+
VS Code uses js-beautify internally, bit it lacks the ability to modify the style you wish to use. This extension enables running [js-beautify](http://jsbeautifier.org/) in VS Code, _AND_ honouring any `.jsbeautifyrc` file in the open file's path tree to load *your* code styling. Run with **⌘⇧P** `Beautify`.
66

7-
See [js-beautify on gitHub](https://github.com/beautify-web/js-beautify) for available options in the rc file. The file must be valid JSON to be used. Only the first file of the correct name found will be used. If the format is bad, the default js-beautify settings will be used.
7+
This package now includes hints when editing your `.jsbeautifyrc`. Only the first file found will be used. If the format is bad, the default js-beautify settings will be used.
88

9-
Also runs http and css beautify from the same package, as determined by the file extension. If the file is unsaved, js-beautify will be attempted by default.
9+
Also runs http and css beautify from the same package, as determined by the file extension. If the file is unsaved, or the type is undetermined, you'll be prompted for which beautifier to use.
1010

11-
Extra file extenstion may be added under user or workspace settings.
11+
Extra (permanent) file extension may be added under user or workspace settings.
1212

13-
Embeded version of js-beautify is v1.5.10.
13+
Embedded version of js-beautify is v1.5.10.
1414

1515
## Changes:
16+
### 0.0.4: 19 Dec 2015
17+
* Changed default (unknown) processing to ask you what you want to use.
18+
* Fixed [Issue #1: No handler found for the command: 'HookyQR.beautify'](https://github.com/HookyQR/VSCodeBeautify/issues/1)
19+
1620
### 0.0.3: 19 Dec 2015
1721
* _Tries_ to mark any elements in `json.schema` settings as JSON, and thus beautify as JS.
18-
* Added schema for `.jsbeautifyrc` file.
22+
* Added schema for `.jsbeautifyrc` file. (Requires VS Code v0.10.5+ see [Issue #1](https://github.com/HookyQR/VSCodeBeautify/issues/1))
1923
* Added language type so `.jsbeautifyrc` is recognised as JSON.
2024

2125
### 0.0.2: 17 Dec 2015
2226
* Add options for other file extensions.
23-

extension.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ function findRecursive(dir, fileName) {
1515
}
1616
//register on activation
1717
function activate(context) {
18-
18+
1919
var doBeautify = function(active, doc, opts) {
20-
var better = doc.getText();
21-
var type = doc.isUntitled ? "js" : doc.fileName.split('.')
20+
var original = doc.getText();
21+
var type = doc.isUntitled ? "" : doc.fileName.split('.')
2222
.pop()
2323
.toLowerCase();
2424
var cfg = vscode.workspace.getConfiguration('beautify');
2525
//if a type is set on the window, use that
26-
console.log(vscode.window.activeTextEditor);
2726
//check if the file is in the users json schema set
2827
var jsSchema = vscode.workspace.getConfiguration('json')
2928
.schemas;
30-
var range;
29+
//get the whole file:
30+
var range = new vscode.Range(new vscode.Position(0, 0), doc.positionAt(Infinity));
31+
var result;
3132
if (jsSchema) {
3233
var matcher = [];
3334
var extMatch = n => ({
@@ -43,24 +44,43 @@ function activate(context) {
4344
});
4445
if (vscode.languages.match(matcher, doc)) {
4546
//beautify as javascript
46-
better = beautify.js(better, opts);
47+
result = beautify.js(original, opts);
4748
//get the whole file:
4849
range = new vscode.Range(new vscode.Position(0, 0), doc.positionAt(Infinity));
4950
//and make the change:
50-
active.edit(editor => editor.replace(range, better));
51+
active.edit(editor => editor.replace(range, result));
52+
return;
5153
}
5254
}
5355
if (cfg.HTMLfiles.indexOf(type) + 1) {
54-
better = beautify.html(better, opts);
56+
result = beautify.html(original, opts);
5557
} else if (cfg.CSSfiles.indexOf(type) + 1) {
56-
better = beautify.css(better, opts);
58+
result = beautify.css(original, opts);
5759
} else if (cfg.JSfiles.indexOf(type) + 1) {
58-
better = beautify.js(better, opts);
59-
} else return;
60-
//get the whole file:
61-
range = new vscode.Range(new vscode.Position(0, 0), doc.positionAt(Infinity));
60+
result = beautify.js(original, opts);
61+
} else {
62+
//Ask what they want to do:
63+
vscode.window.showQuickPick([{
64+
label: "JS",
65+
description: "Does JavaScript and JSON"
66+
}, {
67+
label: "CSS"
68+
}, {
69+
label: "HTML"
70+
}], {
71+
matchOnDescription: true,
72+
placeHolder: "Couldn't determine type to beautify, pleae choose."
73+
})
74+
.then(function(choice) {
75+
if (!choice || !choice.label) return;
76+
result=beautify[choice.label.toLowerCase()](original, opts);
77+
78+
active.edit(editor => editor.replace(range, result));
79+
});
80+
return;
81+
}
6282
//and make the change:
63-
active.edit(editor => editor.replace(range, better));
83+
active.edit(editor => editor.replace(range, result));
6484
};
6585

6686
var disposable = vscode.commands.registerCommand('HookyQR.beautify', function() {

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "beautify",
33
"displayName": "beautify",
44
"description": "Beautify code in place for VS Code",
5-
"version": "0.0.3",
5+
"version": "0.0.4",
66
"publisher": "HookyQR",
77
"engines": {
88
"vscode": "^0.10.1"
@@ -15,9 +15,6 @@
1515
],
1616
"license": "MIT",
1717
"main": "./extension",
18-
"extensionDependencies": [
19-
"vscode.json"
20-
],
2118
"contributes": {
2219
"languages": [{
2320
"id": "json",

0 commit comments

Comments
 (0)