summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-16 21:06:06 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-16 21:06:06 +0800
commit5aaecf51b9fccddf52ed3e4749757a03819fae61 (patch)
tree87ceb62c6eb926cb54d8ba794697f0d3ddd0b1e3 /script/vm
parenta6798e6adb81da6b7f833bc39da0a6368178a090 (diff)
downloadlua-language-server-5aaecf51b9fccddf52ed3e4749757a03819fae61.zip
support `---@meta [name]`
once declared `name`, user can only require this file by declared name meta file can not be required with name `_`
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/doc.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/script/vm/doc.lua b/script/vm/doc.lua
index f0f7c54c..a6ea248f 100644
--- a/script/vm/doc.lua
+++ b/script/vm/doc.lua
@@ -44,12 +44,38 @@ function vm.isMetaFile(uri)
for _, doc in ipairs(status.ast.docs) do
if doc.type == 'doc.meta' then
cache.isMeta = true
+ cache.metaName = doc.name
return true
end
end
return false
end
+---@param uri uri
+---@return string?
+function vm.getMetaName(uri)
+ if not vm.isMetaFile(uri) then
+ return nil
+ end
+ local cache = files.getCache(uri)
+ if not cache then
+ return nil
+ end
+ if not cache.metaName then
+ return nil
+ end
+ return cache.metaName[1]
+end
+
+---@param uri uri
+---@return boolean
+function vm.isMetaFileRequireable(uri)
+ if not vm.isMetaFile(uri) then
+ return false
+ end
+ return vm.getMetaName(uri) ~= '_'
+end
+
---@param doc parser.object
---@return table<string, boolean>?
function vm.getValidVersions(doc)