Skip to content

Commit

Permalink
Fixes #88
Browse files Browse the repository at this point in the history
  • Loading branch information
swr1bm86 committed Apr 27, 2017
1 parent 30062fb commit 785126b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@
"command": "idris.new-project",
"title": "Idris: New Project",
"description": "Create a new ipkg based project using idringen"
},
{
"command": "idris.search",
"title": "Idris: Search for values by type",
"description": "Search Idris values by a concrete type signature"
}
],
"snippets": [
Expand Down
3 changes: 2 additions & 1 deletion src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ let getCommands = () => {
['idris.start-refresh-repl', runCommand(commands.startREPL)],
['idris.send-selection-repl', runCommand(commands.sendREPL)],
['idris.cleanup-ibc', runCommand(cleanupIbc)],
['idris.new-project', newProject]
['idris.new-project', newProject],
['idris.search', runCommand(commands.search)]
]
}

Expand Down
33 changes: 28 additions & 5 deletions src/idris/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,18 @@ let evalSelection = (uri) => {
})
}

let startup = (uri) => {
let createIdrisTerm = () => {
const pathToIdris = vscode.workspace.getConfiguration('idris').get('executablePath');
const idrisPath = which.sync(pathToIdris)
const pkgOpts = ipkg.getPkgOpts(innerCompilerOptions)
term = vscode.window.createTerminal("Idris REPL", idrisPath, pkgOpts)

return term
}

let startup = (uri) => {
let term = createIdrisTerm()

if (innerCompilerOptions.src && uri.includes(innerCompilerOptions.src)) {
term.sendText(`:cd ${path.resolve(innerCompilerOptions.src)}`.replace(/\\/g, "/"))
uri = path.relative(path.resolve(innerCompilerOptions.src), path.resolve(uri))
Expand All @@ -361,16 +367,32 @@ let startup = (uri) => {
term.show()
}

let startREPL = (uri) => {
let toggleTerm = (action, arg) => {
if (term == null) {
startup(uri)
action(arg)
} else {
term.hide()
term.dispose()
startup(uri)
action(arg)
}
}

let search = (_) => {
vscode.window.showInputBox({ prompt: 'Type signature' }).then(sig => {
let searchInTerm = (sig) => {
let term = createIdrisTerm()

term.sendText(`:search ${sig}`)
term.show()
}
toggleTerm(searchInTerm, sig)
})
}

let startREPL = (uri) => {
toggleTerm(startup, uri)
}

let sendREPL = (uri) => {
let editor = vscode.window.activeTextEditor
let selection = editor.selection
Expand Down Expand Up @@ -716,5 +738,6 @@ module.exports = {
clearOutputChannel,
buildIPKG,
checkTotality,
clearTotalityDiagnostics
clearTotalityDiagnostics,
search
}
17 changes: 0 additions & 17 deletions src/idris/idris-repl.js

This file was deleted.

10 changes: 7 additions & 3 deletions src/idris/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ class IdrisModel {
this.requestId = 0
this.ideModeRef = null
this.idrisBuildRef = null
this.idrisReplRef = null
this.subjects = {}
this.warnings = {}
this.idrisBuildSubject = null
this.idrisReplSubject = null
this.compilerOptions = {}
}

Expand All @@ -27,7 +29,7 @@ class IdrisModel {

idrisBuild(compilerOptions, ipkgFile) {
this.idrisBuildRef = new IdrisBuild(ipkgFile)
this.idrisBuildRef.on('message', (obj) => { this.handleIdrisBuildCommand(obj) })
this.idrisBuildRef.on('message', (obj) => { this.handleIdrisBuildMessage(obj) })
this.idrisBuildRef.start(compilerOptions)
return this.idrisBuildRef
}
Expand All @@ -39,6 +41,8 @@ class IdrisModel {
stop() {
if (this.ideModeRef)
this.ideModeRef.stop()
if (this.idrisReplRef)
this.idrisReplRef.stop()
}

setCompilerOptions(options) {
Expand All @@ -58,8 +62,8 @@ class IdrisModel {
return ++this.requestId
}

handleIdrisBuildCommand(cmd) {
this.idrisBuildSubject.onNext(cmd)
handleIdrisBuildMessage(msg) {
this.idrisBuildSubject.onNext(msg)
}

handleIdeModeCommand(cmd) {
Expand Down

0 comments on commit 785126b

Please sign in to comment.