Skip to content

Commit 2c3cea5

Browse files
committed
update to 3.13
1 parent e76a64b commit 2c3cea5

22 files changed

+309
-52
lines changed

changelog.md

+52
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,59 @@
33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
55

6+
## 3.13.1
7+
`2024-11-13`
8+
* `FIX` Incorrect type check in some case
9+
10+
## 3.13.0
11+
`2024-11-13`
12+
* `NEW` Setting: `Lua.type.inferTableSize`: A Small Table array can be infered
13+
* `NEW` Add custom repository support for addonManager. New configuration setting: `Lua.addonManager.repositoryBranch` and `Lua.addonManager.repositoryPath`
14+
* `NEW` Infer function parameter types when the function is used as an callback argument and that argument has a `fun()` annotation. Enable with `Lua.type.inferParamType` setting. [#2695](https://github.com/LuaLS/lua-language-server/pull/2695)
15+
```lua
16+
---@param callback fun(a: integer)
17+
function register(callback) end
18+
19+
local function callback(a) end --> a: integer
20+
register(callback)
21+
```
22+
* `CHG` Basic types allow contravariance
23+
```lua
24+
---@class int32: integer
25+
26+
---@type integer
27+
local n
28+
29+
---@type int32
30+
local a = n
31+
```
32+
* `FIX` Improve type narrow with **literal alias type** during completion and signature help
33+
34+
## 3.12.0
35+
`2024-10-30`
36+
* `NEW` Support importing `enum` through class name suffix matching in quick fixes, allowing the import of `enum` from `table.table.enum; return table`.
37+
* `NEW` Support limited multiline annotations
38+
```lua
39+
---@type {
40+
--- x: number,
41+
--- y: number,
42+
--- z: number,
43+
---}
44+
local point --> local point: { x: number, y: number, z: number }
45+
```
46+
* `FIX` A regression related to type narrow and generic param introduced since `v3.10.1`
47+
* `FIX` Parse storagePath to improve reliability of resolving ${addons} placeholder
48+
* `FIX` Reference should also look in tablefield
49+
* `FIX` Determine that the index of `{...}` is an integer when iterating
50+
51+
## 3.11.1
52+
`2024-10-9`
53+
* `FIX` Fixed an issue preventing to set the locale to Japanese
54+
* `FIX` Preserve newlines between function comment and @see
55+
* `FIX` Accept storagePath option from client to resolve addon directory not found
56+
657
## 3.11.0
58+
`2024-9-30`
759
* `NEW` Added support for Japanese locale
860
* `NEW` Infer function parameter types when overriding the same-named class function in an instance of that class [#2158](https://github.com/LuaLS/lua-language-server/issues/2158)
961
* `NEW` Types with literal fields can be narrowed.

locale/en-us/setting.lua

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
config.addonManager.enable =
44
"Whether the addon manager is enabled or not."
5+
config.addonManager.repositoryBranch =
6+
"Specifies the git branch used by the addon manager."
7+
config.addonManager.repositoryPath =
8+
"Specifies the git path used by the addon manager."
59
config.runtime.version =
610
"Lua runtime version."
711
config.runtime.path =

locale/ja-jp/meta.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ string.lower =
665665
'文字列内のすべての大文字を小文字に取り換えた文字列を返す。'
666666
string.match =
667667
'文字列の中から `pattern` に最初にマッチした部分を返す(§6.4.1 を参照)。マッチしたものがない場合、`nil` を返す。'
668-
'文字列 `s` の中で `pattern`(§6.4.1 を参照)に一致する最初の部分を見つける。見つかった場合、そのキャプチャされた値を返す。見つからなければ `nil` を返す。'
669668
string.pack =
670669
'第一引数で指定されたフォーマットに沿って、可変数の引数をバイナリ文字列にシリアライズしたものを返す(§6.4.2 を参照)。'
671670
string.packsize =
@@ -744,7 +743,7 @@ utf8 =
744743
utf8.char =
745744
'0個以上の整数を受け取り、それぞれを対応するUTF-8文字に変換し、これらの文字を連結した文字列を返す。'
746745
utf8.charpattern =
747-
'1つのUTF-8文字にマッチするパターンを返す。このパターンを用いる際には、対象の文字列が有効なUTF-8文字列である必要がある。
746+
'1つのUTF-8文字にマッチするパターンを返す。このパターンを用いる際には、対象の文字列が有効なUTF-8文字列である必要がある。'
748747
utf8.codes =
749748
[[
750749
次の構文において`p`が各UTF-8文字のバイト位置、`c`が各UTF-8文字の文字コードとなるような値を返す。無効なバイトシーケンスが文字列に含まれた場合にはエラーを出す。

locale/ja-jp/script.lua

-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@ COMMAND_MARK_GLOBAL =
465465
'グローバル変数として指定します'
466466
COMMAND_REMOVE_SPACE =
467467
'すべての行末スペースを削除します'
468-
'Clear all postemptive spaces'
469468
COMMAND_ADD_BRACKETS =
470469
'括弧を追加します。'
471470
COMMAND_RUNTIME_VERSION =

locale/ja-jp/setting.lua

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
config.addonManager.enable = -- TODO: need translate!
44
"Whether the addon manager is enabled or not."
5+
config.addonManager.repositoryBranch = -- TODO: need translate!
6+
"Specifies the git branch used by the addon manager."
7+
config.addonManager.repositoryPath = -- TODO: need translate!
8+
"Specifies the git path used by the addon manager."
59
config.runtime.version = -- TODO: need translate!
610
"Lua runtime version."
711
config.runtime.path = -- TODO: need translate!

locale/pt-br/setting.lua

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
config.addonManager.enable = -- TODO: need translate!
44
"Whether the addon manager is enabled or not."
5+
config.addonManager.repositoryBranch = -- TODO: need translate!
6+
"Specifies the git branch used by the addon manager."
7+
config.addonManager.repositoryPath = -- TODO: need translate!
8+
"Specifies the git path used by the addon manager."
59
config.runtime.version = -- TODO: need translate!
610
"Lua runtime version."
711
config.runtime.path = -- TODO: need translate!

locale/zh-cn/setting.lua

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
config.addonManager.enable =
44
"是否启用扩展的附加插件管理器(Addon Manager)"
5+
config.addonManager.repositoryBranch =
6+
"指定插件管理器(Addon Manager)使用的git仓库分支"
7+
config.addonManager.repositoryPath =
8+
"指定插件管理器(Addon Manager)使用的git仓库路径"
59
config.runtime.version =
610
"Lua运行版本。"
711
config.runtime.path =

locale/zh-tw/setting.lua

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
config.addonManager.enable = -- TODO: need translate!
44
"Whether the addon manager is enabled or not."
5+
config.addonManager.repositoryBranch = -- TODO: need translate!
6+
"Specifies the git branch used by the addon manager."
7+
config.addonManager.repositoryPath = -- TODO: need translate!
8+
"Specifies the git path used by the addon manager."
59
config.runtime.version =
610
"Lua執行版本。"
711
config.runtime.path =

main.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local fs = require 'bee.filesystem'
22
local util = require 'utility'
33
local version = require 'version'
4+
45
require 'config.env'
56

67
local function getValue(value)
@@ -52,7 +53,6 @@ ROOT = fs.absolute(util.expandPath(rootPath))
5253
LOGPATH = LOGPATH and util.expandPath(LOGPATH) or (ROOT:string() .. '/log')
5354
METAPATH = METAPATH and util.expandPath(METAPATH) or (ROOT:string() .. '/meta')
5455

55-
5656
---@diagnostic disable-next-line: deprecated
5757
debug.setcstacklimit(200)
5858
collectgarbage('generational', 10, 50)

meta/template/basic.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function setfenv(f, table) end
246246
---@field __newindex table|fun(t,k,v)|nil
247247
---@field __call (fun(t,...):...)|nil
248248
---#if VERSION > 5.1 or VERSION == JIT then
249-
---@field __pairs (fun(t):(fun(t,k,v):any,any))|nil
249+
---@field __pairs (fun(t):((fun(t,k,v):any,any),any,any))|nil
250250
---#end
251251
---#if VERSION == JIT or VERSION == 5.2 then
252252
---@field __ipairs (fun(t):(fun(t,k,v):(integer|nil),any))|nil

script/config/template.lua

+3
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ local template = {
403403
['Lua.type.weakNilCheck'] = Type.Boolean >> false,
404404
['Lua.type.inferParamType'] = Type.Boolean >> false,
405405
['Lua.type.checkTableShape'] = Type.Boolean >> false,
406+
['Lua.type.inferTableSize'] = Type.Integer >> 10,
406407
['Lua.doc.privateName'] = Type.Array(Type.String),
407408
['Lua.doc.protectedName'] = Type.Array(Type.String),
408409
['Lua.doc.packageName'] = Type.Array(Type.String),
@@ -414,6 +415,8 @@ local template = {
414415
["Lua.docScriptPath"] = Type.String,
415416
-- VSCode
416417
["Lua.addonManager.enable"] = Type.Boolean >> true,
418+
["Lua.addonManager.repositoryPath"] = Type.String,
419+
["Lua.addonManager.repositoryBranch"] = Type.String,
417420
['files.associations'] = Type.Hash(Type.String, Type.String),
418421
-- copy from VSCode default
419422
['files.exclude'] = Type.Hash(Type.String, Type.Boolean) >> {

script/core/code-action.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,16 @@ local function checkMissingRequire(results, uri, start, finish)
695695
end
696696

697697
local function addRequires(global, endpos)
698-
autoreq.check(state, global, endpos, function(moduleFile, _stemname, _targetSource)
698+
if not global then
699+
return
700+
end
701+
autoreq.check(state, global, endpos, function (moduleFile, _stemname, _targetSource, fullKeyPath)
699702
local visiblePaths = rpath.getVisiblePath(uri, furi.decode(moduleFile))
700703
if not visiblePaths or #visiblePaths == 0 then return end
701704

702705
for _, target in ipairs(findRequireTargets(visiblePaths)) do
703706
results[#results+1] = {
704-
title = lang.script('ACTION_AUTOREQUIRE', target, global),
707+
title = lang.script('ACTION_AUTOREQUIRE', target .. (fullKeyPath or ''), global),
705708
kind = 'refactor.rewrite',
706709
command = {
707710
title = 'autoRequire',
@@ -711,7 +714,8 @@ local function checkMissingRequire(results, uri, start, finish)
711714
uri = guide.getUri(state.ast),
712715
target = moduleFile,
713716
name = global,
714-
requireName = target
717+
requireName = target,
718+
fullKeyPath = fullKeyPath,
715719
},
716720
},
717721
}

script/core/command/autoRequire.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ local function askAutoRequire(uri, visiblePaths)
101101
return nameMap[result]
102102
end
103103

104-
local function applyAutoRequire(uri, row, name, result, fmt)
104+
local function applyAutoRequire(uri, row, name, result, fmt, fullKeyPath)
105105
local quotedResult = ('%q'):format(result)
106106
if fmt.quot == "'" then
107107
quotedResult = ([['%s']]):format(quotedResult:sub(2, -2)
@@ -119,7 +119,7 @@ local function applyAutoRequire(uri, row, name, result, fmt)
119119
if fmt.col and fmt.col > #text then
120120
sp = (' '):rep(fmt.col - #text - 1)
121121
end
122-
text = ('local %s%s= require%s\n'):format(name, sp, quotedResult)
122+
text = ('local %s%s= require%s%s\n'):format(name, sp, quotedResult, fullKeyPath)
123123
client.editText(uri, {
124124
{
125125
start = guide.positionOf(row, 0),
@@ -159,6 +159,6 @@ return function (data)
159159

160160
local offset, fmt = findInsertRow(uri)
161161
if offset and fmt then
162-
applyAutoRequire(uri, offset, name, requireName, fmt)
162+
applyAutoRequire(uri, offset, name, requireName, fmt, data.fullKeyPath or '')
163163
end
164164
end

script/core/completion/auto-require.lua

+59
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ local rpath = require 'workspace.require-path'
88
local vm = require 'vm'
99
local matchKey = require 'core.matchkey'
1010

11+
local ipairs = ipairs
12+
1113
---@class auto-require
1214
local m = {}
1315

@@ -36,6 +38,7 @@ end
3638
function m.check(state, word, position, callback)
3739
local globals = util.arrayToHash(config.get(state.uri, 'Lua.diagnostics.globals'))
3840
local locals = guide.getVisibleLocals(state.ast, position)
41+
local hit = false
3942
for uri in files.eachFile(state.uri) do
4043
if uri == guide.getUri(state.ast) then
4144
goto CONTINUE
@@ -85,12 +88,68 @@ function m.check(state, word, position, callback)
8588
and vm.getDeprecated(targetSource.node) then
8689
goto INNER_CONTINUE
8790
end
91+
hit = true
8892
callback(uri, stemName, targetSource)
8993
end
9094
::INNER_CONTINUE::
9195
end
9296
::CONTINUE::
9397
end
98+
-- 如果没命中, 则检查枚举
99+
if not hit then
100+
local docs = vm.getDocSets(state.uri)
101+
for _, doc in ipairs(docs) do
102+
if doc.type ~= 'doc.enum' or vm.getDeprecated(doc) then
103+
goto CONTINUE
104+
end
105+
-- 检查枚举名是否匹配
106+
if not (doc.enum[1] == word or doc.enum[1]:match(".*%.([^%.]*)$") == word) then
107+
goto CONTINUE
108+
end
109+
local uri = guide.getUri(doc)
110+
local targetState = files.getState(uri)
111+
if not targetState then
112+
goto CONTINUE
113+
end
114+
local targetSource = m.getTargetSource(targetState)
115+
if not targetSource or (targetSource.type ~= 'getlocal' and targetSource.type ~= 'table') or vm.getDeprecated(targetSource.node) then
116+
goto CONTINUE
117+
end
118+
-- 枚举的完整路径
119+
local fullKeyPath = ""
120+
local node = doc.bindSource.parent
121+
while node do
122+
-- 检查是否可见
123+
if not vm.isVisible(state.ast, node) then
124+
goto CONTINUE
125+
end
126+
if node.type == 'setfield' or node.type == 'getfield' then
127+
fullKeyPath = "." .. node.field[1] .. fullKeyPath
128+
end
129+
if node.type == 'getlocal' then
130+
node = node.node
131+
break
132+
end
133+
node = node.node
134+
end
135+
-- 匹配导出的值, 确定最终路径
136+
if targetSource.node == node then
137+
hit = true
138+
elseif targetSource.type == 'table' then
139+
for _, value in ipairs(targetSource) do
140+
if value.value.node == node then
141+
fullKeyPath = "." .. value.value[1] .. fullKeyPath
142+
hit = true
143+
break
144+
end
145+
end
146+
end
147+
if hit then
148+
callback(guide.getUri(doc), nil, nil, fullKeyPath)
149+
end
150+
::CONTINUE::
151+
end
152+
end
94153
end
95154

96155
files.watch(function (ev, uri)

script/core/hover/description.lua

+3-8
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ local function tryDocFieldComment(source)
336336
end
337337
end
338338

339-
local function getFunctionComment(source, raw)
339+
local function getFunctionCommentMarkdown(source, raw)
340340
local docGroup = source.bindDocs
341341
if not docGroup then
342342
return
@@ -393,11 +393,7 @@ local function getFunctionComment(source, raw)
393393
local enums = getBindEnums(source, docGroup)
394394
md:add('lua', enums)
395395

396-
local comment = md:string()
397-
if comment == '' then
398-
return nil
399-
end
400-
return comment
396+
return md
401397
end
402398

403399
---@async
@@ -407,8 +403,7 @@ local function tryDocComment(source, raw)
407403
source = source.value
408404
end
409405
if source.type == 'function' then
410-
local comment = getFunctionComment(source, raw)
411-
md:add('md', comment)
406+
md:add('md', getFunctionCommentMarkdown(source, raw))
412407
source = source.parent
413408
end
414409
local comment = lookUpDocComments(source)

script/core/signature.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ local function isEventNotMatch(call, src)
114114
end
115115
local eventLiteral = event.extends.types[1] and guide.getLiteral(event.extends.types[1])
116116
if eventLiteral == nil then
117-
return false
117+
-- extra checking when function param is not pure literal
118+
-- eg: it maybe an alias type with literal values
119+
local eventMap = vm.getLiterals(event.extends.types[1])
120+
if not eventMap then
121+
return false
122+
end
123+
return not eventMap[literal]
118124
end
119125
return eventLiteral ~= literal
120126
end

0 commit comments

Comments
 (0)