From e9f9999f41309c3f0083a3c4c44c444d66cf20e1 Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Wed, 10 Jun 2020 19:47:42 -0600 Subject: [PATCH] better file select for debugger - native support for moonscript --- debugger/debug.lua | 41 ++++++++++++++++++++++++++++++++-- moonscript/autorun/startup.lua | 37 ++++++++++++++++++++++++++++++ moonscript/moon | 2 +- 3 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 moonscript/autorun/startup.lua diff --git a/debugger/debug.lua b/debugger/debug.lua index 2a3ac39..adf4f24 100644 --- a/debugger/debug.lua +++ b/debugger/debug.lua @@ -214,7 +214,7 @@ local page = UI.Page { breaks = UI.Tab { title = 'Breakpoints', index = 2, - menuBar = UI.MenuBar { + UI.MenuBar { buttons = { { text = 'Toggle', event = 'toggle' }, { text = 'Remove', event = 'remove' }, @@ -274,7 +274,7 @@ local page = UI.Page { }, }, - menuBar = UI.MenuBar { + UI.MenuBar { y = -1, backgroundColor = 'primary', buttonClass = 'InverseButton', @@ -362,6 +362,43 @@ local page = UI.Page { y = '50%', modal = true, enable = function() end, + getFiles = function() + local paths = { } + for _,v in pairs(Util.split(client.env.package.path, '(.-);')) do + v = v:match('(.+)%?') or '' + if v:sub(1, 1) ~= '/' then + v = fs.combine(fs.getDir(filename), v) + end + if fs.exists(v) and fs.isDir(v) then + paths[fs.combine(v, '')] = true + end + end + + local t = { } + for k in pairs(paths) do + local function recurse(dir) + local files = fs.list(dir) + for _,f in ipairs(files) do + local fullName = fs.combine(dir, f) + if fs.isDir(fullName) then + -- skip virtual dirs + if f ~= '.git' and fs.native.isDir(fullName) then + recurse(fullName) + end + elseif fullName:match('(.+)%.lua$') then + table.insert(t, { + name = f, + dir = dir, + lname = f:lower(), + fullName = fullName, + }) + end + end + end + recurse(k) + end + return t + end, show = function(self) UI.QuickSelect.enable(self) self:focusFirst() diff --git a/moonscript/autorun/startup.lua b/moonscript/autorun/startup.lua new file mode 100644 index 0000000..f50e546 --- /dev/null +++ b/moonscript/autorun/startup.lua @@ -0,0 +1,37 @@ +local Map = require('opus.map') + +local fs = _G.fs +local shell = _ENV.shell + +local commands = Map.transpose { + 'packages/moonscript/moon', + 'packages/moonscript/moonc' +} + +local function compatEnv(source) + local env = Map.shallowCopy(source._G) + Map.merge(env, source) + env._G = env + _G.requireInjector(env, 'packages/moon') + return env +end + +shell.registerHandler(function(args, env) + if args[1]:match('(.+)%.moon$') then + return { + title = fs.getName(args[1]):match('([^%.]+)'), + path = 'packages/moonscript/moon', + args = args, + load = loadfile, + env = compatEnv(env), + } + end + local command = shell.resolveProgram(args[1]) or '' + return commands[command] and { + title = fs.getName(command), + path = command, + args = { table.unpack(args, 2) }, + load = loadfile, + env = compatEnv(env), + } +end) diff --git a/moonscript/moon b/moonscript/moon index bd17e3c..f4605ac 100644 --- a/moonscript/moon +++ b/moonscript/moon @@ -48,7 +48,7 @@ run = function() require("moonscript.version").print_version() os.exit() end - local script_fname = shell.resolve(opts.script) + local script_fname = shell.resolveProgram(opts.script) args = { unpack(arg, base + 1) }