diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-16 21:04:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-16 21:04:34 +0800 |
commit | be5b3c282faa214bf75f0d719d7a0d809bc09aa1 (patch) | |
tree | 01ef7bd7f499bd78d96e740ad74886e42d10f9bf /script/vm | |
parent | 23eac92eb9e6cb133336f67e104c00b9f200cb5b (diff) | |
download | lua-language-server-be5b3c282faa214bf75f0d719d7a0d809bc09aa1.zip |
improve
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/docs.lua | 4 | ||||
-rw-r--r-- | script/vm/getDocs.lua | 58 | ||||
-rw-r--r-- | script/vm/globals.lua | 1 | ||||
-rw-r--r-- | script/vm/vm.lua | 7 |
4 files changed, 62 insertions, 8 deletions
diff --git a/script/vm/docs.lua b/script/vm/docs.lua index 95cb4127..df87d46a 100644 --- a/script/vm/docs.lua +++ b/script/vm/docs.lua @@ -1,5 +1,4 @@ local files = require 'files' -local await = require 'await' local noder = require 'core.noder' local docsMap = {} @@ -25,7 +24,8 @@ local function pushDocs(uri) end local nodes = noder.compileNodes(state.ast) for id in pairs(nodes) do - if id:sub(1, 3) == 'dn:' then + if id:sub(1, 3) == 'dn:' + and noder.getFirstID(id) == id then if not docsMap[id] then docsMap[id] = {} end diff --git a/script/vm/getDocs.lua b/script/vm/getDocs.lua index 0f12c763..bf99a247 100644 --- a/script/vm/getDocs.lua +++ b/script/vm/getDocs.lua @@ -3,7 +3,9 @@ local guide = require 'parser.guide' ---@type vm local vm = require 'vm.vm' local config = require 'config' -local searcher = require 'core.searcher' +local docs = require 'vm.docs' +local define = require 'proto.define' +local noder = require 'core.noder' local function getDocDefinesInAst(results, root, name) for _, doc in ipairs(root.docs) do @@ -24,15 +26,61 @@ end ---@return parser.guide.object[] function vm.getDocDefines(name) local results = {} - for uri in files.eachFile() do - local state = files.getState(uri) - if state then - getDocDefinesInAst(results, state.ast, name) + if name then + local id = 'dn:' .. name + local uris = docs.getUrisByID(id) + if not uris then + return results + end + for uri in pairs(uris) do + local state = files.getState(uri) + if state then + getDocDefinesInAst(results, state.ast, name) + end + end + else + for uri in files.eachFile() do + local state = files.getState(uri) + if state then + getDocDefinesInAst(results, state.ast, name) + end end end return results end +function vm.isDocDefined(name) + if define.BuiltinClass[name] then + return true + end + local cache = vm.getCache 'isDocDefined' + if cache[name] ~= nil then + return cache[name] + end + local id = 'dn:' .. name + local uris = docs.getUrisByID(id) + if not uris then + cache[name] = false + return + end + for uri in pairs(uris) do + local state = files.getState(uri) + local node = noder.getNodeByID(state.ast, id) + if node and node.sources then + for _, source in ipairs(node.sources) do + local doc = source.parent + if doc.type == 'doc.class' + or doc.type == 'doc.alias' then + cache[name] = true + return true + end + end + end + end + cache[name] = false + return false +end + function vm.getDocEnums(doc) if not doc then return nil diff --git a/script/vm/globals.lua b/script/vm/globals.lua index cb759551..3c74f8b0 100644 --- a/script/vm/globals.lua +++ b/script/vm/globals.lua @@ -1,5 +1,4 @@ local files = require 'files' -local await = require 'await' local noder = require 'core.noder' local globalsMap = {} diff --git a/script/vm/vm.lua b/script/vm/vm.lua index ebd0102b..0e7f3176 100644 --- a/script/vm/vm.lua +++ b/script/vm/vm.lua @@ -59,6 +59,13 @@ function m.getArgInfo(source) return nil end +function m.getSpecial(source) + if not source then + return nil + end + return source.special +end + function m.getKeyName(source) if not source then return nil |