Skip to content

Commit 1924930

Browse files
committed
小小的一步
1 parent 3412a51 commit 1924930

File tree

13 files changed

+3289
-45
lines changed

13 files changed

+3289
-45
lines changed

.luarc.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"diagnostics": {
33
"disable": [
44
"close-non-object",
5-
"incomplete-signature-doc",
6-
"missing-global-doc",
75
"missing-local-export-doc"
86
],
97
"groupFileStatus": {
@@ -49,8 +47,12 @@
4947
"format_line": "false"
5048
}
5149
},
50+
"hover": {
51+
"expandAlias": false
52+
},
5253
"type": {
53-
"castNumberToInteger": false
54+
"castNumberToInteger": false,
55+
"weakUnionCheck": false
5456
},
5557
"doc": {
5658
"privateName": [

main.lua

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,22 @@
1-
local fs = require 'bee.filesystem'
2-
local util = require 'utility'
3-
local version = require 'version'
1+
local fs = require 'bee.filesystem'
42

5-
local function getValue(value)
6-
if value == 'true' or value == nil then
7-
value = true
8-
elseif value == 'false' then
9-
value = false
10-
elseif tonumber(value) then
11-
value = tonumber(value)
12-
elseif value:sub(1, 1) == '"' and value:sub(-1, -1) == '"' then
13-
value = value:sub(2, -2)
14-
end
15-
return value
16-
end
3+
---@class LuaLS
4+
luals = {}
175

18-
local function loadArgs()
19-
---@type string?
20-
local lastKey
21-
for _, v in ipairs(arg) do
22-
---@type string?
23-
local key, tail = v:match '^%-%-([%w_]+)(.*)$'
24-
local value
25-
if key then
26-
value = tail:match '=(.+)'
27-
lastKey = nil
28-
if not value then
29-
lastKey = key
30-
end
31-
else
32-
if lastKey then
33-
key = lastKey
34-
value = v
35-
lastKey = nil
36-
end
37-
end
38-
if key then
39-
_G[key:upper():gsub('-', '_')] = getValue(value)
40-
end
41-
end
42-
end
6+
luals.util = require 'tools.utility'
7+
luals.inspect = require 'tools.inspect'
8+
luals.json = require 'tools.json'
9+
package.loaded['json'] = luals.json
10+
require 'tools.json-beautify'
11+
require 'tools.jsonc'
12+
require 'tools.json-edit'
4313

44-
loadArgs()
14+
--语言服务器自身的状态
15+
---@class LuaLS.Runtime
16+
luals.runtime = require 'runtime.lua'
4517

4618
local currentPath = debug.getinfo(1, 'S').source:sub(2)
4719
local rootPath = currentPath:gsub('[/\\]*[^/\\]-$', '')
48-
4920
rootPath = (rootPath == '' and '.' or rootPath)
5021
ROOT = fs.path(util.expandPath(rootPath))
5122
LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')

script/master/init.lua

Whitespace-only changes.

script/meta/globals.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---@meta _
2+
jit = nil

script/meta/json.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---@meta tools.json
2+
3+
---@class Json.Null
4+
5+
---@alias Json.Type Json.Null | boolean | string | number | table<string, Json.Type> | Json.Type[]
6+
7+
---@class Json
8+
---@field null Json.Null
9+
---@field supportSparseArray boolean
10+
local M = {}
11+
12+
---@param v Json.Type
13+
---@return string
14+
function M.encode(v) end
15+
16+
---@param str string
17+
---@return Json.Type
18+
function M.decode(str) end
19+
20+
---@param str string
21+
---@return Json.Type
22+
function M.decode_jsonc(str) end
23+
24+
---@return table
25+
function M.createEmptyObject() end
26+
27+
---@param t table
28+
---@return boolean
29+
function M.isObject(t) end
30+
31+
---@class Json.BeatifyOption
32+
local beautifyOption = {
33+
newline = "\n",
34+
indent = " ",
35+
depth = 0,
36+
}
37+
38+
---@param v Json.Type
39+
---@param option Json.BeatifyOption
40+
---@return string
41+
function M.beautify(v, option) end
42+
43+
---@alias Json.Patch Json.Patch.Add | Json.Patch.Remove | Json.Patch.Replace
44+
45+
---@alias Json.Patch.Add { op: 'add', path: string, value: Json.Type }
46+
---@alias Json.Patch.Remove { op:'remove', path: string }
47+
---@alias Json.Patch.Replace { op:'replace', path: string, value: Json.Type }
48+
49+
---@param str string
50+
---@param patch Json.Patch
51+
---@param option Json.BeatifyOption
52+
function M.edit(str, patch, option) end
53+
54+
return M

script/runtime/argparser.lua

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---@class ArgParser
2+
local M = {}
3+
4+
---@alias ArgParser.Value string | number | boolean
5+
6+
---@param args string[]?
7+
---@param fomratKey boolean?
8+
---@return table<string, ArgParser.Value>
9+
function M.parse(args, fomratKey)
10+
local result = {}
11+
if not args then
12+
return result
13+
end
14+
local i = 1
15+
while args[i] do
16+
local argv = args[i]
17+
local nextArg = args[i + 1]
18+
local key, value, consumedNextArg = M.parseOne(argv, nextArg)
19+
if not key then
20+
break
21+
end
22+
if fomratKey then
23+
key = key:upper():gsub('-', '_')
24+
end
25+
result[key] = value
26+
if consumedNextArg then
27+
i = i + 2
28+
else
29+
i = i + 1
30+
end
31+
end
32+
return result
33+
end
34+
35+
---@param argv string
36+
---@param nextArg string?
37+
---@return string?
38+
---@return ArgParser.Value?
39+
---@return boolean? consumedNextArg
40+
function M.parseOne(argv, nextArg)
41+
local key, tail = argv:match '^%-%-([%w_]+)(.*)$'
42+
if not key then
43+
return nil
44+
end
45+
local value = tail:match '=(.+)'
46+
if value then
47+
value = M.parseValue(value)
48+
return key, value, false
49+
elseif nextArg and nextArg:sub(1, 2) ~= '--' then
50+
value = M.parseValue(nextArg)
51+
return key, value, true
52+
end
53+
return key, true, false
54+
end
55+
56+
---@param value string
57+
---@return ArgParser.Value
58+
function M.parseValue(value)
59+
if value == 'true' or value == nil then
60+
return true
61+
elseif value == 'false' then
62+
return false
63+
elseif tonumber(value) then
64+
return tonumber(value) --[[@as number]]
65+
elseif value:sub(1, 1) == '"' and value:sub(-1, -1) == '"' then
66+
return value:sub(2, -2)
67+
end
68+
return value
69+
end
70+
71+
return M

script/runtime/init.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
local argparser = require 'runtime.argparser'
3+
4+
---@class LuaLS.Runtime
5+
local M = {}
6+
7+
--启动时的命令行参数
8+
M.args = argparser.parse(arg, true)
9+
10+
--路径相关
11+
---@class LuaLS.Path
12+
M.path = {}
13+
14+
local function findRoot()
15+
local lastPath
16+
for i = 1, 10 do
17+
local currentPath = debug.getinfo(i, 'S').source
18+
if currentPath:sub(1, 1) ~= '@' then
19+
break
20+
end
21+
lastPath = currentPath:sub(2)
22+
end
23+
return lastPath
24+
end
25+
26+
--语言服务器根路径
27+
M.path.root = findRoot()
28+
29+
return M

0 commit comments

Comments
 (0)