From 4133ed413c78b749dd77ccbab70981fd5fb3a537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 31 Jul 2024 18:48:50 +0800 Subject: You can now click on "References" in CodeLen to display the reference list --- changelog.md | 1 + script/core/code-lens.lua | 36 ++++++++++++++++++++++++++++++------ 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 -- cgit v1.2.3