diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-02-04 14:37:11 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-02-04 14:37:11 +0800 |
commit | cf2c5fee7f6f9b3e49930f34390671b9b267f9d7 (patch) | |
tree | 9a67aef06d01d6b8f880f44a7d71e4e0e44b6ec5 /script/core | |
parent | 35c898944ec53c102bf16ec14d6f72be2e567870 (diff) | |
download | lua-language-server-cf2c5fee7f6f9b3e49930f34390671b9b267f9d7.zip |
fix #378 add cache for finding class
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/undefined-doc-name.lua | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/script/core/diagnostics/undefined-doc-name.lua b/script/core/diagnostics/undefined-doc-name.lua index 5c1e8fbf..3d6c3cd8 100644 --- a/script/core/diagnostics/undefined-doc-name.lua +++ b/script/core/diagnostics/undefined-doc-name.lua @@ -4,27 +4,6 @@ local lang = require 'language' local define = require 'proto.define' local vm = require 'vm' -local function hasNameOfClassOrAlias(name) - local docs = vm.getDocTypes(name) - for _, otherDoc in ipairs(docs) do - if otherDoc.type == 'doc.class.name' - or otherDoc.type == 'doc.alias.name' then - return true - end - end - return false -end - -local function hasNameOfGeneric(name, source) - if not source.typeGeneric then - return false - end - if not source.typeGeneric[name] then - return false - end - return true -end - return function (uri, callback) local state = files.getAst(uri) if not state then @@ -35,6 +14,33 @@ return function (uri, callback) return end + local classCache = {} + local function hasNameOfClassOrAlias(name) + if classCache[name] ~= nil then + return classCache[name] + end + local docs = vm.getDocTypes(name) + for _, otherDoc in ipairs(docs) do + if otherDoc.type == 'doc.class.name' + or otherDoc.type == 'doc.alias.name' then + classCache[name] = true + return true + end + end + classCache[name] = false + return false + end + + local function hasNameOfGeneric(name, source) + if not source.typeGeneric then + return false + end + if not source.typeGeneric[name] then + return false + end + return true + end + guide.eachSource(state.ast.docs, function (source) if source.type ~= 'doc.extends.name' and source.type ~= 'doc.type.name' then |