summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-07-31 18:48:50 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-07-31 18:48:50 +0800
commit4133ed413c78b749dd77ccbab70981fd5fb3a537 (patch)
tree3d5846c542dcaad3e24f7cdb430175e66f76eb7a
parentaae2c7888bad227b6df897b97c01f123744175de (diff)
downloadlua-language-server-4133ed413c78b749dd77ccbab70981fd5fb3a537.zip
You can now click on "References" in CodeLen to display the reference list
-rw-r--r--changelog.md1
-rw-r--r--script/core/code-lens.lua36
2 files changed, 31 insertions, 6 deletions
diff --git a/changelog.md b/changelog.md
index 9cdb86e9..fadf1296 100644
--- a/changelog.md
+++ b/changelog.md
@@ -14,6 +14,7 @@
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
* `FIX` Inconsistent type narrow behavior of function call args [#2758](https://github.com/LuaLS/lua-language-server/issues/2758)
* `FIX` Typos in annotation descriptions
+* `NEW` You can now click on "References" in CodeLen to display the reference list
## 3.9.3
`2024-6-11`
diff --git a/script/core/code-lens.lua b/script/core/code-lens.lua
index bc39ec86..bebfeedf 100644
--- a/script/core/code-lens.lua
+++ b/script/core/code-lens.lua
@@ -4,6 +4,7 @@ local await = require 'await'
local conv = require 'proto.converter'
local getRef = require 'core.reference'
local lang = require 'language'
+local client = require 'client'
---@class parser.state
---@field package _codeLens? codeLens
@@ -88,12 +89,35 @@ end
function mt:resolveReference(source)
local refs = getRef(self.uri, source.finish, false)
local count = refs and #refs or 0
- local command = conv.command(
- lang.script('COMMAND_REFERENCE_COUNT', count),
- '',
- {}
- )
- return command
+ if client.getOption('codeLensViewReferences') then
+ local locations = {}
+ for _, ref in ipairs(refs or {}) do
+ local state = files.getState(ref.uri)
+ if state then
+ locations[#locations+1] = conv.location(
+ ref.uri,
+ conv.packRange(state, ref.target.start, ref.target.finish)
+ )
+ end
+ end
+ local command = conv.command(
+ lang.script('COMMAND_REFERENCE_COUNT', count),
+ 'lua.showReferences',
+ {
+ self.uri,
+ conv.packPosition(self.state, source.start),
+ locations,
+ }
+ )
+ return command
+ else
+ local command = conv.command(
+ lang.script('COMMAND_REFERENCE_COUNT', count),
+ '',
+ {}
+ )
+ return command
+ end
end
---@async