From 5aaecf51b9fccddf52ed3e4749757a03819fae61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 16 Jan 2023 21:06:06 +0800 Subject: support `---@meta [name]` once declared `name`, user can only require this file by declared name meta file can not be required with name `_` --- test/crossfile/completion.lua | 52 ++++++++++++++++++++++++++++++++++++++++++- test/crossfile/hover.lua | 49 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) (limited to 'test/crossfile') diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua index 3ad8c385..d613f621 100644 --- a/test/crossfile/completion.lua +++ b/test/crossfile/completion.lua @@ -10,6 +10,7 @@ local define = require 'proto.define' rawset(_G, 'TEST', true) local CompletionItemKind = define.CompletionItemKind +local NeedRemoveMeta = false local EXISTS = {} @@ -87,7 +88,9 @@ function TEST(data) assert(result ~= nil) result.complete = nil result.enableCommon = nil - removeMetas(result) + if NeedRemoveMeta then + removeMetas(result) + end for _, item in ipairs(result) do if item.id then local r = core.resolve(item.id) @@ -439,6 +442,51 @@ TEST { config.set(nil, 'Lua.runtime.path', originRuntimePath) +TEST { + { + path = 'abc.lua', + content = '---@meta _', + }, + { + path = 'test.lua', + content = 'require "a"', + main = true, + }, + completion = nil +} + +TEST { + { + path = 'abc.lua', + content = '---@meta xxxxx', + }, + { + path = 'test.lua', + content = 'require "a"', + main = true, + }, + completion = nil +} + +TEST { + { + path = 'abc.lua', + content = '---@meta xxxxx', + }, + { + path = 'test.lua', + content = 'require "xx"', + main = true, + }, + completion = { + { + label = 'xxxxx', + kind = CompletionItemKind.File, + textEdit = EXISTS, + } + } +} + TEST { { path = 'a.lua', @@ -561,6 +609,8 @@ TEST { completion = nil, } +NeedRemoveMeta = true + TEST { { path = 'f/a.lua' }, { path = 'f/b.lua' }, diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index d47bb41b..3cd560ff 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -173,6 +173,55 @@ TEST { } end +TEST { + { + path = 'a.lua', + content = '---@meta _', + }, + { + path = 'b.lua', + content = 'require ', + }, + hover = [[ +```lua +1 个字节 +```]], +} + +TEST { + { + path = 'a.lua', + content = '---@meta xxx', + }, + { + path = 'b.lua', + content = 'require ', + }, + hover = [[ +```lua +1 个字节 +```]], +} + +TEST { + { + path = 'a.lua', + content = '---@meta xxx', + }, + { + path = 'b.lua', + content = 'require ', + }, + hover = [=[ +```lua +3 个字节 +``` + +--- + +* [[meta]](file:///a.lua)]=], +} + TEST { { path = 'a.lua', -- cgit v1.2.3