Skip to content

Commit

Permalink
feat : added config option to compileOnSave with default to true
Browse files Browse the repository at this point in the history
closes #66
  • Loading branch information
basarat committed Feb 9, 2015
1 parent 4197cd4 commit 47739d8
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
25 changes: 25 additions & 0 deletions lib/main/atom/atomConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var packageName = 'atom-typescript';
function getConfig(name) {
return atom.config.get(packageName + '.' + name);
}
var Config = (function () {
function Config() {
this.schema = {
compileOnSave: {
title: 'Compile on save',
type: 'boolean',
default: true
}
};
}
Object.defineProperty(Config.prototype, "compileOnSave", {
get: function () {
return getConfig('compileOnSave');
},
enumerable: true,
configurable: true
});
return Config;
})();
var config = new Config();
module.exports = config;
25 changes: 25 additions & 0 deletions lib/main/atom/atomConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
///ts:ref=globals
/// <reference path="../../globals.ts"/> ///ts:ref:generated

// Documentation https://atom.io/docs/api/v0.177.0/Config and http://json-schema.org/examples.html
// To add a new setting you need to add to
// schema
// getter/setter

var packageName = 'atom-typescript';
function getConfig<T>(name: string): T {
return atom.config.get(packageName + '.' + name);
}

class Config {
schema = {
compileOnSave: {
title: 'Compile on save',
type: 'boolean',
default: true
}
}
get compileOnSave() { return getConfig<boolean>('compileOnSave') }
}
var config = new Config();
export = config;
7 changes: 6 additions & 1 deletion lib/main/atomts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var statusBarMessage;
var editorWatch;
var autoCompleteWatch;
var parent = require('../worker/parent');
var atomConfig = require('./atom/atomConfig');
exports.config = atomConfig.schema;
function activate(state) {
var linter = apd.require('linter');
var acp = apd.require('autocomplete-plus');
Expand Down Expand Up @@ -45,7 +47,10 @@ function activate(state) {
});
var saveObserver = editor.onDidSave(function (event) {
onDisk = true;
parent.updateText({ filePath: filePath, text: editor.getText() }).then(function () { return parent.emitFile({ filePath: filePath }); }).then(function (res) { return errorView.showEmittedMessage(res); });
var textUpdated = parent.updateText({ filePath: filePath, text: editor.getText() });
if (atomConfig.compileOnSave) {
textUpdated.then(function () { return parent.emitFile({ filePath: filePath }); }).then(function (res) { return errorView.showEmittedMessage(res); });
}
});
var destroyObserver = editor.onDidDestroy(function () {
errorView.setErrors(filePath, []);
Expand Down
13 changes: 10 additions & 3 deletions lib/main/atomts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface PackageState {

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

// Export config
import atomConfig = require('./atom/atomConfig');
export var config = atomConfig.schema;

export function activate(state: PackageState) {

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

// TODO: store by file path
parent.updateText({ filePath: filePath, text: editor.getText() })
.then(() => parent.emitFile({ filePath }))
.then((res) => errorView.showEmittedMessage(res));
var textUpdated = parent.updateText({ filePath: filePath, text: editor.getText() });

if (atomConfig.compileOnSave) {
textUpdated.then(() => parent.emitFile({ filePath }))
.then((res) => errorView.showEmittedMessage(res));
}
});

// Observe editors closing
Expand Down
1 change: 1 addition & 0 deletions lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"files": [
"./globals.ts",
"./linter.ts",
"./main/atom/atomConfig.ts",
"./main/atom/atomUtils.ts",
"./main/atom/autoCompleteProvider.ts",
"./main/atom/buildView.ts",
Expand Down

1 comment on commit 47739d8

@basarat
Copy link
Member Author

@basarat basarat commented on 47739d8 Feb 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Closes #67 . 9:50pm after a working day. Time to sleep ❤️

Please sign in to comment.