Skip to content

Commit 7a93273

Browse files
committed
Fix incorrect positional args hinting
1 parent 4ec848d commit 7a93273

2 files changed

Lines changed: 8 additions & 18 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4-
### Added
5-
6-
### Changed
7-
84
### Fixed
5+
- Hints showing when placing a positional argument after keyword ones
96

107
## [0.1.2] - 2022-07-18
118
### Fixed

src/main/kotlin/space/whitememory/pythoninlayparams/PythonInlayHintsProvider.kt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class PythonInlayHintsProvider : InlayParameterHintsProvider {
4141

4242
// Handle lambda expression calls
4343
if (resolved is PyTargetExpression) {
44+
// TODO: Handle other cases besides lambda expressions
4445
// Use the target to find the lambda expression object, and assign it to get its parameters up ahead
4546
resolved = PsiTreeUtil.getNextSiblingOfType(resolved, PyLambdaExpression::class.java) ?: return inlayInfos
4647
}
@@ -73,15 +74,11 @@ class PythonInlayHintsProvider : InlayParameterHintsProvider {
7374
// If there's no parameters in the object, we use the dataclass attributes instead, if there is any
7475
if (resolvedParameters.isEmpty() && dataclassAttributes.isNotEmpty() && !hasExplicitInit) {
7576
dataclassAttributes.zip(args).forEach { (attr, arg) ->
76-
if (arg is PyStarArgument) {
77-
// It's unpacking, so we don't need to show hits after this
77+
if (arg is PyStarArgument || arg is PyKeywordArgument) {
78+
// It's a keyword argument or unpacking,
79+
// we don't need to show hits after this
7880
return inlayInfos
7981
}
80-
if (arg is PyKeywordArgument) {
81-
// Keyword arguments don't need a hint,
82-
// Keep for proper ordering and to avoid displaying issues
83-
return@forEach
84-
}
8582

8683
if (isHintNameValid(attr, arg)) {
8784
inlayInfos.add(InlayInfo(attr, arg.textOffset))
@@ -92,15 +89,11 @@ class PythonInlayHintsProvider : InlayParameterHintsProvider {
9289

9390
resolvedParameters.zip(args).forEach { (param, arg) ->
9491
val paramName = param.name ?: return@forEach
95-
if (arg is PyStarArgument) {
96-
// It's unpacking, so we don't need to show hits after this
92+
if (arg is PyStarArgument || arg is PyKeywordArgument) {
93+
// It's a keyword argument or unpacking,
94+
// we don't need to show hits after this
9795
return inlayInfos
9896
}
99-
if (arg is PyKeywordArgument) {
100-
// Keyword arguments don't need a hint,
101-
// Keep for proper ordering and to avoid displaying issues
102-
return@forEach
103-
}
10497

10598
if (param is PyNamedParameter && param.isPositionalContainer) {
10699
// This is an *args parameter that takes more than one argument

0 commit comments

Comments
 (0)