Skip to content

Commit 47739d8

Browse files
committed
feat : added config option to compileOnSave with default to true
closes #66
1 parent 4197cd4 commit 47739d8

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

lib/main/atom/atomConfig.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
var packageName = 'atom-typescript';
2+
function getConfig(name) {
3+
return atom.config.get(packageName + '.' + name);
4+
}
5+
var Config = (function () {
6+
function Config() {
7+
this.schema = {
8+
compileOnSave: {
9+
title: 'Compile on save',
10+
type: 'boolean',
11+
default: true
12+
}
13+
};
14+
}
15+
Object.defineProperty(Config.prototype, "compileOnSave", {
16+
get: function () {
17+
return getConfig('compileOnSave');
18+
},
19+
enumerable: true,
20+
configurable: true
21+
});
22+
return Config;
23+
})();
24+
var config = new Config();
25+
module.exports = config;

lib/main/atom/atomConfig.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
///ts:ref=globals
2+
/// <reference path="../../globals.ts"/> ///ts:ref:generated
3+
4+
// Documentation https://atom.io/docs/api/v0.177.0/Config and http://json-schema.org/examples.html
5+
// To add a new setting you need to add to
6+
// schema
7+
// getter/setter
8+
9+
var packageName = 'atom-typescript';
10+
function getConfig<T>(name: string): T {
11+
return atom.config.get(packageName + '.' + name);
12+
}
13+
14+
class Config {
15+
schema = {
16+
compileOnSave: {
17+
title: 'Compile on save',
18+
type: 'boolean',
19+
default: true
20+
}
21+
}
22+
get compileOnSave() { return getConfig<boolean>('compileOnSave') }
23+
}
24+
var config = new Config();
25+
export = config;

lib/main/atomts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ var statusBarMessage;
1010
var editorWatch;
1111
var autoCompleteWatch;
1212
var parent = require('../worker/parent');
13+
var atomConfig = require('./atom/atomConfig');
14+
exports.config = atomConfig.schema;
1315
function activate(state) {
1416
var linter = apd.require('linter');
1517
var acp = apd.require('autocomplete-plus');
@@ -45,7 +47,10 @@ function activate(state) {
4547
});
4648
var saveObserver = editor.onDidSave(function (event) {
4749
onDisk = true;
48-
parent.updateText({ filePath: filePath, text: editor.getText() }).then(function () { return parent.emitFile({ filePath: filePath }); }).then(function (res) { return errorView.showEmittedMessage(res); });
50+
var textUpdated = parent.updateText({ filePath: filePath, text: editor.getText() });
51+
if (atomConfig.compileOnSave) {
52+
textUpdated.then(function () { return parent.emitFile({ filePath: filePath }); }).then(function (res) { return errorView.showEmittedMessage(res); });
53+
}
4954
});
5055
var destroyObserver = editor.onDidDestroy(function () {
5156
errorView.setErrors(filePath, []);

lib/main/atomts.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export interface PackageState {
3131

3232
import parent = require('../worker/parent');
3333

34+
// Export config
35+
import atomConfig = require('./atom/atomConfig');
36+
export var config = atomConfig.schema;
37+
3438
export function activate(state: PackageState) {
3539

3640
// Don't activate if we have a dependency that isn't available
@@ -121,9 +125,12 @@ export function activate(state: PackageState) {
121125
onDisk = true;
122126

123127
// TODO: store by file path
124-
parent.updateText({ filePath: filePath, text: editor.getText() })
125-
.then(() => parent.emitFile({ filePath }))
126-
.then((res) => errorView.showEmittedMessage(res));
128+
var textUpdated = parent.updateText({ filePath: filePath, text: editor.getText() });
129+
130+
if (atomConfig.compileOnSave) {
131+
textUpdated.then(() => parent.emitFile({ filePath }))
132+
.then((res) => errorView.showEmittedMessage(res));
133+
}
127134
});
128135

129136
// Observe editors closing

lib/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"files": [
1515
"./globals.ts",
1616
"./linter.ts",
17+
"./main/atom/atomConfig.ts",
1718
"./main/atom/atomUtils.ts",
1819
"./main/atom/autoCompleteProvider.ts",
1920
"./main/atom/buildView.ts",

0 commit comments

Comments
 (0)