Skip to content

Commit 8d31712

Browse files
Merge branch 'master' into doc-update
2 parents 96a11fb + c156377 commit 8d31712

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+219
-126
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
matrix:
88
include:
99
- { os: ubuntu-20.04, platform: linux-x64 }
10-
- { os: macos-latest, platform: darwin-x64 }
10+
- { os: macos-14, platform: darwin-arm64 }
1111
- { os: windows-latest, platform: win32-x64 }
1212
runs-on: ${{ matrix.os }}
1313
steps:

locale/en-us/setting.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ When checking the type of union type, ignore the `nil` in it.
293293
294294
When this setting is `false`, the `number|nil` type cannot be assigned to the `number` type. It can be with `true`.
295295
]]
296+
config.type.inferParamType =
297+
[[
298+
When a parameter type is not annotated, it is inferred from the function's call sites.
299+
300+
When this setting is `false`, the type of the parameter is `any` when it is not annotated.
301+
]]
296302
config.doc.privateName =
297303
'Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.'
298304
config.doc.protectedName =

locale/pt-br/setting.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,12 @@ When checking the type of union type, ignore the `nil` in it.
293293
294294
When this setting is `false`, the `number|nil` type cannot be assigned to the `number` type. It can be with `true`.
295295
]]
296+
config.type.inferParamType = -- TODO: need translate!
297+
[[
298+
When the parameter type is not annotated, the parameter type is inferred from the function's incoming parameters.
299+
300+
When this setting is `false`, the type of the parameter is `any` when it is not annotated.
301+
]]
296302
config.doc.privateName = -- TODO: need translate!
297303
'Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.'
298304
config.doc.protectedName = -- TODO: need translate!

locale/zh-cn/setting.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ config.type.weakNilCheck =
292292
293293
此设置为 `false` 时,`numer|nil` 类型无法赋给 `number` 类型;为 `true` 是则可以。
294294
]]
295+
config.type.inferParamType =
296+
[[
297+
未注释参数类型时,参数类型由函数传入参数推断。
298+
299+
如果设置为 "false",则在未注释时,参数类型为 "any"。
300+
]]
295301
config.doc.privateName =
296302
'将特定名称的字段视为私有,例如 `m_*` 意味着 `XXX.m_id` 与 `XXX.m_type` 是私有字段,只能在定义所在的类中访问。'
297303
config.doc.protectedName =

locale/zh-tw/setting.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ When checking the type of union type, ignore the `nil` in it.
292292
293293
When this setting is `false`, the `number|nil` type cannot be assigned to the `number` type. It can be with `true`.
294294
]]
295+
config.type.inferParamType = -- TODO: need translate!
296+
[[
297+
未注释参数类型时,参数类型由函数传入参数推断。
298+
299+
如果设置为 "false",则在未注释时,参数类型为 "any"。
300+
]]
295301
config.doc.privateName = -- TODO: need translate!
296302
'Treat specific field names as private, e.g. `m_*` means `XXX.m_id` and `XXX.m_type` are private, witch can only be accessed in the class where the definition is located.'
297303
config.doc.protectedName = -- TODO: need translate!

make.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ lm:executable "lua-language-server" {
5555
}
5656

5757
local platform = require 'bee.platform'
58-
local exe = platform.OS == 'Windows' and ".exe" or ""
58+
local exe = platform.os == 'windows' and ".exe" or ""
5959

6060
lm:copy "copy_lua-language-server" {
61-
input = lm.bindir .. "/lua-language-server" .. exe,
62-
output = "bin/lua-language-server" .. exe,
61+
inputs = "$bin/lua-language-server" .. exe,
62+
outputs = "bin/lua-language-server" .. exe,
6363
}
6464

6565
lm:copy "copy_bootstrap" {
66-
input = "make/bootstrap.lua",
67-
output = "bin/main.lua",
66+
inputs = "make/bootstrap.lua",
67+
outputs = "bin/main.lua",
6868
}
6969

7070
lm:msvc_copydll 'copy_vcrt' {
7171
type = "vcrt",
72-
output = "bin",
72+
outputs = "bin",
7373
}
7474

7575
lm:phony "all" {
@@ -93,7 +93,7 @@ if lm.notest then
9393
end
9494

9595
lm:rule "run-bee-test" {
96-
lm.bindir .. "/lua-language-server" .. exe, "$in",
96+
"$bin/lua-language-server" .. exe, "$in",
9797
description = "Run test: $in.",
9898
pool = "console",
9999
}
@@ -107,13 +107,13 @@ lm:rule "run-unit-test" {
107107
lm:build "bee-test" {
108108
rule = "run-bee-test",
109109
deps = { "lua-language-server", "copy_script" },
110-
input = "3rd/bee.lua/test/test.lua",
110+
inputs = "3rd/bee.lua/test/test.lua",
111111
}
112112

113113
lm:build 'unit-test' {
114114
rule = "run-unit-test",
115115
deps = { "bee-test", "all" },
116-
input = "test.lua",
116+
inputs = "test.lua",
117117
}
118118

119119
lm:default {

make/detect_platform.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local lm = require 'luamake'
22

33
local platform = require 'bee.platform'
44

5-
if platform.OS == 'macOS' then
5+
if platform.os == 'macos' then
66
if lm.platform == nil then
77
elseif lm.platform == "darwin-arm64" then
88
lm.target = "arm64-apple-macos11"
@@ -11,7 +11,7 @@ if platform.OS == 'macOS' then
1111
else
1212
error "unknown platform"
1313
end
14-
elseif platform.OS == 'Windows' then
14+
elseif platform.os == 'windows' then
1515
if lm.platform == nil then
1616
elseif lm.platform == "win32-ia32" then
1717
lm.arch = "x86"
@@ -20,7 +20,7 @@ elseif platform.OS == 'Windows' then
2020
else
2121
error "unknown platform"
2222
end
23-
elseif platform.OS == 'Linux' then
23+
elseif platform.os == 'linux' then
2424
if lm.platform == nil then
2525
elseif lm.platform == "linux-x64" then
2626
elseif lm.platform == "linux-arm64" then
@@ -52,7 +52,7 @@ local ARCH <const> = {
5252
}
5353

5454
local function detectArch()
55-
if platform.OS == 'Windows' then
55+
if platform.os == 'windows' then
5656
return detectWindowsArch()
5757
end
5858
local posixArch = detectPosixArch()
@@ -67,5 +67,5 @@ local function targetPlatformArch()
6767
end
6868

6969
if not lm.notest then
70-
lm.notest = (platform.OS ~= 'Windows' and targetPlatformArch() ~= detectArch())
70+
lm.notest = (platform.os ~= 'windows' and targetPlatformArch() ~= detectArch())
7171
end

script/cli/doc.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ local function collectTypes(global, results)
189189
field.rawdesc = getDesc(source, true)
190190
field.extends = packObject(source.value)
191191
field.visible = vm.getVisibleType(source)
192+
local depr = vm.getDeprecated(source)
193+
if (depr and not depr.versions) then
194+
field.deprecated = true
195+
end
192196
return
193197
end
194198
if source.type == 'tableindex' then
@@ -250,6 +254,10 @@ local function collectVars(global, results)
250254
result.rawdesc = result.rawdesc or getDesc(set, true)
251255
result.defines[#result.defines].extends['desc'] = getDesc(set)
252256
result.defines[#result.defines].extends['rawdesc'] = getDesc(set, true)
257+
local depr = vm.getDeprecated(set)
258+
if (depr and not depr.versions) then
259+
result.defines[#result.defines].extends['deprecated'] = true
260+
end
253261
end
254262
end
255263
if #result.defines == 0 then

script/client.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ local function searchPatchInfo(cfg, rawKey)
278278
}
279279
end
280280

281-
---@param uri uri
281+
---@param uri? uri
282282
---@param cfg table
283283
---@param change config.change
284284
---@return json.patch?
@@ -330,7 +330,7 @@ local function makeConfigPatch(uri, cfg, change)
330330
return nil
331331
end
332332

333-
---@param uri uri
333+
---@param uri? uri
334334
---@param path string
335335
---@param changes config.change[]
336336
---@return string?

script/config/template.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ local template = {
397397
['Lua.type.castNumberToInteger'] = Type.Boolean >> true,
398398
['Lua.type.weakUnionCheck'] = Type.Boolean >> false,
399399
['Lua.type.weakNilCheck'] = Type.Boolean >> false,
400+
['Lua.type.inferParamType'] = Type.Boolean >> false,
400401
['Lua.doc.privateName'] = Type.Array(Type.String),
401402
['Lua.doc.protectedName'] = Type.Array(Type.String),
402403
['Lua.doc.packageName'] = Type.Array(Type.String),

script/core/command/autoRequire.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ end
132132

133133
---@async
134134
return function (data)
135+
---@type uri
135136
local uri = data.uri
136137
local target = data.target
137138
local name = data.name
@@ -158,5 +159,7 @@ return function (data)
158159
end
159160

160161
local offset, fmt = findInsertRow(uri)
161-
applyAutoRequire(uri, offset, name, requireName, fmt)
162+
if offset and fmt then
163+
applyAutoRequire(uri, offset, name, requireName, fmt)
164+
end
162165
end

script/core/completion/completion.lua

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ end
147147

148148
local function findParent(state, position)
149149
local text = state.lua
150+
if not text then
151+
return
152+
end
150153
local offset = guide.positionToOffset(state, position)
151154
for i = offset, 1, -1 do
152155
local char = text:sub(i, i)
@@ -675,6 +678,7 @@ local function checkGlobal(state, word, startPos, position, parent, oop, results
675678
end
676679

677680
---@async
681+
---@param parent parser.object
678682
local function checkField(state, word, start, position, parent, oop, results)
679683
if parent.tag == '_ENV' or parent.special == '_G' then
680684
local globals = vm.getGlobalSets(state.uri, 'variable')
@@ -955,8 +959,7 @@ local function checkFunctionArgByDocParam(state, word, startPos, results)
955959
end
956960
end
957961

958-
local function isAfterLocal(state, startPos)
959-
local text = state.lua
962+
local function isAfterLocal(state, text, startPos)
960963
local offset = guide.positionToOffset(state, startPos)
961964
local pos = lookBackward.skipSpace(text, offset)
962965
local word = lookBackward.findWord(text, pos)
@@ -965,6 +968,8 @@ end
965968

966969
local function collectRequireNames(mode, myUri, literal, source, smark, position, results)
967970
local collect = {}
971+
local source_start = source and smark and (source.start + #smark) or position
972+
local source_finish = source and smark and (source.finish - #smark) or position
968973
if mode == 'require' then
969974
for uri in files.eachFile(myUri) do
970975
if myUri == uri then
@@ -978,8 +983,8 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
978983
if not collect[info.name] then
979984
collect[info.name] = {
980985
textEdit = {
981-
start = smark and (source.start + #smark) or position,
982-
finish = smark and (source.finish - #smark) or position,
986+
start = source_start,
987+
finish = source_finish,
983988
newText = smark and info.name or util.viewString(info.name),
984989
},
985990
path = relative,
@@ -1006,8 +1011,8 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
10061011
if not collect[open] then
10071012
collect[open] = {
10081013
textEdit = {
1009-
start = smark and (source.start + #smark) or position,
1010-
finish = smark and (source.finish - #smark) or position,
1014+
start = source_start,
1015+
finish = source_finish,
10111016
newText = smark and open or util.viewString(open),
10121017
},
10131018
path = path,
@@ -1034,8 +1039,8 @@ local function collectRequireNames(mode, myUri, literal, source, smark, position
10341039
if not collect[path] then
10351040
collect[path] = {
10361041
textEdit = {
1037-
start = smark and (source.start + #smark) or position,
1038-
finish = smark and (source.finish - #smark) or position,
1042+
start = source_start,
1043+
finish = source_finish,
10391044
newText = smark and path or util.viewString(path),
10401045
}
10411046
}
@@ -1097,6 +1102,9 @@ end
10971102

10981103
local function checkLenPlusOne(state, position, results)
10991104
local text = state.lua
1105+
if not text then
1106+
return
1107+
end
11001108
guide.eachSourceContain(state.ast, position, function (source)
11011109
if source.type == 'getindex'
11021110
or source.type == 'setindex' then
@@ -1392,6 +1400,9 @@ end
13921400

13931401
local function checkEqualEnum(state, position, results)
13941402
local text = state.lua
1403+
if not text then
1404+
return
1405+
end
13951406
local start = lookBackward.findTargetSymbol(text, guide.positionToOffset(state, position), '=')
13961407
if not start then
13971408
return
@@ -1493,6 +1504,9 @@ local function tryWord(state, position, triggerCharacter, results)
14931504
return
14941505
end
14951506
local text = state.lua
1507+
if not text then
1508+
return
1509+
end
14961510
local offset = guide.positionToOffset(state, position)
14971511
local finish = lookBackward.skipSpace(text, offset)
14981512
local word, start = lookBackward.findWord(text, offset)
@@ -1518,7 +1532,7 @@ local function tryWord(state, position, triggerCharacter, results)
15181532
checkProvideLocal(state, word, startPos, results)
15191533
checkFunctionArgByDocParam(state, word, startPos, results)
15201534
else
1521-
local afterLocal = isAfterLocal(state, startPos)
1535+
local afterLocal = isAfterLocal(state, text, startPos)
15221536
local stop = checkKeyWord(state, startPos, position, word, hasSpace, afterLocal, results)
15231537
if stop then
15241538
return
@@ -1530,8 +1544,10 @@ local function tryWord(state, position, triggerCharacter, results)
15301544
checkLocal(state, word, startPos, results)
15311545
checkTableField(state, word, startPos, results)
15321546
local env = guide.getENV(state.ast, startPos)
1533-
checkGlobal(state, word, startPos, position, env, false, results)
1534-
checkModule(state, word, startPos, results)
1547+
if env then
1548+
checkGlobal(state, word, startPos, position, env, false, results)
1549+
checkModule(state, word, startPos, results)
1550+
end
15351551
end
15361552
end
15371553
end
@@ -1592,6 +1608,9 @@ end
15921608

15931609
local function checkTableLiteralField(state, position, tbl, fields, results)
15941610
local text = state.lua
1611+
if not text then
1612+
return
1613+
end
15951614
local mark = {}
15961615
for _, field in ipairs(tbl) do
15971616
if field.type == 'tablefield'
@@ -1610,9 +1629,11 @@ local function checkTableLiteralField(state, position, tbl, fields, results)
16101629
local left = lookBackward.findWord(text, guide.positionToOffset(state, position))
16111630
if not left then
16121631
local pos = lookBackward.findAnyOffset(text, guide.positionToOffset(state, position))
1613-
local char = text:sub(pos, pos)
1614-
if char == '{' or char == ',' or char == ';' then
1615-
left = ''
1632+
if pos then
1633+
local char = text:sub(pos, pos)
1634+
if char == '{' or char == ',' or char == ';' then
1635+
left = ''
1636+
end
16161637
end
16171638
end
16181639
if left then
@@ -1801,6 +1822,7 @@ local function getluaDocByContain(state, position)
18011822
return result
18021823
end
18031824

1825+
---@return parser.state.err?, parser.object?
18041826
local function getluaDocByErr(state, start, position)
18051827
local targetError
18061828
for _, err in ipairs(state.errs) do
@@ -2008,7 +2030,7 @@ local function tryluaDocByErr(state, position, err, docState, results)
20082030
for _, doc in ipairs(vm.getDocSets(state.uri)) do
20092031
if doc.type == 'doc.class'
20102032
and not used[doc.class[1]]
2011-
and doc.class[1] ~= docState.class[1] then
2033+
and docState and doc.class[1] ~= docState.class[1] then
20122034
used[doc.class[1]] = true
20132035
results[#results+1] = {
20142036
label = doc.class[1],

0 commit comments

Comments
 (0)