From 88b155930b1fe6a8cf086c55ea3b108c8b1f0e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sun, 10 Apr 2022 02:53:51 +0800 Subject: fix repeated docname --- script/core/completion/completion.lua | 12 ++++++++++-- test/completion/common.lua | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index e6f07b7b..27d1b20a 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1671,9 +1671,12 @@ end local function tryluaDocByErr(state, position, err, docState, results) if err.type == 'LUADOC_MISS_CLASS_EXTENDS_NAME' then + local used = {} for _, doc in ipairs(vm.getDocSets(state.uri)) do if doc.type == 'doc.class' + and not used[doc.class[1]] and doc.class[1] ~= docState.class[1] then + used[doc.class[1]] = true results[#results+1] = { label = doc.class[1], kind = define.CompletionItemKind.Class, @@ -1681,14 +1684,19 @@ local function tryluaDocByErr(state, position, err, docState, results) end end elseif err.type == 'LUADOC_MISS_TYPE_NAME' then + local used = {} for _, doc in ipairs(vm.getDocSets(state.uri)) do - if doc.type == 'doc.class' then + if doc.type == 'doc.class' + and not used[doc.class[1]] then + used[doc.class[1]] = true results[#results+1] = { label = doc.class[1], kind = define.CompletionItemKind.Class, } end - if doc.type == 'doc.alias' then + if doc.type == 'doc.alias' + and not used[doc.alias[1]] then + used[doc.alias[1]] = true results[#results+1] = { label = doc.alias[1], kind = define.CompletionItemKind.Class, diff --git a/test/completion/common.lua b/test/completion/common.lua index 0d00ddf9..5ee2b844 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -3292,3 +3292,22 @@ local t = x[] assert(res.label ~= 'do') end end) + +TEST [[ +---@class ZZZZZ.XXXX +---@class ZZZZZ.XXXX +---@class ZZZZZ.XXXX +---@class ZZZZZ.XXXX +---@class ZZZZZ.XXXX + +---@type +]] +(function (results) + local count = 0 + for _, res in ipairs(results) do + if res.label == 'ZZZZZ.XXXX' then + count = count + 1 + end + end + assert(count == 1) +end) -- cgit v1.2.3