Skip to content

Commit

Permalink
fixed a rather stupid error with the promise
Browse files Browse the repository at this point in the history
should now stop crashing when idris is not
installed
  • Loading branch information
archaeron committed May 26, 2015
1 parent 518503e commit 981804c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
19 changes: 10 additions & 9 deletions lib/language-idris.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ IdrisController = require './idris-controller'
IdrisModel = require './idris-model'
{CompositeDisposable} = require 'atom'
utils = require './utils'
exec = require('child_process').exec

module.exports =
config:
Expand All @@ -11,23 +12,23 @@ module.exports =
default: 'idris'

activate: ->
warningNoIdris = 'Please put idris into your path or set the right path in the settings of this package.'

pathToIdris = atom.config.get "language-idris.pathToIdris"

# check for the verion of idris. this has two purposes:
# 1. see if there is an idris set in your path or the package config
# 2. see if the version of idris is new enough for the ide mode
# and switch to ideslave for older ones
idrisVersionPromise = utils.execPromise "#{pathToIdris} --version --nobanner"
process = exec "#{pathToIdris} --version --nobanner"
process.stdout.on 'data', @startIdrisProcesses
process.stderr.on 'data', @showWarnings
process.on 'error', @showWarnings

idrisVersionPromise.then ((version) ->
Promise.resolve utils.parseVersion(version)
), (error) ->
atom.notifications.addWarning warningNoIdris
.then @startIdrisProcesses
showWarnings: (error) ->
warningNoIdris = 'Please put idris into your path or set the right path in the settings of this package.'
atom.notifications.addWarning warningNoIdris

startIdrisProcesses: (version) ->
startIdrisProcesses: (v) =>
version = utils.parseVersion v
@statusbar = new StatusBarView()
@model = new IdrisModel(version)
@controller =
Expand Down
11 changes: 0 additions & 11 deletions lib/utils.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
exec = require('child_process').exec

parseVersion = (vers) ->
vers.trim().replace('-', '').split('.').map (n) ->
parseInt n, 10
Expand All @@ -23,14 +21,6 @@ versionGreaterEq = (a, b) ->
.map ([a, b]) -> a >= b
.reduce ((acc, xs) -> if !acc then acc else xs), true

execPromise = (command, args) ->
promise = new Promise (resolve, reject) ->
process = exec command, args
process.stdout.on 'data', resolve
process.stderr.on 'data', reject
process.on 'error', reject
process.on 'close', reject

isString = (s) ->
typeof(s) == 'string' || s instanceof String

Expand Down Expand Up @@ -72,7 +62,6 @@ formatSexp = (sexp) ->
module.exports =
parseVersion: parseVersion
versionGreaterEq: versionGreaterEq
execPromise: execPromise
serialize: serialize
hexLength: hexLength
formatSexp: formatSexp

0 comments on commit 981804c

Please sign in to comment.