diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-20 16:58:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-20 16:58:57 +0800 |
commit | 135f38d1b4f4d7b989f738bead5b59bdaf58f7e1 (patch) | |
tree | 0057af75111840f34da65a43cd8df8ce92f63f85 /script-beta/vm/getDocs.lua | |
parent | bb319039fdf41326f23ef0c7288123889434b0a8 (diff) | |
download | lua-language-server-135f38d1b4f4d7b989f738bead5b59bdaf58f7e1.zip |
luadoc的第一步
Diffstat (limited to 'script-beta/vm/getDocs.lua')
-rw-r--r-- | script-beta/vm/getDocs.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/script-beta/vm/getDocs.lua b/script-beta/vm/getDocs.lua new file mode 100644 index 00000000..5c8e6304 --- /dev/null +++ b/script-beta/vm/getDocs.lua @@ -0,0 +1,58 @@ +local files = require 'files' +local util = require 'utility' +local guide = require 'parser.guide' +local vm = require 'vm.vm' + +local function getTypesOfFile(uri) + local classes = {} + local ast = files.getAst(uri) + if not ast or not ast.ast.docs then + return classes + end + guide.eachSource(ast.ast.docs, function (src) + if src.type == 'doc.type.name' + or src.type == 'doc.class.name' + or src.type == 'doc.extends.name' then + local name = src[1] + if name then + if not classes[name] then + classes[name] = {} + end + classes[name][#classes[name]+1] = src + end + end + end) + return classes +end + +local function getDocTypes(name) + local results = {} + for uri in files.eachFile() do + local cache = files.getCache(uri) + cache.classes = cache.classes or getTypesOfFile(uri) + if name == '*' then + for _, sources in util.sortPairs(cache.classes) do + for _, source in ipairs(sources) do + results[#results+1] = source + end + end + else + if cache.classes[name] then + for _, source in ipairs(cache.classes[name]) do + results[#results+1] = source + end + end + end + end + return results +end + +function vm.getDocTypes(name) + local cache = vm.getCache('getDocTypes')[name] + if cache ~= nil then + return cache + end + cache = getDocTypes(name) + vm.getCache('getDocTypes')[name] = cache + return cache +end |