diff --git a/package.json b/package.json index 15e5f25..5039159 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,10 @@ { "command": "idris.send-selection-repl", "group": "idris@13" + }, + { + "command": "idris.cleanup-ibc", + "group": "idris@14" } ] }, @@ -222,6 +226,11 @@ "command": "idris.send-selection-repl", "title": "Send selected code to REPL", "description": "Send selected text to a refreshed REPL with currently opened file" + }, + { + "command": "idris.cleanup-ibc", + "title": "Cleanup idris binary files", + "description": "Cleanup idris binary files" } ], "keybindings": [ @@ -314,6 +323,12 @@ "mac": "shift+cmd+x", "when": "editorFocus && editorLangId == idris", "command": "idris.send-selection-repl" + }, + { + "key": "shift+ctrl+u", + "mac": "shift+cmd+u", + "when": "editorFocus && editorLangId == idris", + "command": "idris.cleanup-ibc" } ], "snippets": [ @@ -335,7 +350,8 @@ "cson": "4.0.0", "eslint-plugin-promise": "3.5.0", "request": "2.81.0", - "chalk": "1.1.3" + "chalk": "1.1.3", + "glob": "7.1.1" }, "devDependencies": { "vscode": "^1.0.5" diff --git a/src/controller.js b/src/controller.js index 629096f..45e4c95 100644 --- a/src/controller.js +++ b/src/controller.js @@ -1,6 +1,8 @@ let ipkg = require('./ipkg/ipkg') let commands = require('./idris/commands') let vscode = require('vscode') +let glob = require("glob") +let fs = require('fs'); let getCommands = () => { return [ @@ -18,15 +20,31 @@ let getCommands = () => { ['idris.apropos', runCommand(commands.apropos)], ['idris.eval-selection', runCommand(commands.evalSelection)], ['idris.start-refresh-repl', runCommand(commands.startREPL)], - ['idris.send-selection-repl', runCommand(commands.sendREPL)] + ['idris.send-selection-repl', runCommand(commands.sendREPL)], + ['idris.cleanup-ibc', runCommand(cleanupIbc)] ] } -let getCompilerOptsPromise = () => { +let getSafeRoot = () => { let root = vscode.workspace.rootPath let safeRoot = root === undefined ? "" : root - let compilerOptions = ipkg.compilerOptions(safeRoot) + return safeRoot +} + +let cleanupIbc = (_) => { + glob(getSafeRoot() + "/**/*", (err, files) => { + if (!err) { + files.forEach((file) => { + if (file.endsWith(".ibc")) { + fs.unlinkSync(file) + } + }) + } + }) +} +let getCompilerOptsPromise = () => { + let compilerOptions = ipkg.compilerOptions(getSafeRoot()) return compilerOptions }