Skip to content

Commit 3b5947f

Browse files
authored
Merge branch 'master' into inconsistent-behavior-(missing-fields)
2 parents df9db56 + fcf2952 commit 3b5947f

File tree

13 files changed

+257
-27
lines changed

13 files changed

+257
-27
lines changed

changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
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` Improve the `missing-fields` logic to be able to correctly handle classes defined several times [#22770](https://github.com/LuaLS/lua-language-server/pull/2770)
17-
*
17+
* `FIX` Typos in annotation descriptions
18+
* `NEW` You can now click on "References" in CodeLen to display the reference list
19+
1820
## 3.9.3
1921
`2024-6-11`
2022
* `FIX` Sometimes providing incorrect autocompletion when chaining calls

locale/en-us/script.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
11671167
### Vector Add Metamethod
11681168
```
11691169
---@class Vector
1170-
---@operation add(Vector):Vector
1170+
---@operator add(Vector):Vector
11711171
11721172
vA = Vector.new(1, 2, 3)
11731173
vB = Vector.new(10, 20, 30)
@@ -1178,7 +1178,7 @@ vC = vA + vB
11781178
### Unary Minus
11791179
```
11801180
---@class Passcode
1181-
---@operation unm:integer
1181+
---@operator unm:integer
11821182
11831183
pA = Passcode.new(1234)
11841184
pB = -pA

locale/pt-br/script.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
11671167
### Vector Add Metamethod
11681168
```
11691169
---@class Vector
1170-
---@operation add(Vector):Vector
1170+
---@operator add(Vector):Vector
11711171
11721172
vA = Vector.new(1, 2, 3)
11731173
vB = Vector.new(10, 20, 30)
@@ -1178,7 +1178,7 @@ vC = vA + vB
11781178
### Unary Minus
11791179
```
11801180
---@class Passcode
1181-
---@operation unm:integer
1181+
---@operator unm:integer
11821182
11831183
pA = Passcode.new(1234)
11841184
pB = -pA
@@ -1216,7 +1216,7 @@ setColor(colors.green)
12161216
LUADOC_DESC_SOURCE = -- TODO: need translate!
12171217
[=[
12181218
Provide a reference to some source code which lives in another file. When
1219-
searching for the defintion of an item, its `@source` will be used.
1219+
searching for the definition of an item, its `@source` will be used.
12201220
12211221
## Syntax
12221222
`@source <path>`
@@ -1264,7 +1264,7 @@ end
12641264
LUADOC_DESC_PRIVATE = -- TODO: need translate!
12651265
[=[
12661266
Mark a function as private to a @class. Private functions can be accessed only
1267-
from within their class and are not accessable from child classes.
1267+
from within their class and are not accessible from child classes.
12681268
12691269
## Syntax
12701270
`@private`

locale/zh-cn/script.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
11671167
### Vector Add Metamethod
11681168
```
11691169
---@class Vector
1170-
---@operation add(Vector):Vector
1170+
---@operator add(Vector):Vector
11711171
11721172
vA = Vector.new(1, 2, 3)
11731173
vB = Vector.new(10, 20, 30)
@@ -1178,7 +1178,7 @@ vC = vA + vB
11781178
### Unary Minus
11791179
```
11801180
---@class Passcode
1181-
---@operation unm:integer
1181+
---@operator unm:integer
11821182
11831183
pA = Passcode.new(1234)
11841184
pB = -pA
@@ -1216,7 +1216,7 @@ setColor(colors.green)
12161216
LUADOC_DESC_SOURCE = -- TODO: need translate!
12171217
[=[
12181218
Provide a reference to some source code which lives in another file. When
1219-
searching for the defintion of an item, its `@source` will be used.
1219+
searching for the definition of an item, its `@source` will be used.
12201220
12211221
## Syntax
12221222
`@source <path>`
@@ -1264,7 +1264,7 @@ end
12641264
LUADOC_DESC_PRIVATE = -- TODO: need translate!
12651265
[=[
12661266
Mark a function as private to a @class. Private functions can be accessed only
1267-
from within their class and are not accessable from child classes.
1267+
from within their class and are not accessible from child classes.
12681268
12691269
## Syntax
12701270
`@private`

locale/zh-tw/script.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ Provide type declaration for [operator metamethods](http://lua-users.org/wiki/Me
11611161
### Vector Add Metamethod
11621162
```
11631163
---@class Vector
1164-
---@operation add(Vector):Vector
1164+
---@operator add(Vector):Vector
11651165
11661166
vA = Vector.new(1, 2, 3)
11671167
vB = Vector.new(10, 20, 30)
@@ -1172,7 +1172,7 @@ vC = vA + vB
11721172
### Unary Minus
11731173
```
11741174
---@class Passcode
1175-
---@operation unm:integer
1175+
---@operator unm:integer
11761176
11771177
pA = Passcode.new(1234)
11781178
pB = -pA
@@ -1210,7 +1210,7 @@ setColor(colors.green)
12101210
LUADOC_DESC_SOURCE = -- TODO: need translate!
12111211
[=[
12121212
Provide a reference to some source code which lives in another file. When
1213-
searching for the defintion of an item, its `@source` will be used.
1213+
searching for the definition of an item, its `@source` will be used.
12141214
12151215
## Syntax
12161216
`@source <path>`
@@ -1258,7 +1258,7 @@ end
12581258
LUADOC_DESC_PRIVATE = -- TODO: need translate!
12591259
[=[
12601260
Mark a function as private to a @class. Private functions can be accessed only
1261-
from within their class and are not accessable from child classes.
1261+
from within their class and are not accessible from child classes.
12621262
12631263
## Syntax
12641264
`@private`

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

script/core/diagnostics/unused-function.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local define = require 'proto.define'
55
local lang = require 'language'
66
local await = require 'await'
77
local client = require 'client'
8+
local util = require 'utility'
89

910
local function isToBeClosed(source)
1011
if not source.attrs then
@@ -105,8 +106,11 @@ return function (uri, callback)
105106
turnBlack(source, black, white, links)
106107
end
107108

109+
local tagSupports = client.getAbility('textDocument.completion.completionItem.tagSupport.valueSet')
110+
local supportUnnecessary = tagSupports and util.arrayHas(tagSupports, define.DiagnosticTag.Unnecessary)
111+
108112
for source in pairs(white) do
109-
if client.isVSCode() then
113+
if supportUnnecessary then
110114
callback {
111115
start = source.start,
112116
finish = source.finish,

script/core/fix-indent.lua

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
local files = require 'files'
2+
local guide = require 'parser.guide'
3+
local lookBackward = require 'core.look-backward'
4+
local proto = require 'proto.proto'
5+
6+
---@param state parser.state
7+
local function insertIndentation(state, position, edits)
8+
local text = state.originText or state.lua
9+
local lines = state.originLines or state.lines
10+
local row = guide.rowColOf(position)
11+
if not lines or not text then
12+
return
13+
end
14+
local offset = lines[row]
15+
local indent = text:match('^%s*', offset)
16+
for _, edit in ipairs(edits) do
17+
edit.text = edit.text:gsub('\n', '\n' .. indent)
18+
end
19+
end
20+
21+
---@param state parser.state
22+
local function findForward(state, position, ...)
23+
local lines = state.originLines or state.lines
24+
local offset = guide.positionToOffsetByLines(lines, position)
25+
local firstOffset = state.originText:match('^[ \t]*()', offset + 1)
26+
if not firstOffset then
27+
return nil
28+
end
29+
for _, symbol in ipairs { ... } do
30+
if state.originText:sub(firstOffset, firstOffset + #symbol - 1) == symbol then
31+
return guide.offsetToPositionByLines(lines, firstOffset - 1), symbol
32+
end
33+
end
34+
return nil
35+
end
36+
37+
---@param state parser.state
38+
local function findBackward(state, position, ...)
39+
local text = state.originText or state.lua
40+
local lines = state.originLines or state.lines
41+
if not text or not lines then
42+
return nil
43+
end
44+
local offset = guide.positionToOffsetByLines(lines, position)
45+
local lastOffset = lookBackward.findAnyOffset(text, offset)
46+
if not lastOffset then
47+
return nil
48+
end
49+
for _, symbol in ipairs { ... } do
50+
if text:sub(lastOffset - #symbol + 1, lastOffset) == symbol then
51+
return guide.offsetToPositionByLines(lines, lastOffset)
52+
end
53+
end
54+
return nil
55+
end
56+
57+
---@param state parser.state
58+
---@param change table
59+
---@param result any[]
60+
local function checkSplitOneLine(state, change, result)
61+
if change.text ~= '\r\n'
62+
and change.text ~= '\n' then
63+
return
64+
end
65+
66+
local lines = state.originLines or state.lines
67+
local position = lines[change.range.start.line + 1]
68+
69+
local fPosition, fSymbol = findForward(state, position, 'end', '}')
70+
if not fPosition or not fSymbol then
71+
return
72+
end
73+
local bPosition = findBackward(state, position, 'then', 'do', ')', '{')
74+
if not bPosition then
75+
return
76+
end
77+
local edits = {}
78+
edits[#edits+1] = {
79+
start = bPosition,
80+
finish = position,
81+
text = '\n\t',
82+
}
83+
edits[#edits+1] = {
84+
start = position,
85+
finish = fPosition + 1,
86+
text = '',
87+
}
88+
edits[#edits+1] = {
89+
start = fPosition + 1,
90+
finish = fPosition + 1,
91+
text = '\n' .. fSymbol:sub(1, 1)
92+
}
93+
insertIndentation(state, bPosition, edits)
94+
for _, edit in ipairs(edits) do
95+
result[#result+1] = edit
96+
end
97+
end
98+
99+
---@param state parser.state
100+
local function applyEdits(state, edits)
101+
if #edits == 0 then
102+
return
103+
end
104+
105+
local lines = state.originLines or state.lines
106+
107+
local results = {}
108+
for i, edit in ipairs(edits) do
109+
local startPos = guide.offsetToPositionByLines(lines, edit.start)
110+
local endPos = guide.offsetToPositionByLines(lines, edit.finish)
111+
local startRow, startCol = guide.rowColOf(startPos)
112+
local endRow, endCol = guide.rowColOf(endPos)
113+
results[i] = {
114+
range = {
115+
start = {
116+
line = startRow,
117+
character = startCol,
118+
},
119+
['end'] = {
120+
line = endRow,
121+
character = endCol,
122+
}
123+
},
124+
newText = edit.text,
125+
}
126+
end
127+
128+
proto.request('workspace/applyEdit', {
129+
label = 'Fix Indent',
130+
edit = {
131+
changes = {
132+
[state.uri] = {
133+
{
134+
range = {
135+
start = {
136+
line = 1,
137+
character = 0,
138+
},
139+
['end'] = {
140+
line = 1,
141+
character = 0,
142+
}
143+
},
144+
newText = '\t',
145+
},
146+
}
147+
}
148+
},
149+
})
150+
proto.notify('$/command', {
151+
command = 'cursorMove',
152+
})
153+
end
154+
155+
return function (uri, changes)
156+
do return end
157+
local state = files.compileState(uri)
158+
if not state then
159+
return
160+
end
161+
162+
local edits = {}
163+
for _, change in ipairs(changes) do
164+
if change.range then
165+
checkSplitOneLine(state, change, edits)
166+
end
167+
end
168+
169+
applyEdits(state, edits)
170+
end

0 commit comments

Comments
 (0)