Skip to content

Commit 4133ed4

Browse files
committed
You can now click on "References" in CodeLen to display the reference list
1 parent aae2c78 commit 4133ed4

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* `CHG` Change spacing of parameter inlay hints to match other LSPs, like `rust-analyzer`
1515
* `FIX` Inconsistent type narrow behavior of function call args [#2758](https://github.com/LuaLS/lua-language-server/issues/2758)
1616
* `FIX` Typos in annotation descriptions
17+
* `NEW` You can now click on "References" in CodeLen to display the reference list
1718

1819
## 3.9.3
1920
`2024-6-11`

script/core/code-lens.lua

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local await = require 'await'
44
local conv = require 'proto.converter'
55
local getRef = require 'core.reference'
66
local lang = require 'language'
7+
local client = require 'client'
78

89
---@class parser.state
910
---@field package _codeLens? codeLens
@@ -88,12 +89,35 @@ end
8889
function mt:resolveReference(source)
8990
local refs = getRef(self.uri, source.finish, false)
9091
local count = refs and #refs or 0
91-
local command = conv.command(
92-
lang.script('COMMAND_REFERENCE_COUNT', count),
93-
'',
94-
{}
95-
)
96-
return command
92+
if client.getOption('codeLensViewReferences') then
93+
local locations = {}
94+
for _, ref in ipairs(refs or {}) do
95+
local state = files.getState(ref.uri)
96+
if state then
97+
locations[#locations+1] = conv.location(
98+
ref.uri,
99+
conv.packRange(state, ref.target.start, ref.target.finish)
100+
)
101+
end
102+
end
103+
local command = conv.command(
104+
lang.script('COMMAND_REFERENCE_COUNT', count),
105+
'lua.showReferences',
106+
{
107+
self.uri,
108+
conv.packPosition(self.state, source.start),
109+
locations,
110+
}
111+
)
112+
return command
113+
else
114+
local command = conv.command(
115+
lang.script('COMMAND_REFERENCE_COUNT', count),
116+
'',
117+
{}
118+
)
119+
return command
120+
end
97121
end
98122

99123
---@async

0 commit comments

Comments
 (0)