Skip to content

Commit

Permalink
Fixes #38
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhmale committed Mar 27, 2017
1 parent a02be7b commit f9874dd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
}
],
"configuration": {
"type": "idris",
"type": "object",
"title": "Settings for Idris project",
"properties": {
"idris.executablePath": {
Expand Down
23 changes: 17 additions & 6 deletions src/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@ let getCommands = () => {
]
}

let getCompilerOptsPromise = () => {
let root = vscode.workspace.rootPath
let safeRoot = root === undefined ? "" : root
let compilerOptions = ipkg.compilerOptions(safeRoot)

return compilerOptions
}

let reInitialize = () => {
getCompilerOptsPromise().subscribe((compilerOptions) => {
commands.reInitialize(compilerOptions)
})
}

let withCompilerOptions = (callback) => {
let document = vscode.window.activeTextEditor.document
if (document.languageId != 'idris') return

let uri = document.uri.fsPath
let root = vscode.workspace.rootPath
let safeRoot = root === undefined ? "" : root
let compilerOptions = ipkg.compilerOptions(safeRoot)

compilerOptions.subscribe((compilerOptions) => {
getCompilerOptsPromise().subscribe((compilerOptions) => {
commands.initialize(compilerOptions)
callback(uri)
})
Expand All @@ -52,5 +62,6 @@ module.exports = {
destroy: commands.destroy,
diagnosticCollection: commands.diagnosticCollection,
withCompilerOptions: withCompilerOptions,
typeCheckOnSave: typeCheckOnSave
typeCheckOnSave: typeCheckOnSave,
reInitialize: reInitialize
}
16 changes: 12 additions & 4 deletions src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ let typeHover = require('./typeHover')

let IDRIS_MODE = { language: 'idris', scheme: 'file' }

let idrisExecutablePath = vscode.workspace.getConfiguration('idris').get('executablePath');

var triggers = []
for (var i = 0; i < 26; i++) {
triggers.push(String.fromCharCode(97 + i))
Expand All @@ -19,17 +21,23 @@ function activate(context) {
}
})

vscode.workspace.onDidSaveTextDocument((event) => {
controller.typeCheckOnSave()
})

context.subscriptions.push(controller.diagnosticCollection)
controller.getCommands().forEach(([key, value]) => {
let disposable = vscode.commands.registerCommand(key, value)
context.subscriptions.push(disposable)
})
context.subscriptions.push(vscode.languages.registerCompletionItemProvider(IDRIS_MODE, new completion.IdrisCompletionProvider(), ...triggers))
context.subscriptions.push(vscode.languages.registerHoverProvider(IDRIS_MODE, new typeHover.IdrisHoverProvider()))
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument((event) => {
controller.typeCheckOnSave()
}))
context.subscriptions.push(vscode.workspace.onDidChangeConfiguration(() => {
let newIdrisExecutablePath = vscode.workspace.getConfiguration('idris').get('executablePath')
if (idrisExecutablePath != newIdrisExecutablePath) {
idrisExecutablePath = newIdrisExecutablePath
controller.reInitialize()
}
}))
}
exports.activate = activate

Expand Down
6 changes: 6 additions & 0 deletions src/idris/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ let initialize = (compilerOptions) => {
model.setCompilerOptions(compilerOptions);
}

let reInitialize = (compilerOptions) => {
model = new IdrisModel()
model.setCompilerOptions(compilerOptions)
}

let getModel = () => {
return model
}
Expand Down Expand Up @@ -489,6 +494,7 @@ module.exports = {
getModel,
diagnosticCollection,
initialize,
reInitialize,
typecheckFile,
typeForWord,
docsForWord,
Expand Down

0 comments on commit f9874dd

Please sign in to comment.