diff options
-rw-r--r-- | meta/template/basic.lua | 54 | ||||
-rw-r--r-- | meta/template/debug.lua | 24 | ||||
-rw-r--r-- | meta/template/io.lua | 64 | ||||
-rw-r--r-- | meta/template/os.lua | 12 | ||||
-rw-r--r-- | script/core/completion/completion.lua | 12 | ||||
-rw-r--r-- | script/vm/compiler.lua | 3 | ||||
-rw-r--r-- | script/vm/infer.lua | 7 | ||||
-rw-r--r-- | test/completion/common.lua | 18 | ||||
-rw-r--r-- | test/hover/init.lua | 38 |
9 files changed, 117 insertions, 115 deletions
diff --git a/meta/template/basic.lua b/meta/template/basic.lua index f3ebae94..f2f6a49c 100644 --- a/meta/template/basic.lua +++ b/meta/template/basic.lua @@ -13,18 +13,18 @@ arg = {} function assert(v, message, ...) end ---@alias gcoptions ----|>'"collect"' # ---#DESTAIL 'cgopt.collect' ----| '"stop"' # ---#DESTAIL 'cgopt.stop' ----| '"restart"' # ---#DESTAIL 'cgopt.restart' ----| '"count"' # ---#DESTAIL 'cgopt.count' ----| '"step"' # ---#DESTAIL 'cgopt.step' ----| '"isrunning"' # ---#DESTAIL 'cgopt.isrunning' +---|>"collect" # ---#DESTAIL 'cgopt.collect' +---| "stop" # ---#DESTAIL 'cgopt.stop' +---| "restart" # ---#DESTAIL 'cgopt.restart' +---| "count" # ---#DESTAIL 'cgopt.count' +---| "step" # ---#DESTAIL 'cgopt.step' +---| "isrunning" # ---#DESTAIL 'cgopt.isrunning' ---#if VERSION >= 5.4 then ----| '"incremental"' # ---#DESTAIL 'cgopt.incremental' ----| '"generational"' # ---#DESTAIL 'cgopt.generational' +---| "incremental" # ---#DESTAIL 'cgopt.incremental' +---| "generational" # ---#DESTAIL 'cgopt.generational' ---#else ----| '"setpause"' # ---#DESTAIL 'cgopt.setpause' ----| '"setstepmul"' # ---#DESTAIL 'cgopt.setstepmul' +---| "setpause" # ---#DESTAIL 'cgopt.setpause' +---| "setstepmul" # ---#DESTAIL 'cgopt.setstepmul' ---#end ---#if VERSION >= 5.4 then @@ -76,9 +76,9 @@ function getmetatable(object) end function ipairs(t) end ---@alias loadmode ----| '"b"' # ---#DESTAIL 'loadmode.b' ----| '"t"' # ---#DESTAIL 'loadmode.t' ----|>'"bt"' # ---#DESTAIL 'loadmode.bt' +---| "b" # ---#DESTAIL 'loadmode.b' +---| "t" # ---#DESTAIL 'loadmode.t' +---|>"bt" # ---#DESTAIL 'loadmode.bt' ---#if VERSION <= 5.1 and not JIT then ---#DES 'load<5.1' @@ -197,7 +197,7 @@ function rawlen(v) end function rawset(table, index, value) end ---#DES 'select' ----@param index integer|'"#"' +---@param index integer|"#" ---@return any ---@nodiscard function select(index, ...) end @@ -229,16 +229,16 @@ function tonumber(e) end function tostring(v) end ---@alias type ----| '"nil"' ----| '"number"' ----| '"string"' ----| '"boolean"' ----| '"table"' ----| '"function"' ----| '"thread"' ----| '"userdata"' +---| "nil" +---| "number" +---| "string" +---| "boolean" +---| "table" +---| "function" +---| "thread" +---| "userdata" ---#if VERSION == JIT then ----| '"cdata"' +---| "cdata" ---#end ---#DES 'type' @@ -249,13 +249,13 @@ function type(v) end ---#DES '_VERSION' ---#if VERSION == 5.1 then -_VERSION = 'Lua 5.1' +_VERSION = "Lua 5.1" ---#elseif VERSION == 5.2 then -_VERSION = 'Lua 5.2' +_VERSION = "Lua 5.2" ---#elseif VERSION == 5.3 then -_VERSION = 'Lua 5.3' +_VERSION = "Lua 5.3" ---#elseif VERSION == 5.4 then -_VERSION = 'Lua 5.4' +_VERSION = "Lua 5.4" ---#end ---@version >5.4 diff --git a/meta/template/debug.lua b/meta/template/debug.lua index e7ac5911..9f48ee98 100644 --- a/meta/template/debug.lua +++ b/meta/template/debug.lua @@ -45,20 +45,20 @@ function debug.getfenv(o) end function debug.gethook(co) end ---@alias infowhat string ----|+'"n"' # ---#DESTAIL 'infowhat.n' ----|+'"S"' # ---#DESTAIL 'infowhat.S' ----|+'"l"' # ---#DESTAIL 'infowhat.l' ----|+'"t"' # ---#DESTAIL 'infowhat.t' +---|+"n" # ---#DESTAIL 'infowhat.n' +---|+"S" # ---#DESTAIL 'infowhat.S' +---|+"l" # ---#DESTAIL 'infowhat.l' +---|+"t" # ---#DESTAIL 'infowhat.t' ---#if VERSION <= 5.1 and not JIT then ----|+'"u"' # ---#DESTAIL 'infowhat.u<5.1' +---|+"u" # ---#DESTAIL 'infowhat.u<5.1' ---#else ----|+'"u"' # ---#DESTAIL 'infowhat.u>5.2' +---|+"u" # ---#DESTAIL 'infowhat.u>5.2' ---#end ----|+'"f"' # ---#DESTAIL 'infowhat.f' +---|+"f" # ---#DESTAIL 'infowhat.f' ---#if VERSION >= 5.4 then ----|+'"r"' # ---#DESTAIL 'infowhat.r' +---|+"r" # ---#DESTAIL 'infowhat.r' ---#end ----|+'"L"' # ---#DESTAIL 'infowhat.L' +---|+"L" # ---#DESTAIL 'infowhat.L' ---#DES 'debug.getinfo' ---@overload fun(f: integer|function, what?: infowhat):debuginfo @@ -141,9 +141,9 @@ function debug.setcstacklimit(limit) end function debug.setfenv(object, env) end ---@alias hookmask string ----|+'"c"' # ---#DESTAIL 'hookmask.c' ----|+'"r"' # ---#DESTAIL 'hookmask.r' ----|+'"l"' # ---#DESTAIL 'hookmask.l' +---|+"c" # ---#DESTAIL 'hookmask.c' +---|+"r" # ---#DESTAIL 'hookmask.r' +---|+"l" # ---#DESTAIL 'hookmask.l' ---#DES 'debug.sethook' ---@overload fun(hook: (async fun(...):...), mask: hookmask, count?: integer) diff --git a/meta/template/io.lua b/meta/template/io.lua index a3420479..2200a626 100644 --- a/meta/template/io.lua +++ b/meta/template/io.lua @@ -11,18 +11,18 @@ io = {} ---@alias openmode ----|>'"r"' # ---#DESTAIL 'openmode.r' ----| '"w"' # ---#DESTAIL 'openmode.w' ----| '"a"' # ---#DESTAIL 'openmode.a' ----| '"r+"' # ---#DESTAIL 'openmode.r+' ----| '"w+"' # ---#DESTAIL 'openmode.w+' ----| '"a+"' # ---#DESTAIL 'openmode.a+' ----| '"rb"' # ---#DESTAIL 'openmode.rb' ----| '"wb"' # ---#DESTAIL 'openmode.wb' ----| '"ab"' # ---#DESTAIL 'openmode.ab' ----| '"r+b"' # ---#DESTAIL 'openmode.r+b' ----| '"w+b"' # ---#DESTAIL 'openmode.w+b' ----| '"a+b"' # ---#DESTAIL 'openmode.a+b' +---|>"r" # ---#DESTAIL 'openmode.r' +---| "w" # ---#DESTAIL 'openmode.w' +---| "a" # ---#DESTAIL 'openmode.a' +---| "r+" # ---#DESTAIL 'openmode.r+' +---| "w+" # ---#DESTAIL 'openmode.w+' +---| "a+" # ---#DESTAIL 'openmode.a+' +---| "rb" # ---#DESTAIL 'openmode.rb' +---| "wb" # ---#DESTAIL 'openmode.wb' +---| "ab" # ---#DESTAIL 'openmode.ab' +---| "r+b" # ---#DESTAIL 'openmode.r+b' +---| "w+b" # ---#DESTAIL 'openmode.w+b' +---| "a+b" # ---#DESTAIL 'openmode.a+b' ---#DES 'io.close' ---@param file? file* @@ -59,8 +59,8 @@ function io.open(filename, mode) end function io.output(file) end ---@alias popenmode ----| '"r"' # ---#DESTAIL 'popenmode.r' ----| '"w"' # ---#DESTAIL 'popenmode.w' +---| "r" # ---#DESTAIL 'popenmode.r' +---| "w" # ---#DESTAIL 'popenmode.w' ---#DES 'io.popen' ---@param prog string @@ -82,9 +82,9 @@ function io.read(...) end function io.tmpfile() end ---@alias filetype ----| '"file"' # ---#DESTAIL 'filetype.file' ----| '"closed file"' # ---#DESTAIL 'filetype.closed file' ----| 'nil' # ---#DESTAIL 'filetype.nil' +---| "file" # ---#DESTAIL 'filetype.file' +---| "closed file" # ---#DESTAIL 'filetype.closed file' +---| `nil` # ---#DESTAIL 'filetype.nil' ---#DES 'io.type' ---@param file file* @@ -103,20 +103,20 @@ local file = {} ---@alias readmode integer|string ---#if VERSION >= 5.3 then ----| '"n"' # ---#DESTAIL 'readmode.n' ----| '"a"' # ---#DESTAIL 'readmode.a' ----|>'"l"' # ---#DESTAIL 'readmode.l' ----| '"L"' # ---#DESTAIL 'readmode.L' +---| "n" # ---#DESTAIL 'readmode.n' +---| "a" # ---#DESTAIL 'readmode.a' +---|>"l" # ---#DESTAIL 'readmode.l' +---| "L" # ---#DESTAIL 'readmode.L' ---#else ----| '"*n"' # ---#DESTAIL 'readmode.n' ----| '"*a"' # ---#DESTAIL 'readmode.a' ----|>'"*l"' # ---#DESTAIL 'readmode.l' +---| "*n" # ---#DESTAIL 'readmode.n' +---| "*a" # ---#DESTAIL 'readmode.a' +---|>"*l" # ---#DESTAIL 'readmode.l' ---#if JIT then ----| '"*L"' # ---#DESTAIL 'readmode.L' +---| "*L" # ---#DESTAIL 'readmode.L' ---#end ---#end ----@alias exitcode '"exit"'|'"signal"' +---@alias exitcode "exit"|"signal" ---#DES 'file:close' ---@return boolean? suc @@ -140,9 +140,9 @@ function file:lines(...) end function file:read(...) end ---@alias seekwhence ----| '"set"' # ---#DESTAIL 'seekwhence.set' ----|>'"cur"' # ---#DESTAIL 'seekwhence.cur' ----| '"end"' # ---#DESTAIL 'seekwhence.end' +---| "set" # ---#DESTAIL 'seekwhence.set' +---|>"cur" # ---#DESTAIL 'seekwhence.cur' +---| "end" # ---#DESTAIL 'seekwhence.end' ---#DES 'file:seek' ---@param whence? seekwhence @@ -152,9 +152,9 @@ function file:read(...) end function file:seek(whence, offset) end ---@alias vbuf ----| '"no"' # ---#DESTAIL 'vbuf.no' ----| '"full"' # ---#DESTAIL 'vbuf.full' ----| '"line"' # ---#DESTAIL 'vbuf.line' +---| "no" # ---#DESTAIL 'vbuf.no' +---| "full" # ---#DESTAIL 'vbuf.full' +---| "line" # ---#DESTAIL 'vbuf.line' ---#DES 'file:setvbuf' ---@param mode vbuf diff --git a/meta/template/os.lua b/meta/template/os.lua index fbc56ac1..102a9228 100644 --- a/meta/template/os.lua +++ b/meta/template/os.lua @@ -87,12 +87,12 @@ function os.remove(filename) end function os.rename(oldname, newname) end ---@alias localecategory ----|>'"all"' ----| '"collate"' ----| '"ctype"' ----| '"monetary"' ----| '"numeric"' ----| '"time"' +---|>"all" +---| "collate" +---| "ctype" +---| "monetary" +---| "numeric" +---| "time" ---#DES 'os.setlocale' ---@param locale string|nil diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index c1b942b0..1f089c61 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -443,6 +443,7 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP or config.get(state.uri, 'Lua.runtime.unicodeName') then return nil end + name = ('%q'):format(name) end local textEdit, additionalTextEdits local startOffset = guide.positionToOffset(state, startPos) @@ -459,12 +460,7 @@ local function checkFieldFromFieldToIndex(state, name, src, parent, word, startP wordStartOffset = offset - #word end local wordStartPos = guide.offsetToPosition(state, wordStartOffset) - local newText - if vm.getKeyType(src) == 'string' then - newText = ('[%q]'):format(name) - else - newText = ('[%s]'):format(name) - end + local newText = ('[%s]'):format(name) textEdit = { start = wordStartPos, finish = position, @@ -541,7 +537,7 @@ local function checkFieldThen(state, name, src, word, startPos, position, parent textEdit = { start = str.start + #str[2], finish = position, - newText = name, + newText = name:sub(#str[2] + 1, - #str[2] - 1), } else textEdit, additionalTextEdits = checkFieldFromFieldToIndex(state, name, src, parent, word, startPos, position) @@ -583,7 +579,7 @@ local function checkFieldOfRefs(refs, state, word, startPos, position, parent, o if isGlobal and locals and locals[name] then goto CONTINUE end - if not matchKey(word, name, count >= 100) then + if not matchKey(word, name:gsub([=[^['"]]=], ''), count >= 100) then goto CONTINUE end if not vm.isVisible(parent, src) then diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 3342710a..a3057629 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1177,7 +1177,8 @@ local compilerSwitch = util.switch() end -- { f = function (<?x?>) end } - if guide.isAssign(parent) then + if guide.isAssign(parent) + and parent.value == source then vm.setNode(source, vm.compileNode(parent)) end end) diff --git a/script/vm/infer.lua b/script/vm/infer.lua index 0b5a6dcb..74cab4ed 100644 --- a/script/vm/infer.lua +++ b/script/vm/infer.lua @@ -483,7 +483,12 @@ function mt:viewLiterals() or n.type == 'number' or n.type == 'integer' or n.type == 'boolean' then - local literal = util.viewLiteral(n[1]) + local literal + if n.type == 'string' then + literal = util.viewString(n[1], n[2]) + else + literal = util.viewLiteral(n[1]) + end if literal and not mark[literal] then literals[#literals+1] = literal mark[literal] = true diff --git a/test/completion/common.lua b/test/completion/common.lua index e0668ea3..8d23822a 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1006,12 +1006,12 @@ t.<??> ]] { { - label = 'a.b.c', + label = "'a.b.c'", kind = define.CompletionItemKind.Field, textEdit = { start = 40002, finish = 40002, - newText = '["a.b.c"]', + newText = "['a.b.c']", }, additionalTextEdits = { { @@ -1032,12 +1032,12 @@ t. <??> ]] { { - label = 'a.b.c', + label = "'a.b.c'", kind = define.CompletionItemKind.Field, textEdit = { start = 40005, finish = 40005, - newText = '["a.b.c"]', + newText = "['a.b.c']", }, additionalTextEdits = { { @@ -1058,7 +1058,7 @@ t['<??>'] ]] { { - label = 'a.b.c', + label = "'a.b.c'", kind = define.CompletionItemKind.Field, textEdit = { start = 40003, @@ -1075,12 +1075,12 @@ z<??> ]] { { - label = 'z.b.c', + label = "'z.b.c'", kind = define.CompletionItemKind.Field, textEdit = { start = 20000, finish = 20001, - newText = '_ENV["z.b.c"]', + newText = "_ENV['z.b.c']", }, }, } @@ -1094,12 +1094,12 @@ z<??> ]] { { - label = 'z.b.c', + label = "'z.b.c'", kind = define.CompletionItemKind.Field, textEdit = { start = 20000, finish = 20001, - newText = '_G["z.b.c"]', + newText = "_G['z.b.c']", }, }, } diff --git a/test/hover/init.lua b/test/hover/init.lua index 751299bb..a3741764 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -490,7 +490,7 @@ local self: { id: integer = 1, remove: function, __index: table, - __name: string = "obj", + __name: string = 'obj', } ]] @@ -610,7 +610,7 @@ end local <?r?> = a(1) ]] [[ -local r: string = "a" +local r: string = 'a' ]] TEST[[ @@ -620,7 +620,7 @@ end local _, <?r?> = pcall(a, 1) ]] [[ -local r: string = "a" +local r: string = 'a' ]] TEST[[ @@ -633,7 +633,7 @@ local n: integer TEST[[ local <?x?> = '\a' ]] -[[local x: string = "\007"]] +[[local x: string = '\007']] TEST [[ local <?t?> = { @@ -827,9 +827,9 @@ local <?t?> = { ]] [[ local t: { - [1]: string = "aaa", - [2]: string = "bbb", - [3]: string = "ccc", + [1]: string = 'aaa', + [2]: string = 'bbb', + [3]: string = 'ccc', } ]] @@ -1712,13 +1712,13 @@ local <?t?> = { ]] [[ local t: { - x: string = "e", - y: string = "f", - ['z']: string = "g", - [10]: string = "d", - [1]: string = "a", - [2]: string = "b", - [3]: string = "c"|"h", + x: string = 'e', + y: string = 'f', + ['z']: string = 'g', + [10]: string = 'd', + [1]: string = 'a', + [2]: string = 'b', + [3]: string = 'c'|'h', } ]] @@ -1830,7 +1830,7 @@ local t = { local <?x?> = t[#t] ]] [[ -local x: string = "x" +local x: string = 'x' ]] TEST [[ @@ -1864,10 +1864,10 @@ local <?x?> = { ]] [[ local x: { - x: string = "", - y: string = "", - _x: string = "", - _y: string = "", + x: string = '', + y: string = '', + _x: string = '', + _y: string = '', } ]] |