Skip to content

Commit 80a9ae8

Browse files
authored
Merge branch 'LuaLS:master' into master
2 parents 6bbfaf9 + 3154cef commit 80a9ae8

File tree

11 files changed

+90
-26
lines changed

11 files changed

+90
-26
lines changed

3rd/bee.lua

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# changelog
22

33
## 3.6.11
4+
* `CHG` completion: don't show loading process
45
* `FIX` [#1886]
6+
* `FIX` [#1887]
7+
* `FIX` [#1889]
8+
* `FIX` [#1895]
59

610
[#1886]: https://github.com/LuaLS/lua-language-server/issues/1886
11+
[#1887]: https://github.com/LuaLS/lua-language-server/issues/1887
12+
[#1889]: https://github.com/LuaLS/lua-language-server/issues/1889
13+
[#1895]: https://github.com/LuaLS/lua-language-server/issues/1895
714

815
## 3.6.10
916
`2023-2-7`

script/client.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,30 @@ local function tryModifySpecifiedConfig(uri, finalChanges)
376376
if #finalChanges == 0 then
377377
return false
378378
end
379+
log.info('tryModifySpecifiedConfig', uri, inspect(finalChanges))
379380
local workspace = require 'workspace'
380381
local scp = scope.getScope(uri)
381382
if scp:get('lastLocalType') ~= 'json' then
383+
log.info('lastLocalType ~= json')
382384
return false
383385
end
384386
local validChanges = getValidChanges(uri, finalChanges)
385387
if #validChanges == 0 then
388+
log.info('No valid changes')
386389
return false
387390
end
388391
local path = workspace.getAbsolutePath(uri, CONFIGPATH)
389392
if not path then
393+
log.info('Can not get absolute path')
390394
return false
391395
end
392396
local newJson = editConfigJson(uri, path, validChanges)
393397
if not newJson then
398+
log.info('Can not edit config json')
394399
return false
395400
end
396401
util.saveFile(path, newJson)
402+
log.info('Apply changes to config file', inspect(validChanges))
397403
removeAppliedChanges(finalChanges, validChanges)
398404
return true
399405
end
@@ -402,31 +408,38 @@ local function tryModifyRC(uri, finalChanges, create)
402408
if #finalChanges == 0 then
403409
return false
404410
end
411+
log.info('tryModifyRC', uri, inspect(finalChanges))
405412
local workspace = require 'workspace'
406413
local path = workspace.getAbsolutePath(uri, '.luarc.jsonc')
407414
if not path then
415+
log.info('Can not get absolute path of .luarc.jsonc')
408416
return false
409417
end
410418
path = fs.exists(fs.path(path)) and path or workspace.getAbsolutePath(uri, '.luarc.json')
411419
if not path then
420+
log.info('Can not get absolute path of .luarc.json')
412421
return false
413422
end
414423
local buf = util.loadFile(path)
415424
if not buf and not create then
425+
log.info('Can not load .luarc.json and not create')
416426
return false
417427
end
418428
local validChanges = getValidChanges(uri, finalChanges)
419429
if #validChanges == 0 then
430+
log.info('No valid changes')
420431
return false
421432
end
422433
if not buf then
423434
util.saveFile(path, '')
424435
end
425436
local newJson = editConfigJson(uri, path, validChanges)
426437
if not newJson then
438+
log.info('Can not edit config json')
427439
return false
428440
end
429441
util.saveFile(path, newJson)
442+
log.info('Apply changes to .luarc.json', inspect(validChanges))
430443
removeAppliedChanges(finalChanges, validChanges)
431444
return true
432445
end
@@ -435,6 +448,7 @@ local function tryModifyClient(uri, finalChanges)
435448
if #finalChanges == 0 then
436449
return false
437450
end
451+
log.info('tryModifyClient', uri, inspect(finalChanges))
438452
if not m.getOption 'changeConfiguration' then
439453
return false
440454
end
@@ -447,12 +461,14 @@ local function tryModifyClient(uri, finalChanges)
447461
end
448462
end
449463
if #scpChanges == 0 then
464+
log.info('No changes in client scope')
450465
return false
451466
end
452467
proto.notify('$/command', {
453468
command = 'lua.config',
454469
data = scpChanges,
455470
})
471+
log.info('Apply client changes', uri, inspect(scpChanges))
456472
removeAppliedChanges(finalChanges, scpChanges)
457473
return true
458474
end
@@ -462,7 +478,9 @@ local function tryModifyClientGlobal(finalChanges)
462478
if #finalChanges == 0 then
463479
return
464480
end
481+
log.info('tryModifyClientGlobal', inspect(finalChanges))
465482
if not m.getOption 'changeConfiguration' then
483+
log.info('Client dose not support modifying config')
466484
return
467485
end
468486
local changes = {}
@@ -471,10 +489,15 @@ local function tryModifyClientGlobal(finalChanges)
471489
changes[#changes+1] = change
472490
end
473491
end
492+
if #changes == 0 then
493+
log.info('No global changes')
494+
return
495+
end
474496
proto.notify('$/command', {
475497
command = 'lua.config',
476498
data = changes,
477499
})
500+
log.info('Apply client global changes', inspect(changes))
478501
removeAppliedChanges(finalChanges, changes)
479502
end
480503

@@ -522,6 +545,7 @@ function m.setConfig(changes, onlyMemory)
522545
if #finalChanges == 0 then
523546
return
524547
end
548+
log.info('Modify config', inspect(finalChanges))
525549
xpcall(function ()
526550
local ws = require 'workspace'
527551
tryModifyClientGlobal(finalChanges)
@@ -541,6 +565,7 @@ function m.setConfig(changes, onlyMemory)
541565
end
542566
if #finalChanges > 0 then
543567
m.showMessage('Warning', lang.script('CONFIG_MODIFY_FAIL', buildMaunuallyMessage(finalChanges)))
568+
log.warn('Config modify fail', inspect(finalChanges))
544569
end
545570
end
546571
end, log.error)

script/config/template.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ local template = {
210210
'assert',
211211
'error',
212212
'type',
213+
'os.exit',
213214
}
214215
),
215216
['Lua.runtime.meta'] = Type.String >> '${version} ${language} ${encoding}',

script/core/diagnostics/missing-return.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local await = require 'await'
77
---@param block parser.object
88
---@return boolean
99
local function hasReturn(block)
10-
if block.hasReturn or block.hasError then
10+
if block.hasReturn or block.hasExit then
1111
return true
1212
end
1313
if block.type == 'if' then

script/core/diagnostics/unreachable-code.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
---@param block parser.object
2424
---@return boolean
2525
local function hasReturn(block)
26-
if block.hasReturn or block.hasError then
26+
if block.hasReturn or block.hasExit then
2727
return true
2828
end
2929
if block.type == 'if' then

script/parser/compile.lua

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ local Specials = {
118118
['assert'] = true,
119119
['error'] = true,
120120
['type'] = true,
121+
['os.exit'] = true,
121122
}
122123

123124
local UnarySymbol = {
@@ -1379,12 +1380,24 @@ local function parseNumber()
13791380
return result
13801381
end
13811382

1382-
local function isKeyWord(word)
1383+
local function isKeyWord(word, nextToken)
13831384
if KeyWord[word] then
13841385
return true
13851386
end
13861387
if word == 'goto' then
1387-
return State.version ~= 'Lua 5.1'
1388+
if State.version == 'Lua 5.1' then
1389+
return false
1390+
end
1391+
if State.version == 'LuaJIT' then
1392+
if not nextToken then
1393+
return false
1394+
end
1395+
if CharMapWord[ssub(nextToken, 1, 1)] then
1396+
return true
1397+
end
1398+
return false
1399+
end
1400+
return true
13881401
end
13891402
return false
13901403
end
@@ -1410,7 +1423,7 @@ local function parseName(asAction)
14101423
finish = finishPos,
14111424
}
14121425
end
1413-
if isKeyWord(word) then
1426+
if isKeyWord(word, Tokens[Index + 1]) then
14141427
pushError {
14151428
type = 'KEYWORD',
14161429
start = startPos,
@@ -1491,7 +1504,7 @@ local function parseExpList(mini)
14911504
break
14921505
end
14931506
local nextToken = peekWord()
1494-
if isKeyWord(nextToken)
1507+
if isKeyWord(nextToken, Tokens[Index + 2])
14951508
and nextToken ~= 'function'
14961509
and nextToken ~= 'true'
14971510
and nextToken ~= 'false'
@@ -2223,7 +2236,7 @@ local function parseParams(params)
22232236
finish = getPosition(Tokens[Index] + #token - 1, 'right'),
22242237
}
22252238
end
2226-
if isKeyWord(token) then
2239+
if isKeyWord(token, Tokens[Index + 3]) then
22272240
pushError {
22282241
type = 'KEYWORD',
22292242
start = getPosition(Tokens[Index], 'left'),
@@ -2887,14 +2900,15 @@ local function compileExpAsAction(exp)
28872900
end
28882901

28892902
if exp.type == 'call' then
2890-
if exp.node.special == 'error' then
2903+
if exp.node.special == 'error'
2904+
or exp.node.special == 'os.exit' then
28912905
for i = #Chunk, 1, -1 do
28922906
local block = Chunk[i]
28932907
if block.type == 'ifblock'
28942908
or block.type == 'elseifblock'
28952909
or block.type == 'elseblock'
28962910
or block.type == 'function' then
2897-
block.hasError = true
2911+
block.hasExit = true
28982912
break
28992913
end
29002914
end
@@ -3785,7 +3799,7 @@ function parseAction()
37853799
return parseRepeat()
37863800
end
37873801

3788-
if token == 'goto' and isKeyWord 'goto' then
3802+
if token == 'goto' and isKeyWord('goto', Tokens[Index + 3]) then
37893803
return parseGoTo()
37903804
end
37913805

script/parser/guide.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ local type = type
7272
---@field hasGoTo? true
7373
---@field hasReturn? true
7474
---@field hasBreak? true
75-
---@field hasError? true
75+
---@field hasExit? true
7676
---@field [integer] parser.object|any
7777
---@field package _root parser.object
7878

script/provider/provider.lua

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -597,19 +597,7 @@ m.register 'textDocument/completion' {
597597
function (params)
598598
local uri = files.getRealUri(params.textDocument.uri)
599599
if not workspace.isReady(uri) then
600-
local count, max = workspace.getLoadingProcess(uri)
601-
return {
602-
{
603-
label = lang.script('HOVER_WS_LOADING', count, max),
604-
textEdit = {
605-
range = {
606-
start = params.position,
607-
['end'] = params.position,
608-
},
609-
newText = '',
610-
},
611-
}
612-
}
600+
return nil
613601
end
614602
local _ <close> = progress.create(uri, lang.script.WINDOW_PROCESSING_COMPLETION, 0.5)
615603
--log.info(util.dump(params))

script/vm/tracer.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ local lookIntoChild = util.switch()
282282
---@param topNode vm.node
283283
---@param outNode? vm.node
284284
: call(function (tracer, action, topNode, outNode)
285+
if action.type == 'loop' then
286+
tracer:lookIntoChild(action.init, topNode)
287+
tracer:lookIntoChild(action.max, topNode)
288+
end
285289
if action[1] then
286290
tracer:lookIntoBlock(action, action.bstart, topNode:copy())
287291
local lastAssign = tracer:getLastAssign(action.start, action.finish)
@@ -369,7 +373,7 @@ local lookIntoChild = util.switch()
369373
local neverReturn = subBlock.hasReturn
370374
or subBlock.hasGoTo
371375
or subBlock.hasBreak
372-
or subBlock.hasError
376+
or subBlock.hasExit
373377
if neverReturn then
374378
mergedNode = true
375379
else

test/type_inference/init.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,17 @@ end
26202620
print(<?n?>)
26212621
]]
26222622

2623+
TEST 'integer' [[
2624+
---@type integer?
2625+
local n
2626+
2627+
if not n then
2628+
os.exit()
2629+
end
2630+
2631+
print(<?n?>)
2632+
]]
2633+
26232634
TEST 'table' [[
26242635
---@type table?
26252636
local n
@@ -4208,3 +4219,17 @@ end
42084219
function Y()
42094220
end
42104221
]]
4222+
4223+
TEST 'A_Class' [[
4224+
---@class A_Class
4225+
local A = { x = 5 }
4226+
4227+
function A:func()
4228+
for i = 1, <?self?>.x do
4229+
print(i)
4230+
end
4231+
4232+
self.y = 3
4233+
self.y = self.y + 3
4234+
end
4235+
]]

0 commit comments

Comments
 (0)