Skip to content

Completion for keyword arguments #3397

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
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

monkeyWzr
Copy link
Contributor

Motivation

Closes #2913.

Implementation

  • add trigger characters for completion: (, ,
  • find possible candidates from method's signature and existing arguments
  • handle nesting method calls

Automated Tests

Added.

Manual Tests

Kapture 2025-04-16 at 18 21 51

@monkeyWzr monkeyWzr requested a review from a team as a code owner April 16, 2025 09:23
Copy link

graphite-app bot commented Apr 16, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@monkeyWzr monkeyWzr force-pushed the keyword_arg_completion branch from de0b146 to 011ef16 Compare April 16, 2025 09:26
@vinistock vinistock added enhancement New feature or request server This pull request should be included in the server gem's release notes labels May 23, 2025
Comment on lines +174 to +177
if ["(", ","].include?(@trigger_character)
complete_keyword_arguments(node)
return
end
Copy link
Member

Choose a reason for hiding this comment

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

Instead of checking on call nodes if the trigger character matches, we should start handling the event for Prism::ParametersNode, so that completion is triggered for parameters.

This should be a matter of

  1. Registering the event
  2. Adding the node as a possible target
  3. Creating an on_parameters_node_enter handler
  4. Doing the work to provide keyword completion inside that method

Comment on lines +541 to +547
if @node_context.parent.is_a?(Prism::CallNode) && method_name
call_node = T.cast(@node_context.parent, Prism::CallNode)
candidates = keyword_argument_completion_candidates(call_node, method_name)
candidates.each do |param|
build_keyword_argument_completion_item(param, range)
end
end
Copy link
Member

Choose a reason for hiding this comment

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

You won't need this check after registering for parameter node events.

Comment on lines +662 to +663
type = @type_inferrer.send(:infer_receiver_for_call_node, node, @node_context)
return unless type
Copy link
Member

Choose a reason for hiding this comment

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

Let's not rely on a private API. We can just call @type_inferrer.infer_receiver_type(@node_context) and make any necessary modifications to handle the new scenario in the type inferrer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request server This pull request should be included in the server gem's release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide completion for keyword arguments in method calls
2 participants