diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/hover/arg.lua | 36 | ||||
-rw-r--r-- | script/core/hover/init.lua | 4 | ||||
-rw-r--r-- | script/core/hover/label.lua | 7 | ||||
-rw-r--r-- | script/core/hover/name.lua | 19 | ||||
-rw-r--r-- | test/hover/init.lua | 2 | ||||
-rw-r--r-- | test/signature/init.lua | 13 |
7 files changed, 50 insertions, 32 deletions
diff --git a/changelog.md b/changelog.md index 2a7b44af..ba2897e3 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ * `FIX` missed syntax error `local a <const>= 1` * `FIX` workspace: preload blocked when hitting `Lua.workspace.maxPreload` * `FIX` [#443](https://github.com/sumneko/lua-language-server/issues/443) +* `FIX` [#445](https://github.com/sumneko/lua-language-server/issues/445) ## 1.17.4 `2021-3-4` diff --git a/script/core/hover/arg.lua b/script/core/hover/arg.lua index bb77c3db..1fded40e 100644 --- a/script/core/hover/arg.lua +++ b/script/core/hover/arg.lua @@ -14,29 +14,31 @@ local function optionalArg(arg) end local function asFunction(source, oop) - if not source.args then - return '' - end local args = {} - for i = 1, #source.args do - local arg = source.args[i] - local name = arg.name or guide.getKeyName(arg) - if name then - args[i] = ('%s%s: %s'):format( - name, - optionalArg(arg) and '?' or '', - vm.getInferType(arg) - ) - else - args[i] = ('%s'):format(vm.getInferType(arg)) - end - end local methodDef local parent = source.parent if parent and parent.type == 'setmethod' then methodDef = true end - if not methodDef and oop then + if methodDef then + args[#args+1] = ('self: %s'):format(vm.getInferType(parent.node)) + end + if source.args then + for i = 1, #source.args do + local arg = source.args[i] + local name = arg.name or guide.getKeyName(arg) + if name then + args[#args+1] = ('%s%s: %s'):format( + name, + optionalArg(arg) and '?' or '', + vm.getInferType(arg) + ) + else + args[#args+1] = ('%s'):format(vm.getInferType(arg)) + end + end + end + if oop then return table.concat(args, ', ', 2) else return table.concat(args, ', ') diff --git a/script/core/hover/init.lua b/script/core/hover/init.lua index f0315bd8..f358357b 100644 --- a/script/core/hover/init.lua +++ b/script/core/hover/init.lua @@ -24,7 +24,7 @@ local function getHoverAsValue(source) local oop = source.type == 'method' or source.type == 'getmethod' or source.type == 'setmethod' - local label = getLabel(source, oop) + local label = getLabel(source) local desc = getDesc(source) if not desc then local values = vm.getDefs(source, 0) @@ -62,7 +62,7 @@ local function getHoverAsFunction(source) return end mark[value] =true - local label = getLabel(value, oop) + local label = getLabel(value) if label then defs = defs + 1 labels[label] = (labels[label] or 0) + 1 diff --git a/script/core/hover/label.lua b/script/core/hover/label.lua index a54abd09..b486dce6 100644 --- a/script/core/hover/label.lua +++ b/script/core/hover/label.lua @@ -10,9 +10,10 @@ local config = require 'config' local files = require 'files' local function asFunction(source, oop) - local name = buildName(source, oop) - local arg = buildArg(source, oop) - local rtn = buildReturn(source) + local name + name, oop = buildName(source, oop) + local arg = buildArg(source, oop) + local rtn = buildReturn(source) local lines = {} lines[1] = ('function %s(%s)'):format(name, arg) lines[2] = rtn diff --git a/script/core/hover/name.lua b/script/core/hover/name.lua index 645cdaa9..7a8f951c 100644 --- a/script/core/hover/name.lua +++ b/script/core/hover/name.lua @@ -64,40 +64,41 @@ function buildName(source, oop) if oop == nil then oop = source.type == 'setmethod' or source.type == 'getmethod' + or nil end if source.type == 'local' then - return asLocal(source) or '' + return asLocal(source) or '', oop end if source.type == 'getlocal' or source.type == 'setlocal' then - return asLocal(source.node) or '' + return asLocal(source.node) or '', oop end if source.type == 'setglobal' or source.type == 'getglobal' then - return asGlobal(source) or '' + return asGlobal(source) or '', oop end if source.type == 'setmethod' or source.type == 'getmethod' then - return asField(source, true) or '' + return asField(source, oop) or '', oop end if source.type == 'setfield' or source.type == 'getfield' then - return asField(source, oop) or '' + return asField(source, oop) or '', oop end if source.type == 'tablefield' then - return asTableField(source) or '' + return asTableField(source) or '', oop end if source.type == 'doc.type.function' then - return asDocFunction(source) + return asDocFunction(source), oop end if source.type == 'doc.field' then - return asDocField(source) + return asDocField(source), oop end local parent = source.parent if parent then return buildName(parent, oop) end - return '' + return '', oop end return buildName diff --git a/test/hover/init.lua b/test/hover/init.lua index fa7d3f22..d0e50036 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -245,7 +245,7 @@ function string.sub(s: string, i: integer, j?: integer) TEST[[ ('xx'):<?sub?>() ]] -[[function string:sub(i: integer, j?: integer) +[[function string.sub(s: string, i: integer, j?: integer) -> string]] TEST [[ diff --git a/test/signature/init.lua b/test/signature/init.lua index c7483c87..372709e3 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -214,3 +214,16 @@ function pairs(t: <T>) ]], arg = {16, 21}, } + +TEST [[ +function m:f() +end + +m.f($) +]] +{ + label = [[ +function m.f(self: table) +]], + arg = {14, 24}, +} |