diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | script/core/hover/label.lua | 35 | ||||
-rw-r--r-- | script/core/signature.lua | 2 | ||||
-rw-r--r-- | test/completion/common.lua | 4 | ||||
-rw-r--r-- | test/crossfile/hover.lua | 28 | ||||
-rw-r--r-- | test/hover/init.lua | 90 | ||||
-rw-r--r-- | test/signature/init.lua | 4 |
7 files changed, 102 insertions, 63 deletions
diff --git a/changelog.md b/changelog.md index 6ffe7f1c..9a493187 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,8 @@ ## 3.1.0 * `CHG` inlay-hint: move to LSP and enable by default. Its font is now controlled by the client. +* `CHG` hover: split `local` into `local` / `parameter` / `upvalue` / `self`. +* `CHG` hover: added parentheses to some words, such as `global` / `field` / `class`. ## 3.0.2 `2022-4-15` diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index c2239344..8224e9d3 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -17,8 +17,8 @@ local function asFunction(source, oop) local lines = {} lines[1] = string.format('%s%s %s(%s)' - , vm.isAsync(source) and 'async ' or '' - , oop and 'method' or 'function' + , vm.isAsync(source) and '(async) ' or '' + , oop and '(method)' or 'function' , name or '' , oop and table.concat(args, ', ', 2) or table.concat(args, ', ') ) @@ -31,10 +31,10 @@ local function asDocTypeName(source) local defs = vm.getDefs(source) for _, doc in ipairs(defs) do if doc.type == 'doc.class' then - return 'class ' .. doc.class[1] + return '(class) ' .. doc.class[1] end if doc.type == 'doc.alias' then - return lang.script('HOVER_EXTENDS', infer.getInfer(doc.extends):view()) + return '(alias) ' .. doc.alias[1] .. ' ' .. lang.script('HOVER_EXTENDS', infer.getInfer(doc.extends):view()) end end end @@ -72,12 +72,28 @@ end ---@async local function asLocal(source) - return asValue(source, 'local') + local node + if source.type == 'local' + or source.type == 'self' then + node = source + else + node = source.node + end + if node.type == 'self' then + return asValue(source, '(self)') + end + if node.parent.type == 'funcargs' then + return asValue(source, '(parameter)') + elseif guide.getParentFunction(source) ~= guide.getParentFunction(node) then + return asValue(source, '(upvalue)') + else + return asValue(source, 'local') + end end ---@async local function asGlobal(source) - return asValue(source, 'global') + return asValue(source, '(global)') end local function isGlobalField(source) @@ -112,7 +128,7 @@ local function asField(source) if isGlobalField(source) then return asGlobal(source) end - return asValue(source, 'field') + return asValue(source, '(field)') end local function asDocFieldName(source) @@ -126,9 +142,9 @@ local function asDocFieldName(source) end local view = infer.getInfer(source.extends):view() if not class then - return ('field ?.%s: %s'):format(name, view) + return ('(field) ?.%s: %s'):format(name, view) end - return ('field %s.%s: %s'):format(class.class[1], name, view) + return ('(field) %s.%s: %s'):format(class.class[1], name, view) end local function asString(source) @@ -177,6 +193,7 @@ return function (source, oop) or source.type == 'doc.type.function' then return asFunction(source, oop) elseif source.type == 'local' + or source.type == 'self' or source.type == 'getlocal' or source.type == 'setlocal' then return asLocal(source) diff --git a/script/core/signature.lua b/script/core/signature.lua index 505526b6..bade7d7a 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -45,7 +45,7 @@ local function makeOneSignature(source, oop, index) label = label:gsub('%s*->.+', '') local params = {} local i = 0 - local argStart, argLabel = label:match '()(%b())' + local argStart, argLabel = label:match '%S()(%b())' local converted = argLabel : sub(2, -2) : gsub('%b<>', function (str) diff --git a/test/completion/common.lua b/test/completion/common.lua index 4667305f..538ac401 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1750,7 +1750,7 @@ zz<??> detail = 'integer = 1', description = [[ ```lua -global zzz: integer = 1 +(global) zzz: integer = 1 ``` --- @@ -2094,7 +2094,7 @@ print(t.aa<??>) kind = define.CompletionItemKind.Field, description = [[ ```lua -field cc.aaa: number +(field) cc.aaa: number ```]] }, } diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index 4461e775..b0b66253 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -235,7 +235,7 @@ TEST { }, hover = [[ ```lua -method mt:add(a: any, b: any) +(method) mt:add(a: any, b: any) ```]] } @@ -256,7 +256,7 @@ TEST { }, hover = [[ ```lua -global t: { +(global) t: { [1]: integer = 1|2, } ```]], @@ -279,7 +279,7 @@ TEST { }, hover = [[ ```lua -global t: { +(global) t: { [1]: integer = 2, } ```]], @@ -346,7 +346,7 @@ TEST { }, hover = [[ ```lua -global x: integer = 1 +(global) x: integer = 1 ``` --- @@ -484,7 +484,7 @@ function f(<?x?>) end }, hover = [[ ```lua -local x: string +(parameter) x: string ``` --- @@ -535,7 +535,7 @@ function f(<?x?>) end }, hover = [[ ```lua -local x: string +(parameter) x: string ```]]} @@ -766,7 +766,7 @@ G.A = 1 }, hover = [[ ```lua -global G.A: integer = 1 +(global) G.A: integer = 1 ``` --- @@ -787,7 +787,7 @@ G.<?A?> = 1 }, hover = [[ ```lua -global G.A: integer = 1 +(global) G.A: integer = 1 ``` --- @@ -811,7 +811,7 @@ food.secondField = 2 }, hover = [[ ```lua -field Food.firstField: number = 0 +(field) Food.firstField: number = 0 ```]]} TEST {{ path = 'a.lua', content = '', }, { @@ -1071,7 +1071,7 @@ G = {} }, hover = [[ ```lua -global G: A { +(global) G: A { x: number, } ```]] @@ -1087,13 +1087,13 @@ TEST { }, hover = [[ ```lua -method C:f(a: any, b: any) +(method) C:f(a: any, b: any) ``` --- ```lua -method C:f(a: any) +(method) C:f(a: any) ```]] } @@ -1128,12 +1128,12 @@ TEST { }, hover = [[ ```lua -async method C:f(a: any, b: any) +(async) (method) C:f(a: any, b: any) ``` --- ```lua -async method C:f(a: any) +(async) (method) C:f(a: any) ```]] } diff --git a/test/hover/init.lua b/test/hover/init.lua index 199df06d..f347cd99 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -67,7 +67,7 @@ local obj = setmetatable({}, mt) obj:<?init?>(1, '测试') ]] [[ -method mt:init(a: any, b: any, c: any) +(method) mt:init(a: any, b: any, c: any) ]] --TEST [[ @@ -117,7 +117,7 @@ local obj = setmetatable({}, mt) obj:<?init?>(1, '测试') ]] [[ -method mt:init(a: any, b: any, c: any) +(method) mt:init(a: any, b: any, c: any) -> table ]] @@ -135,7 +135,7 @@ obj:init(1, '测试') obj.<?init?>(obj, 1, '测试') ]] [[ -method mt:init(a: any, b: any, c: any) +(method) mt:init(a: any, b: any, c: any) -> table ]] @@ -150,7 +150,7 @@ obj.<?xxx?>() TEST [[ obj.<?xxx?>() ]] -[[global obj.xxx: unknown]] +[[(global) obj.xxx: unknown]] TEST [[ local <?x?> = 1 @@ -160,26 +160,26 @@ local <?x?> = 1 TEST [[ <?x?> = 1 ]] -"global x: integer = 1" +"(global) x: integer = 1" TEST [[ local t = {} t.<?x?> = 1 ]] -"field t.x: integer = 1" +"(field) t.x: integer = 1" TEST [[ t = {} t.<?x?> = 1 ]] -"global t.x: integer = 1" +"(global) t.x: integer = 1" TEST [[ t = { <?x?> = 1 } ]] -"field x: integer = 1" +"(field) x: integer = 1" TEST [[ local <?obj?> = {} @@ -329,7 +329,7 @@ local t = init() t:<?add?>() ]] [[ -method mt:add(a: any, b: any) +(method) mt:add(a: any, b: any) ]] TEST [[ @@ -347,7 +347,7 @@ local t = init() t:<?add?>() ]] [[ -method mt:add(a: any, b: any) +(method) mt:add(a: any, b: any) ]] TEST [[ @@ -487,7 +487,7 @@ function mt:test(a, b) end ]] [[ -method mt:test(a: any, b: any) +(method) mt:test(a: any, b: any) ]] TEST[[ @@ -515,7 +515,7 @@ TEST [[ print(<?utf8?>) ]] [[ -global utf8: utf8lib { +(global) utf8: utf8lib { char: function, charpattern: string, codepoint: function, @@ -529,7 +529,7 @@ TEST [[ print(io.<?stderr?>) ]] [[ -global io.stderr: file* { +(global) io.stderr: file* { close: function, flush: function, lines: function, @@ -544,7 +544,7 @@ TEST [[ print(<?io?>) ]] [[ -global io: iolib { +(global) io: iolib { close: function, flush: function, input: function, @@ -758,7 +758,7 @@ local t = { print(t.<?v?>) ]] [[ -field t.v: { +(field) t.v: { b: integer = 1, c: integer = 2, d: integer = 3, @@ -789,7 +789,7 @@ TEST [[ <?_G?> ]] [[ -global _G: _G { +(global) _G: _G { _G: _G, _VERSION: string = "Lua 5.4", arg: string[], @@ -908,7 +908,7 @@ TEST[[ <?x?> = class() ]] [[ -global x: Class +(global) x: Class ]] TEST[[ @@ -918,7 +918,7 @@ local t = { } ]] [[ -field x: Class +(field) x: Class ]] TEST[[ @@ -934,7 +934,7 @@ TEST[[ <?x?> = class() ]] [[ -global x: Class +(global) x: Class ]] TEST[[ @@ -970,7 +970,7 @@ function f(<?t?>) end ]] [[ -local t: Class +(parameter) t: Class ]] TEST [[ @@ -983,7 +983,7 @@ function f(t) end ]] [[ -local t: Class +(parameter) t: Class ]] TEST [[ @@ -1274,7 +1274,7 @@ TEST [[ function t(<?f?>) end ]] [[ -local f: fun():void +(parameter) f: fun():void ]] TEST [[ @@ -1284,7 +1284,7 @@ local t = {f = f} t:<?f?>() ]] [[ -field t.f: fun(a: any, b: any) +(field) t.f: fun(a: any, b: any) ]] TEST [[ @@ -1293,7 +1293,7 @@ local function f(<?names?>) end ]] [[ -local names: string[] +(parameter) names: string[] ]] TEST [[ @@ -1389,7 +1389,7 @@ TEST [[ ---@type <?A?> ]] [[ -class A +(class) A ]] TEST [[ @@ -1406,7 +1406,7 @@ TEST [[ ---@type <?A?> ]] [[ -展开为 string|"enum1"|"enum2" +(alias) A 展开为 string|"enum1"|"enum2" ]] TEST [[ @@ -1437,7 +1437,7 @@ t = {} function <?t?>.f() end ]] [[ -global t: c { +(global) t: c { f: function, } ]] @@ -1497,7 +1497,7 @@ TEST [[ local function f(<?callback?>) end ]] [[ -local callback: fun(x: integer, ...: any) +(parameter) callback: fun(x: integer, ...: any) ]] TEST [[ @@ -1626,7 +1626,7 @@ function m:f() end ]] [[ -local self: E { +(self) self: E { f: function, } ]] @@ -1675,7 +1675,7 @@ TEST [[ <?a?>.b = 10 * 60 ]] [[ -global a: { +(global) a: { b: integer = 600, } ]] @@ -1684,14 +1684,14 @@ TEST [[ a.<?b?> = 10 * 60 ]] [[ -global a.b: integer = 600 +(global) a.b: integer = 600 ]] TEST [[ a.<?b?>.c = 1 * 1 ]] [[ -global a.b: { +(global) a.b: { c: integer = 1, } ]] @@ -1730,7 +1730,7 @@ local t = nil t.<?x?>() ]] [[ -field t.x: unknown +(field) t.x: unknown ]] TEST [[ @@ -1743,7 +1743,7 @@ b = a print(b.<?x?>) ]] [[ -field A.x: unknown +(field) A.x: unknown ]] TEST [[ @@ -1760,7 +1760,7 @@ TEST [[ local function <?f?>() end ]] [[ -async function f() +(async) function f() ]] TEST [[ @@ -1884,3 +1884,23 @@ local t: B { y: string, } ]] + +TEST [[ +local <?x?> +local function f() + x +end +]] +[[ +local x: unknown +]] + +TEST [[ +local x +local function f() + <?x?> +end +]] +[[ +(upvalue) x: unknown +]] diff --git a/test/signature/init.lua b/test/signature/init.lua index 34aed96d..701df286 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -65,7 +65,7 @@ end mt:f(<??> ]] -'method mt:f(<!a: any!>)' +'(method) mt:f(<!a: any!>)' TEST [[ local function x(a, b) @@ -88,7 +88,7 @@ x(1, 2, 3, <??> TEST [[ (''):sub(<??> ]] -'method string:sub(<!i: integer!>, j?: integer)' +'(method) string:sub(<!i: integer!>, j?: integer)' TEST [[ (''):sub(1)<??> |