Skip to content

Commit cdf37c1

Browse files
committed
Reload configuration on changed
1 parent fd71080 commit cdf37c1

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.0.3
2+
- Reload configuration on changed
3+
14
### 1.0.2
25

36
- Add more phpfmt modes

extension.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,16 @@ class PHPFmt {
7272

7373
format(context, text) {
7474
return new Promise((resolve, reject) => {
75-
cp.exec(`${this.phpBin} -r "echo PHP_VERSION_ID;"`, (err, stdout) => {
76-
if (err) {
77-
window.showErrorMessage('cannot find php bin');
78-
reject();
79-
} else if (Number(stdout.toString()) < 70000) {
75+
try {
76+
const stdout = cp.execSync(`${this.phpBin} -r "echo PHP_VERSION_ID;"`);
77+
if (Number(stdout.toString()) < 70000) {
8078
window.showErrorMessage('php version < 7.0');
81-
reject();
79+
return reject();
8280
}
83-
});
81+
} catch (e) {
82+
window.showErrorMessage('cannot find php bin');
83+
return reject();
84+
}
8485

8586
const fileName =
8687
tmpDir +
@@ -93,12 +94,12 @@ class PHPFmt {
9394
fs.writeFileSync(fileName, text);
9495

9596
// test whether the php file has syntax error
96-
cp.exec(`${this.phpBin} -l ${fileName}`, err => {
97-
if (err && err.code && err.code !== 0) {
98-
window.showErrorMessage('syntax error in your php file');
99-
reject();
100-
}
101-
});
97+
try {
98+
cp.execSync(`${this.phpBin} -l ${fileName}`);
99+
} catch (e) {
100+
window.showErrorMessage('syntax error in your php file');
101+
return reject();
102+
}
102103

103104
const args = this.getArgs(fileName);
104105
args.unshift(`${context.extensionPath}/fmt.phar`);
@@ -142,8 +143,6 @@ class PHPFmt {
142143
}
143144

144145
exports.activate = context => {
145-
const phpfmt = new PHPFmt();
146-
147146
context.subscriptions.push(
148147
commands.registerTextEditorCommand('phpfmt.format', textEditor => {
149148
if (textEditor.document.languageId === 'php') {
@@ -160,6 +159,8 @@ exports.activate = context => {
160159
const lastLine = document.lineAt(document.lineCount - 1);
161160
const range = new Range(new Position(0, 0), lastLine.range.end);
162161

162+
const phpfmt = new PHPFmt();
163+
163164
phpfmt
164165
.format(context, originalText)
165166
.then(text => {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vscode-phpfmt",
33
"displayName": "phpfmt",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"description": "phpfmt for Visual Studio Code",
66
"main": "extension.js",
77
"scripts": {

0 commit comments

Comments
 (0)