diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-17 18:32:11 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-17 18:32:11 +0800 |
commit | 2b434ab4f4a078773a27e205a60b63a9ae4efe1b (patch) | |
tree | c63f76d3fa15d5f5994759e3e3bc8aa6575d3a8b | |
parent | 54a97c8ebd12bee141eb5d0d0a3b92f9d411d0d5 (diff) | |
download | lua-language-server-2b434ab4f4a078773a27e205a60b63a9ae4efe1b.zip |
过所有测试
-rw-r--r-- | meta/template/basic.lua | 1 | ||||
-rw-r--r-- | script-beta/core/completion.lua | 64 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 1 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 32 | ||||
-rw-r--r-- | test-beta/signature/init.lua | 2 |
5 files changed, 77 insertions, 23 deletions
diff --git a/meta/template/basic.lua b/meta/template/basic.lua index 4b093b52..b8b052fe 100644 --- a/meta/template/basic.lua +++ b/meta/template/basic.lua @@ -10,6 +10,7 @@ arg = {} function assert(v, message) end ---@alias cgopt54 +---|>'"collect"' ---| '"stop"' ---| '"restart"' ---| '"count"' diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 6c8d9040..a1a35a92 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -352,6 +352,21 @@ local function checkFieldFromFieldToIndex(name, parent, word, start, offset) return textEdit, additionalTextEdits end +local function isDeprecated(value) + if value.deprecated then + return true + end + if not value.bindDocs then + return false + end + for _, doc in ipairs(value.bindDocs) do + if doc.type == 'doc.deprecated' then + return true + end + end + return false +end + local function checkFieldThen(name, src, word, start, offset, parent, oop, results) local value = guide.getObjectValue(src) or src local kind = define.CompletionItemKind.Field @@ -364,7 +379,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul buildFunction(results, src, oop, { label = name, kind = kind, - deprecated = value.deprecated, + deprecated = isDeprecated(value) or nil, id = stack(function () return { detail = buildDetail(src), @@ -680,6 +695,9 @@ local function checkUri(ast, text, offset, results) if files.eq(myUri, uri) then goto CONTINUE end + if vm.isMetaFile(uri) then + goto CONTINUE + end local path = workspace.getRelativePath(uri) local infos = rpath.getVisiblePath(path, config.config.runtime.path) for _, info in ipairs(infos) do @@ -692,17 +710,11 @@ local function checkUri(ast, text, offset, results) } } end - if vm.isMetaFile(uri) then - collect[info.expect][#collect[info.expect]+1] = ([=[* [[meta]](%s)]=]):format( - uri - ) - else - collect[info.expect][#collect[info.expect]+1] = ([=[* [%s](%s) %s]=]):format( - path, - uri, - lang.script('HOVER_USE_LUA_PATH', info.searcher) - ) - end + collect[info.expect][#collect[info.expect]+1] = ([=[* [%s](%s) %s]=]):format( + path, + uri, + lang.script('HOVER_USE_LUA_PATH', info.searcher) + ) end end ::CONTINUE:: @@ -714,6 +726,9 @@ local function checkUri(ast, text, offset, results) if files.eq(myUri, uri) then goto CONTINUE end + if vm.isMetaFile(uri) then + goto CONTINUE + end local path = workspace.getRelativePath(uri) if matchKey(literal, path) then if not collect[path] then @@ -918,10 +933,20 @@ local function getCallEnums(source, index) return enums end if source.type == 'function' and source.bindDocs then - local arg = source.args and source.args[index] - if not arg then + if not source.args then return end + local arg + if index <= #source.args then + arg = source.args[index] + else + local lastArg = source.args[#source.args] + if lastArg.type == '...' then + arg = lastArg + else + return + end + end for _, doc in ipairs(source.bindDocs) do if doc.type == 'doc.param' and doc.param[1] == arg[1] then @@ -934,6 +959,17 @@ local function getCallEnums(source, index) } end return enums + elseif doc.type == 'doc.vararg' + and arg.type == '...' then + local enums = {} + for _, enum in ipairs(vm.getDocEnums(doc.vararg)) do + enums[#enums+1] = { + label = enum[1], + description = enum.comment, + kind = define.CompletionItemKind.EnumMember, + } + end + return enums end end end diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 8324cfd0..e633cfaf 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1161,6 +1161,7 @@ function m.getSimple(obj, max) or obj.type == 'tableindex' or obj.type == 'select' or obj.type == 'table' + or obj.type == 'string' or obj.type == 'doc.class.name' or obj.type == 'doc.class' or obj.type == 'doc.type.name' then diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index e11bd0fb..a37ca753 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -329,6 +329,26 @@ do$ label = 'loadfile()', kind = define.CompletionItemKind.Snippet, }, + { + label = 'loadstring', + kind = define.CompletionItemKind.Function, + deprecated = true, + }, + { + label = 'loadstring()', + kind = define.CompletionItemKind.Snippet, + deprecated = true, + }, + { + label = 'module', + kind = define.CompletionItemKind.Function, + deprecated = true, + }, + { + label = 'module()', + kind = define.CompletionItemKind.Snippet, + deprecated = true, + }, } TEST [[ @@ -850,7 +870,7 @@ xx$ TEST [[ local index -tbl[ind$] +tbl[inde$] ]] { { @@ -1271,16 +1291,12 @@ TEST [[ } TEST [[ ----@class Class ----@param x C$ +---@class ZClass +---@param x ZC$ ]] { { - label = 'Class', - kind = define.CompletionItemKind.Class, - }, - { - label = 'function', + label = 'ZClass', kind = define.CompletionItemKind.Class, }, } diff --git a/test-beta/signature/init.lua b/test-beta/signature/init.lua index ee89bb3d..978bbe34 100644 --- a/test-beta/signature/init.lua +++ b/test-beta/signature/init.lua @@ -111,7 +111,7 @@ TEST [[ ]] { label = [[ -function string:sub(i: integer [, j: integer]) +function string:sub(i: integer, j: integer?) ]], arg = {21, 30}, } |