summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSangHyeon Jade Lee <dltkdgus1764@gmail.com>2017-07-24 15:51:34 +0900
committerSangHyeon Jade Lee <dltkdgus1764@gmail.com>2017-07-24 15:51:40 +0900
commit1a21006440659bb2d2763895ec5760cdc3a3580f (patch)
treee5ede5e488e7dd3f02182e2cd421e1bca6fcec0b
parent290e311ed5cb181ce4a15f3812c78c5364311c24 (diff)
format : add vscode-uncrustify js changed file to apply directly on installed vscode-uncrustify
Signed-off-by: SangHyeon Jade Lee <dltkdgus1764@gmail.com>
-rw-r--r--tools/format/vscode-uncrustify/CHANGELOG.md110
-rw-r--r--tools/format/vscode-uncrustify/out/src/extension.js219
-rw-r--r--tools/format/vscode-uncrustify/out/src/formatter.js86
-rw-r--r--tools/format/vscode-uncrustify/package.json133
4 files changed, 548 insertions, 0 deletions
diff --git a/tools/format/vscode-uncrustify/CHANGELOG.md b/tools/format/vscode-uncrustify/CHANGELOG.md
new file mode 100644
index 0000000..0ccecb5
--- /dev/null
+++ b/tools/format/vscode-uncrustify/CHANGELOG.md
@@ -0,0 +1,110 @@
1# Changelog
2
3#### 2.4.2
4- Added new feature for Range Selection Rormatting - Modified by SangHyeon Jade Lee
5
6#### 2.4.1
7- Fixed extension activation (#10)
8
9### 2.4.0
10- Fixed string values not being displayed in graphical config editor
11- Added text box to graphical config editor for custom values (#8)
12
13### 2.3.0
14- Fixed behavior when invoking uncrustify commands manually when they are not supposed to be (#7)
15- Added `uncustify.open` command to open currently used uncrustify config file (#7)
16- Replaced `uncrustify.download` command with `uncrustify.create` that creates config files instead of downoading thems
17
18#### 2.2.1
19- Fixed editor css and js files not being loaded
20
21### 2.2.0
22- Fixed preset loading that could interrupt config file download
23- Added the ability to upgrade config files when they are not made for the same version as the uncrustify executable
24
25### 2.1.0
26- Added ability to save and load configuration file presets
27
28#### 2.0.1
29- Corrected image in README
30
31## 2.0.0
32- Added graphical config editor to ease configuration
33
34### 1.6.0
35- Added command to automatically download a default config file for uncrustify
36
37#### 1.5.6
38- Removed useless error message appearing even when everything is fine; this time it's working I swear
39
40#### 1.5.5
41- Removed forgotten test that forced uncrustify not to work...
42
43#### 1.5.4
44- Updated README to add forgotten doc about the "debug mode"
45
46#### 1.5.3
47- Added a "debug mode" that shows a bunch of logs in the uncrustify output channel (see)
48
49#### 1.5.2
50- Fixed README wrongly asserting that Apex is officially supported by uncrustify (#6)
51
52#### 1.5.1
53- Fixed local uncrusify install
54
55### 1.5.0
56- Added support for environment variables in the `uncrustify.configPath` option
57
58#### 1.4.4
59- Actually fixed the bug
60
61#### 1.4.3
62- Fixed a crash occuring when uncrustify is already installed
63
64#### 1.4.2
65- Uncrustify can now be automatically installed on Windows as well
66
67#### 1.4.1
68- The installation progress is now displayed in an OutputChannel
69- The README was updated to reflect the possible automatic installation of uncrustify by the extension
70
71### 1.4.0
72- The extension now uses Typescript 2
73- On MacOS and Linux, uncrustify can be installed by the extension if it's not detected
74
75#### 1.3.5
76- The user is now warned whenever the path to `uncrustify.cfg` is incorrect, and the C# language id is correctly set for uncrustify
77
78#### 1.3.4
79- Actually fixed C# support
80
81#### 1.3.3
82- Updated README
83
84#### 1.3.2
85- Fixed C# support
86
87#### 1.3.1
88- Updated README
89
90### 1.3.0
91- Added Apex support
92
93#### 1.2.3
94- Added an icon and a background color for the extension marketplace
95
96#### 1.2.2
97- Remove another useless file, write changelog
98
99#### 1.2.1
100- Remove useless files
101
102### 1.2.0
103- Try to use default uncrustify configuration file on Posix systems
104
105### 1.1.0
106Add URLs and fix keywords
107- (should have been 1.0.1 but I accidently wrote `vsce publish minor` instead of `vsce publish patch`)
108
109## 1.0.0
110- Initial release \ No newline at end of file
diff --git a/tools/format/vscode-uncrustify/out/src/extension.js b/tools/format/vscode-uncrustify/out/src/extension.js
new file mode 100644
index 0000000..4e757d0
--- /dev/null
+++ b/tools/format/vscode-uncrustify/out/src/extension.js
@@ -0,0 +1,219 @@
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const cp = require("child_process");
5const vsc = require("vscode");
6const pkg = require("meta-pkg");
7const logger = require("./logger");
8const util = require("./util");
9const formatter_1 = require("./formatter");
10const configurator_1 = require("./configurator");
11let extContext;
12exports.extContext = extContext;
13function activate(context) {
14 logger.dbg('extension started');
15 exports.extContext = extContext = context;
16 let message = 'Uncrustify does not seem to be installed';
17 let choices = [];
18 let installerChoices = {};
19 let uncrustify = {
20 name: 'uncrustify',
21 targets: ['uncrustify'],
22 backends: {
23 packagekit: 'uncrustify',
24 brew: 'uncrustify',
25 fallback: {
26 version: {
27 feed: 'https://sourceforge.net/projects/uncrustify/rss?path=/',
28 regexp: /uncrustify\/uncrustify-([\d.]+)\/uncrustify-\1-win32\.zip/
29 },
30 win32: {
31 source: 'http://downloads.sourceforge.net/project/uncrustify/uncrustify/uncrustify-%VERSION%/uncrustify-%VERSION%-win32.zip',
32 bin: '.'
33 }
34 }
35 }
36 };
37 pkg.isInstalled(uncrustify)
38 .then((installed) => {
39 logger.dbg('uncrustify installed: ' + installed);
40 return installed
41 ? pkg.isUpgradable(uncrustify).then((upgradable) => {
42 message = 'Uncrustify can be upgraded';
43 return upgradable;
44 })
45 : Promise.resolve(!installed);
46 }).then((shouldInstall) => {
47 logger.dbg('should uncrustify be installed: ' + shouldInstall);
48 return shouldInstall ? pkg.getInstallers(uncrustify) : null;
49 }).then((installers) => {
50 logger.dbg('installers found: ' + (installers
51 ? installers.map((i) => i.prettyName).join(', ')
52 : 'none'));
53 if (installers && installers.length) {
54 installers.forEach((installer) => {
55 let choice = 'Install using ' + installer.prettyName;
56 choices.push(choice);
57 installerChoices[choice] = installer;
58 });
59 return vsc.window.showWarningMessage(message, ...choices).then((choice) => choice);
60 }
61 }).then((choice) => {
62 logger.dbg('installer choice: ' + choice);
63 if (choice) {
64 logger.show();
65 return installerChoices[choice]
66 .install((data) => logger.log(data, false))
67 .then((alreadyInstalled) => !alreadyInstalled);
68 }
69 }).then((didIntall) => {
70 if (didIntall) {
71 logger.dbg('uncrustify installed');
72 vsc.window.showInformationMessage('Uncrustify installed successfully');
73 }
74 });
75 let formatterSub = vsc.languages.registerDocumentFormattingEditProvider(util.MODES, new formatter_1.default());
76 context.subscriptions.push(formatterSub);
77 logger.dbg('registered formatter');
78 let rangeformatterSub = vsc.languages.registerDocumentRangeFormattingEditProvider(util.MODES, new formatter_1.default());
79 context.subscriptions.push(rangeformatterSub);
80 logger.dbg('registered rangeformatter');
81 let configurationSub = vsc.workspace.registerTextDocumentContentProvider('uncrustify', new configurator_1.default());
82 context.subscriptions.push(configurationSub);
83 vsc.commands.registerCommand('uncrustify.create', () => {
84 logger.dbg('command: create');
85 if (!vsc.workspace.rootPath) {
86 return vsc.window.showWarningMessage('No folder is open');
87 }
88 let output = '';
89 return new Promise((resolve) => cp.spawn('uncrustify', ['--update-config-with-doc'])
90 .stdout
91 .on('data', (data) => output += data.toString())
92 .on('close', () => resolve(output)))
93 .then((config) => new Promise((resolve) => fs.writeFile(util.configPath(), config, resolve)));
94 });
95 vsc.commands.registerCommand('uncrustify.open', () => vsc.commands.executeCommand('vscode.open', vsc.Uri.file(util.configPath())));
96 vsc.commands.registerCommand('uncrustify.save', (config) => {
97 logger.dbg('command: save');
98 if (!config) {
99 logger.dbg('error saving config: no config passed');
100 return;
101 }
102 return new Promise((resolve, reject) => fs.readFile(util.configPath(), (err, data) => {
103 if (err) {
104 reject(err);
105 }
106 resolve(data);
107 })).then((data) => {
108 let result = data.toString();
109 for (let key in config) {
110 result = result.replace(new RegExp(`^(${key}\\s*=\\s*)\\S+(.*)`, 'm'), `$1${config[key]}$2`);
111 }
112 return result;
113 }).then((result) => new Promise((resolve, reject) => fs.writeFile(util.configPath(), result, (err) => {
114 if (err) {
115 reject(err);
116 }
117 resolve();
118 logger.dbg('saved config file');
119 }))).catch((reason) => logger.dbg('error saving config file: ' + reason));
120 });
121 vsc.commands.registerCommand('uncrustify.savePreset', (config, name) => {
122 logger.dbg('command: savePreset');
123 if (!config) {
124 logger.dbg('error saving preset: no config passed');
125 return;
126 }
127 let promise = name !== undefined
128 ? Promise.resolve(name)
129 : vsc.window.showInputBox({ placeHolder: 'Name of the preset' });
130 return promise.then((chosenName) => {
131 if (!chosenName && name === undefined) {
132 vsc.window.showErrorMessage('Name can\'t be empty !');
133 throw new Error('Name is empty');
134 }
135 let presets = extContext.globalState.get('presets', {});
136 presets[chosenName] = config;
137 logger.dbg('saved preset ' + chosenName);
138 return extContext.globalState.update('presets', presets);
139 }).then(() => (name === undefined) && vsc.window.showInformationMessage('Preset saved !'));
140 });
141 presetCommand('loadPreset', (presets, name, internal) => {
142 logger.dbg('command: loadPreset');
143 if (!presets || !name) {
144 logger.dbg('error loading presets');
145 return;
146 }
147 return vsc.commands.executeCommand('uncrustify.create')
148 .then(() => vsc.commands.executeCommand('uncrustify.save', presets[name]))
149 .then(() => {
150 configurator_1.default.oldConfig = presets[name];
151 if (!internal) {
152 vsc.window.showInformationMessage('Preset loaded !');
153 }
154 });
155 });
156 presetCommand('deletePreset', (presets, name, internal) => {
157 logger.dbg('command: deletePreset');
158 if (!presets || !name) {
159 logger.dbg('error loading presets');
160 return;
161 }
162 delete presets[name];
163 return extContext.globalState.update('presets', presets)
164 .then(() => !internal && vsc.window.showInformationMessage('Preset deleted !'));
165 });
166 vsc.commands.registerCommand('uncrustify.upgrade', (config) => {
167 logger.dbg('command: upgrade');
168 if (!config) {
169 logger.dbg('error upgrading config: no config passed');
170 return;
171 }
172 return vsc.commands.executeCommand('uncrustify.savePreset', config, '')
173 .then(() => vsc.commands.executeCommand('uncrustify.loadPreset', ''))
174 .then(() => vsc.commands.executeCommand('uncrustify.deletePreset', ''))
175 .then(() => vsc.commands.executeCommand('vscode.open', vsc.Uri.file(util.configPath())));
176 });
177 if (vsc.workspace.getConfiguration('uncrustify').get('graphicalConfig')) {
178 function graphicalEdit(doc) {
179 if (doc.uri.scheme === 'file' && doc.fileName === util.configPath()) {
180 logger.dbg('launching graphical editor');
181 vsc.commands.executeCommand('workbench.action.closeActiveEditor')
182 .then(() => vsc.commands.executeCommand('vscode.previewHtml', util.configUri(), undefined, 'Uncrustify configuration'));
183 }
184 }
185 vsc.workspace.onDidOpenTextDocument(graphicalEdit);
186 if (vsc.window.activeTextEditor) {
187 graphicalEdit(vsc.window.activeTextEditor.document);
188 }
189 }
190}
191exports.activate = activate;
192;
193function deactivate() { }
194exports.deactivate = deactivate;
195;
196function presetCommand(commandName, callback) {
197 vsc.commands.registerCommand('uncrustify.' + commandName, (name) => {
198 logger.dbg('command: ' + commandName);
199 let presets = extContext.globalState.get('presets', {});
200 let names = [];
201 for (let name in presets) {
202 names.push(name);
203 }
204 if (names.length === 0) {
205 vsc.window.showErrorMessage('No presets saved');
206 return;
207 }
208 let promise = name !== undefined
209 ? Promise.resolve(name)
210 : vsc.window.showQuickPick(names);
211 return promise.then((chosenName) => {
212 if (!chosenName && name === undefined) {
213 throw new Error('No preset selected');
214 }
215 return callback(presets, chosenName, name !== undefined);
216 });
217 });
218}
219//# sourceMappingURL=extension.js.map \ No newline at end of file
diff --git a/tools/format/vscode-uncrustify/out/src/formatter.js b/tools/format/vscode-uncrustify/out/src/formatter.js
new file mode 100644
index 0000000..6ab4a9f
--- /dev/null
+++ b/tools/format/vscode-uncrustify/out/src/formatter.js
@@ -0,0 +1,86 @@
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fs = require("fs");
4const cp = require("child_process");
5const vsc = require("vscode");
6const logger = require("./logger");
7const util = require("./util");
8class Formatter {
9 provideDocumentFormattingEdits(document, options, token) {
10 return this.formatUncrustify(document, null, options, token);
11 }
12 provideDocumentRangeFormattingEdits(document, range, options, token) {
13 return this.formatUncrustify(document, range, options, token);
14 }
15 formatUncrustify(document, range, options, token) {
16 return new Promise((resolve, reject) => {
17 token.onCancellationRequested(reject);
18 let configPath = util.configPath();
19 logger.dbg('config file: ' + configPath);
20 try {
21 if (configPath) {
22 configPath = configPath.replace(/(%\w+%)|(\$\w+)/, (variable) => {
23 let end = variable.startsWith('%') ? 2 : 1;
24 return process.env[variable.substr(1, variable.length - end)];
25 });
26 }
27 fs.accessSync(configPath);
28 }
29 catch (err) {
30 logger.dbg('error accessing config file: ' + err);
31 vsc.window.showErrorMessage('The uncrustify config file path is incorrect: ' + configPath);
32 reject();
33 return;
34 }
35 let uncrustifyExecutable = vsc.workspace.getConfiguration('uncrustify').get('executablePath', 'uncrustify');
36 let args;
37 if (range)
38 args = ['-l', languageMap[document.languageId], '-c', configPath, '--frag'];
39 else
40 args = ['-l', languageMap[document.languageId], '-c', configPath];
41 let output = '';
42 let error = '';
43 let uncrustify = cp.spawn(uncrustifyExecutable, args);
44 logger.dbg(`launched: ${uncrustifyExecutable} ${args.join(' ')}`);
45 uncrustify.on('error', reject);
46 uncrustify.on('exit', (code) => {
47 logger.dbg('uncrustify exited with status: ' + code);
48 if (code !== 0) {
49 vsc.window.showErrorMessage('Uncrustify exited with error code: ' + code);
50 reject();
51 }
52 });
53 uncrustify.stdout.on('data', (data) => output += data);
54 uncrustify.stdout.on('close', () => {
55 if (!range) {
56 let lastLine = document.lineCount - 1;
57 let lastCol = document.lineAt(lastLine).text.length;
58 let fullrange = new vsc.Range(0, 0, lastLine, lastCol);
59 resolve([new vsc.TextEdit(fullrange, output)]);
60 }
61 resolve([new vsc.TextEdit(range, output)]);
62 });
63 uncrustify.stderr.on('data', (data) => error += data);
64 uncrustify.stderr.on('close', () => logger.dbg('uncrustify exited with error: ' + error));
65 if (range)
66 uncrustify.stdin.write(document.getText(range));
67 else
68 uncrustify.stdin.write(document.getText());
69 uncrustify.stdin.end();
70 });
71 }
72}
73exports.default = Formatter;
74;
75const languageMap = {
76 'apex': 'JAVA',
77 'c': 'C',
78 'cpp': 'CPP',
79 'csharp': 'CS',
80 'd': 'D',
81 'java': 'JAVA',
82 'objective-c': 'OC',
83 'pawn': 'PAWN',
84 'vala': 'VALA'
85};
86//# sourceMappingURL=formatter.js.map \ No newline at end of file
diff --git a/tools/format/vscode-uncrustify/package.json b/tools/format/vscode-uncrustify/package.json
new file mode 100644
index 0000000..5f1f694
--- /dev/null
+++ b/tools/format/vscode-uncrustify/package.json
@@ -0,0 +1,133 @@
1{
2 "name": "uncrustify",
3 "displayName": "Uncrustify",
4 "description": "Code format using uncrustify",
5 "version": "2.4.2",
6 "publisher": "LaurentTreguier",
7 "license": "MIT",
8 "homepage": "https://github.com/LaurentTreguier/vscode-uncrustify",
9 "icon": "images/uncrustify.png",
10 "galleryBanner": {
11 "color": "#1F1F1F",
12 "theme": "dark"
13 },
14 "repository": {
15 "type": "git",
16 "url": "https://github.com/LaurentTreguier/vscode-uncrustify.git"
17 },
18 "bugs": {
19 "url": "https://github.com/LaurentTreguier/vscode-uncrustify/issues"
20 },
21 "engines": {
22 "vscode": "^1.6.0"
23 },
24 "categories": [
25 "Languages",
26 "Formatters"
27 ],
28 "keywords": [
29 "uncrustify",
30 "format",
31 "formatting",
32 "formatter"
33 ],
34 "activationEvents": [
35 "onLanguage:apex",
36 "onLanguage:c",
37 "onLanguage:cpp",
38 "onLanguage:csharp",
39 "onLanguage:d",
40 "onLanguage:java",
41 "onLanguage:objective-c",
42 "onLanguage:pawn",
43 "onLanguage:vala",
44 "workspaceContains:uncrustify.cfg",
45 "onCommand:uncrustify.create",
46 "onCommand:uncrustify.open",
47 "onCommand:uncrustify.save",
48 "onCommand:uncrustify.savePreset",
49 "onCommand:uncrustify.loadPreset",
50 "onCommand:uncrustify.deletePreset",
51 "onCommand:uncrustify.upgrade"
52 ],
53 "main": "./out/src/extension",
54 "contributes": {
55 "configuration": {
56 "title": "Uncrustify configuration",
57 "properties": {
58 "uncrustify.executablePath": {
59 "type": "string",
60 "default": "uncrustify",
61 "description": "Path to the uncrustify executable"
62 },
63 "uncrustify.configPath": {
64 "type": "string",
65 "default": null,
66 "description": "Path to the uncrustify configuration file"
67 },
68 "uncrustify.graphicalConfig": {
69 "type": "boolean",
70 "default": true,
71 "description": "Toggles the graphical config editor"
72 },
73 "uncrustify.debug": {
74 "type": "boolean",
75 "default": false,
76 "description": "Activates logs for debugging the extension"
77 }
78 }
79 },
80 "commands": [
81 {
82 "title": "Create default config file",
83 "category": "Uncrustify",
84 "command": "uncrustify.create"
85 },
86 {
87 "title": "Open config file",
88 "category": "Uncustify",
89 "command": "uncrustify.open"
90 },
91 {
92 "title": "Save config file",
93 "category": "Uncustify",
94 "command": "uncrustify.save"
95 },
96 {
97 "title": "Save config file as preset",
98 "category": "Uncustify",
99 "command": "uncrustify.savePreset"
100 },
101 {
102 "title": "Load preset config file",
103 "category": "Uncrustify",
104 "command": "uncrustify.loadPreset"
105 },
106 {
107 "title": "Delete preset config file",
108 "category": "Uncrustify",
109 "command": "uncrustify.deletePreset"
110 },
111 {
112 "title": "Upgrade config file",
113 "category": "Uncrustify",
114 "command": "uncrustify.upgrade"
115 }
116 ]
117 },
118 "scripts": {
119 "vscode:prepublish": "tsc -p ./",
120 "compile": "tsc -watch -p ./",
121 "postinstall": "node ./node_modules/vscode/bin/install"
122 },
123 "dependencies": {
124 "meta-pkg": "^0.6.4",
125 "request": "^2.81.0"
126 },
127 "devDependencies": {
128 "@types/node": "^8.0.14",
129 "@types/request": "^2.0.0",
130 "typescript": "^2.4.2",
131 "vscode": "^1.1.0"
132 }
133}