summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-12-18 05:57:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-12-18 05:57:36 +0800
commita2ca88cc7e078ce0c06a2140be3efdcf6cfe6c02 (patch)
tree6a8b094d46ab58f6e5776692d8d36cfa66a88ff1
parent97324851ab26d32a8b5fa56b7b3a867692100fb4 (diff)
downloadlua-language-server-a2ca88cc7e078ce0c06a2140be3efdcf6cfe6c02.zip
complete code lens
-rw-r--r--locale/en-us/script.lua2
-rw-r--r--locale/en-us/setting.lua2
-rw-r--r--locale/pt-br/script.lua2
-rw-r--r--locale/pt-br/setting.lua2
-rw-r--r--locale/zh-cn/script.lua2
-rw-r--r--locale/zh-cn/setting.lua2
-rw-r--r--locale/zh-tw/script.lua2
-rw-r--r--locale/zh-tw/setting.lua2
-rw-r--r--script/config/template.lua1
-rw-r--r--script/core/code-lens.lua7
-rw-r--r--script/provider/capability.lua1
-rw-r--r--script/provider/code-lens.lua29
-rw-r--r--script/provider/provider.lua3
13 files changed, 54 insertions, 3 deletions
diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua
index fb203d7e..4bcff620 100644
--- a/locale/en-us/script.lua
+++ b/locale/en-us/script.lua
@@ -447,6 +447,8 @@ COMMAND_JSON_TO_LUA_FAILED =
'Convert JSON to Lua failed: {}'
COMMAND_ADD_DICT =
'Add Word to dictionary'
+COMMAND_REFERENCE_COUNT =
+'{} references'
COMPLETION_IMPORT_FROM =
'Import from {}'
diff --git a/locale/en-us/setting.lua b/locale/en-us/setting.lua
index 507893bd..c1681e98 100644
--- a/locale/en-us/setting.lua
+++ b/locale/en-us/setting.lua
@@ -256,6 +256,8 @@ config.hint.semicolon.SameLine =
'When two statements are on the same line, display a semicolon between them.'
config.hint.semicolon.Disable =
'Disable virtual semicolons.'
+config.codeLens.enable =
+'Enable code lens.'
config.format.enable =
'Enable code formatter.'
config.format.defaultConfig =
diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua
index aabb3a19..6549de99 100644
--- a/locale/pt-br/script.lua
+++ b/locale/pt-br/script.lua
@@ -447,6 +447,8 @@ COMMAND_JSON_TO_LUA_FAILED =
'Converção de JSON para Lua falhou: {}.'
COMMAND_ADD_DICT =
'Adicione uma palavra ao dicionário'
+COMMAND_REFERENCE_COUNT = -- TODO: need translate!
+'{} references'
COMPLETION_IMPORT_FROM =
'Importa de {}.'
diff --git a/locale/pt-br/setting.lua b/locale/pt-br/setting.lua
index efc936e2..be21a0ee 100644
--- a/locale/pt-br/setting.lua
+++ b/locale/pt-br/setting.lua
@@ -256,6 +256,8 @@ config.hint.semicolon.SameLine = -- TODO: need translate!
'When two statements are on the same line, display a semicolon between them.'
config.hint.semicolon.Disable = -- TODO: need translate!
'Disable virtual semicolons.'
+config.codeLens.enable = -- TODO: need translate!
+'Enable code lens.'
config.format.enable = -- TODO: need translate!
'Enable code formatter.'
config.format.defaultConfig = -- TODO: need translate!
diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua
index 6adaa17d..1c5725ab 100644
--- a/locale/zh-cn/script.lua
+++ b/locale/zh-cn/script.lua
@@ -447,6 +447,8 @@ COMMAND_JSON_TO_LUA_FAILED =
'JSON 转 Lua 失败:{}'
COMMAND_ADD_DICT = -- TODO: need translate!
'Add Word to dictionary'
+COMMAND_REFERENCE_COUNT =
+'{} 个引用'
COMPLETION_IMPORT_FROM =
'从 {} 中导入'
diff --git a/locale/zh-cn/setting.lua b/locale/zh-cn/setting.lua
index c1dde6fb..bdb1e779 100644
--- a/locale/zh-cn/setting.lua
+++ b/locale/zh-cn/setting.lua
@@ -255,6 +255,8 @@ config.hint.semicolon.SameLine =
'2个语句在同一行时,在它们之间显示分号。'
config.hint.semicolon.Disable =
'禁用虚拟分号。'
+config.codeLens.enable = -- TODO: need translate!
+'启用代码度量。'
config.format.enable =
'启用代码格式化程序。'
config.format.defaultConfig =
diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua
index ec69bea8..b33851b0 100644
--- a/locale/zh-tw/script.lua
+++ b/locale/zh-tw/script.lua
@@ -447,6 +447,8 @@ COMMAND_JSON_TO_LUA_FAILED =
'JSON 轉 Lua 失敗:{}'
COMMAND_ADD_DICT =
'添加單字到字典裡'
+COMMAND_REFERENCE_COUNT = -- TODO: need translate!
+'{} references'
COMPLETION_IMPORT_FROM =
'從 {} 中匯入'
diff --git a/locale/zh-tw/setting.lua b/locale/zh-tw/setting.lua
index b33ed782..dfd647fd 100644
--- a/locale/zh-tw/setting.lua
+++ b/locale/zh-tw/setting.lua
@@ -255,6 +255,8 @@ config.hint.semicolon.SameLine =
'兩個陳述式在同一行時,在它們之間顯示分號。'
config.hint.semicolon.Disable =
'停用虛擬分號。'
+config.codeLens.enable = -- TODO: need translate!
+'Enable code lens.'
config.format.enable =
'啟用程式碼格式化程式。'
config.format.defaultConfig =
diff --git a/script/config/template.lua b/script/config/template.lua
index ea79c2d3..f8521ffe 100644
--- a/script/config/template.lua
+++ b/script/config/template.lua
@@ -374,6 +374,7 @@ local template = {
},
['Lua.window.statusBar'] = Type.Boolean >> true,
['Lua.window.progressBar'] = Type.Boolean >> true,
+ ['Lua.codeLens.enable'] = Type.Boolean >> false,
['Lua.format.enable'] = Type.Boolean >> true,
['Lua.format.defaultConfig'] = Type.Hash(Type.String, Type.String)
>> {},
diff --git a/script/core/code-lens.lua b/script/core/code-lens.lua
index a440e106..e83857b2 100644
--- a/script/core/code-lens.lua
+++ b/script/core/code-lens.lua
@@ -3,13 +3,14 @@ local guide = require 'parser.guide'
local await = require 'await'
local conv = require 'proto.converter'
local getRef = require 'core.reference'
+local lang = require 'language'
---@class parser.state
---@field package _codeLens codeLens
---@class codeLens.resolving
----@field mode 'reference'
----@field source parser.object
+---@field mode 'reference'
+---@field source? parser.object
---@class codeLens.result
---@field position integer
@@ -89,7 +90,7 @@ function mt:resolveReference(source)
local refs = getRef(self.uri, source.finish, false)
local count = refs and #refs or 0
local command = conv.command(
- ('%d个引用'):format(count),
+ lang.script('COMMAND_REFERENCE_COUNT', count),
'',
{}
)
diff --git a/script/provider/capability.lua b/script/provider/capability.lua
index 19024a54..4f7ec388 100644
--- a/script/provider/capability.lua
+++ b/script/provider/capability.lua
@@ -7,6 +7,7 @@ local define = require 'proto.define'
require 'provider.semantic-tokens'
require 'provider.formatting'
require 'provider.inlay-hint'
+require 'provider.code-lens'
local m = {}
diff --git a/script/provider/code-lens.lua b/script/provider/code-lens.lua
new file mode 100644
index 00000000..5802b17e
--- /dev/null
+++ b/script/provider/code-lens.lua
@@ -0,0 +1,29 @@
+local proto = require 'proto'
+local client = require 'client'
+local json = require 'json'
+local config = require 'config'
+
+local function refresh()
+ if not client.isReady() then
+ return
+ end
+ if not client.getAbility 'workspace.codeLens.refreshSupport' then
+ return
+ end
+ log.debug('Refresh codeLens.')
+ proto.request('workspace/codeLens/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.codeLens'
+ or key:find '^files' then
+ refresh()
+ end
+end)
+
+return {}
diff --git a/script/provider/provider.lua b/script/provider/provider.lua
index 868fe81a..51bdf531 100644
--- a/script/provider/provider.lua
+++ b/script/provider/provider.lua
@@ -927,6 +927,9 @@ m.register 'textDocument/codeLens' {
---@async
function (params)
local uri = files.getRealUri(params.textDocument.uri)
+ if not config.get(uri, 'Lua.codeLens.enable') then
+ return
+ end
workspace.awaitReady(uri)
local state = files.getState(uri)
if not state then