@@ -12,9 +12,9 @@ local M = {}
1212--- @field DBGADDRESS ? string # 调试器地址,默认为 '127.0.0.1'
1313M .args = {
1414 -- 指定日志输出目录,默认为 `./log`
15- LOGPATH = ' ${LUALS} /log' ,
15+ LOGPATH = ' $LUALSPATH /log' ,
1616 -- 指定meta文件的生成目录,默认为 `./meta`
17- METAPATH = ' ${LUALS} /meta' ,
17+ METAPATH = ' $LUALSPATH /meta' ,
1818 -- 是否为开发模式
1919 DEVELOP = false ,
2020 -- 调试器端口号,默认为 11411
@@ -40,39 +40,42 @@ M.args = {
4040 --- @type ' Error' | ' Warning' | ' Information' | ' Hint'
4141 CHECKLEVEL = ' Warning' ,
4242 -- 诊断报告生成的文件路径(json),默认为 `$LOGPATH/check.json`
43- CHECK_OUT_PATH = ' ${ LOGPATH} /check.json' ,
43+ CHECK_OUT_PATH = ' $LOGPATH/check.json' ,
4444
4545 -- 命令行:生成文档
4646 DOC = ' ' ,
4747}
4848luals .util .tableMerge (M .args , argparser .parse (arg , true ))
4949
50- -- 启动时的版本号
51- M .version = version .getVersion ()
52-
53- -- 路径相关
54- --- @class LuaLS.Path
55- M .path = {}
56-
5750--- @return string
5851local function findRoot ()
59- local lastPath
60- for i = 1 , 10 do
61- local currentPath = debug.getinfo (i , ' S' ).source
62- if currentPath :sub ( 1 , 1 ) ~= ' @ ' then
52+ local currentPath
53+ for i = 1 , 100 do
54+ currentPath = debug.getinfo (i , ' S' ).source
55+ if currentPath :match ' @%a: ' then
6356 break
6457 end
65- lastPath = currentPath :sub (2 )
6658 end
67- assert (lastPath , ' Can not find root path' )
68- local rootPath = lastPath :gsub (' [/\\ ]*[^/\\ ]-$' , ' ' )
59+ assert (currentPath , ' Can not find root path' )
60+ local rootPath = currentPath : sub ( 2 ) :gsub (' [/\\ ]*[^/\\ ]-$' , ' ' )
6961 rootPath = (rootPath == ' ' and ' .' or rootPath )
7062 return rootPath
7163end
7264
65+ -- 环境变量
66+ M .env = {}
7367-- 语言服务器根路径
74- M .rootUri = luals .uri .encode (luals .util .expandPath (findRoot ()))
75- M .logUri = luals .uri .encode (luals .util .expandPath (M .args .LOGPATH ))
76- M .metaUri = luals .uri .encode (luals .util .expandPath (M .args .METAPATH ))
68+ M .rootPath = luals .util .expandPath (findRoot ())
69+ M .env .LUALSPATH = M .rootPath
70+ M .logPath = luals .util .expandPath (M .args .LOGPATH , M .env )
71+ M .env .LOGPATH = M .logPath
72+ M .metaPath = luals .util .expandPath (M .args .METAPATH , M .env )
73+ M .env .METAPATH = M .metaPath
74+ M .rootUri = luals .uri .encode (M .rootPath )
75+ M .logUri = luals .uri .encode (M .logPath )
76+ M .metaUri = luals .uri .encode (M .metaPath )
77+
78+ -- 启动时的版本号
79+ M .version = version .getVersion (M .rootPath )
7780
7881return M
0 commit comments