Skip to content

Commit 29693f2

Browse files
authored
Merge branch 'master' into max-fields-count
2 parents c22efbb + e1c38e6 commit 29693f2

File tree

7 files changed

+174
-10
lines changed

7 files changed

+174
-10
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Unreleased
44
<!-- Add all new changes here. They will be moved under a version at release -->
55
* `NEW` Added `completion.maxFieldCount` which lets you increase the amount of fields to analyze before requiring more specific input
6+
* `New` Omit parameter hints when the argument name matches
7+
* `FIX` Fix a typo in `no-unknown` diagnostic message
8+
* `FIX` Autodoc generation so it does not include documentation for builtin Lua language features
69

710
## 3.16.1
811
`2025-12-8`

locale/en-us/script.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ DIAG_COSE_NON_OBJECT =
8989
DIAG_COUNT_DOWN_LOOP =
9090
'Do you mean `{}` ?'
9191
DIAG_UNKNOWN =
92-
'Can not infer type.'
92+
'Cannot infer type.'
9393
DIAG_DEPRECATED =
9494
'Deprecated.'
9595
DIAG_DIFFERENT_REQUIRES =

script/cli/doc/export.lua

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,7 @@ end
274274
---@async
275275
---@return table globals
276276
function export.gatherGlobals()
277-
local all_globals = vm.getAllGlobals()
278-
local globals = {}
279-
for _, g in pairs(all_globals) do
280-
table.insert(globals, g)
281-
end
282-
return globals
277+
return util.valuesOf(vm.getExportableGlobals())
283278
end
284279

285280
---builds a lua table of based on `globals` and their elements

script/core/hint.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ local function paramName(uri, results, start, finish)
145145
and (paramConfig ~= 'Literal' or guide.isLiteral(arg)) then
146146
mark[arg] = true
147147
local param = params[i]
148-
if param and param[1] then
148+
if param and param[1] and param[1] ~= arg[1] then
149149
results[#results+1] = {
150150
text = param[1] .. ':',
151151
offset = arg.start,

script/vm/global.lua

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local globalSubs = util.multiTable(2)
2323
---@field links table<uri, vm.global.link>
2424
---@field setsCache? table<uri, parser.object[]>
2525
---@field cate vm.global.cate
26+
---@field uri string
2627
local mt = {}
2728
mt.__index = mt
2829
mt.type = 'global'
@@ -155,10 +156,11 @@ end
155156

156157
---@param cate vm.global.cate
157158
---@return vm.global
158-
local function createGlobal(name, cate)
159+
local function createGlobal(name, cate, uri)
159160
return setmetatable({
160161
name = name,
161162
cate = cate,
163+
uri = uri,
162164
links = util.multiTable(2, function ()
163165
return {
164166
sets = {},
@@ -444,7 +446,7 @@ function vm.declareGlobal(cate, name, uri)
444446
globalSubs[uri][key] = true
445447
end
446448
if not allGlobals[key] then
447-
allGlobals[key] = createGlobal(name, cate)
449+
allGlobals[key] = createGlobal(name, cate, uri)
448450
end
449451
return allGlobals[key]
450452
end
@@ -510,6 +512,19 @@ function vm.getAllGlobals()
510512
return allGlobals
511513
end
512514

515+
---@return table<string, vm.global>
516+
function vm.getExportableGlobals()
517+
local exportableGlobals = {}
518+
for key, global in pairs(allGlobals) do
519+
--If the source uri for the global matches the global variable METAPATH
520+
--then the global is a builtin Lua language feature and should not be exported
521+
if global.uri and not string.find(global.uri, METAPATH, 1, true) then
522+
exportableGlobals[key] = global
523+
end
524+
end
525+
return exportableGlobals
526+
end
527+
513528
---@param suri uri
514529
---@param cate vm.global.cate
515530
---@return parser.object[]

test.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ local function testAll()
7676
test 'diagnostics'
7777
test 'crossfile'
7878
test 'highlight'
79+
test 'inlay_hint'
7980
test 'rename'
8081
test 'signature'
8182
test 'command'

test/inlay_hint/init.lua

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
local core = require 'core.hint'
2+
local files = require 'files'
3+
local catch = require 'catch'
4+
local config = require 'config'
5+
local define = require 'proto.define'
6+
7+
rawset(_G, 'TEST', true)
8+
9+
---@diagnostic disable: await-in-sync
10+
local function TEST(script, expect, opts)
11+
opts = opts or {}
12+
local newScript, catched = catch(script, '!')
13+
14+
files.setText(TESTURI, newScript)
15+
files.compileState(TESTURI)
16+
17+
local results = core(TESTURI, 0, math.huge)
18+
table.sort(results, function (a, b)
19+
if a.offset ~= b.offset then
20+
return a.offset < b.offset
21+
end
22+
return a.text < b.text
23+
end)
24+
25+
if #expect ~= #results then
26+
print('Expect count:', #expect, 'Result count:', #results)
27+
for i, res in ipairs(results) do
28+
print((' %d: text=%s kind=%s where=%s offset=%s'):format(
29+
i,
30+
tostring(res.text),
31+
tostring(res.kind),
32+
tostring(res.where),
33+
tostring(res.offset)
34+
))
35+
end
36+
end
37+
38+
assert(#expect == #results)
39+
for i, res in ipairs(results) do
40+
local info = expect[i]
41+
local pos = catched['!'][info.pos]
42+
assert(pos)
43+
local offset = info.useFinish and pos[2] or pos[1]
44+
assert(res.text == info.text)
45+
assert(res.kind == info.kind)
46+
assert(res.where == info.where)
47+
assert(res.offset == offset)
48+
end
49+
50+
files.remove(TESTURI)
51+
end
52+
53+
config.set(nil, 'Lua.hint.enable', true)
54+
55+
config.set(nil, 'Lua.hint.setType', true)
56+
57+
TEST([[
58+
---@return integer
59+
local function returnsInt()
60+
return 1
61+
end
62+
63+
local <!val!> = returnsInt()
64+
]], {
65+
{
66+
pos = 1,
67+
text = ': integer',
68+
kind = define.InlayHintKind.Type,
69+
where = 'right',
70+
useFinish = true,
71+
},
72+
})
73+
74+
config.set(nil, 'Lua.hint.paramName', 'Literal')
75+
76+
TEST([[
77+
local function foo(first, second)
78+
end
79+
80+
foo(<!1!>, x)
81+
foo(<!1!>, <!2!>)
82+
]], {
83+
{
84+
pos = 1,
85+
text = 'first:',
86+
kind = define.InlayHintKind.Parameter,
87+
where = 'left',
88+
},
89+
{
90+
pos = 2,
91+
text = 'first:',
92+
kind = define.InlayHintKind.Parameter,
93+
where = 'left',
94+
},
95+
{
96+
pos = 3,
97+
text = 'second:',
98+
kind = define.InlayHintKind.Parameter,
99+
where = 'left',
100+
},
101+
})
102+
103+
config.set(nil, 'Lua.hint.paramName', 'All')
104+
105+
TEST([[
106+
local function foo(first, second)
107+
end
108+
109+
local first, second
110+
foo(<!first!>, <!second!>)
111+
]], {})
112+
113+
114+
config.set(nil, 'Lua.hint.arrayIndex', 'Enable')
115+
116+
TEST([[
117+
local t = {
118+
<!'first'!>,
119+
<!'second'!>,
120+
<!'third'!>,
121+
<!'fourth'!>,
122+
}
123+
]], {
124+
{
125+
pos = 1,
126+
text = '[1]',
127+
kind = define.InlayHintKind.Other,
128+
where = 'left',
129+
},
130+
{
131+
pos = 2,
132+
text = '[2]',
133+
kind = define.InlayHintKind.Other,
134+
where = 'left',
135+
},
136+
{
137+
pos = 3,
138+
text = '[3]',
139+
kind = define.InlayHintKind.Other,
140+
where = 'left',
141+
},
142+
{
143+
pos = 4,
144+
text = '[4]',
145+
kind = define.InlayHintKind.Other,
146+
where = 'left',
147+
},
148+
})
149+
150+
config.set(nil, 'Lua.hint.enable', false)

0 commit comments

Comments
 (0)