Skip to content

Commit

Permalink
update to 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Nov 15, 2024
1 parent e76a64b commit 2c3cea5
Show file tree
Hide file tree
Showing 22 changed files with 309 additions and 52 deletions.
52 changes: 52 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,59 @@
## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->

## 3.13.1
`2024-11-13`
* `FIX` Incorrect type check in some case

## 3.13.0
`2024-11-13`
* `NEW` Setting: `Lua.type.inferTableSize`: A Small Table array can be infered
* `NEW` Add custom repository support for addonManager. New configuration setting: `Lua.addonManager.repositoryBranch` and `Lua.addonManager.repositoryPath`
* `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)
```lua
---@param callback fun(a: integer)
function register(callback) end

local function callback(a) end --> a: integer
register(callback)
```
* `CHG` Basic types allow contravariance
```lua
---@class int32: integer

---@type integer
local n

---@type int32
local a = n
```
* `FIX` Improve type narrow with **literal alias type** during completion and signature help

## 3.12.0
`2024-10-30`
* `NEW` Support importing `enum` through class name suffix matching in quick fixes, allowing the import of `enum` from `table.table.enum; return table`.
* `NEW` Support limited multiline annotations
```lua
---@type {
--- x: number,
--- y: number,
--- z: number,
---}
local point --> local point: { x: number, y: number, z: number }
```
* `FIX` A regression related to type narrow and generic param introduced since `v3.10.1`
* `FIX` Parse storagePath to improve reliability of resolving ${addons} placeholder
* `FIX` Reference should also look in tablefield
* `FIX` Determine that the index of `{...}` is an integer when iterating

## 3.11.1
`2024-10-9`
* `FIX` Fixed an issue preventing to set the locale to Japanese
* `FIX` Preserve newlines between function comment and @see
* `FIX` Accept storagePath option from client to resolve addon directory not found

## 3.11.0
`2024-9-30`
* `NEW` Added support for Japanese locale
* `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)
* `NEW` Types with literal fields can be narrowed.
Expand Down
4 changes: 4 additions & 0 deletions locale/en-us/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

config.addonManager.enable =
"Whether the addon manager is enabled or not."
config.addonManager.repositoryBranch =
"Specifies the git branch used by the addon manager."
config.addonManager.repositoryPath =
"Specifies the git path used by the addon manager."
config.runtime.version =
"Lua runtime version."
config.runtime.path =
Expand Down
3 changes: 1 addition & 2 deletions locale/ja-jp/meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ string.lower =
'文字列内のすべての大文字を小文字に取り換えた文字列を返す。'
string.match =
'文字列の中から `pattern` に最初にマッチした部分を返す(§6.4.1 を参照)。マッチしたものがない場合、`nil` を返す。'
'文字列 `s` の中で `pattern`(§6.4.1 を参照)に一致する最初の部分を見つける。見つかった場合、そのキャプチャされた値を返す。見つからなければ `nil` を返す。'
string.pack =
'第一引数で指定されたフォーマットに沿って、可変数の引数をバイナリ文字列にシリアライズしたものを返す(§6.4.2 を参照)。'
string.packsize =
Expand Down Expand Up @@ -744,7 +743,7 @@ utf8 =
utf8.char =
'0個以上の整数を受け取り、それぞれを対応するUTF-8文字に変換し、これらの文字を連結した文字列を返す。'
utf8.charpattern =
'1つのUTF-8文字にマッチするパターンを返す。このパターンを用いる際には、対象の文字列が有効なUTF-8文字列である必要がある。
'1つのUTF-8文字にマッチするパターンを返す。このパターンを用いる際には、対象の文字列が有効なUTF-8文字列である必要がある。'
utf8.codes =
[[
次の構文において`p`が各UTF-8文字のバイト位置、`c`が各UTF-8文字の文字コードとなるような値を返す。無効なバイトシーケンスが文字列に含まれた場合にはエラーを出す。
Expand Down
1 change: 0 additions & 1 deletion locale/ja-jp/script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ COMMAND_MARK_GLOBAL =
'グローバル変数として指定します'
COMMAND_REMOVE_SPACE =
'すべての行末スペースを削除します'
'Clear all postemptive spaces'
COMMAND_ADD_BRACKETS =
'括弧を追加します。'
COMMAND_RUNTIME_VERSION =
Expand Down
4 changes: 4 additions & 0 deletions locale/ja-jp/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

config.addonManager.enable = -- TODO: need translate!
"Whether the addon manager is enabled or not."
config.addonManager.repositoryBranch = -- TODO: need translate!
"Specifies the git branch used by the addon manager."
config.addonManager.repositoryPath = -- TODO: need translate!
"Specifies the git path used by the addon manager."
config.runtime.version = -- TODO: need translate!
"Lua runtime version."
config.runtime.path = -- TODO: need translate!
Expand Down
4 changes: 4 additions & 0 deletions locale/pt-br/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

config.addonManager.enable = -- TODO: need translate!
"Whether the addon manager is enabled or not."
config.addonManager.repositoryBranch = -- TODO: need translate!
"Specifies the git branch used by the addon manager."
config.addonManager.repositoryPath = -- TODO: need translate!
"Specifies the git path used by the addon manager."
config.runtime.version = -- TODO: need translate!
"Lua runtime version."
config.runtime.path = -- TODO: need translate!
Expand Down
4 changes: 4 additions & 0 deletions locale/zh-cn/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

config.addonManager.enable =
"是否启用扩展的附加插件管理器(Addon Manager)"
config.addonManager.repositoryBranch =
"指定插件管理器(Addon Manager)使用的git仓库分支"
config.addonManager.repositoryPath =
"指定插件管理器(Addon Manager)使用的git仓库路径"
config.runtime.version =
"Lua运行版本。"
config.runtime.path =
Expand Down
4 changes: 4 additions & 0 deletions locale/zh-tw/setting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

config.addonManager.enable = -- TODO: need translate!
"Whether the addon manager is enabled or not."
config.addonManager.repositoryBranch = -- TODO: need translate!
"Specifies the git branch used by the addon manager."
config.addonManager.repositoryPath = -- TODO: need translate!
"Specifies the git path used by the addon manager."
config.runtime.version =
"Lua執行版本。"
config.runtime.path =
Expand Down
2 changes: 1 addition & 1 deletion main.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local fs = require 'bee.filesystem'
local util = require 'utility'
local version = require 'version'

require 'config.env'

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


---@diagnostic disable-next-line: deprecated
debug.setcstacklimit(200)
collectgarbage('generational', 10, 50)
Expand Down
2 changes: 1 addition & 1 deletion meta/template/basic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function setfenv(f, table) end
---@field __newindex table|fun(t,k,v)|nil
---@field __call (fun(t,...):...)|nil
---#if VERSION > 5.1 or VERSION == JIT then
---@field __pairs (fun(t):(fun(t,k,v):any,any))|nil
---@field __pairs (fun(t):((fun(t,k,v):any,any),any,any))|nil
---#end
---#if VERSION == JIT or VERSION == 5.2 then
---@field __ipairs (fun(t):(fun(t,k,v):(integer|nil),any))|nil
Expand Down
3 changes: 3 additions & 0 deletions script/config/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ local template = {
['Lua.type.weakNilCheck'] = Type.Boolean >> false,
['Lua.type.inferParamType'] = Type.Boolean >> false,
['Lua.type.checkTableShape'] = Type.Boolean >> false,
['Lua.type.inferTableSize'] = Type.Integer >> 10,
['Lua.doc.privateName'] = Type.Array(Type.String),
['Lua.doc.protectedName'] = Type.Array(Type.String),
['Lua.doc.packageName'] = Type.Array(Type.String),
Expand All @@ -414,6 +415,8 @@ local template = {
["Lua.docScriptPath"] = Type.String,
-- VSCode
["Lua.addonManager.enable"] = Type.Boolean >> true,
["Lua.addonManager.repositoryPath"] = Type.String,
["Lua.addonManager.repositoryBranch"] = Type.String,
['files.associations'] = Type.Hash(Type.String, Type.String),
-- copy from VSCode default
['files.exclude'] = Type.Hash(Type.String, Type.Boolean) >> {
Expand Down
10 changes: 7 additions & 3 deletions script/core/code-action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,16 @@ local function checkMissingRequire(results, uri, start, finish)
end

local function addRequires(global, endpos)
autoreq.check(state, global, endpos, function(moduleFile, _stemname, _targetSource)
if not global then
return
end
autoreq.check(state, global, endpos, function (moduleFile, _stemname, _targetSource, fullKeyPath)
local visiblePaths = rpath.getVisiblePath(uri, furi.decode(moduleFile))
if not visiblePaths or #visiblePaths == 0 then return end

for _, target in ipairs(findRequireTargets(visiblePaths)) do
results[#results+1] = {
title = lang.script('ACTION_AUTOREQUIRE', target, global),
title = lang.script('ACTION_AUTOREQUIRE', target .. (fullKeyPath or ''), global),
kind = 'refactor.rewrite',
command = {
title = 'autoRequire',
Expand All @@ -711,7 +714,8 @@ local function checkMissingRequire(results, uri, start, finish)
uri = guide.getUri(state.ast),
target = moduleFile,
name = global,
requireName = target
requireName = target,
fullKeyPath = fullKeyPath,
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions script/core/command/autoRequire.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ local function askAutoRequire(uri, visiblePaths)
return nameMap[result]
end

local function applyAutoRequire(uri, row, name, result, fmt)
local function applyAutoRequire(uri, row, name, result, fmt, fullKeyPath)
local quotedResult = ('%q'):format(result)
if fmt.quot == "'" then
quotedResult = ([['%s']]):format(quotedResult:sub(2, -2)
Expand All @@ -119,7 +119,7 @@ local function applyAutoRequire(uri, row, name, result, fmt)
if fmt.col and fmt.col > #text then
sp = (' '):rep(fmt.col - #text - 1)
end
text = ('local %s%s= require%s\n'):format(name, sp, quotedResult)
text = ('local %s%s= require%s%s\n'):format(name, sp, quotedResult, fullKeyPath)
client.editText(uri, {
{
start = guide.positionOf(row, 0),
Expand Down Expand Up @@ -159,6 +159,6 @@ return function (data)

local offset, fmt = findInsertRow(uri)
if offset and fmt then
applyAutoRequire(uri, offset, name, requireName, fmt)
applyAutoRequire(uri, offset, name, requireName, fmt, data.fullKeyPath or '')
end
end
59 changes: 59 additions & 0 deletions script/core/completion/auto-require.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ local rpath = require 'workspace.require-path'
local vm = require 'vm'
local matchKey = require 'core.matchkey'

local ipairs = ipairs

---@class auto-require
local m = {}

Expand Down Expand Up @@ -36,6 +38,7 @@ end
function m.check(state, word, position, callback)
local globals = util.arrayToHash(config.get(state.uri, 'Lua.diagnostics.globals'))
local locals = guide.getVisibleLocals(state.ast, position)
local hit = false
for uri in files.eachFile(state.uri) do
if uri == guide.getUri(state.ast) then
goto CONTINUE
Expand Down Expand Up @@ -85,12 +88,68 @@ function m.check(state, word, position, callback)
and vm.getDeprecated(targetSource.node) then
goto INNER_CONTINUE
end
hit = true
callback(uri, stemName, targetSource)
end
::INNER_CONTINUE::
end
::CONTINUE::
end
-- 如果没命中, 则检查枚举
if not hit then
local docs = vm.getDocSets(state.uri)
for _, doc in ipairs(docs) do
if doc.type ~= 'doc.enum' or vm.getDeprecated(doc) then
goto CONTINUE
end
-- 检查枚举名是否匹配
if not (doc.enum[1] == word or doc.enum[1]:match(".*%.([^%.]*)$") == word) then
goto CONTINUE
end
local uri = guide.getUri(doc)
local targetState = files.getState(uri)
if not targetState then
goto CONTINUE
end
local targetSource = m.getTargetSource(targetState)
if not targetSource or (targetSource.type ~= 'getlocal' and targetSource.type ~= 'table') or vm.getDeprecated(targetSource.node) then
goto CONTINUE
end
-- 枚举的完整路径
local fullKeyPath = ""
local node = doc.bindSource.parent
while node do
-- 检查是否可见
if not vm.isVisible(state.ast, node) then
goto CONTINUE
end
if node.type == 'setfield' or node.type == 'getfield' then
fullKeyPath = "." .. node.field[1] .. fullKeyPath
end
if node.type == 'getlocal' then
node = node.node
break
end
node = node.node
end
-- 匹配导出的值, 确定最终路径
if targetSource.node == node then
hit = true
elseif targetSource.type == 'table' then
for _, value in ipairs(targetSource) do
if value.value.node == node then
fullKeyPath = "." .. value.value[1] .. fullKeyPath
hit = true
break
end
end
end
if hit then
callback(guide.getUri(doc), nil, nil, fullKeyPath)
end
::CONTINUE::
end
end
end

files.watch(function (ev, uri)
Expand Down
11 changes: 3 additions & 8 deletions script/core/hover/description.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ local function tryDocFieldComment(source)
end
end

local function getFunctionComment(source, raw)
local function getFunctionCommentMarkdown(source, raw)
local docGroup = source.bindDocs
if not docGroup then
return
Expand Down Expand Up @@ -393,11 +393,7 @@ local function getFunctionComment(source, raw)
local enums = getBindEnums(source, docGroup)
md:add('lua', enums)

local comment = md:string()
if comment == '' then
return nil
end
return comment
return md
end

---@async
Expand All @@ -407,8 +403,7 @@ local function tryDocComment(source, raw)
source = source.value
end
if source.type == 'function' then
local comment = getFunctionComment(source, raw)
md:add('md', comment)
md:add('md', getFunctionCommentMarkdown(source, raw))
source = source.parent
end
local comment = lookUpDocComments(source)
Expand Down
8 changes: 7 additions & 1 deletion script/core/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ local function isEventNotMatch(call, src)
end
local eventLiteral = event.extends.types[1] and guide.getLiteral(event.extends.types[1])
if eventLiteral == nil then
return false
-- extra checking when function param is not pure literal
-- eg: it maybe an alias type with literal values
local eventMap = vm.getLiterals(event.extends.types[1])
if not eventMap then
return false
end
return not eventMap[literal]
end
return eventLiteral ~= literal
end
Expand Down
Loading

0 comments on commit 2c3cea5

Please sign in to comment.