diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-16 00:26:13 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-16 00:26:13 +0800 |
commit | 8b5c02c49fa397a40f03dc5c27dd6872dee13b2c (patch) | |
tree | e32be7bba8631552620d8e0c9c418749b7985192 /script | |
parent | c4f70450e6727a693586ad7941581ac51014545c (diff) | |
download | lua-language-server-8b5c02c49fa397a40f03dc5c27dd6872dee13b2c.zip |
move inlay-hint to LSP
Diffstat (limited to 'script')
-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 |
4 files changed, 75 insertions, 39 deletions
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) |