Skip to content

Commit e76a64b

Browse files
committed
add test launch config
1 parent ab2404d commit e76a64b

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

.vscode/launch.json

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
"kind": "bin"
2020
}
2121
},
22-
"args": [
23-
24-
],
22+
"args": [],
2523
"cwd": "${workspaceFolder}"
2624
},
2725
{
@@ -47,5 +45,25 @@
4745
],
4846
},
4947
},
48+
{
49+
"name": "🍺test",
50+
"type": "lua",
51+
"request": "launch",
52+
"stopOnEntry": false,
53+
"luaexe": "${workspaceFolder}/bin/lua-language-server",
54+
"program": "${workspaceFolder}/test.lua",
55+
"luaVersion": "lua54",
56+
"sourceCoding": "utf8",
57+
"console": "integratedTerminal",
58+
"address": "127.0.0.1:11428",
59+
"internalConsoleOptions": "openOnSessionStart",
60+
"outputCapture": [
61+
"print",
62+
"stderr",
63+
],
64+
"windows": {
65+
"luaexe": "${workspaceFolder}/bin/lua-language-server.exe"
66+
}
67+
},
5068
]
5169
}

crates/luals/src/main.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use mlua::prelude::*;
2-
use std::env;
2+
use std::{env, path::{Path, PathBuf}};
33

44
#[tokio::main(flavor = "current_thread")]
55
async fn main() -> LuaResult<()> {
@@ -8,23 +8,33 @@ async fn main() -> LuaResult<()> {
88
let lua = unsafe { Lua::unsafe_new() };
99
luals_basic::lua_preload(&lua)?;
1010

11-
build_args(&lua);
12-
let current_path = std::env::current_dir()?;
13-
let main_path = current_path.join("main.lua");
14-
let main = lua.load(main_path);
11+
let start_file_name = build_args(&lua);
12+
let main = lua.load(start_file_name);
1513
main.call_async(()).await?;
1614
Ok(())
1715
}
1816

19-
fn build_args(lua: &Lua) {
17+
fn build_args(lua: &Lua) -> PathBuf {
2018
let args = std::env::args().skip(1).collect::<Vec<_>>();
19+
if args.len() > 0 && args[0] == "-e" {
20+
let code = args[1].clone();
21+
let chunk = lua.load(code);
22+
chunk.call::<()>(mlua::MultiValue::new()).unwrap();
23+
24+
let start_file_name = args[2].clone();
25+
return start_file_name.into();
26+
}
27+
2128
let table = lua.create_table().unwrap();
2229
for (i, arg) in args.iter().enumerate() {
2330
table.set(i + 1, arg.clone()).unwrap();
2431
}
2532
let exe_path = env::current_exe().unwrap();
2633
table.set(-1, exe_path.to_str().unwrap()).unwrap();
2734
lua.globals().set("arg", table).unwrap();
35+
let current_path = std::env::current_dir().unwrap();
36+
let main_path = current_path.join("main.lua");
37+
main_path
2838
}
2939

3040
fn dynamic_set_root() {

main.lua

-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ xpcall(dofile, log.debug, (ROOT / 'debugger.lua'):string())
7777

7878
require 'cli'
7979

80-
if TEST then
81-
require 'test'
82-
return
83-
end
8480
local _, service = xpcall(require, log.error, 'service')
8581

8682
service.start()

0 commit comments

Comments
 (0)