Skip to content
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

Merged
merged 3 commits into from
Jan 24, 2024

Conversation

jonas-w
Copy link
Contributor

@jonas-w jonas-w commented Jan 15, 2024

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 and activeParameter 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 of 0 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.

Copy link
Owner

@fwcd fwcd left a 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

Copy link
Owner

@fwcd fwcd left a 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!

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)
Copy link
Owner

Choose a reason for hiding this comment

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

Style nit

Suggested change
return SignatureHelp(signatures, activeSignature,activeParameter)
return SignatureHelp(signatures, activeSignature, activeParameter)

Copy link
Contributor Author

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 fwcd added the code quality Refactoring, tests etc. label Jan 18, 2024
@jonas-w
Copy link
Contributor Author

jonas-w commented Jan 24, 2024

@fwcd No rush, but just to clarify, the PR should be ready for review again.

@fwcd fwcd merged commit 9ae4ede into fwcd:main Jan 24, 2024
8 checks passed
@fwcd
Copy link
Owner

fwcd commented Jan 24, 2024

Thanks!

@fwcd fwcd added this to the 1.3.10 milestone Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Refactoring, tests etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants