diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 2 | ||||
-rw-r--r-- | script/core/hint.lua | 45 | ||||
-rw-r--r-- | script/provider/provider.lua | 17 |
4 files changed, 43 insertions, 23 deletions
diff --git a/changelog.md b/changelog.md index 9dfe56d5..6ffe7f1c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,7 @@ # changelog ## 3.1.0 -* `CHG` inlay-hint: move to LSP and enable by default. Its format is now controlled by the client. +* `CHG` inlay-hint: move to LSP and enable by default. Its font is now controlled by the client. ## 3.0.2 `2022-4-15` diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index 75026526..8cdb9ce3 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -321,6 +321,8 @@ HOVER_TABLE_TIME_UP = '出于性能考虑,已禁用了部分类型推断。' HOVER_WS_LOADING = '正在加载工作目录:{} / {}' +HOVER_AWAIT_TOOLTIP = +'正在调用异步函数,可能会让出当前协程' ACTION_DISABLE_DIAG = '在工作区禁用诊断 ({})。' diff --git a/script/core/hint.lua b/script/core/hint.lua index 15eff0bf..f6774d2a 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -5,6 +5,7 @@ local config = require 'config' local guide = require 'parser.guide' local await = require 'await' local define = require 'proto.define' +local lang = require 'language' ---@async local function typeHint(uri, results, start, finish) @@ -62,25 +63,26 @@ local function typeHint(uri, results, start, finish) offset = src.finish, kind = define.InlayHintKind.Type, where = 'right', + source = source, } end) end -local function getArgNames(func) +local function getParams(func) if not func.args or #func.args == 0 then return nil end - local names = {} + local params = {} for _, arg in ipairs(func.args) do if arg.type == '...' then break end - names[#names+1] = arg[1] or '' + params[#params+1] = arg end - if #names == 0 then + if #params == 0 then return nil end - return names + return params end local function hasLiteralArgInCall(call) @@ -121,19 +123,16 @@ local function paramName(uri, results, start, finish) if not defs then return end - local args + local params for _, def in ipairs(defs) do - if def.value then - def = def.value - end if def.type == 'function' then - args = getArgNames(def) - if args then + params = getParams(def) + if params then break end end end - if not args then + if not params then return end local firstIndex = 1 @@ -145,12 +144,14 @@ local function paramName(uri, results, start, finish) if not mark[arg] and (paramConfig ~= 'Literal' or guide.isLiteral(arg)) then mark[arg] = true - if args[i] and args[i] ~= '' then + local param = params[i] + if param and param[1] then results[#results+1] = { - text = args[i] .. ':', - offset = arg.start, - kind = define.InlayHintKind.Parameter, - where = 'left', + text = param[1] .. ':', + offset = arg.start, + kind = define.InlayHintKind.Parameter, + where = 'left', + source = param, } end end @@ -204,6 +205,7 @@ local function arrayIndex(uri, results, start, finish) offset = source.start, kind = define.InlayHintKind.Other, where = 'left', + source = source.parent, } end) end @@ -228,10 +230,11 @@ local function awaitHint(uri, results, start, finish) return end results[#results+1] = { - text = 'await ', - offset = node.start, - kind = define.InlayHintKind.Other, - where = 'left', + text = 'await ', + offset = node.start, + kind = define.InlayHintKind.Other, + where = 'left', + tooltip = lang.script.HOVER_AWAIT_TOOLTIP, } end) end diff --git a/script/provider/provider.lua b/script/provider/provider.lua index f595c6b1..24ca003b 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -19,6 +19,8 @@ local json = require 'json' local scope = require 'workspace.scope' local furi = require 'file-uri' local inspect = require 'inspect' +local markdown = require 'provider.markdown' +local guide = require 'parser.guide' ---@async local function updateConfig(uri) @@ -1174,7 +1176,20 @@ m.register 'textDocument/inlayHint' { local hintResults = {} for i, res in ipairs(results) do hintResults[i] = { - label = res.text, + label = { + { + value = res.text, + tooltip = res.tooltip, + location = res.source and converter.location( + guide.getUri(res.source), + converter.packRange( + guide.getUri(res.source), + res.source.start, + res.source.finish + ) + ), + }, + }, position = converter.packPosition(uri, res.offset), kind = res.kind, paddingLeft = true, |