-
Notifications
You must be signed in to change notification settings - Fork 219
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
Fix negative active signature/parameter #547
Conversation
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.
Thanks! I've left a note below
server/src/main/kotlin/org/javacs/kt/signaturehelp/SignatureHelp.kt
Outdated
Show resolved
Hide resolved
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.
Just some minor things, otherwise this looks very good, thanks!
server/src/main/kotlin/org/javacs/kt/signaturehelp/SignatureHelp.kt
Outdated
Show resolved
Hide resolved
val (signatures, activeDeclaration, activeParameter) = getSignatureTriplet(file, cursor) ?: return nullResult("No call around ${file.describePosition(cursor)}") | ||
return SignatureHelp(signatures, activeDeclaration, activeParameter) | ||
val (signatures, activeSignature, activeParameter) = getSignatureTriplet(file, cursor) ?: return nullResult("No call around ${file.describePosition(cursor)}") | ||
return SignatureHelp(signatures, activeSignature,activeParameter) |
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.
Style nit
return SignatureHelp(signatures, activeSignature,activeParameter) | |
return SignatureHelp(signatures, activeSignature, activeParameter) |
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.
@fwcd yeah sorry I didn't use any formatter, as this file seems to be unformatted, and If I used the formatter of kotlin-language-server it formatted multiple lines, and I didn't want to make the diff of my changes unneedlessly large.
@fwcd No rush, but just to clarify, the PR should be ready for review again. |
Thanks! |
I'm using the Helix Editor and when I put my cursor inside a string, and request the help signature it throws an error that
-1
is an invalid value for u32. (helix is written in Rust)I took a look at the Language Server Protocol Spec and saw that the
activeSignature
andactiveParameter
are unsigned Integers according to the spec, so the implementation in helix seems to be correct.This means these functions should never return a value below 0.
My change sets the activeParameter/activeSignature to
null
if the value is not greater-equals 0, which omits the activeSignature/activeParameter value in the response, as the spec allows, which helix happily accepts. (Helix sets them to the default value of0
if the values are null or omitted see here and here)(I've never written any Kotlin code, so feel free to recommend other ways to implement this)
Alternatives
With my change it is up to the client to choose the signature and parameter, and as the spec mentions,
[...] In future version of the protocol, this property might become mandatory to better express this.
, this change may not be valid in future versions. The alternative would be to return 0 for both functions, if they don't return a value greater-equals than 0.