summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/completion.lua18
-rw-r--r--server/src/core/diagnostics.lua52
2 files changed, 69 insertions, 1 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 3162a48e..eb4e9a1d 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -324,6 +324,21 @@ local function searchCloseGlobal(vm, source, word, callback)
end)
end
+local function searchParams(vm, source, word, callback)
+ ---@type function
+ local func = source:get 'arg'
+ local emmyParams = func:getEmmyParams()
+ if not emmyParams then
+ return
+ end
+ for _, param in ipairs(emmyParams) do
+ local name = param:getName()
+ if matchKey(word, name) then
+ callback(name, param:getSource(), CompletionItemKind.Interface)
+ end
+ end
+end
+
local function searchKeyWords(vm, source, word, callback)
for _, key in ipairs(KEYS) do
if matchKey(word, key) then
@@ -387,6 +402,7 @@ local function searchAsLocal(vm, source, word, callback)
end
local function searchAsArg(vm, source, word, callback)
+ searchParams(vm, source, word, callback)
searchCloseGlobal(vm, source, word, callback)
end
@@ -422,7 +438,7 @@ local function searchEmmyFunctionParam(vm, source, word, callback)
end
for _, arg in ipairs(func.args) do
if matchKey(word, arg.name) then
- callback(arg.name, arg, CompletionItemKind.Unit)
+ callback(arg.name, arg, CompletionItemKind.Interface)
end
end
end
diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua
index 140873c5..f9d6f818 100644
--- a/server/src/core/diagnostics.lua
+++ b/server/src/core/diagnostics.lua
@@ -507,7 +507,57 @@ function mt:checkEmmyAlias(source, callback)
end
end
+function mt:checkEmmyParam(source, callback, mark)
+ local func = source:get 'emmy function'
+ if not func then
+ return
+ end
+ if mark[func] then
+ return
+ end
+ mark[func] = true
+
+ -- 检查不存在的参数
+ local emmyParams = func:getEmmyParams()
+ local funcParams = {}
+ if func.args then
+ for _, arg in ipairs(func.args) do
+ funcParams[arg.name] = true
+ end
+ end
+ for _, param in ipairs(emmyParams) do
+ local name = param:getName()
+ if not funcParams[name] then
+ callback(param:getSource()[1].start, param:getSource()[1].finish, lang.script.DIAG_INEXISTENT_PARAM)
+ end
+ end
+
+ -- 检查重复的param
+ local lists = {}
+ for _, param in ipairs(emmyParams) do
+ local name = param:getName()
+ if not lists[name] then
+ lists[name] = {}
+ end
+ lists[name][#lists[name]+1] = param:getSource()[1]
+ end
+ for _, list in pairs(lists) do
+ if #list > 1 then
+ local related = {}
+ for _, src in ipairs(list) do
+ related[#related+1] = {
+ src.start,
+ src.finish,
+ src.uri,
+ }
+ callback(src.start, src.finish, lang.script.DIAG_DUPLICATE_PARAM)
+ end
+ end
+ end
+end
+
function mt:searchEmmyLua(callback)
+ local mark = {}
self.vm:eachSource(function (source)
if source.type == 'emmyClass' then
self:checkEmmyClass(source, callback)
@@ -515,6 +565,8 @@ function mt:searchEmmyLua(callback)
self:checkEmmyType(source, callback)
elseif source.type == 'emmyAlias' then
self:checkEmmyAlias(source, callback)
+ elseif source.type == 'emmyParam' then
+ self:checkEmmyParam(source, callback, mark)
end
end)
end