-
-
Notifications
You must be signed in to change notification settings - Fork 390
feat: Omit parameter hints when the argument name matches #3313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
roife
wants to merge
1
commit into
LuaLS:master
Choose a base branch
from
roife:omit-param-inlay-hint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+153
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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!>) | ||
| ]], {}) | ||
|
|
||
|
|
||
| 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) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
paramNameset to'All', a call likefoo('s')to a functionfunction foo(s) endshould still display thes:hint.