Skip to content

Be willing to complete in the face of emptiness #772

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 1 commit into
base: bugfix/nearest-enclosing-node
Choose a base branch
from

Conversation

jennybc
Copy link
Member

@jennybc jennybc commented Apr 10, 2025

Fixes #770

Note that this layers on top of #805 which should be merged first. This PR currently targets that branch instead of main to make this clear.

See the last "move" in #805 (comment) for a concrete illustration of what this PR does. If the client asks for completions in any context where we aren't inside a node (i.e. we're just in the 'Program' node), we should basically send all composite completions, instead of no completions.

I give this PR an A for correct behaviour and a C- for expressiveness. I really don't love that we're adding another special case to a free function named is_identifier_like(). It feels like is_identifier_like() is getting at some notion of "should we provide completions?" and this might be the time to articulate the intention more precisely. I suspect this property of the completion site could also become a peer of parameter_hints_cell and pipe_root_cell, i.e. a feature we compute about the completion context early on and then use where needed.

I would add a test before I merge this, but am holding off until after further discussion.

@jennybc jennybc force-pushed the bugfix/completing-nothing branch from 8790f19 to cc1fb06 Compare May 14, 2025 21:17
@jennybc jennybc marked this pull request as ready for review May 14, 2025 23:03
@jennybc jennybc requested a review from DavisVaughan May 14, 2025 23:03
@jennybc jennybc changed the base branch from main to bugfix/nearest-enclosing-node May 14, 2025 23:06
Comment on lines +204 to +216
// Consider when the user asks for completions with no existing
// text-to-complete, such as at the R prompt in the Console, in an empty R
// file, or on an empty line of a non-empty R file.
//
// Gesture-wise, a Positron user could do this with Ctrl + Space, which
// invokes the command editor.action.triggerSuggest.
//
// The nominal completion node in these cases is just the root or 'Program'
// node of the AST. In this case, we should just provide "all" completions,
// for some reasonable definition of "all".
if x.node_type() == NodeType::Program {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with the idea in general, but I don't think this belongs in is_identifier_like(), because the program node itself is not identifier-like.

I think at the call site it should be is_identifier_like(node) | is_empty_line(node) and is_empty_line() should contain this code.

The name is_empty_line is a WIP, if you have anything better to call this, feel free to use that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is a definitely an improvement on the expressive-ness front. I'll do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In a scenario where ark should provide all completions, it provides none
2 participants