Skip to content

Commit 6d1da00

Browse files
authored
Merge branch 'master' into fix/narrow
2 parents 1501f15 + 0c5df12 commit 6d1da00

File tree

9 files changed

+247
-25
lines changed

9 files changed

+247
-25
lines changed

changelog.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
5-
* `FIX` incorrect argument skip pattern for `--check_out_path=`, which incorrectly skips the next argument
5+
* `NEW` CLI: added `--help`.
66
* `CHG` default path for `--doc_out_path` is the current directory
7+
* `FIX` incorrect argument skip pattern for `--check_out_path=`, which incorrectly skips the next argument
78
* `FIX` incorrect error message for `--doc_update`.
89
* `FIX` reimplement section `luals.config` in file doc.json
910
* `FIX` incorrect file names in file doc.json
1011
* `FIX` remove extra `./` path prefix in the check report when using `--check=.`
1112
* `FIX` Narrowing of types with literal fields: [#3056](https://github.com/LuaLS/lua-language-server/issues/3056), [#3089](https://github.com/LuaLS/lua-language-server/issues/3089)
13+
* `FIX` correct lua version of `math.ult` and `math.type`
14+
* `FIX` incorrect links for `pattern` in `string` methods
15+
* `FIX` fix type annotations for bit module
16+
* `FIX` Another regression related to type narrow and generic param introduced since `v3.10.1` [#3087](https://github.com/LuaLS/lua-language-server/issues/3087)
1217

1318
## 3.13.6
1419
`2025-2-6`

locale/en-us/meta.lua

+25-6
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,13 @@ string.char =
647647
'Returns a string with length equal to the number of arguments, in which each character has the internal numeric code equal to its corresponding argument.'
648648
string.dump =
649649
'Returns a string containing a binary representation (a *binary chunk*) of the given function.'
650-
string.find =
650+
string.find['>5.2'] =
651651
'Looks for the first match of `pattern` (see §6.4.1) in the string.'
652+
string.find['=5.1'] =
653+
'Looks for the first match of `pattern` (see §5.4.1) in the string.'
652654
string.format =
653655
'Returns a formatted version of its variable number of arguments following the description given in its first argument.'
654-
string.gmatch =
656+
string.gmatch['>5.2'] =
655657
[[
656658
Returns an iterator function that, each time it is called, returns the next captures from `pattern` (see §6.4.1) over the string s.
657659
@@ -664,17 +666,34 @@ As an example, the following loop will iterate over all the words from string s,
664666
end
665667
```
666668
]]
667-
string.gsub =
669+
string.gmatch['=5.1'] =
670+
[[
671+
Returns an iterator function that, each time it is called, returns the next captures from `pattern` (see §5.4.1) over the string s.
672+
673+
As an example, the following loop will iterate over all the words from string s, printing one per line:
674+
```lua
675+
s =
676+
"hello world from Lua"
677+
for w in string.gmatch(s, "%a+") do
678+
print(w)
679+
end
680+
```
681+
]]
682+
string.gsub['>5.2'] =
668683
'Returns a copy of s in which all (or the first `n`, if given) occurrences of the `pattern` (see §6.4.1) have been replaced by a replacement string specified by `repl`.'
684+
string.gsub['=5.1'] =
685+
'Returns a copy of s in which all (or the first `n`, if given) occurrences of the `pattern` (see §5.4.1) have been replaced by a replacement string specified by `repl`.'
669686
string.len =
670687
'Returns its length.'
671688
string.lower =
672689
'Returns a copy of this string with all uppercase letters changed to lowercase.'
673-
string.match =
690+
string.match['>5.2'] =
674691
'Looks for the first match of `pattern` (see §6.4.1) in the string.'
675-
string.pack =
692+
string.match['=5.1'] =
693+
'Looks for the first match of `pattern` (see §5.4.1) in the string.'
694+
string.pack['>5.2'] =
676695
'Returns a binary string containing the values `v1`, `v2`, etc. packed (that is, serialized in binary form) according to the format string `fmt` (see §6.4.2) .'
677-
string.packsize =
696+
string.packsize['>5.2'] =
678697
'Returns the size of a string resulting from `string.pack` with the given format string `fmt` (see §6.4.2) .'
679698
string.rep['>5.2'] =
680699
'Returns a string that is the concatenation of `n` copies of the string `s` separated by the string `sep`.'

meta/template/bit.lua

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,22 @@ function bit.tohex(x, n) end
2222
function bit.bnot(x) end
2323

2424
---@param x integer
25-
---@param x2 integer
2625
---@param ... integer
2726
---@return integer y
2827
---@nodiscard
29-
function bit.bor(x, x2, ...) end
28+
function bit.bor(x, ...) end
3029

3130
---@param x integer
32-
---@param x2 integer
3331
---@param ... integer
3432
---@return integer y
3533
---@nodiscard
36-
function bit.band(x, x2, ...) end
34+
function bit.band(x, ...) end
3735

3836
---@param x integer
39-
---@param x2 integer
4037
---@param ... integer
4138
---@return integer y
4239
---@nodiscard
43-
function bit.bxor(x, x2, ...) end
40+
function bit.bxor(x, ...) end
4441

4542
---@param x integer
4643
---@param n integer

meta/template/math.lua

+2
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ function math.tanh(x) end
234234
---@nodiscard
235235
function math.tointeger(x) end
236236

237+
---@version >5.3
237238
---#DES 'math.type'
238239
---@param x any
239240
---@return
@@ -243,6 +244,7 @@ function math.tointeger(x) end
243244
---@nodiscard
244245
function math.type(x) end
245246

247+
---@version >5.3
246248
---#DES 'math.ult'
247249
---@param m integer
248250
---@param n integer

script/cli/help.lua

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
local util = require 'utility'
2+
3+
--- @class cli.arg
4+
--- @field type? string|string[]
5+
--- @field description string Description of the argument in markdown format.
6+
--- @field example? string
7+
--- @field default? any
8+
9+
--- @type table<string, cli.arg>
10+
local args = {
11+
['--help'] = {
12+
description = [[
13+
Print this message.
14+
]],
15+
},
16+
['--check'] = {
17+
type = 'string',
18+
description = [[
19+
Perform a "diagnosis report" where the results of the diagnosis are written to the logpath.
20+
]],
21+
example = [[--check=C:\Users\Me\path\to\workspace]]
22+
},
23+
['--checklevel'] = {
24+
type = 'string',
25+
description = [[
26+
To be used with --check. The minimum level of diagnostic that should be logged.
27+
Items with lower priority than the one listed here will not be written to the file.
28+
Options include, in order of priority:
29+
30+
- Error
31+
- Warning
32+
- Information
33+
- Hint
34+
]],
35+
default = 'Warning',
36+
example = [[--checklevel=Information]]
37+
},
38+
['--check_format'] = {
39+
type = { 'json', 'pretty' },
40+
description = [[
41+
Output format for the check results.
42+
- 'pretty': results are displayed to stdout in a human-readable format.
43+
- 'json': results are written to a file in JSON format. See --check_out_path
44+
]],
45+
default = 'pretty'
46+
},
47+
['--version'] = {
48+
type = 'boolean',
49+
description = [[
50+
Get the version of the Lua language server.
51+
This will print it to the command line and immediately exit.
52+
]],
53+
},
54+
['--doc'] = {
55+
type = 'string',
56+
description = [[
57+
Generate documentation from a workspace.
58+
The files will be output in your log path.
59+
]],
60+
example = [[--doc=C:/Users/Me/Documents/myLuaProject/]]
61+
},
62+
['--doc_out_path'] = {
63+
type = 'string',
64+
description = [[
65+
The path to output generated documentation at.
66+
See --doc for more info.
67+
]],
68+
example = [[--doc_out_path=C:/Users/Me/Documents/myLuaProjectDocumentation]]
69+
},
70+
['--logpath'] = {
71+
type = 'string',
72+
description = [[
73+
Where the log should be written to.
74+
]],
75+
default = './log',
76+
example = [[--logpath=D:/luaServer/logs]]
77+
},
78+
['--loglevel'] = {
79+
type = 'string',
80+
description = [[
81+
The minimum level of logging that should appear in the logfile.
82+
Can be used to log more detailed info for debugging and error reporting.
83+
84+
Options:
85+
86+
- error
87+
- warn
88+
- info
89+
- debug
90+
- trace
91+
]],
92+
example = [[--loglevel=trace]]
93+
},
94+
['--metapath'] = {
95+
type = 'string',
96+
description = [[
97+
Where the standard Lua library definition files should be generated to.
98+
]],
99+
default = './meta',
100+
example = [[--metapath=D:/sumnekoLua/metaDefintions]]
101+
},
102+
['--locale'] = {
103+
type = 'string',
104+
description = [[
105+
The language to use. Defaults to en-us.
106+
Options can be found in locale/ .
107+
]],
108+
example = [[--locale=zh-cn]]
109+
},
110+
['--configpath'] = {
111+
type = 'string',
112+
description = [[
113+
The location of the configuration file that will be loaded.
114+
Can be relative to the workspace.
115+
When provided, config files from elsewhere (such as from VS Code) will no longer be loaded.
116+
]],
117+
example = [[--configpath=sumnekoLuaConfig.lua]]
118+
},
119+
['--force-accept-workspace'] = {
120+
type = 'boolean',
121+
description = [[
122+
Allows the use of root/home directory as the workspace.
123+
]]
124+
},
125+
['--socket'] = {
126+
type = 'number',
127+
description = [[
128+
Will communicate to a client over the specified TCP port instead of through stdio.
129+
]],
130+
example = [[--socket=5050]]
131+
},
132+
['--develop'] = {
133+
type = 'boolean',
134+
description = [[
135+
Enables development mode. This allows plugins to write to the logpath.
136+
]]
137+
}
138+
}
139+
140+
for nm, attrs in util.sortPairs(args) do
141+
if attrs.type == 'boolean' then
142+
print(nm)
143+
else
144+
print(nm .. "=<value>")
145+
end
146+
if attrs.description then
147+
local normalized_description = attrs.description:gsub("^%s+", ""):gsub("\n%s+", "\n"):gsub("%s+$", "")
148+
print("\n " .. normalized_description:gsub('\n', '\n '))
149+
end
150+
local attr_type = attrs.type
151+
if type(attr_type) == "table" then
152+
print("\n Values: " .. table.concat(attr_type, ', '))
153+
end
154+
if attrs.default then
155+
print("\n Default: " .. tostring(attrs.default))
156+
end
157+
if attrs.example then
158+
print("\n Example: " .. attrs.example)
159+
end
160+
print()
161+
end

script/cli/init.lua

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
if _G['HELP'] then
2+
require 'cli.help'
3+
os.exit(0, true)
4+
end
5+
16
if _G['VERSION'] then
27
require 'cli.version'
38
os.exit(0, true)

script/global.d.lua

+2
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ THREAD_ID = 1
109109
CHECK_WORKER = ''
110110

111111
QUIET = false
112+
113+
HELP = false

script/vm/compiler.lua

+3-12
Original file line numberDiff line numberDiff line change
@@ -641,20 +641,11 @@ local function matchCall(source)
641641
newNode.originNode = myNode
642642
vm.setNode(source, newNode, true)
643643
if call.args then
644-
-- clear existing node caches of args to allow recomputation with the type narrowed call
644+
-- recompile existing node caches of args to allow recomputation with the type narrowed call
645645
for _, arg in ipairs(call.args) do
646646
if vm.getNode(arg) then
647-
vm.setNode(arg, vm.createNode(), true)
648-
end
649-
end
650-
for n in newNode:eachObject() do
651-
if n.type == 'function'
652-
or n.type == 'doc.type.function' then
653-
for i, arg in ipairs(call.args) do
654-
if vm.getNode(arg) and n.args[i] then
655-
vm.setNode(arg, vm.compileNode(n.args[i]))
656-
end
657-
end
647+
vm.removeNode(arg)
648+
vm.compileNode(arg)
658649
end
659650
end
660651
end

test/type_inference/common.lua

+40
Original file line numberDiff line numberDiff line change
@@ -4743,6 +4743,46 @@ local function f(v) end
47434743
local <?r?> = f('')
47444744
]]
47454745

4746+
TEST 'A' [[
4747+
---@class A
4748+
local A = {}
4749+
4750+
---@generic T
4751+
---@param self T
4752+
---@param s string
4753+
---@return T
4754+
function A:f(s) end
4755+
4756+
---@generic T
4757+
---@param self T
4758+
---@param i integer
4759+
---@return T
4760+
function A:f(i) end
4761+
4762+
local <?r?> = A:f('')
4763+
]]
4764+
4765+
TEST 'B' [[
4766+
---@class A
4767+
local A = {}
4768+
4769+
---@generic T
4770+
---@param self T
4771+
---@param s string
4772+
---@return T
4773+
function A:f(s) end
4774+
4775+
---@generic T
4776+
---@param self T
4777+
---@param i integer
4778+
---@return T
4779+
function A:f(i) end
4780+
4781+
---@class B: A
4782+
local B = {}
4783+
local <?r?> = B:f('')
4784+
]]
4785+
47464786
TEST 'integer' [[
47474787
local function F(...)
47484788
local t = {...}

0 commit comments

Comments
 (0)