diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-02-04 17:02:06 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-02-04 17:02:06 +0800 |
commit | ea009881054fe774a59f440db8da15ce0425a464 (patch) | |
tree | 46ad5a3b1ef0f86a44c940c4efbe4650b39b1b50 /script | |
parent | 6e7c082aa3e1011cdecd1761f7d04eabc0e2b8ba (diff) | |
download | lua-language-server-ea009881054fe774a59f440db8da15ce0425a464.zip |
fix runtime errors
Diffstat (limited to 'script')
-rw-r--r-- | script/core/diagnostics/newline-call.lua | 4 | ||||
-rw-r--r-- | script/core/document-symbol.lua | 4 | ||||
-rw-r--r-- | script/core/highlight.lua | 3 | ||||
-rw-r--r-- | script/core/hint.lua | 3 | ||||
-rw-r--r-- | script/core/reference.lua | 6 | ||||
-rw-r--r-- | script/core/rename.lua | 3 | ||||
-rw-r--r-- | script/core/workspace-symbol.lua | 8 | ||||
-rw-r--r-- | script/files.lua | 7 | ||||
-rw-r--r-- | script/parser/guide.lua | 2 | ||||
-rw-r--r-- | script/string-merger.lua | 6 | ||||
-rw-r--r-- | script/vm/getDocs.lua | 3 | ||||
-rw-r--r-- | script/vm/guideInterface.lua | 2 |
12 files changed, 38 insertions, 13 deletions
diff --git a/script/core/diagnostics/newline-call.lua b/script/core/diagnostics/newline-call.lua index cb318380..ee08cc35 100644 --- a/script/core/diagnostics/newline-call.lua +++ b/script/core/diagnostics/newline-call.lua @@ -4,10 +4,10 @@ local lang = require 'language' return function (uri, callback) local ast = files.getAst(uri) - if not ast then + local lines = files.getLines(uri) + if not ast or not lines then return end - local lines = files.getLines(uri) guide.eachSourceType(ast.ast, 'call', function (source) local node = source.node diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua index f06e613c..3bfc744c 100644 --- a/script/core/document-symbol.lua +++ b/script/core/document-symbol.lua @@ -222,11 +222,11 @@ end local function makeSymbol(uri) local ast = files.getAst(uri) - if not ast then + local text = files.getText(uri) + if not ast or not text then return nil end - local text = files.getText(uri) local symbols = {} local used = {} guide.eachSource(ast.ast, function (source) diff --git a/script/core/highlight.lua b/script/core/highlight.lua index 86b9315a..07481927 100644 --- a/script/core/highlight.lua +++ b/script/core/highlight.lua @@ -229,6 +229,9 @@ return function (uri, offset) else return end + if not target then + return + end if mark[target] then return end diff --git a/script/core/hint.lua b/script/core/hint.lua index aa39812f..737d03aa 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -43,6 +43,9 @@ local function typeHint(uri, edits, start, finish) elseif source.type == 'tableindex' then src = source.index end + if not src then + return + end edits[#edits+1] = { newText = (':%s'):format(infer), start = src.finish, diff --git a/script/core/reference.lua b/script/core/reference.lua index f828e0cb..64dd6268 100644 --- a/script/core/reference.lua +++ b/script/core/reference.lua @@ -93,9 +93,13 @@ return function (uri, offset) elseif src.type == 'table' and src.parent.type ~= 'return' then goto CONTINUE end + local ouri = files.getOriginUri(root.uri) + if not ouri then + goto CONTINUE + end results[#results+1] = { target = src, - uri = files.getOriginUri(root.uri), + uri = ouri, } ::CONTINUE:: end diff --git a/script/core/rename.lua b/script/core/rename.lua index 3f73c338..6df3778e 100644 --- a/script/core/rename.lua +++ b/script/core/rename.lua @@ -453,6 +453,9 @@ function m.rename(uri, pos, newname) rename(source, newname, function (target, start, finish, text) local turi = files.getOriginUri(guide.getUri(target)) + if not turi then + return + end local uid = turi .. start if mark[uid] then return diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua index 4fc6a854..86b644d3 100644 --- a/script/core/workspace-symbol.lua +++ b/script/core/workspace-symbol.lua @@ -20,8 +20,8 @@ local function buildSource(uri, source, key, results) elseif source.type == 'setfield' or source.type == 'tablefield' then local field = source.field - local name = field[1] - if matchKey(key, name) then + local name = field and field[1] + if name and matchKey(key, name) then results[#results+1] = { name = name, kind = define.SymbolKind.Field, @@ -31,8 +31,8 @@ local function buildSource(uri, source, key, results) end elseif source.type == 'setmethod' then local method = source.method - local name = method[1] - if matchKey(key, name) then + local name = method and method[1] + if name and matchKey(key, name) then results[#results+1] = { name = name, kind = define.SymbolKind.Method, diff --git a/script/files.lua b/script/files.lua index 2e0c2666..e233846c 100644 --- a/script/files.lua +++ b/script/files.lua @@ -229,8 +229,11 @@ function m.remove(uri) if not file then return end - m.fileMap[uri] = nil - m._pairsCache = nil + m.fileMap[uri] = nil + m.astMap[uri] = nil + m.linesMap[uri] = nil + m.originLinesMap[uri] = nil + m._pairsCache = nil m.flushFileCache(uri) m.fileCount = m.fileCount - 1 diff --git a/script/parser/guide.lua b/script/parser/guide.lua index f7bbb9eb..28ff828b 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1473,7 +1473,7 @@ function m.getObjectValue(obj) end if obj.type == 'call' then if obj.node.special == 'rawset' then - return obj.args[3] + return obj.args and obj.args[3] else return obj end diff --git a/script/string-merger.lua b/script/string-merger.lua index e6650f04..f84fb34e 100644 --- a/script/string-merger.lua +++ b/script/string-merger.lua @@ -81,6 +81,9 @@ end ---@return integer function m.getOffset(info, offset) local diff = getNearDiff(info, offset, 'start') + if not diff then + return offset + end if offset <= diff.finish then return diff.cstart end @@ -93,6 +96,9 @@ end ---@return integer function m.getOffsetBack(info, offset) local diff = getNearDiff(info, offset, 'cstart') + if not diff then + return offset + end if offset <= diff.cfinish then return diff.start end diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 790a9b50..9fd2f519 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -84,6 +84,9 @@ function vm.getDocEnums(doc, mark, results) end function vm.getDocTypeUnits(doc, mark, results) + if not doc then + return nil + end mark = mark or {} if mark[doc] then return nil diff --git a/script/vm/guideInterface.lua b/script/vm/guideInterface.lua index 323ef76e..473d1bef 100644 --- a/script/vm/guideInterface.lua +++ b/script/vm/guideInterface.lua @@ -42,7 +42,7 @@ function m.require(args, index) end function m.dofile(args, index) - local reqName = args[1] and args[1][1] + local reqName = args and args[1] and args[1][1] if not reqName then return end |