Skip to content

impl Completions: Auto add function call parenthesis #2207#2254

Closed
asukaminato0721 wants to merge 6 commits intofacebook:mainfrom
asukaminato0721:2207
Closed

impl Completions: Auto add function call parenthesis #2207#2254
asukaminato0721 wants to merge 6 commits intofacebook:mainfrom
asukaminato0721:2207

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes part of #2207

Added optional auto‑parentheses for function/method completion items behind python.analysis.completeFunctionParens, with snippet insertion when the client supports it.

Plumbed the setting through LSP config, exposed it in the VS Code settings.

Test Plan

Added an LSP interaction test that asserts snippet behavior.

@meta-cla meta-cla bot added the cla signed label Jan 29, 2026
@asukaminato0721 asukaminato0721 marked this pull request as ready for review January 29, 2026 06:35
Copilot AI review requested due to automatic review settings January 29, 2026 06:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in completion behavior to automatically insert () for function/method completion items (using snippets when supported), exposed via python.analysis.completeFunctionParens and validated with an LSP interaction test.

Changes:

  • Add python.analysis.completeFunctionParens VS Code setting and plumb it through the server’s analysis config.
  • Detect client snippet support and emit snippet-based insertText (name($0)) when available, otherwise plain text (name()).
  • Add an LSP interaction test asserting snippet completion behavior.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pyrefly/lib/test/lsp/lsp_interaction/completion.rs Adds an interaction test to validate snippet insertion when auto-parens is enabled.
pyrefly/lib/state/lsp.rs Implements auto-parens mutation of completion items for functions/methods behind new flags.
pyrefly/lib/lsp/non_wasm/workspace.rs Adds complete_function_parens to the deserialized analysis config.
pyrefly/lib/lsp/non_wasm/server.rs Wires config + client snippet capability into completion request handling.
lsp/package.json Exposes python.analysis.completeFunctionParens in VS Code settings UI.
Cargo.lock Updates lockfile checksum entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +110 to +114
list.items.iter().any(|item| {
item.label == "spam"
&& item.insert_text.as_deref() == Some("spam($0)")
&& item.insert_text_format == Some(InsertTextFormat::SNIPPET)
})
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The new behavior has two branches (snippet vs. non-snippet clients), but this test only asserts the snippet path. Consider adding a companion test (or an additional assertion) with snippetSupport: false to verify the plain-text insertion uses spam() and does not set insertTextFormat to SNIPPET.

Copilot uses AI. Check for mistakes.
Comment on lines 2873 to 2761
pub fn completion_with_incomplete_with_function_parens(
&self,
handle: &Handle,
position: TextSize,
import_format: ImportFormat,
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

completion_with_incomplete_with_function_parens adds multiple boolean parameters, which makes call sites harder to read and easy to misuse. Consider introducing a small options struct (e.g., CompletionOptions { complete_function_parens, supports_snippets, ... }) or an enum/bitflags to keep the API self-documenting as more completion features are added.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good advice. We should probably add something simple here

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@meta-codesync
Copy link

meta-codesync bot commented Feb 2, 2026

@jvansch1 has imported this pull request. If you are a Meta employee, you can view this in D92050705.

fmt
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync bot closed this in cf5807b Feb 4, 2026
@meta-codesync
Copy link

meta-codesync bot commented Feb 4, 2026

@jvansch1 merged this pull request in cf5807b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants