Skip to content

Commit ec4f497

Browse files
committed
fix runtime errors
1 parent 07219cb commit ec4f497

File tree

6 files changed

+43
-25
lines changed

6 files changed

+43
-25
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.5.6
44
* `CHG` diagnostic: now syntax errors in `LuaDoc` are shown as `Warning`
55
* `FIX` return type of `math.floor`
6+
* `FIX` runtime errors
67

78
## 2.5.5
89
`2021-12-16`

script/core/completion/completion.lua

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,14 +1064,14 @@ local function tryLabelInString(label, source)
10641064
if not source or source.type ~= 'string' then
10651065
return label
10661066
end
1067-
local str = parser.grammar(label, 'String')
1068-
if not str then
1067+
local state = parser.parse(label, 'String')
1068+
if not state or not state.ast then
10691069
return label
10701070
end
1071-
if not matchKey(source[1], str[1]) then
1071+
if not matchKey(source[1], state.ast[1]) then
10721072
return nil
10731073
end
1074-
return util.viewString(str[1], source[2])
1074+
return util.viewString(state.ast[1], source[2])
10751075
end
10761076

10771077
local function mergeEnums(a, b, source)
@@ -2048,6 +2048,9 @@ local function completion(uri, position, triggerCharacter)
20482048
await.delay()
20492049
tracy.ZoneBeginN 'completion #1'
20502050
local state = files.getState(uri)
2051+
if not state then
2052+
return nil
2053+
end
20512054
results = {}
20522055
clearStack()
20532056
tracy.ZoneEnd()

script/core/infer.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,9 @@ end
520520
---@param mark? table
521521
---@return table
522522
function m.searchLiterals(source, field, mark)
523+
if not source then
524+
return nil
525+
end
523526
local defs = vm.getDefs(source, field)
524527
local literals = {}
525528
mark = mark or {}
@@ -541,6 +544,9 @@ function m.searchAndViewLiterals(source, field, mark)
541544
return nil
542545
end
543546
local literals = m.searchLiterals(source, field, mark)
547+
if not literals then
548+
return nil
549+
end
544550
local view = m.viewLiterals(literals)
545551
return view
546552
end
@@ -559,10 +565,12 @@ function m.isTrue(source, mark)
559565
if mark.isTrue[source] == nil then
560566
mark.isTrue[source] = false
561567
local literals = m.searchLiterals(source, nil, mark)
562-
for literal in pairs(literals) do
563-
if literal ~= false then
564-
mark.isTrue[source] = true
565-
break
568+
if literals then
569+
for literal in pairs(literals) do
570+
if literal ~= false then
571+
mark.isTrue[source] = true
572+
break
573+
end
566574
end
567575
end
568576
end

script/library.lua

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,13 @@ local function initBuiltIn()
221221
end
222222
m.metaPath = metaPath:string()
223223
m.metaPaths = {}
224-
if not fs.exists(metaPath) then
225-
fs.create_directories(metaPath)
224+
local suc = xpcall(function ()
225+
if not fs.exists(metaPath) then
226+
fs.create_directories(metaPath)
227+
end
228+
end, log.error)
229+
if not suc then
230+
return
226231
end
227232
local out = fsu.dummyFS()
228233
local templateDir = ROOT / 'meta' / 'template'
@@ -462,7 +467,9 @@ local function check3rd(uri)
462467
if checkedUri(uri) then
463468
if files.isLua(uri) then
464469
local text = files.getText(uri)
465-
check3rdByWords(text, thirdConfigs)
470+
if text then
471+
check3rdByWords(text, thirdConfigs)
472+
end
466473
end
467474
check3rdByFileName(uri, thirdConfigs)
468475
end

script/log.lua

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ local mathModf = math.modf
1212
local debugGetInfo = debug.getinfo
1313
local ioStdErr = io.stderr
1414

15-
_ENV = nil
16-
1715
local m = {}
1816

1917
m.file = nil
@@ -91,9 +89,6 @@ function m.raw(thd, level, msg, source, currentline, clock)
9189
return
9290
end
9391
init_log_file()
94-
if not m.file then
95-
return ''
96-
end
9792
local sec, ms = mathModf((m.startTime + clock) / 1000)
9893
local timestr = osDate('%H:%M:%S', sec)
9994
local agl = ''
@@ -107,11 +102,13 @@ function m.raw(thd, level, msg, source, currentline, clock)
107102
buf = ('[%s.%03.f][%s]%s[#%d:%s:%s]: %s\n'):format(timestr, ms * 1000, level, agl, thd, trimSrc(source), currentline, msg)
108103
end
109104
m.size = m.size + #buf
110-
if m.size > m.maxSize then
111-
m.file:write(buf:sub(1, m.size - m.maxSize))
112-
m.file:write('[REACH MAX SIZE]')
113-
else
114-
m.file:write(buf)
105+
if m.file then
106+
if m.size > m.maxSize then
107+
m.file:write(buf:sub(1, m.size - m.maxSize))
108+
m.file:write('[REACH MAX SIZE]')
109+
else
110+
m.file:write(buf)
111+
end
115112
end
116113
return buf
117114
end
@@ -130,9 +127,11 @@ function m.init(root, path)
130127
m.path = path:string()
131128
m.prefixLen = #root:string()
132129
m.size = 0
133-
if not fs.exists(path:parent_path()) then
134-
fs.create_directories(path:parent_path())
135-
end
130+
pcall(function ()
131+
if not fs.exists(path:parent_path()) then
132+
fs.create_directories(path:parent_path())
133+
end
134+
end)
136135
if lastBuf then
137136
init_log_file()
138137
if m.file then

script/parser/newparser.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ local function parseShortString()
942942
end
943943
if not token then
944944
stringIndex = stringIndex + 1
945-
stringPool[stringIndex] = ssub(Lua, currentOffset)
945+
stringPool[stringIndex] = ssub(Lua, currentOffset or -1)
946946
missSymbol(mark)
947947
break
948948
end

0 commit comments

Comments
 (0)