diff options
-rw-r--r-- | script-beta/core/completion.lua | 22 | ||||
-rw-r--r-- | script-beta/vm/getDocs.lua | 34 |
2 files changed, 35 insertions, 21 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 1a7267ce..479d6ab4 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -356,26 +356,6 @@ 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 - elseif doc.type == 'doc.version' then - local valids = vm.getValidVersions(doc) - if not valids[config.config.runtime.version] then - return true - end - 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 @@ -388,7 +368,7 @@ local function checkFieldThen(name, src, word, start, offset, parent, oop, resul buildFunction(results, src, oop, { label = name, kind = kind, - deprecated = isDeprecated(value) or nil, + deprecated = vm.isDeprecated(value) or nil, id = stack(function () return { detail = buildDetail(src), diff --git a/script-beta/vm/getDocs.lua b/script-beta/vm/getDocs.lua index 5e023572..cbc0eff0 100644 --- a/script-beta/vm/getDocs.lua +++ b/script-beta/vm/getDocs.lua @@ -2,6 +2,7 @@ local files = require 'files' local util = require 'utility' local guide = require 'parser.guide' local vm = require 'vm.vm' +local config = require 'config' local function getTypesOfFile(uri) local types = {} @@ -142,3 +143,36 @@ function vm.getValidVersions(doc) end return valids end + +local function isDeprecated(value) + if not value.bindDocs then + return false + end + for _, doc in ipairs(value.bindDocs) do + if doc.type == 'doc.deprecated' then + return true + elseif doc.type == 'doc.version' then + local valids = vm.getValidVersions(doc) + if not valids[config.config.runtime.version] then + return true + end + end + end + return false +end + +function vm.isDeprecated(value) + if isDeprecated(value) then + return true + end + local defs = vm.getDefs(value, 'deep') + if #defs == 0 then + return false + end + for _, def in ipairs(defs) do + if not isDeprecated(def) then + return false + end + end + return true +end |