Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# changelog

## Unreleased
<!-- Add all new changes here. They will be moved under a version at release -->
* `New` Omit parameter hints when the argument name matches

## 3.16.1
`2025-12-8`
Expand Down
2 changes: 1 addition & 1 deletion script/core/hint.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ local function paramName(uri, results, start, finish)
and (paramConfig ~= 'Literal' or guide.isLiteral(arg)) then
mark[arg] = true
local param = params[i]
if param and param[1] then
if param and param[1] and param[1] ~= arg[1] then
results[#results+1] = {
text = param[1] .. ':',
offset = arg.start,
Expand Down
1 change: 1 addition & 0 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local function testAll()
test 'diagnostics'
test 'crossfile'
test 'highlight'
test 'inlay_hint'
test 'rename'
test 'signature'
test 'command'
Expand Down
150 changes: 150 additions & 0 deletions test/inlay_hint/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
local core = require 'core.hint'
local files = require 'files'
local catch = require 'catch'
local config = require 'config'
local define = require 'proto.define'

rawset(_G, 'TEST', true)

---@diagnostic disable: await-in-sync
local function TEST(script, expect, opts)
opts = opts or {}
local newScript, catched = catch(script, '!')

files.setText(TESTURI, newScript)
files.compileState(TESTURI)

local results = core(TESTURI, 0, math.huge)
table.sort(results, function (a, b)
if a.offset ~= b.offset then
return a.offset < b.offset
end
return a.text < b.text
end)

if #expect ~= #results then
print('Expect count:', #expect, 'Result count:', #results)
for i, res in ipairs(results) do
print((' %d: text=%s kind=%s where=%s offset=%s'):format(
i,
tostring(res.text),
tostring(res.kind),
tostring(res.where),
tostring(res.offset)
))
end
end

assert(#expect == #results)
for i, res in ipairs(results) do
local info = expect[i]
local pos = catched['!'][info.pos]
assert(pos)
local offset = info.useFinish and pos[2] or pos[1]
assert(res.text == info.text)
assert(res.kind == info.kind)
assert(res.where == info.where)
assert(res.offset == offset)
end

files.remove(TESTURI)
end

config.set(nil, 'Lua.hint.enable', true)

config.set(nil, 'Lua.hint.setType', true)

TEST([[
---@return integer
local function returnsInt()
return 1
end

local <!val!> = returnsInt()
]], {
{
pos = 1,
text = ': integer',
kind = define.InlayHintKind.Type,
where = 'right',
useFinish = true,
},
})

config.set(nil, 'Lua.hint.paramName', 'Literal')

TEST([[
local function foo(first, second)
end

foo(<!1!>, x)
foo(<!1!>, <!2!>)
]], {
{
pos = 1,
text = 'first:',
kind = define.InlayHintKind.Parameter,
where = 'left',
},
{
pos = 2,
text = 'first:',
kind = define.InlayHintKind.Parameter,
where = 'left',
},
{
pos = 3,
text = 'second:',
kind = define.InlayHintKind.Parameter,
where = 'left',
},
})

config.set(nil, 'Lua.hint.paramName', 'All')

TEST([[
local function foo(first, second)
end

local first, second
foo(<!first!>, <!second!>)
]], {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's great that you've added tests for the new functionality! To make the tests more comprehensive, consider adding a test case for when a string literal's value matches a parameter name. The current implementation might incorrectly omit the hint in this scenario, and this test would help verify the correct behavior.

For example, with paramName set to 'All', a call like foo('s') to a function function foo(s) end should still display the s: hint.


config.set(nil, 'Lua.hint.paramName', 'All')

TEST([[
local function foo(s)
end

foo(<!'s'!>)
]], {
    {
        pos   = 1,
        text  = 's:',
        kind  = define.InlayHintKind.Parameter,
        where = 'left',
    },
})


config.set(nil, 'Lua.hint.arrayIndex', 'Enable')

TEST([[
local t = {
<!'first'!>,
<!'second'!>,
<!'third'!>,
<!'fourth'!>,
}
]], {
{
pos = 1,
text = '[1]',
kind = define.InlayHintKind.Other,
where = 'left',
},
{
pos = 2,
text = '[2]',
kind = define.InlayHintKind.Other,
where = 'left',
},
{
pos = 3,
text = '[3]',
kind = define.InlayHintKind.Other,
where = 'left',
},
{
pos = 4,
text = '[4]',
kind = define.InlayHintKind.Other,
where = 'left',
},
})

config.set(nil, 'Lua.hint.enable', false)
Loading