better file select for debugger - native support for moonscript

This commit is contained in:
kepler155c@gmail.com
2020-06-10 19:47:42 -06:00
parent fae3b6a654
commit e9f9999f41
3 changed files with 77 additions and 3 deletions

View File

@@ -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()

View File

@@ -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)

View File

@@ -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)
}