summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/completion/completion.lua11
-rw-r--r--script/core/infer.lua16
-rw-r--r--script/library.lua13
-rw-r--r--script/log.lua25
-rw-r--r--script/parser/newparser.lua2
6 files changed, 43 insertions, 25 deletions
diff --git a/changelog.md b/changelog.md
index 00c2c275..92465e50 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,6 +3,7 @@
## 2.5.6
* `CHG` diagnostic: now syntax errors in `LuaDoc` are shown as `Warning`
* `FIX` return type of `math.floor`
+* `FIX` runtime errors
## 2.5.5
`2021-12-16`
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index efd62fb6..472b1118 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -1064,14 +1064,14 @@ local function tryLabelInString(label, source)
if not source or source.type ~= 'string' then
return label
end
- local str = parser.grammar(label, 'String')
- if not str then
+ local state = parser.parse(label, 'String')
+ if not state or not state.ast then
return label
end
- if not matchKey(source[1], str[1]) then
+ if not matchKey(source[1], state.ast[1]) then
return nil
end
- return util.viewString(str[1], source[2])
+ return util.viewString(state.ast[1], source[2])
end
local function mergeEnums(a, b, source)
@@ -2048,6 +2048,9 @@ local function completion(uri, position, triggerCharacter)
await.delay()
tracy.ZoneBeginN 'completion #1'
local state = files.getState(uri)
+ if not state then
+ return nil
+ end
results = {}
clearStack()
tracy.ZoneEnd()
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 92aa65d5..d204fff1 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -520,6 +520,9 @@ end
---@param mark? table
---@return table
function m.searchLiterals(source, field, mark)
+ if not source then
+ return nil
+ end
local defs = vm.getDefs(source, field)
local literals = {}
mark = mark or {}
@@ -541,6 +544,9 @@ function m.searchAndViewLiterals(source, field, mark)
return nil
end
local literals = m.searchLiterals(source, field, mark)
+ if not literals then
+ return nil
+ end
local view = m.viewLiterals(literals)
return view
end
@@ -559,10 +565,12 @@ function m.isTrue(source, mark)
if mark.isTrue[source] == nil then
mark.isTrue[source] = false
local literals = m.searchLiterals(source, nil, mark)
- for literal in pairs(literals) do
- if literal ~= false then
- mark.isTrue[source] = true
- break
+ if literals then
+ for literal in pairs(literals) do
+ if literal ~= false then
+ mark.isTrue[source] = true
+ break
+ end
end
end
end
diff --git a/script/library.lua b/script/library.lua
index 81242a91..daf91a38 100644
--- a/script/library.lua
+++ b/script/library.lua
@@ -221,8 +221,13 @@ local function initBuiltIn()
end
m.metaPath = metaPath:string()
m.metaPaths = {}
- if not fs.exists(metaPath) then
- fs.create_directories(metaPath)
+ local suc = xpcall(function ()
+ if not fs.exists(metaPath) then
+ fs.create_directories(metaPath)
+ end
+ end, log.error)
+ if not suc then
+ return
end
local out = fsu.dummyFS()
local templateDir = ROOT / 'meta' / 'template'
@@ -462,7 +467,9 @@ local function check3rd(uri)
if checkedUri(uri) then
if files.isLua(uri) then
local text = files.getText(uri)
- check3rdByWords(text, thirdConfigs)
+ if text then
+ check3rdByWords(text, thirdConfigs)
+ end
end
check3rdByFileName(uri, thirdConfigs)
end
diff --git a/script/log.lua b/script/log.lua
index c3bf02d4..90de895a 100644
--- a/script/log.lua
+++ b/script/log.lua
@@ -12,8 +12,6 @@ local mathModf = math.modf
local debugGetInfo = debug.getinfo
local ioStdErr = io.stderr
-_ENV = nil
-
local m = {}
m.file = nil
@@ -91,9 +89,6 @@ function m.raw(thd, level, msg, source, currentline, clock)
return
end
init_log_file()
- if not m.file then
- return ''
- end
local sec, ms = mathModf((m.startTime + clock) / 1000)
local timestr = osDate('%H:%M:%S', sec)
local agl = ''
@@ -107,11 +102,13 @@ function m.raw(thd, level, msg, source, currentline, clock)
buf = ('[%s.%03.f][%s]%s[#%d:%s:%s]: %s\n'):format(timestr, ms * 1000, level, agl, thd, trimSrc(source), currentline, msg)
end
m.size = m.size + #buf
- if m.size > m.maxSize then
- m.file:write(buf:sub(1, m.size - m.maxSize))
- m.file:write('[REACH MAX SIZE]')
- else
- m.file:write(buf)
+ if m.file then
+ if m.size > m.maxSize then
+ m.file:write(buf:sub(1, m.size - m.maxSize))
+ m.file:write('[REACH MAX SIZE]')
+ else
+ m.file:write(buf)
+ end
end
return buf
end
@@ -130,9 +127,11 @@ function m.init(root, path)
m.path = path:string()
m.prefixLen = #root:string()
m.size = 0
- if not fs.exists(path:parent_path()) then
- fs.create_directories(path:parent_path())
- end
+ pcall(function ()
+ if not fs.exists(path:parent_path()) then
+ fs.create_directories(path:parent_path())
+ end
+ end)
if lastBuf then
init_log_file()
if m.file then
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua
index a84a5028..15d2d600 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -942,7 +942,7 @@ local function parseShortString()
end
if not token then
stringIndex = stringIndex + 1
- stringPool[stringIndex] = ssub(Lua, currentOffset)
+ stringPool[stringIndex] = ssub(Lua, currentOffset or -1)
missSymbol(mark)
break
end