diff options
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/provider/capability.lua | 1 | ||||
-rw-r--r-- | script/provider/inlay-hint.lua | 30 | ||||
-rw-r--r-- | script/provider/provider.lua | 42 | ||||
-rw-r--r-- | script/provider/semantic-tokens.lua | 41 |
5 files changed, 78 insertions, 39 deletions
diff --git a/changelog.md b/changelog.md index bd35dfca..90e7e516 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 3.1.0 +* `CHG` inlay-hint: move to LSP. Its format is now controlled by the client. + ## 3.0.2 `2022-4-15` * `FIX` `table<string, boolean>[string] -> boolean` diff --git a/script/provider/capability.lua b/script/provider/capability.lua index ba5690bf..0f00cec1 100644 --- a/script/provider/capability.lua +++ b/script/provider/capability.lua @@ -6,6 +6,7 @@ local define = require 'proto.define' require 'provider.semantic-tokens' require 'provider.formatting' +require 'provider.inlay-hint' local m = {} diff --git a/script/provider/inlay-hint.lua b/script/provider/inlay-hint.lua new file mode 100644 index 00000000..384e1d47 --- /dev/null +++ b/script/provider/inlay-hint.lua @@ -0,0 +1,30 @@ +local proto = require 'proto' +local client = require 'client' +local json = require "json" +local config = require 'config' + +if not client.getAbility 'workspace.inlayHint.refreshSupport' then + return +end + +local function refresh() + if not client.isReady() then + return + end + log.debug('Refresh inlay hints.') + proto.request('workspace/inlayHint/refresh', json.null) +end + +config.watch(function (uri, key, value, oldValue) + if key == '' then + refresh() + end + if key:find '^Lua.runtime' + or key:find '^Lua.workspace' + or key:find '^Lua.hint' + or key:find '^files' then + refresh() + end +end) + +return {} diff --git a/script/provider/provider.lua b/script/provider/provider.lua index f5b21c66..f595c6b1 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -1155,6 +1155,48 @@ m.register '$/requestHint' { end } +m.register 'textDocument/inlayHint' { + capability = { + inlayHintProvider = { + resolveProvider = true, + }, + }, + ---@async + function (params) + local uri = files.getRealUri(params.textDocument.uri) + if not config.get(uri, 'Lua.hint.enable') then + return + end + workspace.awaitReady(uri) + local core = require 'core.hint' + local start, finish = converter.unpackRange(uri, params.range) + local results = core(uri, start, finish) + local hintResults = {} + for i, res in ipairs(results) do + hintResults[i] = { + label = res.text, + position = converter.packPosition(uri, res.offset), + kind = res.kind, + paddingLeft = true, + paddingRight = true, + } + end + return hintResults + end +} + +m.register 'inlayHint/resolve' { + capability = { + inlayHintProvider = { + resolveProvider = true, + }, + }, + ---@async + function (hint) + return hint + end +} + -- Hint do ---@async diff --git a/script/provider/semantic-tokens.lua b/script/provider/semantic-tokens.lua index 2fa75064..80416fff 100644 --- a/script/provider/semantic-tokens.lua +++ b/script/provider/semantic-tokens.lua @@ -1,46 +1,10 @@ local proto = require 'proto' -local define = require 'proto.define' local client = require 'client' local json = require "json" local config = require 'config' -local lang = require 'language' -local nonil = require 'without-check-nil' -local dontShowAgain = false -local function check(uri) - if dontShowAgain then - return - end - dontShowAgain = true - nonil.disable() - if config.get(uri, 'editor.semanticHighlighting.enabled') == 'configuredByTheme' then - proto.request('window/showMessageRequest', { - type = define.MessageType.Info, - message = lang.script.WINDOW_CHECK_SEMANTIC, - actions = { - { - title = lang.script.WINDOW_APPLY_SETTING, - }, - { - title = lang.script.WINDOW_DONT_SHOW_AGAIN, - }, - } - }, function (item) - if not item then - return - end - if item.title == lang.script.WINDOW_APPLY_SETTING then - client.setConfig { - { - key = 'editor.semanticHighlighting.enabled', - action = 'set', - value = true, - global = true, - } - } - end - end) - end +if not client.getAbility 'workspace.semanticTokens.refreshSupport' then + return end local function refresh() @@ -49,7 +13,6 @@ local function refresh() end log.debug('Refresh semantic tokens.') proto.request('workspace/semanticTokens/refresh', json.null) - --check() end config.watch(function (uri, key, value, oldValue) |