Skip to content

Commit e59af85

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 9b8b14d + 5e41989 commit e59af85

File tree

12 files changed

+227
-23
lines changed

12 files changed

+227
-23
lines changed

changelog.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
2828
---@type myClass
2929
local class
3030

31-
print(class.a.b.c.e.f.g) --> infered as integer
31+
print(class.a.b.c.e.f.g) --> inferred as integer
3232
```
3333
* `CHG` [#1582] the following diagnostics consider `overload`
3434
* `missing-return`
@@ -37,21 +37,54 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
3737
* `return-type-mismatch`
3838
* `CHG` workspace-symbol: supports chain fields based on global variables and types. try `io.open` or `iolib.open`
3939
* `CHG` [#1641] if a function only has varargs and has `---@overload`, the varargs will be ignored
40+
* `CHG` [#1575] search definitions by first argument of `setmetatable`
41+
```lua
42+
---@class Object
43+
local obj = setmetatable({
44+
initValue = 1,
45+
}, mt)
46+
47+
print(obj.initValue) --> `obj.initValue` is integer
48+
```
49+
* `CHG` [#1153] infer type by generic parameters or returns of function
50+
```lua
51+
---@generic T
52+
---@param f fun(x: T)
53+
---@return T[]
54+
local function x(f) end
55+
56+
---@type fun(x: integer)
57+
local cb
58+
59+
local arr = x(cb) --> `arr` is inferred as `integer[]`
60+
```
61+
* `CHG` [#1201] infer parameter type by expected returned function of parent function
62+
```lua
63+
---@return fun(x: integer)
64+
local function f()
65+
return function (x) --> `x` is inferred as `integer`
66+
end
67+
end
68+
```
4069
* `FIX` [#1567]
4170
* `FIX` [#1593]
4271
* `FIX` [#1595]
4372
* `FIX` [#1599]
4473
* `FIX` [#1606]
4574
* `FIX` [#1608]
4675
* `FIX` [#1637]
76+
* `FIX` [#1640]
4777
* `FIX` [#1642]
4878

79+
[#1153]: https://github.com/sumneko/lua-language-server/issues/1153
4980
[#1177]: https://github.com/sumneko/lua-language-server/issues/1177
81+
[#1202]: https://github.com/sumneko/lua-language-server/issues/1202
5082
[#1458]: https://github.com/sumneko/lua-language-server/issues/1458
5183
[#1557]: https://github.com/sumneko/lua-language-server/issues/1557
5284
[#1558]: https://github.com/sumneko/lua-language-server/issues/1558
5385
[#1561]: https://github.com/sumneko/lua-language-server/issues/1561
5486
[#1567]: https://github.com/sumneko/lua-language-server/issues/1567
87+
[#1575]: https://github.com/sumneko/lua-language-server/issues/1575
5588
[#1582]: https://github.com/sumneko/lua-language-server/issues/1582
5689
[#1593]: https://github.com/sumneko/lua-language-server/issues/1593
5790
[#1595]: https://github.com/sumneko/lua-language-server/issues/1595
@@ -60,6 +93,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
6093
[#1608]: https://github.com/sumneko/lua-language-server/issues/1608
6194
[#1626]: https://github.com/sumneko/lua-language-server/issues/1626
6295
[#1637]: https://github.com/sumneko/lua-language-server/issues/1637
96+
[#1640]: https://github.com/sumneko/lua-language-server/issues/1640
6397
[#1641]: https://github.com/sumneko/lua-language-server/issues/1641
6498
[#1642]: https://github.com/sumneko/lua-language-server/issues/1642
6599

meta/3rd/lovr/library/lovr/filesystem.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@
1717
--- <tr>
1818
--- <td>macOS</td>
1919
--- <td><code>/Users/&lt;user&gt;/Library/Application Support/LOVR/&lt;identity&gt;</code></td>
20+
--- </tr>
21+
--- <tr>
22+
--- <td>Linux</td>
23+
--- <td><code>/home/&lt;user&gt;/.local/share/LOVR/&lt;identity&gt;</code></td>
24+
--- </tr>
25+
--- <tr>
26+
--- <td>Android</td>
27+
--- <td><code>/sdcard/Android/data/<identity>/files</code></td>
2028
--- </tr> </table>
2129
---
2230
---`<identity>` should be a unique identifier for your app.
2331
---
2432
---It can be set either in `lovr.conf` or by using `lovr.filesystem.setIdentity`.
2533
---
34+
---On Android, the identity can not be changed and will always be the package id, like `org.lovr.app`.
35+
---
2636
---All filenames are relative to either the save directory or the directory containing the project source.
2737
---
2838
---Files in the save directory take precedence over files in the project.
@@ -278,14 +288,6 @@ function lovr.filesystem.setIdentity(identity) end
278288
---@param path? string # An optional semicolon separated list of search patterns.
279289
function lovr.filesystem.setRequirePath(path) end
280290

281-
---
282-
---Sets the location of the project's source.
283-
---
284-
---This can only be done once, and is usually done internally.
285-
---
286-
---@param identity string # The path containing the project's source.
287-
function lovr.filesystem.setSource(identity) end
288-
289291
---
290292
---Unmounts a directory or archive previously mounted with `lovr.filesystem.mount`.
291293
---

meta/3rd/lovr/library/lovr/graphics.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ function lovr.graphics.newMaterial(properties) end
462462
---
463463
---- glTF: Morph targets are not supported.
464464
---- glTF: Only the default scene is loaded.
465-
---- glTF: Only the default scene is loaded.
466465
---- glTF: Currently, each skin in a Model can have up to 256 joints.
467466
---- glTF: Meshes can't appear multiple times in the node hierarchy with different skins, they need
468467
--- to use 1 skin consistently.

meta/3rd/lovr/library/lovr/physics.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,8 @@ function World:getResponseTime() end
14111411
---
14121412
---The default step count is 20.
14131413
---
1414-
---@param steps number # The step count.
1415-
function World:getStepCount(steps) end
1414+
---@return number steps # The step count.
1415+
function World:getStepCount() end
14161416

14171417
---
14181418
---Returns the tightness of joints in the World.

script/brave/work.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ brave.on('compile', function (param)
6060
, param.version
6161
, param.options
6262
)
63-
log.debug('compile', param.uri, 'takes:', os.clock() - clock)
63+
log.debug('Async compile', param.uri, 'takes:', os.clock() - clock)
6464
return {
6565
state = state,
6666
err = err,

script/files.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ function m.addRef(uri)
420420
return nil
421421
end
422422
file._ref = (file._ref or 0) + 1
423-
log.debug('add ref', uri)
423+
log.debug('add ref', uri, file._ref)
424424
return function ()
425425
m.delRef(uri)
426426
end
@@ -432,7 +432,7 @@ function m.delRef(uri)
432432
return
433433
end
434434
file._ref = (file._ref or 0) - 1
435-
log.debug('del ref', uri)
435+
log.debug('del ref', uri, file._ref)
436436
if file._ref <= 0 and not m.isOpen(uri) then
437437
m.remove(uri)
438438
end

script/vm/compiler.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,27 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
368368
end
369369
end)
370370
end
371+
if src.value
372+
and src.value.type == 'select'
373+
and src.value.vararg.type == 'call' then
374+
local func = src.value.vararg.node
375+
local args = src.value.vararg.args
376+
if func.special == 'setmetatable'
377+
and args
378+
and args[1]
379+
and args[1].type == 'table' then
380+
searchFieldSwitch('table', suri, args[1], key, ref, function (field)
381+
local fieldKey = guide.getKeyName(field)
382+
if fieldKey then
383+
if not searchedFields[fieldKey]
384+
and guide.isSet(field) then
385+
hasFounded[fieldKey] = true
386+
pushResult(field, true)
387+
end
388+
end
389+
end)
390+
end
391+
end
371392
copyToSearched()
372393
searchFieldSwitch(src.type, suri, src, key, ref, function (field)
373394
local fieldKey = guide.getKeyName(field)
@@ -1038,6 +1059,7 @@ local function compileLocal(source)
10381059
end
10391060
if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
10401061
local func = source.parent.parent
1062+
-- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
10411063
local funcNode = vm.compileNode(func)
10421064
local hasDocArg
10431065
for n in funcNode:eachObject() do
@@ -1137,6 +1159,22 @@ local compilerSwitch = util.switch()
11371159
local call = source.parent.parent
11381160
vm.compileCallArg(source, call)
11391161
end
1162+
1163+
-- function f() return function (<?x?>) end end
1164+
if source.parent.type == 'return' then
1165+
for i, ret in ipairs(source.parent) do
1166+
if ret == source then
1167+
local func = guide.getParentFunction(source.parent)
1168+
if func then
1169+
local returnObj = vm.getReturnOfFunction(func, i)
1170+
if returnObj then
1171+
vm.setNode(source, vm.compileNode(returnObj))
1172+
end
1173+
end
1174+
break
1175+
end
1176+
end
1177+
end
11401178
end)
11411179
: case 'paren'
11421180
: call(function (source)

script/vm/sign.lua

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ function mt:resolve(uri, args, removeGeneric)
2222
if not args then
2323
return nil
2424
end
25+
26+
---@type table<string, vm.node>
2527
local resolved = {}
2628

27-
---@param object vm.node.object
29+
---@param object vm.node|vm.node.object
2830
---@param node vm.node
2931
local function resolve(object, node)
32+
if object.type == 'vm.node' then
33+
for o in object:eachObject() do
34+
resolve(o, node)
35+
end
36+
return
37+
end
38+
if object.type == 'doc.type' then
39+
---@cast object parser.object
40+
resolve(vm.compileNode(object), node)
41+
return
42+
end
3043
if object.type == 'doc.generic.name' then
44+
---@type string
3145
local key = object[1]
3246
if object.literal then
3347
-- 'number' -> `T`
@@ -40,8 +54,21 @@ function mt:resolve(uri, args, removeGeneric)
4054
end
4155
else
4256
-- number -> T
43-
resolved[key] = vm.createNode(node, resolved[key])
57+
for n in node:eachObject() do
58+
if n.type ~= 'doc.generic.name'
59+
and n.type ~= 'generic' then
60+
if resolved[key] then
61+
resolved[key]:merge(n)
62+
else
63+
resolved[key] = vm.createNode(n)
64+
end
65+
end
66+
end
67+
if resolved[key] and node:isOptional() then
68+
resolved[key]:addOptional()
69+
end
4470
end
71+
return
4572
end
4673
if object.type == 'doc.type.array' then
4774
for n in node:eachObject() do
@@ -68,6 +95,7 @@ function mt:resolve(uri, args, removeGeneric)
6895
resolve(object.node, vm.compileNode(n[1]))
6996
end
7097
end
98+
return
7199
end
72100
if object.type == 'doc.type.table' then
73101
for _, ufield in ipairs(object.fields) do
@@ -105,6 +133,34 @@ function mt:resolve(uri, args, removeGeneric)
105133
end
106134
::CONTINUE::
107135
end
136+
return
137+
end
138+
if object.type == 'doc.type.function' then
139+
for i, arg in ipairs(object.args) do
140+
for n in node:eachObject() do
141+
if n.type == 'function'
142+
or n.type == 'doc.type.function' then
143+
---@cast n parser.object
144+
local farg = n.args and n.args[i]
145+
if farg then
146+
resolve(arg.extends, vm.compileNode(farg))
147+
end
148+
end
149+
end
150+
end
151+
for i, ret in ipairs(object.returns) do
152+
for n in node:eachObject() do
153+
if n.type == 'function'
154+
or n.type == 'doc.type.function' then
155+
---@cast n parser.object
156+
local fret = vm.getReturnOfFunction(n, i)
157+
if fret then
158+
resolve(ret, vm.compileNode(fret))
159+
end
160+
end
161+
end
162+
end
163+
return
108164
end
109165
end
110166

@@ -190,9 +246,7 @@ function mt:resolve(uri, args, removeGeneric)
190246
local knownTypes, genericNames = getSignInfo(sign)
191247
if not isAllResolved(genericNames) then
192248
local newArgNode = buildArgNode(argNode,sign, knownTypes)
193-
for n in sign:eachObject() do
194-
resolve(n, newArgNode)
195-
end
249+
resolve(sign, newArgNode)
196250
end
197251
end
198252

script/workspace/workspace.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ function m.awaitPreload(scp)
308308

309309
if scp.uri and not scp:get('bad root') then
310310
log.info('Scan files at:', scp:getName())
311+
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri))))
311312
local count = 0
312313
---@async
313314
native:scan(furi.decode(scp.uri), function (path)
@@ -320,12 +321,12 @@ function m.awaitPreload(scp)
320321
client.showMessage('Warning', lang.script('WORKSPACE_SCAN_TOO_MUCH', count, furi.decode(scp.uri)))
321322
end
322323
end)
323-
scp:gc(fw.watch(m.normalize(furi.decode(scp.uri))))
324324
end
325325

326326
for _, libMatcher in ipairs(librarys) do
327327
log.info('Scan library at:', libMatcher.uri)
328328
local count = 0
329+
scp:gc(fw.watch(furi.decode(libMatcher.uri)))
329330
scp:addLink(libMatcher.uri)
330331
---@async
331332
libMatcher.matcher:scan(furi.decode(libMatcher.uri), function (path)
@@ -338,7 +339,6 @@ function m.awaitPreload(scp)
338339
client.showMessage('Warning', lang.script('WORKSPACE_SCAN_TOO_MUCH', count, furi.decode(libMatcher.uri)))
339340
end
340341
end)
341-
scp:gc(fw.watch(furi.decode(libMatcher.uri)))
342342
end
343343

344344
-- must wait for other scopes to add library

0 commit comments

Comments
 (0)