From 5a9dd92de2e1caed7cc66c6448a0ee951b47bd4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 17 Nov 2020 14:45:49 +0800 Subject: =?UTF-8?q?=E8=BF=98=E6=98=AF=E5=BE=97=E6=8A=8A=E5=BA=93=E5=90=8D?= =?UTF-8?q?=E4=B8=8E=E7=B1=BB=E5=9E=8B=E5=90=8D=E5=8C=BA=E5=88=86=E5=BC=80?= =?UTF-8?q?=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- meta/template/bit32.lua | 2 +- meta/template/coroutine.lua | 2 +- meta/template/debug.lua | 2 +- meta/template/file.lua | 2 +- meta/template/io.lua | 28 ++++++++++++++-------------- meta/template/math.lua | 2 +- meta/template/os.lua | 2 +- meta/template/package.lua | 2 +- meta/template/string.lua | 2 +- meta/template/table.lua | 1 + meta/template/utf8.lua | 2 +- script-beta/core/hover/name.lua | 3 +++ script-beta/parser/guide.lua | 12 ++++++++++-- script-beta/parser/luadoc.lua | 2 +- test-beta/hover/init.lua | 26 ++++++++++++++++---------- test-beta/type_inference/init.lua | 4 ++-- 16 files changed, 56 insertions(+), 38 deletions(-) diff --git a/meta/template/bit32.lua b/meta/template/bit32.lua index 636abf20..e45644a3 100644 --- a/meta/template/bit32.lua +++ b/meta/template/bit32.lua @@ -1,6 +1,6 @@ ---@meta ----@class bit32 +---@class bit32* bit32 = {} ---@param x integer diff --git a/meta/template/coroutine.lua b/meta/template/coroutine.lua index 013b883f..04b1a477 100644 --- a/meta/template/coroutine.lua +++ b/meta/template/coroutine.lua @@ -1,6 +1,6 @@ ---@meta ----@class coroutine +---@class coroutine* coroutine = {} ---@param f function diff --git a/meta/template/debug.lua b/meta/template/debug.lua index 94b9af49..87f9c118 100644 --- a/meta/template/debug.lua +++ b/meta/template/debug.lua @@ -1,6 +1,6 @@ ---@meta ----@class debug +---@class debug* debug = {} ---@class debuginfo diff --git a/meta/template/file.lua b/meta/template/file.lua index 763ae3ed..002db560 100644 --- a/meta/template/file.lua +++ b/meta/template/file.lua @@ -1,6 +1,6 @@ ---@meta ----@class file +---@class file* local file = {} ---@alias readmode number diff --git a/meta/template/io.lua b/meta/template/io.lua index 1576c2b6..4adb252a 100644 --- a/meta/template/io.lua +++ b/meta/template/io.lua @@ -1,9 +1,9 @@ ---@meta ----@class io ----@field stdin file ----@field stdout file ----@field stderr file +---@class io* +---@field stdin file* +---@field stdout file* +---@field stderr file* io = {} ---@alias openmode @@ -20,7 +20,7 @@ io = {} ---| '"w+b"' ---| '"a+b"' ----@param file file? +---@param file file*? ---@return boolean suc? ---@return exitcode exitcode? ---@return integer code? @@ -28,8 +28,8 @@ function io.close(file) end function io.flush() end ----@overload fun():file ----@param file string|file +---@overload fun():file* +---@param file string|file* function io.input(file) end ---@param filename string? @@ -39,12 +39,12 @@ function io.lines(filename, ...) end ---@param filename string ---@param mode openmode ----@return file? +---@return file*? ---@return string errmsg? function io.open(filename, mode) end ----@overload fun():file ----@param file string|file +---@overload fun():file* +---@param file string|file* function io.output(file) end ---@alias popenmode @@ -53,7 +53,7 @@ function io.output(file) end ---@param prog string ---@param mode popenmode? ----@return file? +---@return file*? ---@return string errmsg? function io.popen(prog, mode) end @@ -62,18 +62,18 @@ function io.popen(prog, mode) end ---@return ... function io.read(...) end ----@return file +---@return file* function io.tmpfile() end ---@alias filetype ---| '"file"' ---| '"closed file"' ---| 'nil' ----@param file file +---@param file file* ---@return filetype function io.type(file) end ----@return file +---@return file* ---@return string errmsg? function io.write(...) end diff --git a/meta/template/math.lua b/meta/template/math.lua index 39f2cbe7..ad008b0e 100644 --- a/meta/template/math.lua +++ b/meta/template/math.lua @@ -1,6 +1,6 @@ ---@meta ----@class math +---@class math* ---@field huge number ---@field maxinteger integer ---@field mininteger integer diff --git a/meta/template/os.lua b/meta/template/os.lua index e2694372..aabd9fc2 100644 --- a/meta/template/os.lua +++ b/meta/template/os.lua @@ -1,6 +1,6 @@ ---@meta ----@class os +---@class os* os = {} ---@return number diff --git a/meta/template/package.lua b/meta/template/package.lua index a7be0599..db9ec830 100644 --- a/meta/template/package.lua +++ b/meta/template/package.lua @@ -1,6 +1,6 @@ ---@meta ----@class package +---@class package* ---@field conifg string ---@field cpath string ---@field loaded table diff --git a/meta/template/string.lua b/meta/template/string.lua index 54891666..04a58456 100644 --- a/meta/template/string.lua +++ b/meta/template/string.lua @@ -1,6 +1,6 @@ ---@meta ----@class string +---@class string* string = {} ---@param s string diff --git a/meta/template/table.lua b/meta/template/table.lua index 1cb2de96..7e77fc36 100644 --- a/meta/template/table.lua +++ b/meta/template/table.lua @@ -1,5 +1,6 @@ ---@meta +---@class table* table = {} ---@param list table diff --git a/meta/template/utf8.lua b/meta/template/utf8.lua index 52bea1cc..4ce0690a 100644 --- a/meta/template/utf8.lua +++ b/meta/template/utf8.lua @@ -1,6 +1,6 @@ ---@meta ----@class utf8 +---@class utf8* ---@field charpattern string utf8 = {} diff --git a/script-beta/core/hover/name.lua b/script-beta/core/hover/name.lua index 8394a75b..230de253 100644 --- a/script-beta/core/hover/name.lua +++ b/script-beta/core/hover/name.lua @@ -20,6 +20,9 @@ local function asField(source, oop) local class = vm.getClass(source.node, 'deep') local node = class or guide.getName(source.node) or '?' local method = guide.getName(source) + if node:sub(-1) == '*' then + node = node:sub(1, -2) + end if oop then return ('%s:%s'):format(node, method) else diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 0c29c96a..a3e18863 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -937,6 +937,10 @@ local function stepRefOfDocType(status, obj, mode) or obj.type == 'doc.type.name' or obj.type == 'doc.alias.name' or obj.type == 'doc.extends.name' then + if obj.array + or obj.generic then + return results + end local name = obj[1] if not name or not status.interface.docType then return results @@ -1076,6 +1080,9 @@ local function convertSimpleList(list) simple[#simple+1] = m.getSimpleName(c) ::CONTINUE:: end + if simple.mode == 'global' and #simple == 0 then + simple[1] = 's|_G' + end return simple end @@ -2046,7 +2053,7 @@ function m.checkSameSimpleInString(status, ref, start, queue, mode) return end local newStatus = m.status(status) - local docs = status.interface.docType(ref.type) + local docs = status.interface.docType('string*') local mark = {} for i = 1, #docs do local doc = docs[i] @@ -2586,7 +2593,8 @@ function m.viewInferType(infers) local infer = infers[i] if infer.source.type == 'doc.class' or infer.source.type == 'doc.class.name' - or infer.source.type == 'doc.type.name' then + or infer.source.type == 'doc.type.name' + or infer.source.type == 'doc.type.enum' then local tp = infer.type or 'any' if not mark[tp] then types[#types+1] = tp diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index 74acfaf2..06edf24c 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -12,7 +12,7 @@ Sp <- %s+ X16 <- [a-fA-F0-9] Word <- [a-zA-Z0-9_] Token <- Name / String / Symbol -Name <- ({} {[a-zA-Z_] [a-zA-Z0-9_.]*} {}) +Name <- ({} {[a-zA-Z_] [a-zA-Z0-9_.*]*} {}) -> Name String <- ({} StringDef {}) -> String diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index b12a9206..6b316919 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -498,7 +498,7 @@ TEST [[ print() ]] [[ -global utf8: utf8 { +global utf8: utf8* { char: function, charpattern: string, codepoint: function, @@ -512,7 +512,7 @@ TEST [[ print(io.) ]] [[ -global io.stderr: file { +global io.stderr: file* { close: function, flush: function, lines: function, @@ -527,7 +527,7 @@ TEST [[ print() ]] [[ -global io: io { +global io: io* { close: function, flush: function, input: function, @@ -536,9 +536,9 @@ global io: io { output: function, popen: function, read: function, - stderr: file, - stdin: file, - stdout: file, + stderr: file*, + stdin: file*, + stdout: file*, tmpfile: function, type: function, write: function, @@ -549,7 +549,7 @@ TEST [[ local = require 'utf8' ]] [[ -local sssss: utf8 { +local sssss: utf8* { char: function, charpattern: string, codepoint: function, @@ -775,7 +775,7 @@ local = { ]] [[ local t: { - f: file, + f: file*, } ]] @@ -784,7 +784,7 @@ io.() ]] [[ function io.popen(prog: string, mode: "r"|"w"?) - -> file? + -> file*? 2. errmsg: string? ]] @@ -793,21 +793,25 @@ TEST [[ ]] [[ global _G: _G { - _G: table, + _G: _G, _VERSION: string = "Lua 5.4", arg: table, assert: function, + bit32: table, collectgarbage: function, coroutine: table, debug: table, dofile: function, error: function, + getfenv: function, getmetatable: function, io: table, ipairs: function, load: function, loadfile: function, + loadstring: function, math: table, + module: function, next: function, os: table, package: table, @@ -820,12 +824,14 @@ global _G: _G { rawset: function, require: function, select: function, + setfenv: function, setmetatable: function, string: table, table: table, tonumber: function, tostring: function, type: function, + unpack: function, utf8: table, warn: function, xpcall: function, diff --git a/test-beta/type_inference/init.lua b/test-beta/type_inference/init.lua index edbe0fe2..1b610bb3 100644 --- a/test-beta/type_inference/init.lua +++ b/test-beta/type_inference/init.lua @@ -139,7 +139,7 @@ TEST 'number' [[ = a + b ]] -TEST 'table' [[ +TEST 'table*' [[ () ]] @@ -200,7 +200,7 @@ end _, = pcall(x) ]] -TEST 'os' [[ +TEST 'os*' [[ local = require 'os' ]] -- cgit v1.2.3