summaryrefslogtreecommitdiff
path: root/script/core
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-04 17:02:06 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-04 17:02:06 +0800
commitea009881054fe774a59f440db8da15ce0425a464 (patch)
tree46ad5a3b1ef0f86a44c940c4efbe4650b39b1b50 /script/core
parent6e7c082aa3e1011cdecd1761f7d04eabc0e2b8ba (diff)
downloadlua-language-server-ea009881054fe774a59f440db8da15ce0425a464.zip
fix runtime errors
Diffstat (limited to 'script/core')
-rw-r--r--script/core/diagnostics/newline-call.lua4
-rw-r--r--script/core/document-symbol.lua4
-rw-r--r--script/core/highlight.lua3
-rw-r--r--script/core/hint.lua3
-rw-r--r--script/core/reference.lua6
-rw-r--r--script/core/rename.lua3
-rw-r--r--script/core/workspace-symbol.lua8
7 files changed, 22 insertions, 9 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,