 Logger = require './Logger'
 Rx = require 'rx-lite'
 JS = require './utils/js'
+path = require 'path'
 
 class IdrisModel
   requestId: 0


  makeLemma: (line, word) ->
    @prepareCommand [':make-lemma', line, word]

  makeCase: (line, word) ->
    @prepareCommand [':make-case', line, word]

    @ideMode(@compilerOptions).send [cmd, id]
    subject

  changeDirectory: (dir) ->
    @interpret ":cd #{dir}"

  load: (uri) ->
    dir =
      if @compilerOptions.src
        @compilerOptions.src
      else
        path.dirname uri

    cd =
      if dir != @compilerOptions.src
        @compilerOptions.src = dir
        @changeDirectory dir
          .map (_) -> dir
      else
        Rx.Observable.of dir

    cd.flatMap (_) =>
      @prepareCommand [':load-file', uri]

  docsFor: (word) ->
    @prepareCommand [':docs-for', word]
